2

I try to create a custom p2sh script using the btcruby gem.

Here is the code I used to generate my script:

def self.create_script
    myscript=BTC::Script.new
    myscript<<BTC::Script::OP_IF
    myscript.append("026edc650b929056b58e4247274a02e3f1665dd10fb1da2575ebae27447f24363e")
    myscript<<BTC::Script::OP_CHECKSIGVERIFY
    myscript<<BTC::Script::OP_ELSE
    myscript.append("f1887875")
    myscript<<BTC::Script::OP_CHECKLOCKTIMEVERIFY
    myscript<<BTC::Script::OP_DROP
    myscript<<BTC::Script::OP_ENDIF
    myscript.append("026edc650b929056b58e4247274a02e3f1665dd10fb1da2575ebae27447f24363e")
    myscript<<BTC::Script::OP_CHECKSIG
end

here is how I generate the transaction to spend from this script (output_script is the script generated by create_script):

def self.create_transaction(output_script, private_key)
    tx = BTC::Transaction.new

    tx.add_input(BTC::TransactionInput.new(previous_id: 'baacd6ca42f27d707795b5e7a8a346de57a9eb2c333cbf404106f612b3504499',
                                  previous_index: 0))

    tx.add_output(BTC::TransactionOutput.new(value: 80_000, script: PublicKeyAddress.parse("14EEEdn7fVBCYawkEAdcjqnKbxvejoZAT9").script))

    key = BTC::Key.new(wif: private_key)
    hashtype = BTC::SIGHASH_ALL
    sighash = tx.signature_hash(input_index: 0,
                            output_script: output_script.p2sh_script,
                            hash_type: hashtype)
    tx.inputs[0].signature_script = BTC::Script.new
    tx.inputs[0].signature_script.append(key.ecdsa_signature(sighash) + BTC::WireFormat.encode_uint8(hashtype))
    tx.inputs[0].signature_script.append_script(input_script)
    tx
end

When I try to execute this transaction I have the following error:

64: scriptsig-not-pushonly

What does this error mean? Is there a mistake in my logic fore creating the spending transaction?

0 Answers0