Skip to content

Commit

Permalink
fix: accept txid (canonical) or txId (deprecated, from insight)
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Apr 20, 2024
1 parent d7a4ee0 commit d71175e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dashtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,13 @@ var DashTx = ("object" === typeof module && exports) || {};
* - ASC `outputIndex` (a.k.a. `output_index`, `vout`)
*/
Tx.sortInputs = function (a, b) {
let aTxid = a.txid || a.txId;
let bTxid = b.txid || b.txId;
// Ascending Lexicographical on TxId (prev-hash) in-memory (not wire) byte order
if (a.txId > b.txId) {
if (aTxid > bTxid) {
return 1;
}
if (a.txId < b.txId) {
if (aTxid < bTxid) {
return -1;
}

Expand Down Expand Up @@ -986,7 +988,8 @@ var DashTx = ("object" === typeof module && exports) || {};

/** @type TxInputSigned */
let txInputSigned = {
txId: txInput.txId,
txId: txInput.txId || txInput.txid,
txid: txInput.txId || txInput.txid,
outputIndex: txInput.outputIndex,
signature: sigHex,
publicKey: pubKeyHex,
Expand Down Expand Up @@ -1039,7 +1042,8 @@ var DashTx = ("object" === typeof module && exports) || {};
txInfoHashable.inputs = txInfo.inputs.map(function (input, i) {
if (inputIndex !== i) {
return {
txId: input.txId,
txId: input.txId || input.txid,
txid: input.txId || input.txid,
outputIndex: input.outputIndex,
};
}
Expand All @@ -1054,7 +1058,8 @@ var DashTx = ("object" === typeof module && exports) || {};
lockScript = `${PKH_SCRIPT_SIZE}${OP_DUP}${OP_HASH160}${PKH_SIZE}${input.pubKeyHash}${OP_EQUALVERIFY}${OP_CHECKSIG}`;
}
return {
txId: input.txId,
txId: input.txId || input.txid,
txid: input.txId || input.txid,
outputIndex: input.outputIndex,
pubKeyHash: input.pubKeyHash,
sigHashType: input.sigHashType,
Expand Down Expand Up @@ -1122,7 +1127,7 @@ var DashTx = ("object" === typeof module && exports) || {};
for (let input of inputs) {
let inputHex = [];

let txId = input.txId;
let txId = input.txId || input.txid;
if (!txId) {
throw new Error("missing required utxo property 'txId'");
}
Expand Down

0 comments on commit d71175e

Please sign in to comment.