Author

Topic: 0.7 gettransaction/getblock RPC calls (Read 7286 times)

newbie
Activity: 40
Merit: 0
April 05, 2013, 08:47:17 AM
#12
Hm. By comparing this pull request

https://github.com/bitcoin/bitcoin/pull/886/files

and comparing it to the code here

https://github.com/bitcoin/bitcoin/blob/master/src/bitcoinrps.cpp
https://github.com/bitcoin/bitcoin/blob/master/src/rpcblockchain.cpp

it seems like it is NOT possible today. Oh well. I will do it on transaction-by-transaction basis. (I wanted to use Blockchain.info API but they are mysteriously missing some blocks from their API results. Oh well.)
newbie
Activity: 40
Merit: 0
April 05, 2013, 08:37:52 AM
#11
Hello.

I stumbled on this old thread while researching about bitcoind.

Is the decomposition with getblock possible in the newest (0.8.1) bitcoind? And if it is, how? (Your options return just errors.)
legendary
Activity: 980
Merit: 1003
I'm not just any shaman, I'm a Sha256man
July 25, 2012, 11:45:55 PM
#10
Finally! I can write my own Bitcoind to Mysql db systems with little effort Smiley
legendary
Activity: 1652
Merit: 2311
Chief Scientist
June 27, 2012, 12:45:07 PM
#9
Thank you Devs, this is great!
Is there some more information on this batch mode available? Would it also be possible to request in one call information about many unrelated TXs (because you mention "all transactions in a block"...)?

See "Batch Mode" in the JSON 2.0 spec: http://www.jsonrpc.org/specification

Yes, you can request information about many unrelated transactions in one call.
hero member
Activity: 488
Merit: 500
June 27, 2012, 11:22:16 AM
#8
More discussions in IRC today prompted further tweaks to this API:

"get any transaction, even transactions that aren't in your wallet" functionality will be moved from gettransaction to a new 'getrawtransaction' API call, for two reasons:
1. It doesn't 'feel' right to mix the high-level info with the nitty-gritty low-level detail.
2. We think there's a potential for security vulnerabilities if there are existing services that assume that 'gettransaction txid' returns an error for any transaction not in the wallet (as it does in all previous releases).

So the new plan is to put the new functionality in a new RPC call:

getrawtransaction [verbose=0]   :  If verbose=0, returns a JSON string that is the hex-encoded, serialized transaction. That is the "machine readable, as concise as possible" use case.  If verbose=1, returns a JSON object with all the nitty-gritty details, to cover all the other use cases.

Also, Jeff already has a pull request for JSON-2.0 "batch" functionality, so if you need information about all transactions in a block or all of a transaction's parent transactions you can get it with one RPC round-trip.

Thank you Devs, this is great!
Is there some more information on this batch mode available? Would it also be possible to request in one call information about many unrelated TXs (because you mention "all transactions in a block"...)?
legendary
Activity: 1652
Merit: 2311
Chief Scientist
June 26, 2012, 05:15:09 PM
#7
I mostly work in C#, but I'm sure its true for other languages too, creating a data structure that you can deserialize an array of different types into, and easily work with is...painful.
Excellent point. I use python, which just works with different types in arrays, and C++/json_spirit, which also just works, but I can that other languages would be painful.

I'll go through the raw transactions API and will replace any "Array of different types" with "Array of Objects".
legendary
Activity: 1260
Merit: 1000
Drunk Posts
June 26, 2012, 10:42:20 AM
#6
Just a personal opinion more than anything else, but I think this

Quote
Each output is a 5-element array that is [txid, output, scriptPubKey, amount, confirmations]

should be an array of object rather than array of array so that it basically matches the output of listtransactions.

I mostly work in C#, but I'm sure its true for other languages too, creating a data structure that you can deserialize an array of different types into, and easily work with is...painful.
legendary
Activity: 1652
Merit: 2311
Chief Scientist
June 25, 2012, 08:40:10 PM
#5
More discussions in IRC today prompted further tweaks to this API:

"get any transaction, even transactions that aren't in your wallet" functionality will be moved from gettransaction to a new 'getrawtransaction' API call, for two reasons:
1. It doesn't 'feel' right to mix the high-level info with the nitty-gritty low-level detail.
2. We think there's a potential for security vulnerabilities if there are existing services that assume that 'gettransaction txid' returns an error for any transaction not in the wallet (as it does in all previous releases).

So the new plan is to put the new functionality in a new RPC call:

getrawtransaction [verbose=0]   :  If verbose=0, returns a JSON string that is the hex-encoded, serialized transaction. That is the "machine readable, as concise as possible" use case.  If verbose=1, returns a JSON object with all the nitty-gritty details, to cover all the other use cases.

Also, Jeff already has a pull request for JSON-2.0 "batch" functionality, so if you need information about all transactions in a block or all of a transaction's parent transactions you can get it with one RPC round-trip.
legendary
Activity: 2576
Merit: 1186
June 25, 2012, 11:37:13 AM
#4
An example...

getblock as it is now in pre-0.7, with decompositions: (1 command, that returns the information requested)
Code:
$ bitcoind getblock 000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16 '{"tx":"obj", "script":"asm"}'
{
    "hash" : "000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16",
    "confirmations" : 43,
    "size" : 1473,
    "height" : 186154,
    "version" : 1,
    "merkleroot" : "47de80c28529a69bddefb90ea15388f10e2647482560bb50857e7b586d45a8c3",
    "time" : 1340614357,
    "nonce" : 728350342,
    "bits" : "1a09b78a",
    "difficulty" : 1726566.55919348,
    "tx" : [
        {
            "txid" : "11af9ba807942f7db6274f40442651c7b58b02b0a942867847b2b8a3932df7b1",
            "version" : 1,
            "locktime" : 0,
            "size" : 142,
            "vin" : [
                {
                    "coinbase" : "048ab7091a027702062f503253482f",
                    "sequence" : 4294967295
                }
            ],
            "vout" : [
                {
                    "value" : 50.00000000,
                    "scriptPubKey" : "04b034ecbcbe86f327d2edd25ce1fce3f4463710c00ae00d1a25198bab882be95c72d3468dc6931f756b03d99a3b7f3a07543834370ad023b37cb1127c6266d91a OP_CHECKSIG"
                }
            ],
            "confirmations" : 0
        },
        {
            "txid" : "9fb85b2c9085284a6c39407025cbec31b4c88b1075f3d98840395bc4e389616d",
            "version" : 1,
            "locktime" : 0,
            "size" : 259,
            "vin" : [
                {
                    "prevout" : {
                        "hash" : "1f16f657fb093f4618c1ad6504130d08fa71bb1964d0be5574f44011124f7b64",
                        "n" : 1
                    },
                    "scriptSig" : "3046022100dea86a40b8ffcfa446e05886e18c7ea8bca371118da48d4adfde846b87af43190221009652d86f7013afd35311fe8d080c9e592758716c08e971c39283ca08746db78501 04a1ce79a9fec1018129bb79c19dc90dcb4657e8cf725c635909ea402143b64e84fb06bf0b2c96ca6f0db9ac8ae480399f7724a9b288faf52c16d1535f13b90fe6",
                    "sequence" : 4294967295
                }
            ],
            "vout" : [
                {
                    "value" : 1066.13121507,
                    "scriptPubKey" : "OP_DUP OP_HASH160 e51a349be7044a8d84c6e8370ff56ff6860f3597 OP_EQUALVERIFY OP_CHECKSIG"
                },
                {
                    "value" : 1242.21306062,
                    "scriptPubKey" : "OP_DUP OP_HASH160 51fb66b01bcdbcdc67049fa97a8da21a2fa912e0 OP_EQUALVERIFY OP_CHECKSIG"
                }
            ],
            "confirmations" : 0
        },
        {
            "txid" : "060cbd899b2c1fac0cdbcf580a3f90aae131b16d516f049baf1d13c66e410892",
            "version" : 1,
            "locktime" : 0,
            "size" : 226,
            "vin" : [
                {
                    "prevout" : {
                        "hash" : "f2b6efbef50c026efc19dac73ed787b0ccc1697c8640e96637ab861e85afca60",
                        "n" : 0
                    },
                    "scriptSig" : "3045022100a0be436cb85b899740792206a17658ef96e6d786e53448cab8b11f9e51be96a6022063ab6d9337fa71b9d5a75e3ebe0a33c151ad6cdca70f9170c1b0297d655c5b3301 022cb39adb02162270b89b08975256293182bcaa84622d18a30c3bd72751d4ddd5",
                    "sequence" : 4294967295
                }
            ],
            "vout" : [
                {
                    "value" : 1.40018289,
                    "scriptPubKey" : "OP_DUP OP_HASH160 d6211f74851b1cc1d181d0fe591445a18f49c818 OP_EQUALVERIFY OP_CHECKSIG"
                },
                {
                    "value" : 1.00000000,
                    "scriptPubKey" : "OP_DUP OP_HASH160 713c581950bbfb0545f1418bbfe825911e8efa5c OP_EQUALVERIFY OP_CHECKSIG"
                }
            ],
            "confirmations" : 0
        },
        {
            "txid" : "2da6e2a83abe9e870a3a4762d8159e523a3068cce26c5670afdcd2c63486a1ac",
            "version" : 1,
            "locktime" : 0,
            "size" : 765,
            "vin" : [
                {
                    "prevout" : {
                        "hash" : "9aa47d859bda3eba62fd366461adda78f6df3293dd7b1681361f54531220b378",
                        "n" : 2
                    },
                    "scriptSig" : "3046022100f10d0f6fc6ce90ae97a04627a659791b1caed48aae8d70b82c73c5c730758576022100aba76d54166189b50e678faac63a4265d6d2daf48889a23a1fc285e042fb9c8901 04addfdfd09989768bc93678fd4eca1bf8d485e98690b7584a7559ab30a63ac16fd33e8e7db59f72c21b402a78bacbde205d642e60037d8b660a57341a60c4e646",
                    "sequence" : 4294967295
                },
                {
                    "prevout" : {
                        "hash" : "125ea4a6f9e86333de7566af28e6a5558a2c66e5c41b197560bd9a8e6c56866b",
                        "n" : 0
                    },
                    "scriptSig" : "3045022100c9e3d69de5bcbb9252b2b637e6846eaef971959653c887e7bb13f6528f1587f2022059d47b80f98460c0a02a9f7a7977202533fe3566a1cbecc599b122af02a8b8ac01 04a875f1a901e23be1435350f1a94820f84f590e297c0a34e393b873ac5b3182d071ca43890a54c750ad2fd6288416a319e70e48f2c2d2fe828666cfc98689ce0e",
                    "sequence" : 4294967295
                },
                {
                    "prevout" : {
                        "hash" : "e2b9a62cd1ad312f510510bf071ae0079b6b858db8b43e86809b7269d8ad1ff7",
                        "n" : 1
                    },
                    "scriptSig" : "3045022100a198dea14374a5d0584cfedeb8f6a457556b9bdd0488c433b179ad328a007c7102200a3179f1b8a95ae4e02183c25fb3234f1efe0db9129806d38579b2845e77a11801 047b19a9c3e6b0a92e9bdeeb294ebea709dd1d9b5e2ccb7e1fb03ca6bfa43b78dd0a6d72ddd9e64130513d63dc1ea5609906a15f1d3044f50ee6415b2e4eaf59e4",
                    "sequence" : 4294967295
                },
                {
                    "prevout" : {
                        "hash" : "b6548149a182fd10330b9f69024bdd55ce521ce367e9125d1bd8c91a8c5539da",
                        "n" : 0
                    },
                    "scriptSig" : "30450220670628b426d996131f064bb861554e31bd3afcdc581ae9824af1610dcc079080022100d240e2f445670f8e2be82f5fc74dfbc98312f0adb5f2ec163449588bdd8e9f8401 045c7e935730d0a7e45615e4a5df7c50b8bdde7fad7c978c569563b5451a756710d7dc0f1a248bd233467f17dd28e27484a91c0af4123c131b87d959dd37850692",
                    "sequence" : 4294967295
                }
            ],
            "vout" : [
                {
                    "value" : 0.19950871,
                    "scriptPubKey" : "OP_DUP OP_HASH160 c6b92e0b69d3a7aa53a28e2bc5a6de3f32fbff5a OP_EQUALVERIFY OP_CHECKSIG"
                }
            ],
            "confirmations" : 0
        }
    ],
    "previousblockhash" : "00000000000006d68b5d22acef2a43b38dc692782d7c12c0ae43259b9eb46078",
    "nextblockhash" : "000000000000023b6a46f950ef1ccd08519c2e26208d1af157c6e7fa541bd043"
}



