Add name attribute to Payments
This commit is contained in:
parent
8bbe7c7178
commit
c403757ce8
23 changed files with 105 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -8,6 +8,7 @@ import { p2wpkh } from './p2wpkh';
|
|||
import { p2wsh } from './p2wsh';
|
||||
|
||||
export interface Payment {
|
||||
name?: string;
|
||||
network?: Network;
|
||||
output?: Buffer;
|
||||
data?: Buffer[];
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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([]);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue