Skip to content

Commit e873d51

Browse files
committed
ref!: make TxUtils.toUint32LE(n) public
1 parent d35a1e4 commit e873d51

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

dashtx.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* @prop {TxHexToBytes} hexToBytes
6363
* @prop {TxBytesToHex} bytesToHex
6464
* @prop {TxStringToHex} strToHex
65+
* @prop {TxToUint32LE} toUint32LE
6566
*/
6667

6768
/**
@@ -1153,7 +1154,7 @@ var DashTx = ("object" === typeof module && exports) || {};
11531154
void Tx.serializeInputs(inputs, { _tx: tx, _sep: _sep });
11541155
void Tx.serializeOutputs(outputs, { _tx: tx, _sep: _sep });
11551156

1156-
let locktimeHex = TxUtils._toUint32LE(locktime);
1157+
let locktimeHex = TxUtils.toUint32LE(locktime);
11571158
tx.push(locktimeHex);
11581159

11591160
if (extraPayload) {
@@ -1165,7 +1166,7 @@ var DashTx = ("object" === typeof module && exports) || {};
11651166
let txHex = tx.join(_sep);
11661167

11671168
if (sigHashType) {
1168-
let sigHashTypeHex = TxUtils._toUint32LE(sigHashType);
1169+
let sigHashTypeHex = TxUtils.toUint32LE(sigHashType);
11691170
txHex = `${txHex}${sigHashTypeHex}`;
11701171
}
11711172

@@ -1215,7 +1216,7 @@ var DashTx = ("object" === typeof module && exports) || {};
12151216
`expected utxo property 'input[${i}]outputIndex' to be an integer representing this input's previous output index`,
12161217
);
12171218
}
1218-
let reverseVout = TxUtils._toUint32LE(voutIndex);
1219+
let reverseVout = TxUtils.toUint32LE(voutIndex);
12191220
tx.push(reverseVout);
12201221

12211222
//@ts-ignore - enum types not handled properly here
@@ -1817,12 +1818,12 @@ var DashTx = ("object" === typeof module && exports) || {};
18171818

18181819
//@ts-ignore
18191820
if (n <= MAX_U16) {
1820-
return "fd" + TxUtils._toUint32LE(n).slice(0, 4);
1821+
return "fd" + TxUtils.toUint32LE(n).slice(0, 4);
18211822
}
18221823

18231824
//@ts-ignore
18241825
if (n <= MAX_U32) {
1825-
return "fe" + TxUtils._toUint32LE(n);
1826+
return "fe" + TxUtils.toUint32LE(n);
18261827
}
18271828

18281829
//@ts-ignore
@@ -1850,7 +1851,7 @@ var DashTx = ("object" === typeof module && exports) || {};
18501851
* which is true in practice, and much simpler.
18511852
* @param {BigInt|Number} n - 32-bit positive int to encode
18521853
*/
1853-
TxUtils._toUint32LE = function (n) {
1854+
TxUtils.toUint32LE = function (n) {
18541855
// make sure n is uint32/int53, not int32
18551856
//n = n >>> 0;
18561857

@@ -1860,14 +1861,21 @@ var DashTx = ("object" === typeof module && exports) || {};
18601861
let hexLE = Tx.utils.reverseHex(hex);
18611862
return hexLE;
18621863
};
1864+
//@ts-ignore
1865+
TxUtils._toUint32LE = function (n) {
1866+
console.warn(
1867+
"warn: use public TxUtils.toUint32LE() instead of internal TxUtils._toUint32LE()",
1868+
);
1869+
return TxUtils.toUint32LE(n);
1870+
};
18631871

18641872
/**
18651873
* Just assumes that all target CPUs are Little-Endian,
18661874
* which is true in practice, and much simpler.
18671875
* @param {BigInt|Number} n - 16-bit positive int to encode
18681876
*/
18691877
TxUtils._toUint16LE = function (n) {
1870-
let hexLE = TxUtils._toUint32LE(n);
1878+
let hexLE = TxUtils.toUint32LE(n);
18711879
// ex: 03000800 => 0300
18721880
hexLE = hexLE.slice(0, 4);
18731881
return hexLE;
@@ -2446,3 +2454,9 @@ if ("object" === typeof module) {
24462454
* @param {String} utf8
24472455
* @returns {String} - encoded bytes as hex
24482456
*/
2457+
2458+
/**
2459+
* @callback TxToUint32LE
2460+
* @param {Uint32} n
2461+
* @returns {Hex}
2462+
*/

0 commit comments

Comments
 (0)