With this functionality removed and adjusted as Gavin is proposing, you now need 1+N calls (N = number of transactions in the block) before you have the data, and those N calls all do a lot more disk I/O since they return more information than you necessarily need:
Code:
$ bitcoind getblock 000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16
{
    "hash" : "000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16",
    "confirmations" : 43,
    "size" : 1473,
    "height" : 186154,
    "version" : 1,
    "merkleroot" : "47de80c28529a69bddefb90ea15388f10e2647482560bb50857e7b586d45a8c3",
    "time" : 1340614357,
    "nonce" : 728350342,
    "bits" : "1a09b78a",
    "difficulty" : 1726566.55919348,
    "tx" : [
        "11af9ba807942f7db6274f40442651c7b58b02b0a942867847b2b8a3932df7b1",
        "9fb85b2c9085284a6c39407025cbec31b4c88b1075f3d98840395bc4e389616d",
        "060cbd899b2c1fac0cdbcf580a3f90aae131b16d516f049baf1d13c66e410892",
        "2da6e2a83abe9e870a3a4762d8159e523a3068cce26c5670afdcd2c63486a1ac"
    ],
    "previousblockhash" : "00000000000006d68b5d22acef2a43b38dc692782d7c12c0ae43259b9eb46078",
    "nextblockhash" : "000000000000023b6a46f950ef1ccd08519c2e26208d1af157c6e7fa541bd043"
}
Now for each transaction...
Code:
$ bitcoind gettransaction 11af9ba807942f7db6274f40442651c7b58b02b0a942867847b2b8a3932df7b1 1
{
    "txid" : "11af9ba807942f7db6274f40442651c7b58b02b0a942867847b2b8a3932df7b1",
    "version" : 1,
    "locktime" : 0,
    "size" : 142,
    "vin" : [
        {
            "coinbase" : "048ab7091a027702062f503253482f",
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 50.00000000,
            "scriptPubKey" : {
                "asm" : "04b034ecbcbe86f327d2edd25ce1fce3f4463710c00ae00d1a25198bab882be95c72d3468dc6931f756b03d99a3b7f3a07543834370ad023b37cb1127c6266d91a OP_CHECKSIG",
                "hex" : "4104b034ecbcbe86f327d2edd25ce1fce3f4463710c00ae00d1a25198bab882be95c72d3468dc6931f756b03d99a3b7f3a07543834370ad023b37cb1127c6266d91aac",
                "reqSigs" : 1,
                "type" : "pubkey",
                "addresses" : [
                    "1NPPwnUg9jweJEYS9q6haxixuzuYTk78Am"
                ]
            }
        }
    ],
    "blockhash" : "000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16",
    "confirmations" : 43,
    "time" : 1340614357
}
Code:
$ bitcoind gettransaction 9fb85b2c9085284a6c39407025cbec31b4c88b1075f3d98840395bc4e389616d 1
{
    "txid" : "9fb85b2c9085284a6c39407025cbec31b4c88b1075f3d98840395bc4e389616d",
    "version" : 1,
    "locktime" : 0,
    "size" : 259,
    "vin" : [
        {
            "prevout" : {
                "hash" : "1f16f657fb093f4618c1ad6504130d08fa71bb1964d0be5574f44011124f7b64",
                "n" : 1
            },
            "scriptSig" : {
                "asm" : "3046022100dea86a40b8ffcfa446e05886e18c7ea8bca371118da48d4adfde846b87af43190221009652d86f7013afd35311fe8d080c9e592758716c08e971c39283ca08746db78501 04a1ce79a9fec1018129bb79c19dc90dcb4657e8cf725c635909ea402143b64e84fb06bf0b2c96ca6f0db9ac8ae480399f7724a9b288faf52c16d1535f13b90fe6",
                "hex" : "493046022100dea86a40b8ffcfa446e05886e18c7ea8bca371118da48d4adfde846b87af43190221009652d86f7013afd35311fe8d080c9e592758716c08e971c39283ca08746db785014104a1ce79a9fec1018129bb79c19dc90dcb4657e8cf725c635909ea402143b64e84fb06bf0b2c96ca6f0db9ac8ae480399f7724a9b288faf52c16d1535f13b90fe6",
                "type" : "pubkeyhash",
                "addresses" : [
                    "1b8C6zVAsmKT28Zefkn4kLvj9Suw9q4bm"
                ]
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 1066.13121507,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 e51a349be7044a8d84c6e8370ff56ff6860f3597 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a914e51a349be7044a8d84c6e8370ff56ff6860f359788ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1MtP8ijPPJZrjZ5TamYvD5Jk3ZEoxkXwKc"
                ]
            }
        },
        {
            "value" : 1242.21306062,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 51fb66b01bcdbcdc67049fa97a8da21a2fa912e0 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a91451fb66b01bcdbcdc67049fa97a8da21a2fa912e088ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "18UUuCHm23GTw6Vkiu1MuuFRDFXWXHiPNh"
                ]
            }
        }
    ],
    "blockhash" : "000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16",
    "confirmations" : 43,
    "time" : 1340614357
}
Code:
$ bitcoind gettransaction 060cbd899b2c1fac0cdbcf580a3f90aae131b16d516f049baf1d13c66e410892 1
{
    "txid" : "060cbd899b2c1fac0cdbcf580a3f90aae131b16d516f049baf1d13c66e410892",
    "version" : 1,
    "locktime" : 0,
    "size" : 226,
    "vin" : [
        {
            "prevout" : {
                "hash" : "f2b6efbef50c026efc19dac73ed787b0ccc1697c8640e96637ab861e85afca60",
                "n" : 0
            },
            "scriptSig" : {
                "asm" : "3045022100a0be436cb85b899740792206a17658ef96e6d786e53448cab8b11f9e51be96a6022063ab6d9337fa71b9d5a75e3ebe0a33c151ad6cdca70f9170c1b0297d655c5b3301 022cb39adb02162270b89b08975256293182bcaa84622d18a30c3bd72751d4ddd5",
                "hex" : "483045022100a0be436cb85b899740792206a17658ef96e6d786e53448cab8b11f9e51be96a6022063ab6d9337fa71b9d5a75e3ebe0a33c151ad6cdca70f9170c1b0297d655c5b330121022cb39adb02162270b89b08975256293182bcaa84622d18a30c3bd72751d4ddd5",
                "type" : "pubkeyhash",
                "addresses" : [
                    "12azr4VhoodQC1PHvsKzS74Meq5S8gEn6j"
                ]
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 1.40018289,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 d6211f74851b1cc1d181d0fe591445a18f49c818 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a914d6211f74851b1cc1d181d0fe591445a18f49c81888ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1LXDHUDL6f84TqQfbxzeNXtsWmmWN8W2o2"
                ]
            }
        },
        {
            "value" : 1.00000000,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 713c581950bbfb0545f1418bbfe825911e8efa5c OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a914713c581950bbfb0545f1418bbfe825911e8efa5c88ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1BKjeTja7iL3ArMKyQM6tSpLXqjtcKc4a1"
                ]
            }
        }
    ],
    "blockhash" : "000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16",
    "confirmations" : 43,
    "time" : 1340614357
}
Code:
$ bitcoind gettransaction 2da6e2a83abe9e870a3a4762d8159e523a3068cce26c5670afdcd2c63486a1ac 1
{
    "txid" : "2da6e2a83abe9e870a3a4762d8159e523a3068cce26c5670afdcd2c63486a1ac",
    "version" : 1,
    "locktime" : 0,
    "size" : 765,
    "vin" : [
        {
            "prevout" : {
                "hash" : "9aa47d859bda3eba62fd366461adda78f6df3293dd7b1681361f54531220b378",
                "n" : 2
            },
            "scriptSig" : {
                "asm" : "3046022100f10d0f6fc6ce90ae97a04627a659791b1caed48aae8d70b82c73c5c730758576022100aba76d54166189b50e678faac63a4265d6d2daf48889a23a1fc285e042fb9c8901 04addfdfd09989768bc93678fd4eca1bf8d485e98690b7584a7559ab30a63ac16fd33e8e7db59f72c21b402a78bacbde205d642e60037d8b660a57341a60c4e646",
                "hex" : "493046022100f10d0f6fc6ce90ae97a04627a659791b1caed48aae8d70b82c73c5c730758576022100aba76d54166189b50e678faac63a4265d6d2daf48889a23a1fc285e042fb9c89014104addfdfd09989768bc93678fd4eca1bf8d485e98690b7584a7559ab30a63ac16fd33e8e7db59f72c21b402a78bacbde205d642e60037d8b660a57341a60c4e646",
                "type" : "pubkeyhash",
                "addresses" : [
                    "1LZvjABG38RPcuCc2z3zGP7xpemXyTqroo"
                ]
            },
            "sequence" : 4294967295
        },
        {
            "prevout" : {
                "hash" : "125ea4a6f9e86333de7566af28e6a5558a2c66e5c41b197560bd9a8e6c56866b",
                "n" : 0
            },
            "scriptSig" : {
                "asm" : "3045022100c9e3d69de5bcbb9252b2b637e6846eaef971959653c887e7bb13f6528f1587f2022059d47b80f98460c0a02a9f7a7977202533fe3566a1cbecc599b122af02a8b8ac01 04a875f1a901e23be1435350f1a94820f84f590e297c0a34e393b873ac5b3182d071ca43890a54c750ad2fd6288416a319e70e48f2c2d2fe828666cfc98689ce0e",
                "hex" : "483045022100c9e3d69de5bcbb9252b2b637e6846eaef971959653c887e7bb13f6528f1587f2022059d47b80f98460c0a02a9f7a7977202533fe3566a1cbecc599b122af02a8b8ac014104a875f1a901e23be1435350f1a94820f84f590e297c0a34e393b873ac5b3182d071ca43890a54c750ad2fd6288416a319e70e48f2c2d2fe828666cfc98689ce0e",
                "type" : "pubkeyhash",
                "addresses" : [
                    "1QHeEZ5akUif9nuTj1MpRXrvEYHnbcR3Gy"
                ]
            },
            "sequence" : 4294967295
        },
        {
            "prevout" : {
                "hash" : "e2b9a62cd1ad312f510510bf071ae0079b6b858db8b43e86809b7269d8ad1ff7",
                "n" : 1
            },
            "scriptSig" : {
                "asm" : "3045022100a198dea14374a5d0584cfedeb8f6a457556b9bdd0488c433b179ad328a007c7102200a3179f1b8a95ae4e02183c25fb3234f1efe0db9129806d38579b2845e77a11801 047b19a9c3e6b0a92e9bdeeb294ebea709dd1d9b5e2ccb7e1fb03ca6bfa43b78dd0a6d72ddd9e64130513d63dc1ea5609906a15f1d3044f50ee6415b2e4eaf59e4",
                "hex" : "483045022100a198dea14374a5d0584cfedeb8f6a457556b9bdd0488c433b179ad328a007c7102200a3179f1b8a95ae4e02183c25fb3234f1efe0db9129806d38579b2845e77a1180141047b19a9c3e6b0a92e9bdeeb294ebea709dd1d9b5e2ccb7e1fb03ca6bfa43b78dd0a6d72ddd9e64130513d63dc1ea5609906a15f1d3044f50ee6415b2e4eaf59e4",
                "type" : "pubkeyhash",
                "addresses" : [
                    "1NKFnJFA65FA5KyiptKsPyQVabPvGpnvNk"
                ]
            },
            "sequence" : 4294967295
        },
        {
            "prevout" : {
                "hash" : "b6548149a182fd10330b9f69024bdd55ce521ce367e9125d1bd8c91a8c5539da",
                "n" : 0
            },
            "scriptSig" : {
                "asm" : "30450220670628b426d996131f064bb861554e31bd3afcdc581ae9824af1610dcc079080022100d240e2f445670f8e2be82f5fc74dfbc98312f0adb5f2ec163449588bdd8e9f8401 045c7e935730d0a7e45615e4a5df7c50b8bdde7fad7c978c569563b5451a756710d7dc0f1a248bd233467f17dd28e27484a91c0af4123c131b87d959dd37850692",
                "hex" : "4830450220670628b426d996131f064bb861554e31bd3afcdc581ae9824af1610dcc079080022100d240e2f445670f8e2be82f5fc74dfbc98312f0adb5f2ec163449588bdd8e9f840141045c7e935730d0a7e45615e4a5df7c50b8bdde7fad7c978c569563b5451a756710d7dc0f1a248bd233467f17dd28e27484a91c0af4123c131b87d959dd37850692",
                "type" : "pubkeyhash",
                "addresses" : [
                    "1ELrvtvpwPEwGcsEQLuv6At6GCDwoXYdEz"
                ]
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 0.19950871,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 c6b92e0b69d3a7aa53a28e2bc5a6de3f32fbff5a OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a914c6b92e0b69d3a7aa53a28e2bc5a6de3f32fbff5a88ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1K7kdWH4t2oetwtPEAzm7zFBnbUSjTWfd8"
                ]
            }
        }
    ],
    "blockhash" : "000000000000010c5ba86d05c6f43df46921d453d23fdafe85229f6a7d840e16",
    "confirmations" : 43,
    "time" : 1340614357
}
legendary
Activity: 2576
Merit: 1186
June 25, 2012, 11:00:42 AM
#3
A month or two ago Pieter and Luke wrote code to modify gettransaction/getblock to return information about any transaction in the blockchain and a new 'decompositions' Object argument was added to those RPC calls that would let you specify 5 different ways to get information about transaction inputs and outputs (no/hash/hex/asm/obj).  So you might do:
Code:
gettransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098 '{"script":hex}'

I think 5 different ways of getting (or not getting if you specify 'no') the information is 4 too many, so I'm modifying the code as follows:
How about not removing much-needed functionality (forcing people to go back to patching bitcoind to add it, instead of being able to simply use it vanilla/unmodified) against a general consensus (when you originally brought this up on IRC, I don't think anyone agreed with removing it)? It was added for good reason, and should remain... what good reason is there to make things slower, more difficult to use, and less flexible?

This does mean getting full information for every transaction in a block means more than one RPC call, but Jeff has a pull request for JSON-2.0 "batch" calls, so getting full information about every transaction in a block will be just two RPC round-trips (one getblock, then one batch with a bunch of gettransaction calls in it).
This doesn't help most use cases at all.
legendary
Activity: 2618
Merit: 1007
June 25, 2012, 05:01:04 AM
#2
Will it be possible to have a pruning algorithm/method that still keeps transaction hashes per block, so if I prune transaction "123abc" from my database, I still know it was in block 12345 and could request that full block from the network eventually? Or might it be the case, that the whole network pruned away that transaction and all that is left is it's hash (as far as I understood, that's how merged mining works for example).

I personally really would like to see also input addresses or at least a very easy way to get to them. What was a little confusing for me for example was the case when I have a input transaction that actually went to multiple addresses (10 BTC to 1bitcoin123 and 20 BTC to 1bitcoin234). How do I then easily determine which of these 2 outputs was used as input to my actual transaction I'm interested in?
legendary
Activity: 1652
Merit: 2311
Chief Scientist
June 24, 2012, 07:35:30 PM
#1
My work on the 'raw transaction' API has me thinking hard about the gettransaction/getblock RPC calls. I want it to be easy for the information returned by those calls to be used by the new createrawtx/etc API calls.

So:  in version 0.6.3 and earlier, gettransaction would only return information about transactions in your wallet, and would not return all of the information about the transaction.

A month or two ago Pieter and Luke wrote code to modify gettransaction/getblock to return information about any transaction in the blockchain and a new 'decompositions' Object argument was added to those RPC calls that would let you specify 5 different ways to get information about transaction inputs and outputs (no/hash/hex/asm/obj).  So you might do:
Code:
gettransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098 '{"script":hex}'

I think 5 different ways of getting (or not getting if you specify 'no') the information is 4 too many, so I'm modifying the code as follows:
  • getblock doesn't change from version 0.6; it returns a list of transaction id's in a "tx" Array.
  • gettransaction gets an extra boolean argument that defaults to 0 (false).  If non-zero is passed, then it is verbose and outputs information about the transaction inputs and outputs in all the different formats (same as what decomposition "obj" does).
  • for compatibility with the 'raw transaction' API calls, gettransaction always return the full serialized-hex-encoded transaction data as a new "rawtx" field.
The thinking is either RPC users will want minimal information quickly, or will want full information and won't care much if they get extra information. If you want full information as quickly as possible, then you should write code to decode the "rawtx" array yourself.

This does mean getting full information for every transaction in a block means more than one RPC call, but Jeff has a pull request for JSON-2.0 "batch" calls, so getting full information about every transaction in a block will be just two RPC round-trips (one getblock, then one batch with a bunch of gettransaction calls in it).

And to be clear: these changes are meant to be 100% backwards-compatible with getblock/gettransaction in version 0.6.3 and earlier.  We're talking about extra arguments and extra information in the returned JSON objects.


Example output for a complicated multisignature testnet transaction:

Short, in-wallet transaction:
Code:
$ ./bitcoind -testnet gettransaction 4ec492788efb3c9e4e23972f095bd575217288c9f6b8237922145aeff8dae8d5
{
    "rawtx" : "0100000001c6660657eb258f9e58d246d767f5aaa15980d4d26ee496e7e24fabf72f2cc3440000000048473044022026b2e3d408a7848ad18b35042163c0efb358c456c6006a0cd13c077ec213aeab02202115a38de465e0c927f858cbb83fca45bddb0e469524667e39fd0c54ab5007d701ffffffff0100f2052a0100000017a914b6cb85e6fa58b2bff3da23074eb0f1a0ddb23e1f8700000000",
    "amount" : -50.00000000,
    "fee" : 0.00000000,
    "confirmations" : 2,
    "blockhash" : "0000000003abdd41db27190bb4f19e36497f647d1ea586ef543c44f7ccd40015",
    "blockindex" : 1,
    "txid" : "4ec492788efb3c9e4e23972f095bd575217288c9f6b8237922145aeff8dae8d5",
    "time" : 1339001503,
    "details" : [
        {
            "account" : "",
            "address" : "2N9uknE7Zy9M3cPxWvkHu9HQiArL3pnbcUF",
            "category" : "send",
            "amount" : -50.00000000,
            "fee" : 0.00000000
        }
    ]
}
Verbose:
Code:
$ ./bitcoind -testnet gettransaction 4ec492788efb3c9e4e23972f095bd575217288c9f6b8237922145aeff8dae8d5 1
{
    "rawtx" : "0100000001c6660657eb258f9e58d246d767f5aaa15980d4d26ee496e7e24fabf72f2cc3440000000048473044022026b2e3d408a7848ad18b35042163c0efb358c456c6006a0cd13c077ec213aeab02202115a38de465e0c927f858cbb83fca45bddb0e469524667e39fd0c54ab5007d701ffffffff0100f2052a0100000017a914b6cb85e6fa58b2bff3da23074eb0f1a0ddb23e1f8700000000",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "prevout" : {
                "hash" : "44c32c2ff7ab4fe2e796e46ed2d48059a1aaf567d746d2589e8f25eb570666c6",
                "n" : 0
            },
            "scriptSig" : {
                "asm" : "3044022026b2e3d408a7848ad18b35042163c0efb358c456c6006a0cd13c077ec213aeab02202115a38de465e0c927f858cbb83fca45bddb0e469524667e39fd0c54ab5007d701",
                "hex" : "473044022026b2e3d408a7848ad18b35042163c0efb358c456c6006a0cd13c077ec213aeab02202115a38de465e0c927f858cbb83fca45bddb0e469524667e39fd0c54ab5007d701",
                "type" : "pubkey",
                "addresses" : [
                    "n4DUWe93vkdfAiSVDaMP3okaU7upK2wtrr"
                ]
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 50.00000000,
            "scriptPubKey" : {
                "asm" : "OP_HASH160 b6cb85e6fa58b2bff3da23074eb0f1a0ddb23e1f OP_EQUAL",
                "hex" : "a914b6cb85e6fa58b2bff3da23074eb0f1a0ddb23e1f87",
                "reqSigs" : 1,
                "type" : "scripthash",
                "addresses" : [
                    "2N9uknE7Zy9M3cPxWvkHu9HQiArL3pnbcUF"
                ]
            }
        }
    ],
    "amount" : -50.00000000,
    "fee" : 0.00000000,
    "confirmations" : 2,
    "blockhash" : "0000000003abdd41db27190bb4f19e36497f647d1ea586ef543c44f7ccd40015",
    "blockindex" : 1,
    "txid" : "4ec492788efb3c9e4e23972f095bd575217288c9f6b8237922145aeff8dae8d5",
    "time" : 1339001503,
    "details" : [
        {
            "account" : "",
            "address" : "2N9uknE7Zy9M3cPxWvkHu9HQiArL3pnbcUF",
            "category" : "send",
            "amount" : -50.00000000,
            "fee" : 0.00000000
        }
    ]
}

The only feature that bothers me is reporting 'addresses/type' for transaction inputs. It bothers me for two reasons:

1) It is expensive to fetch that data, because it means finding the previous transaction in the blockchain and fetching it from disk. It violates the principle that "a feature shouldn't cost you anything if you're not using it."

2) If "we" implement spent-input pruning (Pieter has some fantastic early results) that data might not exist.

I think it would be better to remove the 'addresses/type' information from gettransaction output, so gettransaction never has to lookup previous transactions.

If you care about the previous transaction, then you would have to call gettransaction again, using vin.prevout.hash to look them up (and, again, using the JSON-2.0 'batch' feature to lookup all the prior transactions in one RPC roundtrip).

If/when transaction pruning happens then the semantics are clear: that gettransaction would return an error if the prior transaction was pruned.
Jump to: