Skip to content

Commit aebd10b

Browse files
committed
fix: use nullish coalescing (to allow version and other values to be 0 or "")
1 parent 8dd017c commit aebd10b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

dashtx.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
* @prop {TxHashAndSignInput} hashAndSignInput
8181
*/
8282

83+
// Based on discoveries from
84+
// https://github.com/jojobyte/browser-import-rabbit-hole
85+
8386
/** @type {Tx} */
8487
//@ts-ignore
8588
var DashTx = ("object" === typeof module && exports) || {};
@@ -313,13 +316,13 @@ var DashTx = ("object" === typeof module && exports) || {};
313316

314317
/** @type {TxInfoSigned} */
315318
let txInfoSigned = {
316-
version: txInfo.version || CURRENT_VERSION,
317-
type: txInfo.type || TYPE_VERSION,
319+
version: txInfo.version ?? CURRENT_VERSION,
320+
type: txInfo.type ?? TYPE_VERSION,
318321
/** @type {Array<TxInputSigned>} */
319322
inputs: [],
320323
outputs: txInfo.outputs,
321-
locktime: txInfo.locktime || 0x00,
322-
extraPayload: txInfo.extraPayload || "",
324+
locktime: txInfo.locktime ?? 0x00,
325+
extraPayload: txInfo.extraPayload ?? "",
323326
transaction: "",
324327
};
325328

@@ -578,7 +581,7 @@ var DashTx = ("object" === typeof module && exports) || {};
578581
let txSigned;
579582

580583
for (let n = 0; true; n += 1) {
581-
let changeSats = txDraft.change?.satoshis || 0;
584+
let changeSats = txDraft.change?.satoshis ?? 0;
582585
let hasChange = changeSats > 0;
583586
let canIncreaseFee = txDraft.fullTransfer || hasChange;
584587
if (!canIncreaseFee) {
@@ -1194,7 +1197,7 @@ var DashTx = ("object" === typeof module && exports) || {};
11941197

11951198
Tx.serializeInputs = function (inputs, _opts) {
11961199
let tx = _opts?._tx || [];
1197-
let _sep = _opts?._sep || "";
1200+
let _sep = _opts?._sep ?? "";
11981201

11991202
let nInputs = Tx.utils.toVarInt(inputs.length);
12001203
tx.push(nInputs);
@@ -1276,7 +1279,7 @@ var DashTx = ("object" === typeof module && exports) || {};
12761279

12771280
Tx.serializeOutputs = function (outputs, opts) {
12781281
let tx = opts?._tx || [];
1279-
let _sep = opts?._sep || "";
1282+
let _sep = opts?._sep ?? "";
12801283

12811284
if (!outputs.length) {
12821285
throw new Error(E_NO_OUTPUTS);
@@ -1297,7 +1300,7 @@ var DashTx = ("object" === typeof module && exports) || {};
12971300

12981301
Tx.serializeOutput = function (output, i, _opts) {
12991302
let tx = _opts?._tx || [];
1300-
let _sep = _opts?._sep || "";
1303+
let _sep = _opts?._sep ?? "";
13011304

13021305
if (output.message) {
13031306
if (!output.memo) {
@@ -1310,7 +1313,7 @@ var DashTx = ("object" === typeof module && exports) || {};
13101313
throw new Error(`memo outputs must not have 'address' or 'pubKeyHash'`);
13111314
}
13121315

1313-
let sats = output.satoshis || 0;
1316+
let sats = output.satoshis ?? 0;
13141317
let memoScriptHex = Tx._createMemoScript(output.memo, sats, i);
13151318
let txOut = memoScriptHex.join(_sep);
13161319

0 commit comments

Comments
 (0)