jimmysong / programmingbitcoin

Repository for the book
Other
1.75k stars 656 forks source link

Error on Ch.6 Example - "Coding Script Evaluation" pg. 115 #247

Open vvronskyFX opened 2 years ago

vvronskyFX commented 2 years ago

The desired outcome should print "True": image

The error I am receiving is this: image

It's getting a "NotImplementedError: "

I've completed all other exercises to close out the chapter and this error still persists. Am I missing something here?

Yuji-Kakeya commented 2 years ago

@vvronskyFX Have you completed the exercise No.2? If you edited op.py directly, you might want to try restarting the kernel, as the cache may be the cause.

salmonberry7 commented 1 month ago

You are using an op.py in which the op_checksig function is not implemented. Then when you correct that error (eg with your own code for op_checksig, or taking it from a later chapter) then run it again within the same interactive prompt session, the error still occurs due to caching of the old op.py file. Exit from the interactive prompt and start a new one and it should work. Or just take the code and put it in a Python script test1.py and run it via python3 test1.py :

from script import Script
z = 0x7c076ff316692a3d7eb3c3bb0f8b1488cf72e1afcd929e29307032997a838a3d
sec = bytes.fromhex('04887387e452b8eacc4acfde10d9aaf7f6d9a0f975aabb10d006e4da568744d06c61de6d95231cd89026e286df3b6ae4a894a3378e393e93a0f45b666329a0ae34')
sig = bytes.fromhex('3045022000eff69ef2b1bd93a66ed5219add4fb51e11a840f404876325a1e8ffe0529a2c022100c7207fee197d27c618aea621406f6bf5ef6fca38681d82b2f06fddbdce6feab601')
script_pubkey = Script([sec, 0xac])
script_sig = Script([sig])
combined_script = script_sig + script_pubkey
print(combined_script.evaluate(z))