Update TypeScript to use ! instead of casting

This commit is contained in:
junderw 2019-01-15 17:47:30 +09:00
commit 1732bafbc1
No known key found for this signature in database
GPG key ID: B256185D3A971908
17 changed files with 99 additions and 97 deletions
ts_src/payments

View file

@ -29,7 +29,7 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment {
function isAcceptableSignature (x: Buffer | number) {
return bscript.isCanonicalScriptSignature(<Buffer>x) ||
((<PaymentOpts>opts).allowIncomplete &&
(opts!.allowIncomplete &&
(<number> x === OPS.OP_0)) !== undefined // eslint-disable-line
}
@ -85,7 +85,7 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment {
})
lazy.prop(o, 'signatures', function () {
if (!a.input) return
return (<Array<Buffer | number>>bscript.decompile(a.input)).slice(1)
return bscript.decompile(a.input)!.slice(1)
})
lazy.prop(o, 'input', function () {
if (!a.signatures) return
@ -105,35 +105,35 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment {
if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) throw new TypeError('Output is invalid')
if (
<number>(<Payment>o).m <= 0 || // eslint-disable-line
<number>(<Payment>o).n > 16 || // eslint-disable-line
<number>(<Payment>o).m > <number>(<Payment>o).n || // eslint-disable-line
o.m! <= 0 || // eslint-disable-line
o.n! > 16 || // eslint-disable-line
o.m! > o.n! || // eslint-disable-line
o.n !== chunks.length - 3) throw new TypeError('Output is invalid')
if (!(<Array<Buffer>>o.pubkeys).every(x => ecc.isPoint(x))) throw new TypeError('Output is invalid')
if (!o.pubkeys!.every(x => ecc.isPoint(x))) throw new TypeError('Output is invalid')
if (a.m !== undefined && a.m !== o.m) throw new TypeError('m mismatch')
if (a.n !== undefined && a.n !== o.n) throw new TypeError('n mismatch')
if (a.pubkeys && !stacksEqual(a.pubkeys, (<Array<Buffer>>o.pubkeys))) throw new TypeError('Pubkeys mismatch')
if (a.pubkeys && !stacksEqual(a.pubkeys, o.pubkeys!)) throw new TypeError('Pubkeys mismatch')
}
if (a.pubkeys) {
if (a.n !== undefined && a.n !== a.pubkeys.length) throw new TypeError('Pubkey count mismatch')
o.n = a.pubkeys.length
if (o.n < <number>(<Payment>o).m) throw new TypeError('Pubkey count cannot be less than m')
if (o.n < o.m!) throw new TypeError('Pubkey count cannot be less than m')
}
if (a.signatures) {
if (a.signatures.length < <number>(<Payment>o).m) throw new TypeError('Not enough signatures provided')
if (a.signatures.length > <number>(<Payment>o).m) throw new TypeError('Too many signatures provided')
if (a.signatures.length < o.m!) throw new TypeError('Not enough signatures provided')
if (a.signatures.length > o.m!) throw new TypeError('Too many signatures provided')
}
if (a.input) {
if (a.input[0] !== OPS.OP_0) throw new TypeError('Input is invalid')
if ((<Array<Buffer>>o.signatures).length === 0 || !(<Array<Buffer>>o.signatures).every(isAcceptableSignature)) throw new TypeError('Input has invalid signature(s)')
if (o.signatures!.length === 0 || !o.signatures!.every(isAcceptableSignature)) throw new TypeError('Input has invalid signature(s)')
if (a.signatures && !stacksEqual(a.signatures, (<Array<Buffer>>o.signatures))) throw new TypeError('Signature mismatch')
if (a.m !== undefined && a.m !== (<Array<Buffer>>a.signatures).length) throw new TypeError('Signature count mismatch')
if (a.signatures && !stacksEqual(a.signatures, o.signatures!)) throw new TypeError('Signature mismatch')
if (a.m !== undefined && a.m !== a.signatures!.length) throw new TypeError('Signature count mismatch')
}
}