Update TypeScript to use ! instead of casting

This commit is contained in:
junderw 2019-01-15 17:47:30 +09:00
parent bc28949056
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

@ -36,15 +36,15 @@ export function p2data (a: Payment, opts?: PaymentOpts): Payment {
})
lazy.prop(o, 'data', function () {
if (!a.output) return
return (<Array<Buffer | number>>bscript.decompile(a.output)).slice(1)
return bscript.decompile(a.output)!.slice(1)
})
// extended validation
if (opts.validate) {
if (a.output) {
const chunks = bscript.decompile(a.output)
if ((<Array<Buffer | number>>chunks)[0] !== OPS.OP_RETURN) throw new TypeError('Output is invalid')
if (!(<Array<Buffer | number>>chunks).slice(1).every(typef.Buffer)) throw new TypeError('Output is invalid')
if (chunks![0] !== OPS.OP_RETURN) throw new TypeError('Output is invalid')
if (!chunks!.slice(1).every(typef.Buffer)) throw new TypeError('Output is invalid')
if (a.data && !stacksEqual(a.data, <Array<Buffer>>o.data)) throw new TypeError('Data mismatch')
}