Hi,
Your code looks correct. You can use the command:
echo TXDATA | sx validtx
to check the correctness of the tx (but I'm not sure if the reported
erros are always correct - I need to investigate that).
You can also examine the data using:
echo TXDATA | sx showtx
your sign code is correct, and the other code looks good. If you give me
the hex I can see if I spot anything.
Here's some code for constructing transactions:
https://github.com/spesmilo/sx/blob/master/src/wallet.cpp
(see line 361 to 521)
https://github.com/darkwallet/python-obelisk/blob/master/examples/mktx.py
https://github.com/darkwallet/python-obelisk/blob/master/obelisk/bitcoin.py
(see line 998)
On 08/12/13 20:50, Chang Lan wrote:
> Hi there,
>
> I tried making a valid transaction using libbitcoin, but it seems that
> the transaction turns out to be invalid. Below is the code snippet that
> I used to create a transaction. Can anyone point out if I did it wrong?
> Thanks!
>
> void add_input(transaction_type& tx, const output_point& output)
> {
> transaction_input_type input;
> output_point& prevout = input.previous_output;
> prevout = output;
> input.sequence = 4294967295;
> tx.inputs.push_back(input);
> }
>
>
> bool sign(transaction_type& tx, size_t input_index, const
> elliptic_curve_key& key, const script_type& script_code)
> {
> transaction_input_type& input = tx.inputs[input_index];
> const data_chunk public_key = key.public_key();
> if (public_key.empty())
> {
> std::cerr << "internal error getting public key" << std::endl;
> return false;
> }
> hash_digest tx_hash = script_type::generate_signature_hash(tx,
> input_index, script_code, 1);
> if (tx_hash == null_hash)
> {
> std::cerr << "error generating signature hash" << std::endl;
> return false;
> }
> data_chunk signature = key.sign(tx_hash);
> signature.push_back(0x01);
>
> script_type input_script;
> input_script.push_operation({opcode::special, signature});
> std::cout << key.public_key().size() << std::endl;
> input_script.push_operation({opcode::special, key.public_key()});
> tx.inputs[input_index].script = input_script;
>
> return true;
> }
>
>
> bool create_channel_tx(transaction_type& tx, const data_chunk&
> payee_public_key, const data_chunk& payer_public_key, uint64_t value)
> {
> /* … */
> */* called add_input() for each input */*
> // output 1
> script_type out_script = build_contract_script(acc.key.public_key(),
> remote_public_key);
> transaction_output_type output;
> output.value = value;
> output.script = out_script;
> tx.outputs.push_back(output);
>
> // output 2
> payment_address payaddr;
> set_public_key(payaddr, acc.key.public_key());
> script_type back_script = build_pubkey_hash_script(payaddr.hash());
> transaction_output_type back_output;
> back_output.value = collected_value - value;
> back_output.script = back_script;
> tx.outputs.push_back(back_output);
>
> // sign each input
> for (size_t i = 0; i < tx.inputs.size(); ++i)
> {
> sign(tx, i, acc.key, back_script);
> }
> return true;
> }
>
>
> Chang
>
>
>
> _______________________________________________
> Libbitcoin mailing list
> Libbitcoin@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>