MCPcopy
hub / github.com/jimmysong/programmingbitcoin / verify_input

Method verify_input

code-ch08/tx.py:201–219  ·  view source on GitHub ↗

Returns whether the input has a valid signature

(self, input_index)

Source from the content-addressed store, hash-verified

199 return int.from_bytes(h256, 'big')
200
201 def verify_input(self, input_index):
202 '''Returns whether the input has a valid signature'''
203 # get the relevant input
204 tx_in = self.tx_ins[input_index]
205 # grab the previous ScriptPubKey
206 script_pubkey = tx_in.script_pubkey(testnet=self.testnet)
207 # check to see if the ScriptPubkey is a p2sh using
208 # Script.is_p2sh_script_pubkey()
209 # the last cmd in a p2sh is the RedeemScript
210 # prepend the length of the RedeemScript using encode_varint
211 # parse the RedeemScript
212 # otherwise RedeemScript is None
213 # get the signature hash (z)
214 # pass the RedeemScript to the sig_hash method
215 z = self.sig_hash(input_index)
216 # combine the current ScriptSig and the previous ScriptPubKey
217 combined = tx_in.script_sig + script_pubkey
218 # evaluate the combined script
219 return combined.evaluate(z)
220
221 def verify(self):
222 '''Verify this transaction'''

Callers 2

verifyMethod · 0.95
sign_inputMethod · 0.95

Calls 3

sig_hashMethod · 0.95
script_pubkeyMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected