From 9a29855c16a620f5e318cb697f4e0d643a8ee1a3 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 13 Oct 2013 02:36:23 -0500 Subject: [PATCH] Convert inability to find input tx to a RuleError. This commit modifies the errors that result from missing expected input transactions to a RuleError. This allows the caller to detect a block was rejected due to a rule violation as opposed to an unexpected error. --- validate.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/validate.go b/validate.go index 352ce33c..2b51fbd0 100644 --- a/validate.go +++ b/validate.go @@ -347,18 +347,20 @@ func countP2SHSigOps(msgTx *btcwire.MsgTx, isCoinBaseTx bool, txStore TxStore) ( txInHash := &txIn.PreviousOutpoint.Hash originTx, exists := txStore[*txInHash] if !exists || originTx.Err != nil || originTx.Tx == nil { - return 0, fmt.Errorf("unable to find input transaction "+ + str := fmt.Sprintf("unable to find input transaction "+ "%v referenced from transaction %v", txInHash, txHash) + return 0, RuleError(str) } // Ensure the output index in the referenced transaction is // available. originTxIndex := txIn.PreviousOutpoint.Index if originTxIndex >= uint32(len(originTx.Tx.TxOut)) { - return 0, fmt.Errorf("out of bounds input index %d in "+ + str := fmt.Sprintf("out of bounds input index %d in "+ "transaction %v referenced from transaction %v", originTxIndex, txInHash, txHash) + return 0, RuleError(str) } // We're only interested in pay-to-script-hash types, so skip @@ -379,10 +381,11 @@ func countP2SHSigOps(msgTx *btcwire.MsgTx, isCoinBaseTx bool, txStore TxStore) ( lastSigOps := totalSigOps totalSigOps += numSigOps if totalSigOps < lastSigOps { - return 0, fmt.Errorf("the public key script from "+ + str := fmt.Sprintf("the public key script from "+ "output index %d in transaction %v contains "+ "too many signature operations - overflow", originTxIndex, txInHash) + return 0, RuleError(str) } }