Fix embed.ts and index.ts for payments lint
This commit is contained in:
parent
3f34fe457a
commit
389ec8cb33
4 changed files with 28 additions and 24 deletions
|
@ -1,14 +1,14 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const networks_1 = require("../networks");
|
||||||
const bscript = require("../script");
|
const bscript = require("../script");
|
||||||
const lazy = require("./lazy");
|
const lazy = require("./lazy");
|
||||||
const networks_1 = require("../networks");
|
|
||||||
const typef = require('typeforce');
|
const typef = require('typeforce');
|
||||||
const OPS = bscript.OPS;
|
const OPS = bscript.OPS;
|
||||||
function stacksEqual(a, b) {
|
function stacksEqual(a, b) {
|
||||||
if (a.length !== b.length)
|
if (a.length !== b.length)
|
||||||
return false;
|
return false;
|
||||||
return a.every(function (x, i) {
|
return a.every((x, i) => {
|
||||||
return x.equals(b[i]);
|
return x.equals(b[i]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,12 @@ function p2data(a, opts) {
|
||||||
}, a);
|
}, a);
|
||||||
const network = a.network || networks_1.bitcoin;
|
const network = a.network || networks_1.bitcoin;
|
||||||
const o = { network };
|
const o = { network };
|
||||||
lazy.prop(o, 'output', function () {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.data)
|
if (!a.data)
|
||||||
return;
|
return;
|
||||||
return bscript.compile([OPS.OP_RETURN].concat(a.data));
|
return bscript.compile([OPS.OP_RETURN].concat(a.data));
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'data', function () {
|
lazy.prop(o, 'data', () => {
|
||||||
if (!a.output)
|
if (!a.output)
|
||||||
return;
|
return;
|
||||||
return bscript.decompile(a.output).slice(1);
|
return bscript.decompile(a.output).slice(1);
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import { Payment, PaymentOpts } from './index';
|
|
||||||
import * as bscript from '../script';
|
|
||||||
import * as lazy from './lazy';
|
|
||||||
import { bitcoin as BITCOIN_NETWORK } from '../networks';
|
import { bitcoin as BITCOIN_NETWORK } from '../networks';
|
||||||
|
import * as bscript from '../script';
|
||||||
|
import { Payment, PaymentOpts, Stack } from './index';
|
||||||
|
import * as lazy from './lazy';
|
||||||
|
|
||||||
const typef = require('typeforce');
|
const typef = require('typeforce');
|
||||||
const OPS = bscript.OPS;
|
const OPS = bscript.OPS;
|
||||||
|
|
||||||
function stacksEqual(a: Array<Buffer>, b: Array<Buffer>): boolean {
|
function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
|
||||||
if (a.length !== b.length) return false;
|
if (a.length !== b.length) return false;
|
||||||
|
|
||||||
return a.every(function(x, i) {
|
return a.every((x, i) => {
|
||||||
return x.equals(b[i]);
|
return x.equals(b[i]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -28,15 +29,13 @@ export function p2data(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
);
|
);
|
||||||
|
|
||||||
const network = a.network || BITCOIN_NETWORK;
|
const network = a.network || BITCOIN_NETWORK;
|
||||||
const o = <Payment>{ network };
|
const o = { network } as Payment;
|
||||||
|
|
||||||
lazy.prop(o, 'output', function() {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.data) return;
|
if (!a.data) return;
|
||||||
return bscript.compile(
|
return bscript.compile(([OPS.OP_RETURN] as Stack).concat(a.data));
|
||||||
(<Array<Buffer | number>>[OPS.OP_RETURN]).concat(a.data),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'data', function() {
|
lazy.prop(o, 'data', () => {
|
||||||
if (!a.output) return;
|
if (!a.output) return;
|
||||||
return bscript.decompile(a.output)!.slice(1);
|
return bscript.decompile(a.output)!.slice(1);
|
||||||
});
|
});
|
||||||
|
@ -50,7 +49,7 @@ export function p2data(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
if (!chunks!.slice(1).every(typef.Buffer))
|
if (!chunks!.slice(1).every(typef.Buffer))
|
||||||
throw new TypeError('Output is invalid');
|
throw new TypeError('Output is invalid');
|
||||||
|
|
||||||
if (a.data && !stacksEqual(a.data, <Array<Buffer>>o.data))
|
if (a.data && !stacksEqual(a.data, o.data as Buffer[]))
|
||||||
throw new TypeError('Data mismatch');
|
throw new TypeError('Data mismatch');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,18 +10,18 @@ import { p2wsh } from './p2wsh';
|
||||||
export interface Payment {
|
export interface Payment {
|
||||||
network?: Network;
|
network?: Network;
|
||||||
output?: Buffer;
|
output?: Buffer;
|
||||||
data?: Array<Buffer>;
|
data?: Buffer[];
|
||||||
m?: number;
|
m?: number;
|
||||||
n?: number;
|
n?: number;
|
||||||
pubkeys?: Array<Buffer>;
|
pubkeys?: Buffer[];
|
||||||
input?: Buffer;
|
input?: Buffer;
|
||||||
signatures?: Array<Buffer>;
|
signatures?: Buffer[];
|
||||||
pubkey?: Buffer;
|
pubkey?: Buffer;
|
||||||
signature?: Buffer;
|
signature?: Buffer;
|
||||||
address?: string;
|
address?: string;
|
||||||
hash?: Buffer;
|
hash?: Buffer;
|
||||||
redeem?: Payment;
|
redeem?: Payment;
|
||||||
witness?: Array<Buffer>;
|
witness?: Buffer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PaymentOpts {
|
export interface PaymentOpts {
|
||||||
|
@ -29,6 +29,9 @@ export interface PaymentOpts {
|
||||||
allowIncomplete?: boolean;
|
allowIncomplete?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type StackElement = Buffer | number;
|
||||||
|
export type Stack = StackElement[];
|
||||||
|
|
||||||
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh };
|
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh };
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
10
types/payments/index.d.ts
vendored
10
types/payments/index.d.ts
vendored
|
@ -10,21 +10,23 @@ import { p2wsh } from './p2wsh';
|
||||||
export interface Payment {
|
export interface Payment {
|
||||||
network?: Network;
|
network?: Network;
|
||||||
output?: Buffer;
|
output?: Buffer;
|
||||||
data?: Array<Buffer>;
|
data?: Buffer[];
|
||||||
m?: number;
|
m?: number;
|
||||||
n?: number;
|
n?: number;
|
||||||
pubkeys?: Array<Buffer>;
|
pubkeys?: Buffer[];
|
||||||
input?: Buffer;
|
input?: Buffer;
|
||||||
signatures?: Array<Buffer>;
|
signatures?: Buffer[];
|
||||||
pubkey?: Buffer;
|
pubkey?: Buffer;
|
||||||
signature?: Buffer;
|
signature?: Buffer;
|
||||||
address?: string;
|
address?: string;
|
||||||
hash?: Buffer;
|
hash?: Buffer;
|
||||||
redeem?: Payment;
|
redeem?: Payment;
|
||||||
witness?: Array<Buffer>;
|
witness?: Buffer[];
|
||||||
}
|
}
|
||||||
export interface PaymentOpts {
|
export interface PaymentOpts {
|
||||||
validate?: boolean;
|
validate?: boolean;
|
||||||
allowIncomplete?: boolean;
|
allowIncomplete?: boolean;
|
||||||
}
|
}
|
||||||
|
export declare type StackElement = Buffer | number;
|
||||||
|
export declare type Stack = StackElement[];
|
||||||
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh };
|
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh };
|
||||||
|
|
Loading…
Add table
Reference in a new issue