Can we assume that the ordering of vout matches n index in json rpc

3

Just a random transaction for example:

bitcoind getrawtransaction e16829044c498e1d1c8fa9dc831a7c96c3b74f55b984b54a7d48c4d0156ffcf5 1 

Gives:

{
    ...
    "vout" : [
        {
            "value" : 0.09076500,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "",
                "hex" : "76a914cc4ac9ecfe26163f4e657e5ce9eee9947d0459b988ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1KdCSYosbepwC4yMKWziwM3ytqWfAGg1n8"
                ]
            }
        },
        {
            "value" : 0.00200000,
            "n" : 1,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 04d075b3f501deeef5565143282b6cfe8fad5e94 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a91404d075b3f501deeef5565143282b6cfe8fad5e9488ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1STRonGxnFTeJiA7pgyneKknR29AwBM77"
                ]
            }
        },
        {
            "value" : 0.00200000,
            "n" : 2,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 42d163a80a1fb2579ba05c9dde70152cc1463b19 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a91442d163a80a1fb2579ba05c9dde70152cc1463b1988ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "176JSHRoCTo2jPMFy5ZMR9FHU4LbtZX6Jj"
                ]
            }
        },
        {
            "value" : 0.27422642,
            "n" : 3,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 3871de7b4bd8c08048f8ac112790050406109cba OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a9143871de7b4bd8c08048f8ac112790050406109cba88ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "169TFWEpspsX9Xp5Hwq6bu5FyEe4syGu2f"
                ]
            }
        }
    ],
    "blockhash" : "00000000000000006053fc5faf2c099f30be416175488b34e947ea44480aae83",
    "confirmations" : 265,
    "time" : 1400729945,
    "blocktime" : 1400729945
}

My question is about the orders of the vout array. Can we assume that the ordering matches "n"? Ie. The first vout has n=0, the second vout has n=1 etc.

The reason for asking is to take advantage of array index lookups instead of having to loop through looking for matching n values.

Yada

Posted 2014-05-23T19:02:12.383

Reputation: 173

Answers

1

Yes, that's how inputs reference outputs as well.

Matthieu

Posted 2014-05-23T19:02:12.383

Reputation: 866