Skip to content

Commit f9d3bd0

Browse files
authored
Initial RBF and DLCs
1 parent eea81c6 commit f9d3bd0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/bitcoin/rbf.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const bitcoin = require('bitcoinjs-lib');
2+
const bip65 = require('bip65');
3+
4+
// DLC setup
5+
const oraclePublicKey = Buffer.from('...', 'hex'); // Oracle's public key
6+
const counterpartiesPublicKeys = [
7+
Buffer.from('...', 'hex'), // Counterparty 1's public key
8+
Buffer.from('...', 'hex') // Counterparty 2's public key
9+
];
10+
const outcomeHash = Buffer.from('...', 'hex'); // Outcome's hash
11+
const fundingTransactionOutput = 'txid:vout'; // Funding transaction's output
12+
13+
// RBF setup
14+
const locktime = bip65.encode({ utc: 0 }); // Use a locktime that allows RBF
15+
16+
// Create the DLC contract
17+
const dlcContract = bitcoin.payments.embed({ data: [outcomeHash] });
18+
19+
// Create the transaction
20+
const tx = new bitcoin.TransactionBuilder();
21+
tx.addInput(fundingTransactionOutput, 0);
22+
tx.addOutput(dlcContract.output, 0); // DLC output
23+
tx.locktime = locktime;
24+
tx.enableRBF(); // Enable RBF
25+
26+
// Sign the transaction
27+
tx.sign(0, oraclePublicKey);
28+
counterpartiesPublicKeys.forEach((publicKey) => {
29+
tx.sign(0, publicKey);
30+
});
31+
32+
// Finalize the transaction
33+
const finalTx = tx.build();
34+
console.log(finalTx.toHex());

0 commit comments

Comments
 (0)