Skip to content

Instantly share code, notes, and snippets.

@nopara73
Last active Jul 12, 2017
Embed
What would you like to do?
Build tOffer and tFulFill
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