Fix lint for p2ms payment
This commit is contained in:
parent
db937f8110
commit
4054f3ae87
2 changed files with 31 additions and 33 deletions
|
@ -1,8 +1,8 @@
|
||||||
"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 OPS = bscript.OPS;
|
const OPS = bscript.OPS;
|
||||||
const typef = require('typeforce');
|
const typef = require('typeforce');
|
||||||
const ecc = require('tiny-secp256k1');
|
const ecc = require('tiny-secp256k1');
|
||||||
|
@ -10,7 +10,7 @@ const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
|
||||||
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]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ function p2ms(a, opts) {
|
||||||
o.n = chunks[chunks.length - 2] - OP_INT_BASE;
|
o.n = chunks[chunks.length - 2] - OP_INT_BASE;
|
||||||
o.pubkeys = chunks.slice(1, -2);
|
o.pubkeys = chunks.slice(1, -2);
|
||||||
}
|
}
|
||||||
lazy.prop(o, 'output', function () {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.m)
|
if (!a.m)
|
||||||
return;
|
return;
|
||||||
if (!o.n)
|
if (!o.n)
|
||||||
|
@ -58,34 +58,34 @@ function p2ms(a, opts) {
|
||||||
return;
|
return;
|
||||||
return bscript.compile([].concat(OP_INT_BASE + a.m, a.pubkeys, OP_INT_BASE + o.n, OPS.OP_CHECKMULTISIG));
|
return bscript.compile([].concat(OP_INT_BASE + a.m, a.pubkeys, OP_INT_BASE + o.n, OPS.OP_CHECKMULTISIG));
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'm', function () {
|
lazy.prop(o, 'm', () => {
|
||||||
if (!o.output)
|
if (!o.output)
|
||||||
return;
|
return;
|
||||||
decode(o.output);
|
decode(o.output);
|
||||||
return o.m;
|
return o.m;
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'n', function () {
|
lazy.prop(o, 'n', () => {
|
||||||
if (!o.pubkeys)
|
if (!o.pubkeys)
|
||||||
return;
|
return;
|
||||||
return o.pubkeys.length;
|
return o.pubkeys.length;
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'pubkeys', function () {
|
lazy.prop(o, 'pubkeys', () => {
|
||||||
if (!a.output)
|
if (!a.output)
|
||||||
return;
|
return;
|
||||||
decode(a.output);
|
decode(a.output);
|
||||||
return o.pubkeys;
|
return o.pubkeys;
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'signatures', function () {
|
lazy.prop(o, 'signatures', () => {
|
||||||
if (!a.input)
|
if (!a.input)
|
||||||
return;
|
return;
|
||||||
return bscript.decompile(a.input).slice(1);
|
return bscript.decompile(a.input).slice(1);
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'input', function () {
|
lazy.prop(o, 'input', () => {
|
||||||
if (!a.signatures)
|
if (!a.signatures)
|
||||||
return;
|
return;
|
||||||
return bscript.compile([OPS.OP_0].concat(a.signatures));
|
return bscript.compile([OPS.OP_0].concat(a.signatures));
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'witness', function () {
|
lazy.prop(o, 'witness', () => {
|
||||||
if (!o.input)
|
if (!o.input)
|
||||||
return;
|
return;
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
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 OPS = bscript.OPS;
|
const OPS = bscript.OPS;
|
||||||
const typef = require('typeforce');
|
const typef = require('typeforce');
|
||||||
const ecc = require('tiny-secp256k1');
|
const ecc = require('tiny-secp256k1');
|
||||||
|
|
||||||
const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
|
const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
|
||||||
|
|
||||||
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]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ export function p2ms(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
|
|
||||||
function isAcceptableSignature(x: Buffer | number) {
|
function isAcceptableSignature(x: Buffer | number) {
|
||||||
return (
|
return (
|
||||||
bscript.isCanonicalScriptSignature(<Buffer>x) ||
|
bscript.isCanonicalScriptSignature(x as Buffer) ||
|
||||||
(opts!.allowIncomplete && <number>x === OPS.OP_0) !== undefined
|
(opts!.allowIncomplete && (x as number) === OPS.OP_0) !== undefined
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,23 +52,23 @@ export function p2ms(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
const network = a.network || BITCOIN_NETWORK;
|
const network = a.network || BITCOIN_NETWORK;
|
||||||
const o: Payment = { network };
|
const o: Payment = { network };
|
||||||
|
|
||||||
let chunks: Array<Buffer | number> = [];
|
let chunks: Stack = [];
|
||||||
let decoded = false;
|
let decoded = false;
|
||||||
function decode(output: Buffer | Array<Buffer | number>): void {
|
function decode(output: Buffer | Stack): void {
|
||||||
if (decoded) return;
|
if (decoded) return;
|
||||||
decoded = true;
|
decoded = true;
|
||||||
chunks = <Array<Buffer | number>>bscript.decompile(output);
|
chunks = bscript.decompile(output) as Stack;
|
||||||
o.m = <number>chunks[0] - OP_INT_BASE;
|
o.m = (chunks[0] as number) - OP_INT_BASE;
|
||||||
o.n = <number>chunks[chunks.length - 2] - OP_INT_BASE;
|
o.n = (chunks[chunks.length - 2] as number) - OP_INT_BASE;
|
||||||
o.pubkeys = <Array<Buffer>>chunks.slice(1, -2);
|
o.pubkeys = chunks.slice(1, -2) as Buffer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy.prop(o, 'output', function() {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.m) return;
|
if (!a.m) return;
|
||||||
if (!o.n) return;
|
if (!o.n) return;
|
||||||
if (!a.pubkeys) return;
|
if (!a.pubkeys) return;
|
||||||
return bscript.compile(
|
return bscript.compile(
|
||||||
(<Array<Buffer | number>>[]).concat(
|
([] as Stack).concat(
|
||||||
OP_INT_BASE + a.m,
|
OP_INT_BASE + a.m,
|
||||||
a.pubkeys,
|
a.pubkeys,
|
||||||
OP_INT_BASE + o.n,
|
OP_INT_BASE + o.n,
|
||||||
|
@ -76,31 +76,29 @@ export function p2ms(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'm', function() {
|
lazy.prop(o, 'm', () => {
|
||||||
if (!o.output) return;
|
if (!o.output) return;
|
||||||
decode(o.output);
|
decode(o.output);
|
||||||
return o.m;
|
return o.m;
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'n', function() {
|
lazy.prop(o, 'n', () => {
|
||||||
if (!o.pubkeys) return;
|
if (!o.pubkeys) return;
|
||||||
return o.pubkeys.length;
|
return o.pubkeys.length;
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'pubkeys', function() {
|
lazy.prop(o, 'pubkeys', () => {
|
||||||
if (!a.output) return;
|
if (!a.output) return;
|
||||||
decode(a.output);
|
decode(a.output);
|
||||||
return o.pubkeys;
|
return o.pubkeys;
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'signatures', function() {
|
lazy.prop(o, 'signatures', () => {
|
||||||
if (!a.input) return;
|
if (!a.input) return;
|
||||||
return bscript.decompile(a.input)!.slice(1);
|
return bscript.decompile(a.input)!.slice(1);
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'input', function() {
|
lazy.prop(o, 'input', () => {
|
||||||
if (!a.signatures) return;
|
if (!a.signatures) return;
|
||||||
return bscript.compile(
|
return bscript.compile(([OPS.OP_0] as Stack).concat(a.signatures));
|
||||||
(<Array<Buffer | number>>[OPS.OP_0]).concat(a.signatures),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
lazy.prop(o, 'witness', function() {
|
lazy.prop(o, 'witness', () => {
|
||||||
if (!o.input) return;
|
if (!o.input) return;
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue