Refactor: add function getPsigsFromInputFinalScripts
This commit is contained in:
parent
e4844828de
commit
06b38a7d83
2 changed files with 31 additions and 28 deletions
29
src/psbt.js
29
src/psbt.js
|
@ -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 = {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue