From 6826aa312d46913a4ac67b41286e65153b77f319 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 27 Sep 2016 21:08:48 +1000 Subject: [PATCH] TransactionBuilder: less exits --- src/transaction_builder.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index fdbf16b..259fa6b 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -144,29 +144,30 @@ function extractFromOutputScript (outputScript, kpPubKey) { var scriptType = bscript.classifyOutput(outputScript) var outputScriptChunks = bscript.decompile(outputScript) + var pubKeys switch (scriptType) { case 'pubkeyhash': var pkh1 = outputScriptChunks[2] var pkh2 = bcrypto.hash160(kpPubKey) if (!bufferEquals(pkh1, pkh2)) throw new Error('privateKey cannot sign for this input') - - return { - pubKeys: [kpPubKey], - scriptType: scriptType - } + pubKeys = [kpPubKey] + break case 'pubkey': - return { - pubKeys: outputScriptChunks.slice(0, 1), - scriptType: scriptType - } + pubKeys = outputScriptChunks.slice(0, 1) + break case 'multisig': - return { - pubKeys: outputScriptChunks.slice(1, -2), - scriptType: scriptType - } + pubKeys = outputScriptChunks.slice(1, -2) + break + + default: return + } + + return { + pubKeys: pubKeys, + scriptType: scriptType } }