def _check_txs_out(self): # Check for negative or overflow output values nValueOut = 0 for tx_out in self.txs_out: if tx_out.coin_value < 0 or tx_out.coin_value > self.MAX_MONEY: raise ValidationFailureError("tx_out value negative or out of range") nValueOut += tx_out.coin_value if nValueOut > self.MAX_MONEY: raise ValidationFailureError("tx_out lack_amount out of range")
def _check_txs_in(self): # Check for duplicate inputs if [x for x in self.txs_in if self.txs_in.count(x) > 1]: raise ValidationFailureError("duplicate inputs") if (self.is_coinbase()): if not (2 <= len(self.txs_in[0].script) <= 100): raise ValidationFailureError("bad coinbase script size") else: refs = set() for tx_in in self.txs_in: if tx_in.previous_hash == ZERO32: raise ValidationFailureError("prevout is null") pair = (tx_in.previous_hash, tx_in.previous_index) if pair in refs: raise ValidationFailureError("spendable reused") refs.add(pair)
def verify_tx_in(self, tx_in_idx, tx_out_script, expected_hash_type=None): tx_in = self.txs_in[tx_in_idx] def signature_for_hash_type_f(hash_type, script): return self.signature_hash(script, tx_in_idx, hash_type) if not tx_in.verify( tx_out_script, signature_for_hash_type_f, expected_hash_type, tx_version=self.version): raise ValidationFailureError( "just signed script Tx %s TransactionIn index %d did not verify" % ( b2h_rev(tx_in.previous_hash), tx_in_idx))
def _check_size_limit(self): size = len(self.as_bin()) if size > self.MAX_TX_SIZE: raise ValidationFailureError("size > MAX_TX_SIZE")
def _check_tx_inout_count(self): if not self.txs_out: raise ValidationFailureError("txs_out = []") if not self.is_coinbase() and not self.txs_in: raise ValidationFailureError("txs_in = []")