1

I'm using wallet-less bitcoin daemon (it just syncs blockchain) – the purpose is to read blocks and transactions in them, and do some useful things. This particular question is focused on determining the checks to be made to verify the amount received by each address in a given transaction.

Given tx, I call decoderawtransaction(getrawtransaction(tx)) and receive following details (json):

{
"txid" : "691cb3d61192c7325f203fe14d3d5cf6e98e6bd81877b166f6c37fd629aaa4fb",
"version" : 1,
"locktime" : 0,
"vin" : [
    {
        "txid" : "0c0b442e866f007a0da8a2c1abbe8afad8e96217105b561b097aa835b73a6b70",
        "vout" : 0,
        "scriptSig" : {
            "asm" : "3045022100eb01c02b4655c96b08544908bd44d1fbc165971bdc25705ba1b4790c60716dfa022024adeb306f66a72a2a90455035940b89e7c96c8300b6f73f3ae83af605b9c35d01 03ca8ff2ad5114e703d07b3cee962d54609c1de95fd4511e53de91ba0ce35ef4ee",
            "hex" : "483045022100eb01c02b4655c96b08544908bd44d1fbc165971bdc25705ba1b4790c60716dfa022024adeb306f66a72a2a90455035940b89e7c96c8300b6f73f3ae83af605b9c35d012103ca8ff2ad5114e703d07b3cee962d54609c1de95fd4511e53de91ba0ce35ef4ee"
        },
        "sequence" : 4294967295
    }
],
"vout" : [
    {
        "value" : 0.01000000,
        "n" : 0,
        "scriptPubKey" : {
            "asm" : "OP_DUP OP_HASH160 8bab392bcc5cfce30affc16336cdd68e807147a2 OP_EQUALVERIFY OP_CHECKSIG",
            "hex" : "76a9148bab392bcc5cfce30affc16336cdd68e807147a288ac",
            "reqSigs" : 1,
            "type" : "pubkeyhash",
            "addresses" : [
                "mtFTLXKfDxHuJT36cHugYTZw5CVLejqccq"
            ]
        }
    },
    {
        "value" : 0.04000000,
        "n" : 1,
        "scriptPubKey" : {
            "asm" : "OP_DUP OP_HASH160 d86064ea608dd1ceeae690e548979b854ca55360 OP_EQUALVERIFY OP_CHECKSIG",
            "hex" : "76a914d86064ea608dd1ceeae690e548979b854ca5536088ac",
            "reqSigs" : 1,
            "type" : "pubkeyhash",
            "addresses" : [
                "n1F3j5MdfSLSgpUnaQXNVJb8KBMvnfBYPr"
            ]
        }
    }
]
}

I can see each txout record gives amount as a value (scalar) and addresses as an array.

  1. If addresses array has multiple values, it is a contract (m-to-n transaction perhaps) and I should not consider the money to have been received by any of the addresses for immediate spend.
  2. Assuming addresses has only one value, what are other checks I must make to verify that the address has received the amount mentioned in the field 'value'?

So I need to know a set of all checks to verify the transaction is confirmed, valid and that a particular address in a particular txout has received the specified amount. confirmation can be ascertained depending on the number of blocks that precede block of this transaction (getblockcount - blockheight).

Thanks!

  • 1. Most likely one address received a payment and the other one is change returned to another address controlled by the payer. This is because the output of a transaction must be spent completely. For example, if you have 10 btc in an output and you want to spend 1 btc, you must send 1 to the recipient and 9 to a change address of your own. – Diego Basch Feb 18 '14 at 18:26
  • I am not concerned about distinction between change, fees and payment. I need to verify whether or not an address in each txout has received amount in 'value'. – Varun K Feb 19 '14 at 5:59
1

So you're asking for 3 things: confirmed, valid and that a particular address in a particular txout has received the specified amount.

Confirmed: You've already worked this out. If getblockcount - blockheight > 0 then the tx has at least 1 confirmation, and so on.

Valid: Tx are confirmed in two ways:

  1. by validating nodes (full Bitcoin nodes like bitcoin-qt). Each time a tx is broadcast across full peers, it is validated.
  2. by the network. This network validation occurs when the network agrees that the block containing the tx is valid, which occurs first time at 1 confirmation and increases in confidence with each additional confirmation. Being included in a mined block also means that (1) above has occurred at least once (probably much more).

So if you're only considering confirmed Bitcoin transactions, they've already been fully validated by the network and its nodes, so you don't have to do this yourself. This does not necessarily apply to unconfirmed transactions.

Particular address has received specified amount: There are rules of thumb here, but to be absolutely sure about this last item, you have to consider the tx script. Fortunately, all this entails for most transactions is checking for OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG.

This is the relevant part (for you) of the script contained in the scriptPubKey. As long as it contains this text, you can be sure it's a simple payment in the amount specified to the address specified, regardless of whether it is change or whatever.

If the scriptPubKey contains something else, then you'll need to actually parse the script to figure out the tx details. How to do this is beyond the scope of this question.

So in brief, to fulfill all your conditions, you need to wait for 1 confirmation and check for the exact scriptPubKey text shown above, or else be prepared t ofully parse the script in the case of a complex contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.