I am reading Programming Bitcoin (chapter 7 exercise 5) and I have created a 2 inputs 1 output transaction on testnet which I have signed and it now verifies as true. When I go broadcast the transaction on "https://blockstream.info/testnet/tx/push" I get this error:
sendrawtransaction RPC error: {"code":-26,"message":"mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)"}
Code:
target_address = 'mrXqfcAxxs75ertpHpwKsSmgSs4UPc8t1N'
target_amount = 0.00007370-0.00001000
prev_tx_0 = bytes.fromhex('17782270d1bfdcf3956efbfa49e90b74a2797819b09abd0460cffc69557f219c')
prev_tx_1 = bytes.fromhex('803f028f53b4a784bfb0b27eb05ef908e6a661fdfac791bc1dcde15d6325365b')
##
tx_ins = []
tx_ins.append(TxIn(prev_tx_0,1))
tx_ins.append(TxIn(prev_tx_1,0))
tx_outs = []
h160 = decode_base58(target_address)
script_pubkey = p2pkh_script(h160)
target_satoshis = int((target_amount)*100000000)
tx_outs.append(TxOut(target_satoshis,script_pubkey))
tx_obj = Tx(2,tx_ins, tx_outs, 0, testnet = True)
secret = secret
priv = PrivateKey(secret=secret)
print(tx_obj.sign_input(0,priv))
print(tx_obj.sign_input(1,priv))
print(tx_obj)
tx_obj.sign_input(0,priv)
tx_obj.sign_input(1,priv)
tx_obj.serialize().hex()
Transaction serialization in hex:
02000000029c217f5569fccf6004bd9ab0197879a2740be949fafb6e95f3dcbfd170227817010000006a4730440220697d80930be591d44aed5f795be9dba187d2a6dc780b389ba20ac98ebf31ae3c02204cc1053006dfc1e315229345ae5e150783da436d78f816e8356f4b256533dfd1012103622610a08b9bde7602ffee1ca9da58f74b7ad4b1c2006b2cc7647fd97c75245dffffffff5b3625635de1cd1dbc91c7fafd61a6e608f95eb07eb2b0bf84a7b4538f023f80000000006b483045022100c74e026debb964246d7915bb95ba0ef0b8b4c96200d6d26cebe7273b1ca68cf7022059cefc86bcbfcc4724683f017f9ebfdca762e093bb2f2327808b2e1e6477a0fc012103622610a08b9bde7602ffee1ca9da58f74b7ad4b1c2006b2cc7647fd97c75245dffffffff01e2180000000000001976a91478d44438005bc3000538128db0d02e832b1adecf88ac00000000