Use single func instead of 3
This commit is contained in:
parent
22682fc2c3
commit
4b5a519bfe
3 changed files with 78 additions and 78 deletions
src
37
src/psbt.js
37
src/psbt.js
|
@ -204,18 +204,7 @@ class Psbt {
|
|||
range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx));
|
||||
return this;
|
||||
}
|
||||
finalizeInput(
|
||||
inputIndex,
|
||||
{
|
||||
classifyScript: classifyScriptF,
|
||||
canFinalize: canFinalizeF,
|
||||
getFinalScripts: getFinalScriptsF,
|
||||
} = {
|
||||
classifyScript,
|
||||
canFinalize,
|
||||
getFinalScripts,
|
||||
},
|
||||
) {
|
||||
finalizeInput(inputIndex, finalScriptsFunc = getFinalScripts) {
|
||||
const input = utils_1.checkForInput(this.data.inputs, inputIndex);
|
||||
const { script, isP2SH, isP2WSH, isSegwit } = getScriptFromInput(
|
||||
inputIndex,
|
||||
|
@ -223,14 +212,11 @@ class Psbt {
|
|||
this.__CACHE,
|
||||
);
|
||||
if (!script) throw new Error(`No script found for input #${inputIndex}`);
|
||||
const scriptType = classifyScriptF(script);
|
||||
if (!canFinalizeF(input, script, scriptType))
|
||||
throw new Error(`Can not finalize input #${inputIndex}`);
|
||||
checkPartialSigSighashes(input);
|
||||
const { finalScriptSig, finalScriptWitness } = getFinalScriptsF(
|
||||
const { finalScriptSig, finalScriptWitness } = finalScriptsFunc(
|
||||
inputIndex,
|
||||
input,
|
||||
script,
|
||||
scriptType,
|
||||
input.partialSig,
|
||||
isSegwit,
|
||||
isP2SH,
|
||||
isP2WSH,
|
||||
|
@ -749,7 +735,20 @@ function getTxCacheValue(key, name, inputs, c) {
|
|||
if (key === '__FEE_RATE') return c.__FEE_RATE;
|
||||
else if (key === '__FEE') return c.__FEE;
|
||||
}
|
||||
function getFinalScripts(
|
||||
function getFinalScripts(inputIndex, input, script, isSegwit, isP2SH, isP2WSH) {
|
||||
const scriptType = classifyScript(script);
|
||||
if (!canFinalize(input, script, scriptType))
|
||||
throw new Error(`Can not finalize input #${inputIndex}`);
|
||||
return prepareFinalScripts(
|
||||
script,
|
||||
scriptType,
|
||||
input.partialSig,
|
||||
isSegwit,
|
||||
isP2SH,
|
||||
isP2WSH,
|
||||
);
|
||||
}
|
||||
function prepareFinalScripts(
|
||||
script,
|
||||
scriptType,
|
||||
partialSig,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue