Convert sighash to match esplora.

This commit is contained in:
softsimon 2021-01-03 22:02:10 +07:00
parent a25125091d
commit 7729ad8b79
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -107,7 +107,7 @@ class BitcoinApi implements AbstractBitcoinApi {
value: vout.value * 100000000, value: vout.value * 100000000,
scriptpubkey: vout.scriptPubKey.hex, scriptpubkey: vout.scriptPubKey.hex,
scriptpubkey_address: vout.scriptPubKey && vout.scriptPubKey.addresses ? vout.scriptPubKey.addresses[0] : '', scriptpubkey_address: vout.scriptPubKey && vout.scriptPubKey.addresses ? vout.scriptPubKey.addresses[0] : '',
scriptpubkey_asm: vout.scriptPubKey.asm, scriptpubkey_asm: vout.scriptPubKey.asm ? this.convertScriptSigAsm(vout.scriptPubKey.asm) : '',
scriptpubkey_type: this.translateScriptPubKeyType(vout.scriptPubKey.type), scriptpubkey_type: this.translateScriptPubKeyType(vout.scriptPubKey.type),
}; };
}); });
@ -117,7 +117,7 @@ class BitcoinApi implements AbstractBitcoinApi {
is_coinbase: !!vin.coinbase, is_coinbase: !!vin.coinbase,
prevout: null, prevout: null,
scriptsig: vin.scriptSig && vin.scriptSig.hex || vin.coinbase || '', scriptsig: vin.scriptSig && vin.scriptSig.hex || vin.coinbase || '',
scriptsig_asm: vin.scriptSig && vin.scriptSig.asm || '', scriptsig_asm: vin.scriptSig && this.convertScriptSigAsm(vin.scriptSig.asm) || '',
sequence: vin.sequence, sequence: vin.sequence,
txid: vin.txid || '', txid: vin.txid || '',
vout: vin.vout || 0, vout: vin.vout || 0,
@ -216,6 +216,20 @@ class BitcoinApi implements AbstractBitcoinApi {
}); });
} }
private convertScriptSigAsm(str: string): string {
const a = str.split(' ');
const b: string[] = [];
a.forEach((chunk) => {
if (chunk.substr(0, 3) === 'OP_') {
b.push(chunk);
} else {
chunk = chunk.replace('[ALL]', '01');
b.push('OP_PUSHBYTES_' + Math.round(chunk.length / 2) + ' ' + chunk);
}
});
return b.join(' ');
}
private async $calculateFeeFromInputs(transaction: IEsploraApi.Transaction, addPrevout: boolean): Promise<IEsploraApi.Transaction> { private async $calculateFeeFromInputs(transaction: IEsploraApi.Transaction, addPrevout: boolean): Promise<IEsploraApi.Transaction> {
if (transaction.vin[0].is_coinbase) { if (transaction.vin[0].is_coinbase) {
transaction.fee = 0; transaction.fee = 0;