Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: victorkimba17 on November 08, 2017, 01:58:01 PM



Title: main() in bitcoin-tx.cpp
Post by: victorkimba17 on November 08, 2017, 01:58:01 PM
I notice that is a main() function in bitcoin-tx.cpp. This main() is not the main function of bitcoin core. Because the main function is in bitcoind.cpp

So why there is a main() in bitcoin-tx.cpp ?


Title: Re: main() in bitcoin-tx.cpp
Post by: achow101 on November 08, 2017, 03:12:21 PM
There is a separate binary called bitcoin-tx which lets you do some transaction specific things without needing to run the full Bitcoin Core. It needs a main function for that binary to work.

Likewise, there are main functions in bitcoin-cli.cpp and qt/bitcoin.cpp as those are for separate binaries that need main functions too (bitcoin-cli and bitcoin-qt respectively).


Title: Re: main() in bitcoin-tx.cpp
Post by: victorkimba17 on November 09, 2017, 12:50:30 AM
thank you. should have seen that


Title: Re: main() in bitcoin-tx.cpp
Post by: victorkimba17 on November 10, 2017, 02:52:11 PM
There is a separate binary called bitcoin-tx which lets you do some transaction specific things without needing to run the full Bitcoin Core. It needs a main function for that binary to work.

It looks like bitcoin-tx.cpp is never built into the bincoind binary of Bitcoin core, isn't  it?


Title: Re: main() in bitcoin-tx.cpp
Post by: achow101 on November 12, 2017, 02:05:47 AM
It looks like bitcoin-tx.cpp is never built into the bincoind binary of Bitcoin core, isn't  it?
No, it is not. bitcoin-tx.cpp is for bitcoin-tx, a completely separate binary. It only exists to provide the separate bitcoin-tx binary.


Title: Re: main() in bitcoin-tx.cpp
Post by: victorkimba17 on November 12, 2017, 02:22:41 AM
Thank you. Now I use the bitcoin-tx binary.

bitcoin-tx -create in=0fb9df5614be8b33be0434ce4062750d83f1b7ce05cc1296604f82eb9abf802b:0 outscript=0.00159999:"DUP HASH160 0x14 0x6793a38f79b8cd51dbb6face6dc75a4af5c1bf29 EQUALVERIFY CHECKSIG"

and got the return value
02000000012b80bf9aeb824f609612cc05ceb7f1830d756240ce3404be338bbe1456dfb90f00000 00000ffffffff01ff700200000000001976a9146793a38f
79b8cd51dbb6face6dc75a4af5c1bf2988ac00000000

i understand the outscript format. 0.00159999 is the value to be spent. What about the in format ? what is 0fb9df56..... ? It is previous tx or scriptSig?


Title: Re: main() in bitcoin-tx.cpp
Post by: achow101 on November 12, 2017, 05:14:09 AM
What about the in format ? what is 0fb9df56..... ? It is previous tx or scriptSig?
Read https://bitcoin.org/en/developer-reference#raw-transaction-format


Title: Re: main() in bitcoin-tx.cpp
Post by: victorkimba17 on November 12, 2017, 01:40:31 PM
What about the in format ? what is 0fb9df56..... ? It is previous tx or scriptSig?
Read https://bitcoin.org/en/developer-reference#raw-transaction-format

I read the link about raw transaction format. It says raw transaction has version, tx_in count, Tx_in, TX_out count, Tx_out and lock time.

I can't relate this format to the hex value in the input part.


Title: Re: main() in bitcoin-tx.cpp
Post by: byteball on November 12, 2017, 06:14:28 PM
Code:
in=0fb9df5614be8b33be0434ce4062750d83f1b7ce05cc1296604f82eb9abf802b:0

TxIn (transaction input) structure consists of prevOut, scriptSig and sequence.
In bitcoind code prevOut has type COutPoint which consists of txid and output number.
So the "in=" you quoted means the transaction will spend the output with index 0 from transaction with id 0fb9df5614be8b33be0434ce4062750d83f1b7ce05cc1296604f82eb9abf802b, if the signature in scriptSig will be correct for
the corresponding TxOut's pk_script.

I guess the signature is generated from a key in your wallet file, if it can sign this input.


Title: Re: main() in bitcoin-tx.cpp
Post by: victorkimba17 on November 13, 2017, 05:19:18 AM
So in "bitcoin-tx -create in=0fb9df5614be8b33be0434ce4062750d83f1b7ce05cc1296604f82eb9abf802b:0 ...."
The 0fb9df5614be8b33be0434ce4062750d83f1b7ce05cc1296604f82eb9abf802b is the txid.

Thank you.

We can use the command "bitcoin-tx -create --help"  to see the explanation of the options in the command.