Skip to content

Commit 19a126c

Browse files
authored
Merge pull request bitcoinjs#1433 from bitcoinjs/addNamePayments
Add name attribute to Payments
2 parents eca05f7 + c403757 commit 19a126c

File tree

23 files changed

+105
-8
lines changed

23 files changed

+105
-8
lines changed

src/payments/embed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function p2data(a, opts) {
2424
a,
2525
);
2626
const network = a.network || networks_1.bitcoin;
27-
const o = { network };
27+
const o = { name: 'embed', network };
2828
lazy.prop(o, 'output', () => {
2929
if (!a.data) return;
3030
return bscript.compile([OPS.OP_RETURN].concat(a.data));

src/payments/p2ms.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ function p2ms(a, opts) {
9393
if (!o.input) return;
9494
return [];
9595
});
96+
lazy.prop(o, 'name', () => {
97+
if (!o.m || !o.n) return;
98+
return `p2ms(${o.m} of ${o.n})`;
99+
});
96100
// extended validation
97101
if (opts.validate) {
98102
if (a.output) {

src/payments/p2pk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function p2pk(a, opts) {
2626
return bscript.decompile(a.input);
2727
});
2828
const network = a.network || networks_1.bitcoin;
29-
const o = { network };
29+
const o = { name: 'p2pk', network };
3030
lazy.prop(o, 'output', () => {
3131
if (!a.pubkey) return;
3232
return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]);

src/payments/p2pkh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function p2pkh(a, opts) {
3636
return bscript.decompile(a.input);
3737
});
3838
const network = a.network || networks_1.bitcoin;
39-
const o = { network };
39+
const o = { name: 'p2pkh', network };
4040
lazy.prop(o, 'address', () => {
4141
if (!o.hash) return;
4242
const payload = Buffer.allocUnsafe(21);

src/payments/p2sh.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ function p2sh(a, opts) {
9393
if (o.redeem && o.redeem.witness) return o.redeem.witness;
9494
if (o.input) return [];
9595
});
96+
lazy.prop(o, 'name', () => {
97+
const nameParts = ['p2sh'];
98+
if (o.redeem !== undefined) nameParts.push(o.redeem.name);
99+
return nameParts.join('-');
100+
});
96101
if (opts.validate) {
97102
let hash = Buffer.from([]);
98103
if (a.address) {

src/payments/p2wpkh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function p2wpkh(a, opts) {
4040
};
4141
});
4242
const network = a.network || networks_1.bitcoin;
43-
const o = { network };
43+
const o = { name: 'p2wpkh', network };
4444
lazy.prop(o, 'address', () => {
4545
if (!o.hash) return;
4646
const words = bech32.toWords(o.hash);

src/payments/p2wsh.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ function p2wsh(a, opts) {
103103
if (!a.redeem.witness) return;
104104
return [].concat(a.redeem.witness, a.redeem.output);
105105
});
106+
lazy.prop(o, 'name', () => {
107+
const nameParts = ['p2wsh'];
108+
if (o.redeem !== undefined) nameParts.push(o.redeem.name);
109+
return nameParts.join('-');
110+
});
106111
// extended validation
107112
if (opts.validate) {
108113
let hash = Buffer.from([]);

test/fixtures/p2ms.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"expected": {
1010
"m": 2,
1111
"n": 2,
12+
"name": "p2ms(2 of 2)",
1213
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
1314
"pubkeys": [
1415
"030000000000000000000000000000000000000000000000000000000000000001",
@@ -31,6 +32,7 @@
3132
"expected": {
3233
"m": 1,
3334
"n": 2,
35+
"name": "p2ms(1 of 2)",
3436
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
3537
"pubkeys": [
3638
"030000000000000000000000000000000000000000000000000000000000000001",
@@ -58,6 +60,7 @@
5860
"expected": {
5961
"m": 2,
6062
"n": 3,
63+
"name": "p2ms(2 of 3)",
6164
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
6265
"pubkeys": [
6366
"030000000000000000000000000000000000000000000000000000000000000001",
@@ -84,6 +87,7 @@
8487
"expected": {
8588
"m": 2,
8689
"n": 3,
90+
"name": "p2ms(2 of 3)",
8791
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
8892
"pubkeys": [
8993
"030000000000000000000000000000000000000000000000000000000000000001",
@@ -107,6 +111,7 @@
107111
"expected": {
108112
"m": 2,
109113
"n": 3,
114+
"name": "p2ms(2 of 3)",
110115
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
111116
"pubkeys": [
112117
"030000000000000000000000000000000000000000000000000000000000000001",
@@ -133,6 +138,7 @@
133138
"expected": {
134139
"m": 2,
135140
"n": 2,
141+
"name": "p2ms(2 of 2)",
136142
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
137143
"pubkeys": [
138144
"030000000000000000000000000000000000000000000000000000000000000001",
@@ -161,6 +167,7 @@
161167
"expected": {
162168
"m": 2,
163169
"n": 2,
170+
"name": "p2ms(2 of 2)",
164171
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
165172
"pubkeys": [
166173
"030000000000000000000000000000000000000000000000000000000000000001",

test/fixtures/p2pk.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"options": {},
99
"expected": {
10+
"name": "p2pk",
1011
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
1112
"signature": null,
1213
"input": null,
@@ -19,6 +20,7 @@
1920
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
2021
},
2122
"expected": {
23+
"name": "p2pk",
2224
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
2325
"signature": null,
2426
"input": null,
@@ -32,6 +34,7 @@
3234
"signature": "300602010002010001"
3335
},
3436
"expected": {
37+
"name": "p2pk",
3538
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
3639
"input": "300602010002010001",
3740
"witness": []
@@ -44,6 +47,7 @@
4447
"signature": "300602010002010001"
4548
},
4649
"expected": {
50+
"name": "p2pk",
4751
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
4852
"input": "300602010002010001",
4953
"witness": []
@@ -56,6 +60,7 @@
5660
"input": "300602010002010001"
5761
},
5862
"expected": {
63+
"name": "p2pk",
5964
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
6065
"signature": "300602010002010001",
6166
"witness": []

test/fixtures/p2pkh.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"options": {},
99
"expected": {
10+
"name": "p2pkh",
1011
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
1112
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
1213
"signature": null,
@@ -20,6 +21,7 @@
2021
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1"
2122
},
2223
"expected": {
24+
"name": "p2pkh",
2325
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
2426
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
2527
"signature": null,
@@ -33,6 +35,7 @@
3335
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG"
3436
},
3537
"expected": {
38+
"name": "p2pkh",
3639
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
3740
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
3841
"signature": null,
@@ -46,6 +49,7 @@
4649
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
4750
},
4851
"expected": {
52+
"name": "p2pkh",
4953
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
5054
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
5155
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
@@ -61,6 +65,7 @@
6165
"signature": "300602010002010001"
6266
},
6367
"expected": {
68+
"name": "p2pkh",
6469
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
6570
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
6671
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
@@ -74,6 +79,7 @@
7479
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001"
7580
},
7681
"expected": {
82+
"name": "p2pkh",
7783
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
7884
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
7985
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",

0 commit comments

Comments
 (0)