Created
June 7, 2017 03:19
-
-
Save nopara73/8b94261b91c1781203710b10a6dd1516 to your computer and use it in GitHub Desktop.
BuildProofOfTumbleBitConceptTransactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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