Merge pull request #1433 from bitcoinjs/addNamePayments

Add name attribute to Payments
This commit is contained in:
Jonathan Underwood 2019-07-19 14:30:17 +09:00 committed by GitHub
commit 19a126c205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 105 additions and 8 deletions

View file

@ -24,7 +24,7 @@ function p2data(a, opts) {
a,
);
const network = a.network || networks_1.bitcoin;
const o = { network };
const o = { name: 'embed', network };
lazy.prop(o, 'output', () => {
if (!a.data) return;
return bscript.compile([OPS.OP_RETURN].concat(a.data));

View file

@ -93,6 +93,10 @@ function p2ms(a, opts) {
if (!o.input) return;
return [];
});
lazy.prop(o, 'name', () => {
if (!o.m || !o.n) return;
return `p2ms(${o.m} of ${o.n})`;
});
// extended validation
if (opts.validate) {
if (a.output) {

View file

@ -26,7 +26,7 @@ function p2pk(a, opts) {
return bscript.decompile(a.input);
});
const network = a.network || networks_1.bitcoin;
const o = { network };
const o = { name: 'p2pk', network };
lazy.prop(o, 'output', () => {
if (!a.pubkey) return;
return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]);

View file

@ -36,7 +36,7 @@ function p2pkh(a, opts) {
return bscript.decompile(a.input);
});
const network = a.network || networks_1.bitcoin;
const o = { network };
const o = { name: 'p2pkh', network };
lazy.prop(o, 'address', () => {
if (!o.hash) return;
const payload = Buffer.allocUnsafe(21);

View file

@ -93,6 +93,11 @@ function p2sh(a, opts) {
if (o.redeem && o.redeem.witness) return o.redeem.witness;
if (o.input) return [];
});
lazy.prop(o, 'name', () => {
const nameParts = ['p2sh'];
if (o.redeem !== undefined) nameParts.push(o.redeem.name);
return nameParts.join('-');
});
if (opts.validate) {
let hash = Buffer.from([]);
if (a.address) {

View file

@ -40,7 +40,7 @@ function p2wpkh(a, opts) {
};
});
const network = a.network || networks_1.bitcoin;
const o = { network };
const o = { name: 'p2wpkh', network };
lazy.prop(o, 'address', () => {
if (!o.hash) return;
const words = bech32.toWords(o.hash);

View file

@ -103,6 +103,11 @@ function p2wsh(a, opts) {
if (!a.redeem.witness) return;
return [].concat(a.redeem.witness, a.redeem.output);
});
lazy.prop(o, 'name', () => {
const nameParts = ['p2wsh'];
if (o.redeem !== undefined) nameParts.push(o.redeem.name);
return nameParts.join('-');
});
// extended validation
if (opts.validate) {
let hash = Buffer.from([]);

View file

@ -9,6 +9,7 @@
"expected": {
"m": 2,
"n": 2,
"name": "p2ms(2 of 2)",
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
"pubkeys": [
"030000000000000000000000000000000000000000000000000000000000000001",
@ -31,6 +32,7 @@
"expected": {
"m": 1,
"n": 2,
"name": "p2ms(1 of 2)",
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
"pubkeys": [
"030000000000000000000000000000000000000000000000000000000000000001",
@ -58,6 +60,7 @@
"expected": {
"m": 2,
"n": 3,
"name": "p2ms(2 of 3)",
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
"pubkeys": [
"030000000000000000000000000000000000000000000000000000000000000001",
@ -84,6 +87,7 @@
"expected": {
"m": 2,
"n": 3,
"name": "p2ms(2 of 3)",
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
"pubkeys": [
"030000000000000000000000000000000000000000000000000000000000000001",
@ -107,6 +111,7 @@
"expected": {
"m": 2,
"n": 3,
"name": "p2ms(2 of 3)",
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
"pubkeys": [
"030000000000000000000000000000000000000000000000000000000000000001",
@ -133,6 +138,7 @@
"expected": {
"m": 2,
"n": 2,
"name": "p2ms(2 of 2)",
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
"pubkeys": [
"030000000000000000000000000000000000000000000000000000000000000001",
@ -161,6 +167,7 @@
"expected": {
"m": 2,
"n": 2,
"name": "p2ms(2 of 2)",
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
"pubkeys": [
"030000000000000000000000000000000000000000000000000000000000000001",

View file

@ -7,6 +7,7 @@
},
"options": {},
"expected": {
"name": "p2pk",
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
"signature": null,
"input": null,
@ -19,6 +20,7 @@
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
},
"expected": {
"name": "p2pk",
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
"signature": null,
"input": null,
@ -32,6 +34,7 @@
"signature": "300602010002010001"
},
"expected": {
"name": "p2pk",
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
"input": "300602010002010001",
"witness": []
@ -44,6 +47,7 @@
"signature": "300602010002010001"
},
"expected": {
"name": "p2pk",
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
"input": "300602010002010001",
"witness": []
@ -56,6 +60,7 @@
"input": "300602010002010001"
},
"expected": {
"name": "p2pk",
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
"signature": "300602010002010001",
"witness": []

View file

@ -7,6 +7,7 @@
},
"options": {},
"expected": {
"name": "p2pkh",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
"signature": null,
@ -20,6 +21,7 @@
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1"
},
"expected": {
"name": "p2pkh",
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
"signature": null,
@ -33,6 +35,7 @@
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG"
},
"expected": {
"name": "p2pkh",
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"signature": null,
@ -46,6 +49,7 @@
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
},
"expected": {
"name": "p2pkh",
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
@ -61,6 +65,7 @@
"signature": "300602010002010001"
},
"expected": {
"name": "p2pkh",
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
@ -74,6 +79,7 @@
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001"
},
"expected": {
"name": "p2pkh",
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",

View file

@ -7,6 +7,7 @@
},
"options": {},
"expected": {
"name": "p2sh",
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
"redeem": null,
@ -20,6 +21,7 @@
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086"
},
"expected": {
"name": "p2sh",
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
"redeem": null,
@ -33,6 +35,7 @@
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL"
},
"expected": {
"name": "p2sh",
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
"redeem": null,
@ -49,6 +52,7 @@
}
},
"expected": {
"name": "p2sh-p2pkh",
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
@ -65,6 +69,7 @@
}
},
"expected": {
"name": "p2sh-p2wpkh",
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
@ -81,6 +86,7 @@
}
},
"expected": {
"name": "p2sh-p2pk",
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
"hash": "3454c084887afe854e80221c69d6282926f809c4",
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
@ -97,6 +103,7 @@
}
},
"expected": {
"name": "p2sh-p2pkh",
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
@ -117,6 +124,7 @@
}
},
"expected": {
"name": "p2sh-p2wpkh",
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
@ -133,6 +141,7 @@
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 2103e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058ac"
},
"expected": {
"name": "p2sh-p2pk",
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
"hash": "3454c084887afe854e80221c69d6282926f809c4",
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
@ -154,6 +163,7 @@
]
},
"expected": {
"name": "p2sh-p2wpkh",
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
@ -177,6 +187,7 @@
}
},
"expected": {
"name": "p2sh-p2pkh",
"address": "2N7nfc7zeWuADtpdR4MrR7Wq3dzr7LxTCgS",
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",

View file

@ -7,6 +7,7 @@
},
"options": {},
"expected": {
"name": "p2wpkh",
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
"signature": null,
@ -20,6 +21,7 @@
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
},
"expected": {
"name": "p2wpkh",
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
"signature": null,
@ -33,6 +35,7 @@
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
},
"expected": {
"name": "p2wpkh",
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
"signature": null,
@ -46,6 +49,7 @@
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
},
"expected": {
"name": "p2wpkh",
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
@ -61,6 +65,7 @@
"signature": "300602010002010001"
},
"expected": {
"name": "p2wpkh",
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
@ -80,6 +85,7 @@
]
},
"expected": {
"name": "p2wpkh",
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",

View file

@ -7,6 +7,7 @@
},
"options": {},
"expected": {
"name": "p2wsh",
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
"redeem": null,
@ -20,6 +21,7 @@
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
},
"expected": {
"name": "p2wsh",
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
"redeem": null,
@ -33,6 +35,7 @@
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
},
"expected": {
"name": "p2wsh",
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
"redeem": null,
@ -49,6 +52,7 @@
}
},
"expected": {
"name": "p2wsh-p2pkh",
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
@ -65,6 +69,7 @@
}
},
"expected": {
"name": "p2wsh-p2wpkh",
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
@ -81,6 +86,7 @@
}
},
"expected": {
"name": "p2wsh-p2pk",
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
@ -97,6 +103,7 @@
}
},
"expected": {
"name": "p2wsh-p2pkh",
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
@ -124,6 +131,7 @@
}
},
"expected": {
"name": "p2wsh-p2wpkh",
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
@ -144,6 +152,7 @@
]
},
"expected": {
"name": "p2wsh-p2pk",
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
@ -167,6 +176,7 @@
]
},
"expected": {
"name": "p2wsh-p2wpkh",
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
@ -190,6 +200,7 @@
}
},
"expected": {
"name": "p2wsh-p2pkh",
"address": "tb1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ssaskm8v",
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",

View file

@ -41,6 +41,27 @@ const u = require('./payments.utils')
})
})
if (p === 'p2sh') {
const p2wsh = require('../src/payments/p2wsh').p2wsh
const p2pk = require('../src/payments/p2pk').p2pk
it('properly assembles nested p2wsh with names', () => {
const actual = fn({
redeem: p2wsh({
redeem: p2pk({
pubkey: Buffer.from(
'03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058',
'hex',
)
})
})
})
assert.strictEqual(actual.address, '3MGbrbye4ttNUXM8WAvBFRKry4fkS9fjuw')
assert.strictEqual(actual.name, 'p2sh-p2wsh-p2pk')
assert.strictEqual(actual.redeem.name, 'p2wsh-p2pk')
assert.strictEqual(actual.redeem.redeem.name, 'p2pk')
})
}
// cross-verify dynamically too
if (!fixtures.dynamic) return
const { depends, details } = fixtures.dynamic

View file

@ -29,7 +29,7 @@ export function p2data(a: Payment, opts?: PaymentOpts): Payment {
);
const network = a.network || BITCOIN_NETWORK;
const o = { network } as Payment;
const o = { name: 'embed', network } as Payment;
lazy.prop(o, 'output', () => {
if (!a.data) return;

View file

@ -8,6 +8,7 @@ import { p2wpkh } from './p2wpkh';
import { p2wsh } from './p2wsh';
export interface Payment {
name?: string;
network?: Network;
output?: Buffer;
data?: Buffer[];

View file

@ -102,6 +102,10 @@ export function p2ms(a: Payment, opts?: PaymentOpts): Payment {
if (!o.input) return;
return [];
});
lazy.prop(o, 'name', () => {
if (!o.m || !o.n) return;
return `p2ms(${o.m} of ${o.n})`;
});
// extended validation
if (opts.validate) {

View file

@ -30,7 +30,7 @@ export function p2pk(a: Payment, opts?: PaymentOpts): Payment {
}) as StackFunction;
const network = a.network || BITCOIN_NETWORK;
const o: Payment = { network };
const o: Payment = { name: 'p2pk', network };
lazy.prop(o, 'output', () => {
if (!a.pubkey) return;

View file

@ -41,7 +41,7 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
}) as StackFunction;
const network = a.network || BITCOIN_NETWORK;
const o: Payment = { network };
const o: Payment = { name: 'p2pkh', network };
lazy.prop(o, 'address', () => {
if (!o.hash) return;

View file

@ -116,6 +116,11 @@ export function p2sh(a: Payment, opts?: PaymentOpts): Payment {
if (o.redeem && o.redeem.witness) return o.redeem.witness;
if (o.input) return [];
});
lazy.prop(o, 'name', () => {
const nameParts = ['p2sh'];
if (o.redeem !== undefined) nameParts.push(o.redeem.name!);
return nameParts.join('-');
});
if (opts.validate) {
let hash: Buffer = Buffer.from([]);

View file

@ -45,7 +45,7 @@ export function p2wpkh(a: Payment, opts?: PaymentOpts): Payment {
});
const network = a.network || BITCOIN_NETWORK;
const o: Payment = { network };
const o: Payment = { name: 'p2wpkh', network };
lazy.prop(o, 'address', () => {
if (!o.hash) return;

View file

@ -116,6 +116,11 @@ export function p2wsh(a: Payment, opts?: PaymentOpts): Payment {
if (!a.redeem.witness) return;
return ([] as Buffer[]).concat(a.redeem.witness, a.redeem.output);
});
lazy.prop(o, 'name', () => {
const nameParts = ['p2wsh'];
if (o.redeem !== undefined) nameParts.push(o.redeem.name!);
return nameParts.join('-');
});
// extended validation
if (opts.validate) {

View file

@ -8,6 +8,7 @@ import { p2sh } from './p2sh';
import { p2wpkh } from './p2wpkh';
import { p2wsh } from './p2wsh';
export interface Payment {
name?: string;
network?: Network;
output?: Buffer;
data?: Buffer[];