-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
decoderawtransaction() possible? #1606
Comments
This is the example output for
|
Thank you |
This is most of the info. I do not guarantee that this will be 100% the same as bitcoind in every case. Bugs ahoy. const bitcoinjs = require('bitcoinjs-lib')
function decoderawtransaction(hex) {
const tx = bitcoinjs.Transaction.fromHex(hex)
return {
txid: tx.getId(),
hash: tx.getHash(true).toString('hex'),
size: tx.byteLength(),
vsize: tx.virtualSize(),
weight: tx.weight(),
version: tx.version,
locktime: tx.locktime,
vin: tx.ins.map(input => ({
txid: Buffer.from(input.hash).reverse().toString('hex'),
vout: input.index,
scriptSig: {
asm: bitcoinjs.script.toASM(input.script),
hex: input.script.toString('hex'),
},
txinwitness: input.witness.map(b => b.toString('hex')),
sequence: input.sequence,
})),
vout: tx.outs.map((output, i) => ({
value: output.value,
n: i,
scriptPubKey: {
asm: bitcoinjs.script.toASM(output.script),
hex: output.script.toString('hex'),
},
})),
}
} |
const bitcoinjs = require('bitcoinjs-lib')
function decoderawtransaction(serialized) {
const tx = bitcoinjs.Transaction.fromHex(serialized);
return {
txid: tx.getId(),
hash: tx.getHash(true).reverse().toString('hex'), // should reverse the hash
size: tx.byteLength(),
vsize: tx.virtualSize(),
weight: tx.weight(),
version: tx.version,
locktime: tx.locktime,
vin: tx.ins.map((input) => ({
txid: Buffer.from(input.hash).reverse().toString('hex'),
vout: input.index,
scriptSig: {
asm: bitcoinjs.script.toASM(input.script),
hex: input.script.toString('hex'),
},
txinwitness: input.witness.map((b) => b.toString('hex')),
sequence: input.sequence,
})),
vout: tx.outs.map((output, i) => ({
value: output.value,
n: i,
scriptPubKey: {
asm: bitcoinjs.script.toASM(output.script),
hex: output.script.toString('hex')
},
})),
};
} |
This issue was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a function available that is equivalent to the bitcoin-cli decoderawtransaction() function?
I am trying to decode raw transaction data.
I have tried using the code below to decode transactions but parts of the transaction are still in the buffer format.
The text was updated successfully, but these errors were encountered: