Skip to content

Commit f6232db

Browse files
committedSep 21, 2020
handle p2sh scriptSig case
1 parent cec53e9 commit f6232db

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed
 

‎tna.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,22 @@ export class TNA {
4141
i: input.outputIndex,
4242
s: input._scriptBuffer,
4343
}
44+
4445
try {
45-
sender.a = Utils.toSlpAddress(input.script.toAddress(net).toString(bitcore.Address.CashAddrFormat));
46-
} catch(err) {
47-
throw Error(`txid: ${gene.hash}, input: ${input.prevTxId.toString('hex')}:${input.outputIndex}, script: ${input._scriptBuffer.toString("hex")}, asm: ${input.script.toASM()}, cashAddr: ${input.script.toAddress(net).toString(bitcore.Address.CashAddrFormat)}, err: ${err}`)
46+
if (input.script.toAddress(net).toString(bitcore.Address.CashAddrFormat) !== "false") {
47+
// let bitcore-lib-cash encode the address type
48+
sender.a = Utils.toSlpAddress(input.script.toAddress(net).toString(bitcore.Address.CashAddrFormat));
49+
} else {
50+
// encode as p2sh address type
51+
const scriptSigHexArray = input.script.toASM().split(' ')
52+
const redeemScriptHex = scriptSigHexArray[scriptSigHexArray.length-1]
53+
const redeemScriptHash160 = bitbox.Crypto.hash160(Buffer.from(redeemScriptHex, 'hex'))
54+
sender.a = Utils.slpAddressFromHash160(redeemScriptHash160, options.network, "p2sh")
55+
}
56+
} catch (err) {
57+
throw Error(`txid: ${gene.hash}, input: ${input.prevTxId.toString('hex')}:${input.outputIndex}, address: ${input.script.toAddress(net).toString(bitcore.Address.CashAddrFormat)}, script ${input._scriptBuffer.toString("hex")}, err: ${err}`)
4858
}
59+
4960
xput.e = sender;
5061
inputs.push(xput)
5162
}

0 commit comments

Comments
 (0)