Last active
July 12, 2017 06:24
-
-
Save nopara73/dddff71f05f4930e80290fe505c0969a to your computer and use it in GitHub Desktop.
Build tOffer and tFulFill
This file contains hidden or 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
ExtKey _fundingExtKey = _seed.ExtKey.Derive(0, hardened: false); | |
BitcoinAddress fundingAddress = _fundingExtKey.ScriptPubKey.GetDestinationAddress(_network); // mkvRuHAv3qek4mP3ipjqFnaFXj4d2kKit3 | |
WriteLine($"{nameof(fundingAddress)}: {fundingAddress}"); | |
uint256 txIdToSpend = (await _qBitClient.GetBalance(fundingAddress, unspentOnly: false).ConfigureAwait(false)).Operations.First().TransactionId; | |
ctsToken.ThrowIfCancellationRequested(); | |
Transaction txToSpend = (await _qBitClient.GetTransaction(txIdToSpend).ConfigureAwait(false)).Transaction; | |
ctsToken.ThrowIfCancellationRequested(); | |
// BUILD OFFER TRANSACTION | |
ExtKey tOfferDestinationExtKey = _seed.ExtKey.Derive(1, false); | |
BitcoinAddress tOfferDestinationAddress = tOfferDestinationExtKey.ScriptPubKey.GetDestinationAddress(_network); // mk1soVb7Se1t99v7APGqiXofr2pKVS7hN5 | |
WriteLine($"{nameof(tOfferDestinationAddress)}: {tOfferDestinationAddress}"); | |
var fee = new Money(0.001m, MoneyUnit.BTC); | |
var builder = new TransactionBuilder(); | |
Transaction tOffer = builder | |
.AddCoins(txToSpend) | |
.AddKeys(_fundingExtKey) | |
.SendFees(fee) | |
.Send(tOfferDestinationAddress, txToSpend.Outputs.First().Value - fee) | |
.BuildTransaction(sign: true); | |
TransactionPolicyError[] errors = builder.Check(tOffer); | |
ReportIfErrors(txName: nameof(tOffer), errors: errors); | |
if (errors.Count() == 0) ReportTransaction(txName: nameof(tOffer), transaction: tOffer); | |
// BUILD FULFILL TRANSACTION | |
ExtKey tFulfillDestinationExtKey = _seed.ExtKey.Derive(2, false); | |
BitcoinAddress tFulfillDestinationAddress = tOfferDestinationExtKey.ScriptPubKey.GetDestinationAddress(_network); // mk1soVb7Se1t99v7APGqiXofr2pKVS7hN5 | |
WriteLine($"{nameof(tFulfillDestinationAddress)}: {tFulfillDestinationAddress}"); | |
builder = new TransactionBuilder(); | |
Transaction tFulfill = builder | |
.AddCoins(tOffer) | |
.AddKeys(tOfferDestinationExtKey) | |
.SendFees(fee) | |
.Send(tFulfillDestinationAddress, tOffer.Outputs.First().Value - fee) | |
.BuildTransaction(sign: true); | |
errors = builder.Check(tFulfill); | |
ReportIfErrors(txName: nameof(tFulfill), errors: errors); | |
if (errors.Count() == 0) ReportTransaction(txName: nameof(tFulfill), transaction: tFulfill); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment