Bitgen 0.14 has been released:
http://bitgen.org/The new release includes the following new features:
* Added support for transaction/script decode
* Added support for saving transactions/scripts
* Added support for executing transactions
As en example this transaction is used:
https://blockchain.info/tx/dd62dd9ce8d3a4484c23c904996194b0241690e2b11b02313647a68c1186b48dIn order to get the raw transaction data, "?format=hex" is added to the blockchain.info url:
https://blockchain.info/tx/dd62dd9ce8d3a4484c23c904996194b0241690e2b11b02313647a68c1186b48d?format=hexTo save the transaction in the bitgen format, the command "savetrans" is used with the hex string as a parameter on the command line:
$
bitgen savetrans 0200000001bbac9a005478c48888ecd95f9ce3dfd7e395ddcab61535ebed8dbfcbc8749d1500000
0006a47304402201304595735c8ab411e33df908eacbd1b27f600284a7d4bb772127ce324ee7788
022018af3831efc2f238938e2e1c77001937206b3bed2f6de264ab324f44ce23dbe80121036b5aa
4d546569bfd314235eda77235efe80c47b1666951ae009733512d8a3328feffffff02a0782d0000
0000001976a914311fbc254b0756e9407107139d413a5a5863024a88acf0689c00000000001976a
914c4f19c920b6112caa86b74462b0ff39d81ec30bc88ac20040700
(There should be no spaces or newlines in the hex data)
This will save the file transaction file "btc_DD62DD9CE8D3A4484C23C904996194B0241690E2B11B02313647A68C1186B48D.trans"
The file name will include the transaction hash.
Now this file can be used when decoding the transaction. The raw hex string can also be used, but it is easier to first save the transaction in a file when working with it.
To decode the transaction the following command is used:
$
bitgen decodetrans btc_DD62DD9CE8D3A4484C23C904996194B0241690E2B11B02313647A68C1186B48D.trans
This will give the following output:
Inputs: 1 Outputs: 2
14LTgYzjP9wbPVArV4WYheJW79RbUCEaAG 159D74C8CBBF8DEDEB3515B6CADD95E3D7DFE39C5FD9EC8888C47854009AACBB at 0
15Uk8PAvJPJwnzsMrVsfmpUDRSMF2NK8g5 2980000 satoshi = 0.02980000 btc
1JxLt4uK8Vbeod3VyXr5P7KPCC93Xh9BLs 10250480 satoshi = 0.10250480 btc
It is also possible to add the argument "verbose" at the end of the command line to get extended information:
Transaction data----------------------
Version : 2
Locktime : 459808 (block height)
Inputs: 1 Outputs: 2
--Input index 0
IHash : 159D74C8CBBF8DEDEB3515B6CADD95E3D7DFE39C5FD9EC8888C47854009AACBB at 0
Address: 14LTgYzjP9wbPVArV4WYheJW79RbUCEaAG
Type : P2PKH input
Seq : FFFFFFFE
IScript: 47304402201304595735C8AB411E33DF908EACBD1B27F600284A7D4BB772127CE324EE778802201
8AF3831EFC2F238938E2E1C77001937206B3BED2F6DE264AB324F44CE23DBE80121036B5AA4D546
569BFD314235EDA77235EFE80C47B1666951AE009733512D8A3328
Decoded script: DATA(304402201304595735C8AB411E33DF908EACBD1B27F600284A7D4BB772127CE324EE7788022018A
F3831EFC2F238938E2E1C77001937206B3BED2F6DE264AB324F44CE23DBE801) DATA(036B5AA4D546569BFD314235EDA77235EFE80C47B1666951AE009733512D8A3328)
--Output index 0
OScript: 76A914311FBC254B0756E9407107139D413A5A5863024A88AC
Decoded script: OP_DUP OP_HASH160 DATA(311FBC254B0756E9407107139D413A5A5863024A) OP_EQUALVERIFY OP_CHECKSIG
Script type: P2PKH output
15Uk8PAvJPJwnzsMrVsfmpUDRSMF2NK8g5 2980000 satoshi = 0.02980000 btc
--Output index 1
OScript: 76A914C4F19C920B6112CAA86B74462B0FF39D81EC30BC88AC
Decoded script: OP_DUP OP_HASH160 DATA(C4F19C920B6112CAA86B74462B0FF39D81EC30BC) OP_EQUALVERIFY OP_CHECKSIG
Script type: P2PKH output
1JxLt4uK8Vbeod3VyXr5P7KPCC93Xh9BLs 10250480 satoshi = 0.10250480 btc
It is also possible to "run" a transaction in order to verify if the scripts succeed, this is done with the "runtrans" command.
In order to run a transaction, the transaction(s) it depends on needs to be stored in file(s).
If the files are not found, an error is returned.
This command:
$
bitgen runtrans btc_DD62DD9CE8D3A4484C23C904996194B0241690E2B11B02313647A68C1186B48D.trans
Will give the following result:
InputHash: 159D74C8CBBF8DEDEB3515B6CADD95E3D7DFE39C5FD9EC8888C47854009AACBB Index: 0
Could not find locking transaction file, skipping verification for this input
Transaction FAILED
The specified transaction is missing, but it can be found using blockchain.info and the specified transaction hash:
https://blockchain.info/tx/159D74C8CBBF8DEDEB3515B6CADD95E3D7DFE39C5FD9EC8888C47854009AACBB?format=hexWhen this transaction has been saved as "btc_159D74C8CBBF8DEDEB3515B6CADD95E3D7DFE39C5FD9EC8888C47854009AACBB.trans" the "runtrans" command is successful:
$
bitgen runtrans btc_DD62DD9CE8D3A4484C23C904996194B0241690E2B11B02313647A68C1186B48D.trans
InputHash: 159D74C8CBBF8DEDEB3515B6CADD95E3D7DFE39C5FD9EC8888C47854009AACBB Index: 0
Got script from file
InAmount: 0.13235000
Unlock succeeded for script
Transaction OK, all inputs OK
Total in amount : 0.13235000
Total out amount: 0.13230480
Miner fee : 0.00004520
This will run the script and verify that it executes without errors.