Skip to content

Commit e0dc64b

Browse files
committed
feat: .packAssetLock(outputs)
1 parent d0a2f2d commit e0dc64b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

dashplatform.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//@ts-ignore
2+
var DashPlatform = ("object" === typeof module && exports) || {};
3+
(function (window, DashPlatform) {
4+
"use strict";
5+
6+
let DashTx = window.DashTx || require("dashtx");
7+
8+
let Tx = {};
9+
10+
/**
11+
* ex: 01 01 40420f00 00000000 19 76a914cdfca4ae1cf2333056659a2c 8dc656f36d228402
12+
* @param {Object} opts
13+
* @param {Uint8} [opts.version]
14+
* @param {Array<import('dashtx').TxOutput>} opts.creditOutputs
15+
*/
16+
Tx.packAssetLock = function ({ version = 1, creditOutputs }) {
17+
let versionHex = DashTx.utils.toUint32LE(version);
18+
versionHex = versionHex.slice(0, 2);
19+
20+
let lenHex = DashTx.utils.toUint32LE(creditOutputs.length);
21+
lenHex = lenHex.slice(0, 2);
22+
23+
let hexes = [`${versionHex}${lenHex}`];
24+
for (let creditOutput of creditOutputs) {
25+
//@ts-ignore - TODO check type of TxOutput
26+
let script = creditOutput.script;
27+
let satsHexLE = DashTx.utils.toUint64LE(creditOutput.satoshis);
28+
if (!script) {
29+
script = `${satsHexLE}1976a914${creditOutput.pubKeyHash}88ac`;
30+
}
31+
let assetLock = `${script}`;
32+
hexes.push(assetLock);
33+
}
34+
35+
return hexes.join("");
36+
};
37+
38+
//@ts-ignore
39+
DashPlatform.Tx = Tx;
40+
41+
// @ts-ignore
42+
window.DashPlatform = DashPlatform;
43+
})(("object" === typeof window && window) || {}, DashPlatform);
44+
if ("object" === typeof module) {
45+
module.exports = DashPlatform;
46+
}
47+
48+
/** @typedef {Number} Uint32 */
49+
/** @typedef {Number} Uint8 */
50+
/** @typedef {String} Hex */

0 commit comments

Comments
 (0)