:: Re: [Libbitcoin] How to fill in scr…
Page principale
Supprimer ce message
Répondre à ce message
Auteur: Amir Taaki
Date:  
À: libbitcoin
Sujet: Re: [Libbitcoin] How to fill in scriptSig
There's no public Obelisk server, and we mostly develop against mainnet
so some things may not work (but generally they should).

However if you want to maintain a testnet server, we can have it on the
list of public servers.

On 09/12/13 05:38, Chang Lan wrote:
> Ah I see. I switched to a public mainnet obelisk server and the error
> disappeared. I was wondering if there is any issue with the testnet
> support (I have to use testnet for the project I am doing). Is there any
> public obelisk server for testnet? Then I can test if it’s my obelisk
> server’s problem or not.
>
> Best,
> Chang
>
> On Sunday, December 8, 2013 at 8:34 PM, Amir Taaki wrote:
>
>> Firstly that error should disappear if you use the git version of sx.
>> The Obelisk server format was changed recently and sx was not updated
>> (now fixed in git).
>>
>> The public key in that transaction (which starts with 03, not 04) is a
>> compressed public key. Both public keys are valid.
>>
>> Have you tried creating a transaction on Bitcoin mainnet?
>>
>> Were you successful with this tutorial on testnet?
>> http://sx.dyne.org/offlinetx.html
>> If not, then try mainnet.
>>
>> Then if you are successful with that tutorial, try constructing the same
>> transaction as your code using only command line tools.
>>
>> If that works, then try your code (without signing). Is it the same
>> transaction as when you used the command line tools?
>>
>> Try signing the transaction using command line tools. Note: the
>> script_code which you sign for the inputs should be the address for the
>> previous output of that input (which you are doing correctly in your
>> code by getting the address of your key).
>>
>> If you get the command line signing working then it should be easy to
>> identify the problem in your code. If you can't get the command line
>> signing working, then try performing the entire steps for normal mainnet
>> (not testnet) transactions.
>>
>> Use this to push non standard transactions to the blockchain instead of
>> normal broadcast to get around the bitcoind relay rules:
>>
>> http://eligius.st/~wizkid057/newstats/pushtxn.php
>>
>> On 09/12/13 02:26, Chang Lan wrote:
>>> Same result when I tried with smaller amount of testcoins.
>>>
>>> I noticed that the input script might wrong, but I couldn't use validtx,
>>> since I always got "terminate called after throwing an instance of
>>> 'libbitcoin::end_of_stream’”.
>>>
>>> For example, for this transaction:
>>> 010000000188fd0fc89dcd3f405c151ca59e97995cf85749b7ab600cf52b62bcf83405d915010000008b4830450220408bd8359dfe03a55f881f99b25a28cc691ccb4e29c825947e835c4a03f9bda20221008000ba23c20d19225a3e6f4f7351b0fbb9f7fc2bcb110605653d36ea8ac12a34014104b6d4cb502f6b016e310293dfe16336543f69d0b9afbf1f65f8eb7210753e925ef2e72af93ddf9ab626251a589246107a7524faa00dfc07bc41026c082b07714fffffffff020a0000000000000087524104b6d4cb502f6b016e310293dfe16336543f69d0b9afbf1f65f8eb7210753e925ef2e72af93ddf9ab626251a589246107a7524faa00dfc07bc41026c082b07714f4104b6d4cb502f6b016e310293dfe16336543f69d0b9afbf1f65f8eb7210753e925ef2e72af93ddf9ab626251a589246107a7524faa00dfc07bc41026c082b07714f52aef66c7c4d000000001976a9146afaed9a226fc9e1550278b739b278a9590fccba88ac00000000
>>>
>>> showtx shows:
>>> Input:
>>> previous output:
>>> 15d90534f8bc622bf50c60abb74957f85c99979ea51c155c403fcd9dc80ffd88:1
>>> script: [
>>> 30450220408bd8359dfe03a55f881f99b25a28cc691ccb4e29c825947e835c4a03f9bda20221008000ba23c20d19225a3e6f4f7351b0fbb9f7fc2bcb110605653d36ea8ac12a3401
>>> ] [
>>> 04b6d4cb502f6b016e310293dfe16336543f69d0b9afbf1f65f8eb7210753e925ef2e72af93ddf9ab626251a589246107a7524faa00dfc07bc41026c082b07714f
>>> ]
>>>
>>> However, when I retrieve an arbitrary transaction from network:
>>> $ sx fetch-transaction
>>> 15d90534f8bc622bf50c60abb74957f85c99979ea51c155c403fcd9dc80ffd88 | sx
>>> showtx
>>>
>>> hash: 15d90534f8bc622bf50c60abb74957f85c99979ea51c155c403fcd9dc80ffd88
>>> version: 1
>>> locktime: 0
>>> Input:
>>> previous output:
>>> 36d162f6292c62d9d60cd9ea152aaddb94de0301f5dbe0ff3f055a35bc4ee54e:0
>>> script: [
>>> 3046022100c6fd593068adaa263aa0b98af6b83fd29cf15df7cdeb7d31dc7b44c9c3b4307a022100a50990f3c60df0d3ee8d11d93d39ee07ec4623880ac7e191c9e680562bcfff6f01
>>> ] [ 03cc32d912091b053d34aa12d0a272eb40a1ff9a0309ddcb32a98f39af74af6924 ]
>>>
>>> Why its public key (second part of the script) is shorter than mine?
>>>
>>> (My
>>> code:
>>> https://github.com/changlan/tor-incentive/blob/master/main.cpp#L87)
>>>
>>> Best,
>>> Chang
>>>
>>> On Sunday, December 8, 2013 at 5:17 PM, Amir Taaki wrote:
>>>
>>>> aha ok. I would just use the normal main net. I've got mine built for
>>>> mainnet which is why it interprets your addresses as normal bitcoin
>>>> addresses.
>>>>
>>>> I'll look into that message. have you tried your code with a tiny amount
>>>> of BTC? don't forget to put a fee too.
>>>>
>>>> On 09/12/13 00:34, Chang Lan wrote:
>>>>> The “address” in both input and the second output
>>>>> is mnRQG7kRAapsriWL8hKHRWpw6AgSyWWmn4 in my machine. I have no idea why
>>>>> we saw difference. I built the libbitcoin with ‘—enable-testnet’.
>>>>>
>>>>> I tried to make the transaction using ‘mktx’. Here is we I got:
>>>>>
>>>>> $ sx mktx txfile.tx --input
>>>>> cb502ebca60cfe43bf0cd1c91a50ab07590eb8d35c3b2d29306693dfa36047d0:0
>>>>> --output mnRQG7kRAapsriWL8hKHRWpw6AgSyWWmn4:309999990
>>>>>
>>>>> Added input
>>>>> cb502ebca60cfe43bf0cd1c91a50ab07590eb8d35c3b2d29306693dfa36047d0:0
>>>>> mktx: Unsupported address type.
>>>>>
>>>>> mnRQG7kRAapsriWL8hKHRWpw6AgSyWWmn4 is the address I have:
>>>>> https://blockexplorer.com/testnet/address/mnRQG7kRAapsriWL8hKHRWpw6AgSyWWmn4
>>>>>
>>>>> Best,
>>>>> Chang
>>>>>
>>>>> On Sunday, December 8, 2013 at 1:21 PM, Amir Taaki wrote:
>>>>>
>>>>>> Are you able to construct the tx using the command line tools sx?
>>>>>>
>>>>>> Then you can port the code as you use it piece by piece into your own
>>>>>> application.
>>>>>>
>>>>>> You need to update sx from the git repository (that should be fixed).
>>>>>> Here's what I see:
>>>>>>
>>>>>> hash: 43919afd984bf86a421bc5d32ddc25bbaad996d6429a0e6a81b6d6059aa86db2
>>>>>> version: 1
>>>>>> locktime: 0
>>>>>> Input:
>>>>>> previous output:
>>>>>> cb502ebca60cfe43bf0cd1c91a50ab07590eb8d35c3b2d29306693dfa36047d0:0
>>>>>> script: [
>>>>>> 3045022100b4760147383d74cc68c1004755d3e210949370358309d5d64e81f3ec0e54ba470220540d21755a68946f19eaebb1b7b3c5649ee5825ac7363bdededcf445f2912a3001
>>>>>> ] [
>>>>>> 04a0160a564377fc9af6100827cf0726bf794aa57c6b908731b0cd6057da8a8ae01597c54fdce5b0b58cbd87de98821c71c638724dac5c93c7539d7f3351c20a5f
>>>>>> ]
>>>>>> sequence: 4294967295
>>>>>> address: 17uSy4fSMZPd5c2iR8LubbccEB5jyJi9rc
>>>>>> Output:
>>>>>> value: 10
>>>>>> script: 2 [
>>>>>> 04a0160a564377fc9af6100827cf0726bf794aa57c6b908731b0cd6057da8a8ae01597c54fdce5b0b58cbd87de98821c71c638724dac5c93c7539d7f3351c20a5f
>>>>>> ] [
>>>>>> 04a0160a564377fc9af6100827cf0726bf794aa57c6b908731b0cd6057da8a8ae01597c54fdce5b0b58cbd87de98821c71c638724dac5c93c7539d7f3351c20a5f
>>>>>> ] 2 checkmultisig
>>>>>> Output:
>>>>>> value: 309999990
>>>>>> script: dup hash160 [ 4bbc0f7fff6b9135e3bf1a472b464ec127947cfb ]
>>>>>> equalverify checksig
>>>>>> address: 17uSy4fSMZPd5c2iR8LubbccEB5jyJi9rc
>>>>>>
>>>>>>
>>>>>> On 08/12/13 21:18, Chang Lan wrote:
>>>>>>> Thanks Amir!
>>>>>>>
>>>>>>> I am using testnet so the TXDATA is for testnet:
>>>>>>>
>>>>>>> 0100000001d04760a3df936630292d3b5cd3b80e5907ab501ac9d10cbf43fe0ca6bc2e50cb000000008b483045022100b4760147383d74cc68c1004755d3e210949370358309d5d64e81f3ec0e54ba470220540d21755a68946f19eaebb1b7b3c5649ee5825ac7363bdededcf445f2912a30014104a0160a564377fc9af6100827cf0726bf794aa57c6b908731b0cd6057da8a8ae01597c54fdce5b0b58cbd87de98821c71c638724dac5c93c7539d7f3351c20a5fffffffff020a0000000000000087524104a0160a564377fc9af6100827cf0726bf794aa57c6b908731b0cd6057da8a8ae01597c54fdce5b0b58cbd87de98821c71c638724dac5c93c7539d7f3351c20a5f4104a0160a564377fc9af6100827cf0726bf794aa57c6b908731b0cd6057da8a8ae01597c54fdce5b0b58cbd87de98821c71c638724dac5c93c7539d7f3351c20a5f52ae76397a12000000001976a9144bbc0f7fff6b9135e3bf1a472b464ec127947cfb88ac00000000
>>>>>>>
>>>>>>> sx showtx worked well but when I used the command
>>>>>>>
>>>>>>> echo TXDATA | sx validsx
>>>>>>>
>>>>>>> I got
>>>>>>>
>>>>>>> terminate called after throwing an instance of
>>>>>>> 'libbitcoin::end_of_stream’
>>>>>>>
>>>>>>> Best,
>>>>>>> Chang
>>>>>>>
>>>>>>> On Sunday, December 8, 2013 at 12:59 PM, Amir Taaki wrote:
>>>>>>>
>>>>>>>> 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@??? <mailto:Libbitcoin@lists.dyne.org>
>>>>>>>>> <mailto:Libbitcoin@lists.dyne.org>
>>>>>>>>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>>>>>>>> _______________________________________________
>>>>>>>> Libbitcoin mailing list
>>>>>>>> Libbitcoin@??? <mailto:Libbitcoin@lists.dyne.org>
>>>>>>>> <mailto:Libbitcoin@lists.dyne.org>
>>>>>>>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Libbitcoin mailing list
>>>>> Libbitcoin@??? <mailto:Libbitcoin@lists.dyne.org>
>>>>> <mailto:Libbitcoin@lists.dyne.org>
>>>>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>>>> _______________________________________________
>>>> Libbitcoin mailing list
>>>> Libbitcoin@??? <mailto:Libbitcoin@lists.dyne.org>
>>>> <mailto:Libbitcoin@lists.dyne.org>
>>>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>>>
>>>
>>>
>>> _______________________________________________
>>> Libbitcoin mailing list
>>> Libbitcoin@??? <mailto:Libbitcoin@lists.dyne.org>
>>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>> _______________________________________________
>> Libbitcoin mailing list
>> Libbitcoin@??? <mailto:Libbitcoin@lists.dyne.org>
>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>
>
>
> _______________________________________________
> Libbitcoin mailing list
> Libbitcoin@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/libbitcoin
>