Created
June 7, 2017 04:14
-
-
Save nopara73/c3971e168074a62a75206a13cb89b377 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