MCPcopy
hub / github.com/petertodd/python-bitcoinlib / CheckTransaction

Function CheckTransaction

bitcoin/core/__init__.py:768–810  ·  view source on GitHub ↗

Basic transaction checks that don't depend on any context. Raises CheckTransactionError

(tx)

Source from the content-addressed store, hash-verified

766 pass
767
768def CheckTransaction(tx):
769 """Basic transaction checks that don't depend on any context.
770
771 Raises CheckTransactionError
772 """
773 global coreparams
774
775 if not tx.vin:
776 raise CheckTransactionError("CheckTransaction() : vin empty")
777 if not tx.vout:
778 raise CheckTransactionError("CheckTransaction() : vout empty")
779
780 # Size limits
781 base_tx = CTransaction(tx.vin, tx.vout, tx.nLockTime, tx.nVersion)
782 if len(base_tx.serialize()) > MAX_BLOCK_SIZE:
783 raise CheckTransactionError("CheckTransaction() : size limits failed")
784
785 # Check for negative or overflow output values
786 nValueOut = 0
787 for txout in tx.vout:
788 if txout.nValue < 0:
789 raise CheckTransactionError("CheckTransaction() : txout.nValue negative")
790 if txout.nValue > coreparams.MAX_MONEY:
791 raise CheckTransactionError("CheckTransaction() : txout.nValue too high")
792 nValueOut += txout.nValue
793 if not MoneyRange(nValueOut):
794 raise CheckTransactionError("CheckTransaction() : txout total out of range")
795
796 # Check for duplicate inputs
797 vin_outpoints = set()
798 for txin in tx.vin:
799 if txin.prevout in vin_outpoints:
800 raise CheckTransactionError("CheckTransaction() : duplicate inputs")
801 vin_outpoints.add(txin.prevout)
802
803 if tx.is_coinbase():
804 if not (2 <= len(tx.vin[0].scriptSig) <= 100):
805 raise CheckTransactionError("CheckTransaction() : coinbase script size")
806
807 else:
808 for txin in tx.vin:
809 if txin.prevout.is_null():
810 raise CheckTransactionError("CheckTransaction() : prevout is null")
811
812
813

Callers 3

CheckBlockFunction · 0.85
test_tx_validMethod · 0.85
test_tx_invalidMethod · 0.85

Calls 6

CTransactionClass · 0.85
MoneyRangeFunction · 0.85
is_coinbaseMethod · 0.80
serializeMethod · 0.45
is_nullMethod · 0.45

Tested by 2

test_tx_validMethod · 0.68
test_tx_invalidMethod · 0.68