-
Notifications
You must be signed in to change notification settings - Fork 2
added pmt builder considering the witnesses #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
julianlen
wants to merge
32
commits into
master
Choose a base branch
from
witness-pmt-builder
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 a033ac2
index is left as it was, getWtxid is more an utils than part of the i…
julianlen 94d878e
renamings, deleted useless exports, moved shared methods into a utils
julianlen f1dc68c
modified getTransactionWithRetry docjs and added semicolon to functions
julianlen 247f327
fixed getAllTxs jsdoc with transactionsClient
julianlen 2816e5b
deleted unaccurate comment
julianlen 74c65da
renaming targetTxWTxId to targetWtxid
julianlen 8a39ee6
added to fail if there is no rawTx
julianlen ab4f395
fixed README
julianlen 59cb5d0
Improved getWtxid and started using getWtxids to avoid repeating. Als…
julianlen c01ecf4
extracted 429 to a constant
julianlen 8794e52
getTransactionWithRetry will throw an error instead of returning null
julianlen 765c82b
Modified comments and improved the error thrown by getTransactionWith…
julianlen 987ae3f
renamed and reorder parameters in getInformationReadyForRegister file…
julianlen db4801f
Extracted getBlockTxIdsByTransactionHash so pmt-builder and pmt-witne…
julianlen aaf2d0f
both getInformationReadyForRegister shared the same setup, so extract…
julianlen e578cf1
modified tests to have blockIds with witness, without, and mixed
julianlen eabd63c
improved pmt-builder-uitls comment
julianlen bcbec72
improved assertion method name assertGetWtxidsResult
julianlen 49dbf22
getInformationReadyForRegisterBtcTransaction returns only one pmt dep…
julianlen 9eda8a8
tiny renaming in getInformationReadyForRegisterBtcTransaction
julianlen 26f6444
created a getBlockWtxidsWithTargetWtxidByTransactionHash to avoid get…
julianlen 7882627
avoid to.be.an(array)
julianlen deba852
renamed tests and variables
julianlen 4e73115
if hasWitness it should call getWtxids
julianlen ff9b8c7
unify naming to expectedWtxid in testing
julianlen de4949e
avoid assigning and then returning
julianlen 3f61b5a
renamed getWtxids to fetchBlockWtxidsWithTargetWtxid
julianlen 158814b
instead of testing fetchBlockWtxidsWithTargetWtxid we are testing bui…
julianlen e37266d
renamed blockTxIds with blockTxids
julianlen 88dacbf
Added 4 test cases real txs and blocks with and without witness for m…
julianlen 6e24a04
Deleted the sleep in fetchBlockWtxidsWithTargetWtxid since any error …
julianlen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| const bitcoin = require('bitcoinjs-lib'); | ||
julia-zack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const getWtxid = async (rawTx) => { | ||
| const tx = bitcoin.Transaction.fromHex(rawTx); | ||
| const wtxid = tx.getHash(true).reverse().toString('hex'); | ||
| return wtxid; | ||
| } | ||
julianlen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
julianlen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| module.exports = { getWtxid }; | ||
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
| 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); | ||
| } | ||
julianlen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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); | ||
| } | ||
| })(); | ||
julianlen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.