Refactor: add function getPsigsFromInputFinalScripts

This commit is contained in:
junderw 2019-07-23 15:51:12 +09:00
parent e4844828de
commit 06b38a7d83
No known key found for this signature in database
GPG key ID: B256185D3A971908
2 changed files with 31 additions and 28 deletions

View file

@ -629,20 +629,7 @@ function checkInputsForPartialSig(inputs, action) {
let pSigs = [];
if ((input.partialSig || []).length === 0) {
if (!input.finalScriptSig && !input.finalScriptWitness) return;
const scriptItems = !input.finalScriptSig
? []
: bscript.decompile(input.finalScriptSig) || [];
const witnessItems = !input.finalScriptWitness
? []
: bscript.decompile(input.finalScriptWitness) || [];
pSigs = scriptItems
.concat(witnessItems)
.filter(item => {
return (
Buffer.isBuffer(item) && bscript.isCanonicalScriptSignature(item)
);
})
.map(sig => ({ signature: sig }));
pSigs = getPsigsFromInputFinalScripts(input);
} else {
pSigs = input.partialSig;
}
@ -918,6 +905,20 @@ function getPayment(script, scriptType, partialSig) {
}
return payment;
}
function getPsigsFromInputFinalScripts(input) {
const scriptItems = !input.finalScriptSig
? []
: bscript.decompile(input.finalScriptSig) || [];
const witnessItems = !input.finalScriptWitness
? []
: bscript.decompile(input.finalScriptWitness) || [];
return scriptItems
.concat(witnessItems)
.filter(item => {
return Buffer.isBuffer(item) && bscript.isCanonicalScriptSignature(item);
})
.map(sig => ({ signature: sig }));
}
function getScriptFromInput(inputIndex, input, cache) {
const unsignedTx = cache.__TX;
const res = {

View file

@ -798,20 +798,7 @@ function checkInputsForPartialSig(inputs: PsbtInput[], action: string): void {
let pSigs: PartialSig[] = [];
if ((input.partialSig || []).length === 0) {
if (!input.finalScriptSig && !input.finalScriptWitness) return;
const scriptItems = !input.finalScriptSig
? []
: bscript.decompile(input.finalScriptSig) || [];
const witnessItems = !input.finalScriptWitness
? []
: bscript.decompile(input.finalScriptWitness) || [];
pSigs = scriptItems
.concat(witnessItems)
.filter(item => {
return (
Buffer.isBuffer(item) && bscript.isCanonicalScriptSignature(item)
);
})
.map(sig => ({ signature: sig })) as PartialSig[];
pSigs = getPsigsFromInputFinalScripts(input);
} else {
pSigs = input.partialSig!;
}
@ -1140,6 +1127,21 @@ function getPayment(
return payment!;
}
function getPsigsFromInputFinalScripts(input: PsbtInput): PartialSig[] {
const scriptItems = !input.finalScriptSig
? []
: bscript.decompile(input.finalScriptSig) || [];
const witnessItems = !input.finalScriptWitness
? []
: bscript.decompile(input.finalScriptWitness) || [];
return scriptItems
.concat(witnessItems)
.filter(item => {
return Buffer.isBuffer(item) && bscript.isCanonicalScriptSignature(item);
})
.map(sig => ({ signature: sig })) as PartialSig[];
}
interface GetScriptReturn {
script: Buffer | null;
isSegwit: boolean;