Skip to content

Commit 1c2ac1d

Browse files
committed
fix!: allow empty memos (NULL op returns)
1 parent 95fb79a commit 1c2ac1d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

dashtx.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ var DashTx = ("object" === typeof module && exports) || {};
869869

870870
// memo vs non-memo is settled by 'satoshis' being 0
871871
// (otherwise there's a bug)
872-
if (a.memo) {
873-
if (!b.memo) {
872+
if (typeof a.memo === "string") {
873+
if (typeof b.memo !== "string") {
874874
throw new Error(`'satoshis' must be above 0, except for memos`);
875875
}
876876
if (a.memo < b.memo) {
@@ -1268,7 +1268,7 @@ var DashTx = ("object" === typeof module && exports) || {};
12681268
output.memo = TxUtils.strToHex(output.message);
12691269
}
12701270
}
1271-
if (output.memo) {
1271+
if (typeof output.memo === "string") {
12721272
let invalid = output.address || output.pubKeyHash;
12731273
if (invalid) {
12741274
throw new Error(`memo outputs must not have 'address' or 'pubKeyHash'`);
@@ -1306,7 +1306,7 @@ var DashTx = ("object" === typeof module && exports) || {};
13061306
Tx.createDonationOutput = function (opts) {
13071307
let satoshis = 0;
13081308
let message = opts?.message;
1309-
if (!message) {
1309+
if (typeof message !== "string") {
13101310
let gifts = ["💸", "🎁", "🧧"];
13111311
let indexIsh = Math.random() * 3;
13121312
let index = Math.floor(indexIsh);
@@ -1606,8 +1606,10 @@ var DashTx = ("object" === typeof module && exports) || {};
16061606
output.scriptTypeHex = output.script.slice(0, 2);
16071607
output.scriptType = parseInt(output.scriptTypeHex, 16);
16081608
output.pubKeyHash = "";
1609-
output.memo = "";
1610-
output.message = "";
1609+
/**@type {String?}*/
1610+
output.memo = null;
1611+
/**@type {String?}*/
1612+
output.message = null;
16111613
if (output.scriptTypeHex === OP_RETURN) {
16121614
output.memo = output.script.slice(4, 2 * output.lockScriptSize);
16131615
output.message = "";
@@ -2052,8 +2054,8 @@ if ("object" === typeof module) {
20522054

20532055
/**
20542056
* @typedef TxOutput
2055-
* @prop {String} [memo] - hex bytes of a memo (incompatible with pubKeyHash / address)
2056-
* @prop {String} [message] - memo, but as a UTF-8 string
2057+
* @prop {String?} [memo] - hex bytes of a memo (incompatible with pubKeyHash / address)
2058+
* @prop {String?} [message] - memo, but as a UTF-8 string
20572059
* @prop {String} [address] - payAddr as Base58Check (human-friendly)
20582060
* @prop {String} [pubKeyHash] - payAddr's raw hex value (decoded, not Base58Check)
20592061
* @prop {Uint53} satoshis - the number of smallest units of the currency
@@ -2063,7 +2065,7 @@ if ("object" === typeof module) {
20632065
* @typedef TxOutputSortable
20642066
* @prop {Uint53} satoshis
20652067
* @prop {String} [script] - hex bytes in wire order
2066-
* @prop {String} [memo] - 0x6a, hex bytes
2068+
* @prop {String?} [memo] - 0x6a, hex bytes
20672069
* @prop {String} [pubKeyHash] - 0x76, 0xa9, hex bytes
20682070
* @prop {String} [address] - 0x76, 0xa9, base58check bytes
20692071
*/
@@ -2105,7 +2107,7 @@ if ("object" === typeof module) {
21052107
* Create a donation output with a nice message.
21062108
* @callback TxCreateDonationOutput
21072109
* @param {Object} [opts]
2108-
* @param {String} [opts.message] - UTF-8 Memo String
2110+
* @param {String?} [opts.message] - UTF-8 Memo String
21092111
*/
21102112

21112113
/**

0 commit comments

Comments
 (0)