-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sanity check for transactions standards (#146)
* add sanity check for transactions standards
- Loading branch information
1 parent
8579e3a
commit d19d19c
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/btcsuite/btcd/mempool" | ||
"github.com/btcsuite/btcd/txscript" | ||
"github.com/btcsuite/btcd/wire" | ||
) | ||
|
||
const ( | ||
minTransactionSize = 65 | ||
) | ||
|
||
// Perform subset of transactions standard tests: | ||
// - whether transaction is not considered dust | ||
// - whether transactions is not too small | ||
func CheckTransaction(tx *wire.MsgTx) error { | ||
if tx.SerializeSizeStripped() < minTransactionSize { | ||
return fmt.Errorf("transaction is too small. Tx size: %d, min size: %d", tx.SerializeSizeStripped(), minTransactionSize) | ||
} | ||
|
||
numOpReturns := 0 | ||
for _, txOut := range tx.TxOut { | ||
scriptClass := txscript.GetScriptClass(txOut.PkScript) | ||
if scriptClass == txscript.NullDataTy { | ||
numOpReturns++ | ||
} else if mempool.IsDust(txOut, mempool.DefaultMinRelayTxFee) { | ||
return fmt.Errorf("transaction output is dust. Value: %d", txOut.Value) | ||
} | ||
} | ||
|
||
if numOpReturns > 1 { | ||
return fmt.Errorf("transaction has more than one op_return output") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters