From 18e7c9de80db6f5d335574f33ef39dedab82d0e3 Mon Sep 17 00:00:00 2001
From: Luke Childs <lukechilds123@gmail.com>
Date: Fri, 28 Jun 2019 18:28:28 +0700
Subject: [PATCH] Move comments to main check logic

---
 src/psbt.js    | 3 ++-
 ts_src/psbt.ts | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/psbt.js b/src/psbt.js
index 55e6ac9..2513fb9 100644
--- a/src/psbt.js
+++ b/src/psbt.js
@@ -7,7 +7,6 @@ const checkRedeemScript = (inputIndex, scriptPubKey, redeemScript) => {
   const redeemScriptOutput = payments.p2sh({
     redeem: { output: redeemScript },
   }).output;
-  // If a redeemScript is provided, the scriptPubKey must be for that redeemScript
   if (!scriptPubKey.equals(redeemScriptOutput)) {
     throw new Error(
       `Redeem script for input #${inputIndex} doesn't match the scriptPubKey in the prevout`,
@@ -62,10 +61,12 @@ class Psbt extends bip174_1.Psbt {
       if (input.redeemScript) {
         const prevoutIndex = unsignedTx.ins[inputIndex].index;
         const prevout = nonWitnessUtxoTx.outs[prevoutIndex];
+        // If a redeemScript is provided, the scriptPubKey must be for that redeemScript
         checkRedeemScript(inputIndex, prevout.script, input.redeemScript);
       }
     } else if (input.witnessUtxo) {
       if (input.redeemScript) {
+        // If a redeemScript is provided, the scriptPubKey must be for that redeemScript
         checkRedeemScript(
           inputIndex,
           input.witnessUtxo.script,
diff --git a/ts_src/psbt.ts b/ts_src/psbt.ts
index 7e5d13c..167f15f 100644
--- a/ts_src/psbt.ts
+++ b/ts_src/psbt.ts
@@ -12,7 +12,6 @@ const checkRedeemScript = (
     redeem: { output: redeemScript },
   }).output as Buffer;
 
-  // If a redeemScript is provided, the scriptPubKey must be for that redeemScript
   if (!scriptPubKey.equals(redeemScriptOutput)) {
     throw new Error(
       `Redeem script for input #${inputIndex} doesn't match the scriptPubKey in the prevout`,
@@ -70,10 +69,13 @@ export class Psbt extends PsbtBase {
       if (input.redeemScript) {
         const prevoutIndex = unsignedTx.ins[inputIndex].index;
         const prevout = nonWitnessUtxoTx.outs[prevoutIndex];
+
+        // If a redeemScript is provided, the scriptPubKey must be for that redeemScript
         checkRedeemScript(inputIndex, prevout.script, input.redeemScript);
       }
     } else if (input.witnessUtxo) {
       if (input.redeemScript) {
+        // If a redeemScript is provided, the scriptPubKey must be for that redeemScript
         checkRedeemScript(
           inputIndex,
           input.witnessUtxo.script,