Skip to content

Instantly share code, notes, and snippets.

@nopara73
Created June 7, 2017 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nopara73/8b94261b91c1781203710b10a6dd1516 to your computer and use it in GitHub Desktop.
Save nopara73/8b94261b91c1781203710b10a6dd1516 to your computer and use it in GitHub Desktop.
BuildProofOfTumbleBitConceptTransactions
private static void BuildProofOfTumbleBitConceptTransactions()
{
uint256 txIdToSpend = _qBitClient.GetBalance(_fundingAddress, unspentOnly: false).Result.Operations.First().TransactionId;
Transaction txToSpend = _qBitClient.GetTransaction(txIdToSpend).Result.Transaction;
var tOfferExtKey = _seed.ExtKey.Derive(1, false);
var tOfferDestination = tOfferExtKey.ScriptPubKey.GetDestinationAddress(_network); // mk1soVb7Se1t99v7APGqiXofr2pKVS7hN5
var tFulfillExtKey = _seed.ExtKey.Derive(2, false);
var tFulfillDestination = tFulfillExtKey.ScriptPubKey.GetDestinationAddress(_network); // n4mey3skuXQna149vUaanuAPyEDiunsryT
var fee = new Money(0.001m, MoneyUnit.BTC);
var builder = new TransactionBuilder();
var tOffer = builder
.AddCoins(txToSpend)
.AddKeys(_fundingExtKey)
.SendFees(fee)
.Send(tOfferDestination, txToSpend.Outputs.First().Value - fee)
.BuildTransaction(sign: true);
var errors = builder.Check(tOffer);
if (errors.Count() != 0)
{
ReportErrors(txName: nameof(tOffer), errors: errors);
}
else
{
ReportTransaction(txName: nameof(tOffer), transaction: tOffer);
}
builder = new TransactionBuilder();
var tFulfill = builder
.AddCoins(tOffer)
.AddKeys(tOfferExtKey)
.SendFees(fee)
.Send(tFulfillDestination, tOffer.Outputs.First().Value - fee)
.BuildTransaction(sign: true);
errors = builder.Check(tFulfill);
if (errors.Count() != 0)
{
ReportErrors(txName: nameof(tFulfill), errors: errors);
}
else
{
ReportTransaction(txName: nameof(tFulfill), transaction: tOffer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment