Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
252f877
added pmt builder considering the witnesses
julianlen Mar 30, 2026
a033ac2
index is left as it was, getWtxid is more an utils than part of the i…
julianlen Mar 30, 2026
94d878e
renamings, deleted useless exports, moved shared methods into a utils
julianlen Apr 1, 2026
f1dc68c
modified getTransactionWithRetry docjs and added semicolon to functions
julianlen Apr 1, 2026
247f327
fixed getAllTxs jsdoc with transactionsClient
julianlen Apr 1, 2026
2816e5b
deleted unaccurate comment
julianlen Apr 1, 2026
74c65da
renaming targetTxWTxId to targetWtxid
julianlen Apr 1, 2026
8a39ee6
added to fail if there is no rawTx
julianlen Apr 1, 2026
ab4f395
fixed README
julianlen Apr 6, 2026
59cb5d0
Improved getWtxid and started using getWtxids to avoid repeating. Als…
julianlen Apr 6, 2026
c01ecf4
extracted 429 to a constant
julianlen Apr 6, 2026
8794e52
getTransactionWithRetry will throw an error instead of returning null
julianlen Apr 7, 2026
765c82b
Modified comments and improved the error thrown by getTransactionWith…
julianlen Apr 7, 2026
987ae3f
renamed and reorder parameters in getInformationReadyForRegister file…
julianlen Apr 7, 2026
db4801f
Extracted getBlockTxIdsByTransactionHash so pmt-builder and pmt-witne…
julianlen Apr 7, 2026
aaf2d0f
both getInformationReadyForRegister shared the same setup, so extract…
julianlen Apr 7, 2026
e578cf1
modified tests to have blockIds with witness, without, and mixed
julianlen Apr 7, 2026
eabd63c
improved pmt-builder-uitls comment
julianlen Apr 8, 2026
bcbec72
improved assertion method name assertGetWtxidsResult
julianlen Apr 8, 2026
49dbf22
getInformationReadyForRegisterBtcTransaction returns only one pmt dep…
julianlen Apr 8, 2026
9eda8a8
tiny renaming in getInformationReadyForRegisterBtcTransaction
julianlen Apr 8, 2026
26f6444
created a getBlockWtxidsWithTargetWtxidByTransactionHash to avoid get…
julianlen Apr 8, 2026
7882627
avoid to.be.an(array)
julianlen Apr 8, 2026
deba852
renamed tests and variables
julianlen Apr 8, 2026
4e73115
if hasWitness it should call getWtxids
julianlen Apr 8, 2026
ff9b8c7
unify naming to expectedWtxid in testing
julianlen Apr 8, 2026
de4949e
avoid assigning and then returning
julianlen Apr 8, 2026
3f61b5a
renamed getWtxids to fetchBlockWtxidsWithTargetWtxid
julianlen Apr 8, 2026
158814b
instead of testing fetchBlockWtxidsWithTargetWtxid we are testing bui…
julianlen Apr 8, 2026
e37266d
renamed blockTxIds with blockTxids
julianlen Apr 8, 2026
88dacbf
Added 4 test cases real txs and blocks with and without witness for m…
julianlen Apr 13, 2026
6e24a04
Deleted the sleep in fetchBlockWtxidsWithTargetWtxid since any error …
julianlen Apr 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let expect = require('chai').expect;
let pmtBuilder = require('../index');
const expect = require('chai').expect;
const pmtBuilder = require('../index');
const txs3000 = require('./resources/3000-txs');
const { getWtxid } = require('../tool/pmt-builder-utils');

describe('PMT Builder', () => {
it('should create a valid PMT, block with a single transaction', () => {
Expand Down Expand Up @@ -109,3 +110,12 @@ describe('PMT Builder', () => {
expect(() => pmtBuilder.buildPMT(blockTransactions, randomHash)).to.throw('Filtered hash provided is not part of the leaves');
});
});

describe('getWtxid', () => {
it('should return the correct wtxid for a given raw transaction', async () => {
const expectedWtxid = "b17de7391562cf25c50a37a6e48a3ff232fcacdea734fd5160bb44292bb620e6";
const rawTx = "02000000000101be2994b2fd4d7e8b48652b9618b0f6a62321121b15fe6b5612cdb314d9c770000200000023220020f8e08a83ad7e3ce13df880cdea97aba6d145b6244ead9f8512b159ebea15be55ffffffff0278990700000000001976a9142aa073f0e7bfcbab463670364ef08fa469337f1088ac604ff3020000000017a9147214a88d8e15f5a09050bff1d1a85f19d6e3b8208705004830450221008fc13ebe097363f278ab1d20adaccc92350de298141433c69de782692ac3794d02201ec64821f5ceeaa7ea8b792284f92a4a4ee324216853dfa99c28195425fe53c3014830450221008432682c262647f7c6cf0d39c1b416d48d4876d87337445bbc094a9d9fc27c110220525a6ef39a1295cf18e96cfe9b3211fc965d55068698971bc196acf3eae162cf0100db6452210379d78dcae0be90715a088413c588da6a9381aae42e504f6e05c7b5204ed5bf3a2103d9d48cdc0fdf039d08371c64b1e86e1715e9898d4680595f1d4e3398dbdd9e9e2103df89bd3d49c1ebdef2e9b4e77c84e048dbbcf7c41735b073a68fdcf5d086bd2853ae670350cd00b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f53ae6800000000";
const wTxId = await getWtxid(rawTx);
expect(wTxId).to.be.eq(expectedWtxid);
});
});
17 changes: 15 additions & 2 deletions tool/getInformationReadyForRegisterBtcTransaction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const mempoolJS = require("@mempool/mempool.js");
const pmtBuilder = require("../index");
const { getWtxid } = require("./pmt-builder-utils");

const getInformationReadyForRegisterBtcTransaction = async (transactionHash, network) => {

Expand All @@ -15,18 +16,29 @@ const getInformationReadyForRegisterBtcTransaction = async (transactionHash, net
const blockTxids = await blocks.getBlockTxids({ hash: blockHash });
const rawBtcTransaction = await transactions.getTxHex({ txid: transactionHash });

const resultPmt = pmtBuilder.buildPMT(blockTxids, 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 () => {
Expand All @@ -44,3 +56,4 @@ const getInformationReadyForRegisterBtcTransaction = async (transactionHash, net
}
})();

module.exports = { getInformationReadyForRegisterBtcTransaction };
9 changes: 9 additions & 0 deletions tool/pmt-builder-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const bitcoin = require('bitcoinjs-lib');

const getWtxid = async (rawTx) => {
const tx = bitcoin.Transaction.fromHex(rawTx);
const wtxid = tx.getHash(true).reverse().toString('hex');
return wtxid;
}

module.exports = { getWtxid };
42 changes: 42 additions & 0 deletions tool/pmt-witness-builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const mempoolJS = require("@mempool/mempool.js");
const pmtBuilder = require("../index");
const { getWtxid } = require("./pmt-builder-utils");

const getPmtInformationWithWitness = async (network, txHash) => {
const { bitcoin: { blocks, transactions } } = mempoolJS({
hostname: 'mempool.space',
network // 'testnet' | 'mainnet'
});

const transaction = await transactions.getTx({ txid: txHash });

const blockHash = transaction.status.block_hash;
const blockTxIds = await blocks.getBlockTxids({ hash: blockHash });

const blockWtxids = [];
for (const txid of blockTxIds) {
const rawTx = await transactions.getTxHex({ txid });
const wtxid = await getWtxid(rawTx);
blockWtxids.push(wtxid);
}

const rawTx = await transactions.getTxHex({ txid: txHash });
const targetTxWTxId = await getWtxid(rawTx);
const resultPmt = pmtBuilder.buildPMT(blockWtxids, targetTxWTxId);

return resultPmt;
};

(async () => {
try {
const network = process.argv[2];
const txHash = process.argv[3];

const pmtInformation = await getPmtInformationWithWitness(network, txHash);

console.log('PMT information considering wtxid: ', pmtInformation);

} catch (e) {
console.log(e);
}
})();
Loading