bitcoind – Error required-script-verify-flag-flag-failed (a signature is found in scriptCode)

I found some questions with specific error, but did not find the appropriate answer. So here I am.

I'm working on regtest in a Python library that creates transactions, then uses JSON-RPC to broadcast it on the bitcoind server I have locally.

Here is the test:

  1. Initialize a new regtest blockchain
  2. Generate 101 blocks
  3. Get the address that generates these blocks with the respective private key. Call him Bob.

Then I have Steve, who wants to create a script with an absolute locktime (height of 1000 blocks) and receive 10 bitcoins from Bob.

  1. Steve has a private key and an address. I'm using this address to create a script

    redeem_script = Script ([1000,'OP_CHECKLOCKTIMEVERIFY','OP_DROP', 'OP_DUP', 'OP_HASH160', steve_address.to_hash160(),'OP_EQUALVERIFY', 'OP_CHECKSIG'])

  2. I get the new P2SH address from the script above

  3. With the listunspent, I'm getting a Bob UTXO with the link txid and vout

  4. I create a TXInput with the above (txin = TxInput (txid, vout))

  5. Then I create a TXOutput with the amount I want to send and the redeem_script (txout = TxOutput (amount: 0.001, redeem_script.to_p2sh_script_pub_key ())

  6. I sign the entry with Bob's address (sig = bob_private_key.sign_input (tx, vout, bob_address.to_script_pub_key ()))

  7. And add the script signature to TXInput (txin.script_sig = Script ( [sig, pk] ))

Then I released the signed raw transaction to bitcoind, but I get the following error:

& # 39; mandatory-script-verify-flag-flag-failed (the signature is in scriptCode) (code 16) & # 39;

The raw transaction and the decoded transaction are:

02000000010006fc2306a9089e5e45b58ce0386845c139aeec02c6361519ef5afed3a61fc2000000006a47304402202a740d313de85fda558b12951508a73d9512c807d50d9ffab8a59a03ba2423c802200f1199877e3861a24a127f79436156978519c092f8883a9053babcb5bbdda43a012103ef124954caa832374ff31e5ae6c46736489a72b154ab14754fb3bf39f4a6c3f9ffffffff01a0373f250000000017a914d924aa439960faac94c4d74a81e54331ce92b9c58700000000

{
"txid": "bba3f9881381999c668078af17b41aff23a4adaeed5656be5bc8112a4631ab61",
"hash": "bba3f9881381999c668078af17b41aff23a4adaeed5656be5bc8112a4631ab61",
"version 2,
"size": 189,
"vsize": 189,
"weight": 756,
"closing time": 0,
"wine": [
    {
      "txid": "c21fa6d3fe5aef191536c602ecae39c1456838e08cb5455e9e08a90623fc0600",
      "vout": 0,
      "scriptSig": {
        "asm": "304402202a740d313de85fda558b12951508a73d9512c807d50d9ffab8a59a03ba2423c802200f1199877e3861a24a127f79436156978519c092f8883a9053babcb5bbdda43a[ALL] 03ef124954caa832374ff31e5ae6c46736489a72b154ab14754fb3bf39f4a6c3f9 ",
7th anniversary of death
}
"sequence": 4294967295
}
],
"Vout": [
    {
      "value": 6.24900000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 d924aa439960faac94c4d74a81e54331ce92b9c5 OP_EQUAL",
        "hex": "a914d924aa439960faac94c4d74a81e54331ce92b9c587",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2ND3NYSrRqp742acVwYGSDSxbsm5Ce8wbXe"
        ]
      }
}
]}

An idea? I am a novice and I may have forgotten something important or trivial.