-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetInformationReadyForRegisterBtcTransaction.js
More file actions
59 lines (43 loc) · 1.99 KB
/
getInformationReadyForRegisterBtcTransaction.js
File metadata and controls
59 lines (43 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const mempoolJS = require("@mempool/mempool.js");
const pmtBuilder = require("../index");
const { getWtxid } = require("./pmt-builder-utils");
const getInformationReadyForRegisterBtcTransaction = async (transactionHash, network) => {
const { bitcoin: { blocks, transactions } } = mempoolJS({
hostname: 'mempool.space',
network // 'testnet' | 'mainnet'
});
const transaction = await transactions.getTx({ txid: transactionHash });
const blockHash = transaction.status.block_hash;
const blockHeight = transaction.status.block_height;
const blockTxids = await blocks.getBlockTxids({ hash: blockHash });
const rawBtcTransaction = await transactions.getTxHex({ txid: transactionHash });
const blockTxWids = [];
for (const txid of blockTxids) {
const rawTx = await transactions.getTxHex({ txid });
const wTxId = await getWtxid(rawTx);
blockTxWids.push(wTxId);
}
const resultPmt = pmtBuilder.buildPMT(blockTxids, transactionHash);
const pmt = resultPmt.hex;
const targetTxWTxId = await getWtxid(rawBtcTransaction);
const resultPmtConsideringWitness = pmtBuilder.buildPMT(blockTxWids, targetTxWTxId);
const pmtConsideringWitness = resultPmtConsideringWitness.hex;
const informationReadyForRegisterBtcTransaction = {
tx: `0x${rawBtcTransaction}`,
height: blockHeight,
pmt: `0x${pmt}`,
pmtConsideringWitness: `0x${pmtConsideringWitness}`,
};
return informationReadyForRegisterBtcTransaction;
};
(async () => {
try {
const network = process.argv[2];
const transactionHash = process.argv[3];
const informationReadyForRegisterBtcTransaction = await getInformationReadyForRegisterBtcTransaction(transactionHash, network);
console.log('Transaction Information ready for registerBtcTransaction: ', informationReadyForRegisterBtcTransaction);
} catch (e) {
console.log(e);
}
})();
module.exports = { getInformationReadyForRegisterBtcTransaction };