Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: supermoney on January 14, 2016, 04:07:42 PM



Title: [SOLVED] Clarifications on this tx
Post by: supermoney on January 14, 2016, 04:07:42 PM
I coded my own algorithm for retrieving fee from a received tx (through getrawtransaction command).
By doing some stress tests I encountered the following tx: ab6a33a6281bb9d9a98949e50ac875f1d550e02e030e28a8800f280e2192ac51 (open with blockr.io (http://tbtc.blockr.io/tx/info/ab6a33a6281bb9d9a98949e50ac875f1d550e02e030e28a8800f280e2192ac51) or blocktrail.com (https://www.blocktrail.com/tBTC/tx/ab6a33a6281bb9d9a98949e50ac875f1d550e02e030e28a8800f280e2192ac51))

0.51796901 (inputs) - 0.51740385 (output spent) = 0.00056516 (fee)
Sounds ok according to the shown inputs and outputs on blockr.io and blocktrail.

BUT...
My own script reports the following: tx-result (http://www.googledrive.com/host/0B-dhzfniY3D_XzhQalB6bTY5Uzg) (values got fetched from bitcoind)
There are no inputs with 0.51596901 and only got an input with 0.001, so where the hell did block explorers get those numbers? What's the algorithm? I can't figure it out and started to get mad...

By the way, my script successfully calculated the correct fee of the following txs:
ad560632ae5956088611fd029f7cd992e913b19e8a57ae2c2443db11a41cb99c (http://www.googledrive.com/host/0B-dhzfniY3D_VE9CMEJfV2dJR1E)
9afe2bf122e4ec26cff427015ea680f4e03877077376d1d9b1c6d6f63563acc7 (http://www.googledrive.com/host/0B-dhzfniY3D_c1BYeEdjcXJJcmM)
c359b19f23e0e66dd98cf983269817513f540f23af4b5bbb56833dd22acf10b0 (http://www.googledrive.com/host/0B-dhzfniY3D_ODZSMzJWQmFpQm8)
bd2f097ec1d1ca40d3032177d699c002f6e31fe93305de785c6db8816dbc488e (http://www.googledrive.com/host/0B-dhzfniY3D_VGo2WWgtdVZZU2c)
5ec8c58046e2afc01fe671d4b304fa2e5ec0530a63628e79a64d6cbfdd90a052 (http://www.googledrive.com/host/0B-dhzfniY3D_UzlJcjFGcjNFS0E)
...and many others with multiple inputs and outputs.

UPDATE: added full txinfo from bitcoind -> tx-full (http://www.googledrive.com/host/0B-dhzfniY3D_VnFqT0pjaHNpVDA)

SOLVED: read last post I wrote.


Title: Re: Clarifications on this tx
Post by: DannyHamilton on January 14, 2016, 05:23:19 PM
Looking at the transaction:
http://tbtc.blockr.io/api/v1/tx/raw/ab6a33a6281bb9d9a98949e50ac875f1d550e02e030e28a8800f280e2192ac51
Code:
{
    "status":"success",
    "data":{
        "tx":{
            "hex":"...",
            "version":1,
            "locktime":0,
            "vin":[
                {
                    "txid":"8589f593e1f9da61004a87e7dd6fc2c873cf9124edc90a91ee9f74528aadd236",
                    "vout":1,
                    "scriptSig":{"asm":"..."},
                    "sequence":4294967295
                },{
                    "txid":"0ac8a4f8e7df98544e0bb4f39bf3916ca9b14dae17d3d5c5a02540002fc5376b",
                    "vout":0,
                    "scriptSig":{"asm":"..."},
                    "sequence":4294967295
                },{
                    "txid":"0ac8a4f8e7df98544e0bb4f39bf3916ca9b14dae17d3d5c5a02540002fc5376b",
                    "vout":1,
                    "scriptSig":{"asm":"..."},
                    "sequence":4294967295
                }
            ],
            "vout":[
                {
                    "value":0.51540385,
                    "n":0,
                    "scriptPubKey":{
                        "asm":"...",
                        "hex":"...",
                        "reqSigs":1,
                        "type":"scripthash",
                        "addresses":["2MyRyi1EzM3onzv99gNLWqscQBzmPdd9qKy"]
                    }
                },{
                    "value":0.002,
                    "n":1,
                    "scriptPubKey":{
                        "asm":"...",
                        "hex":"...",
                        "reqSigs":1,
                        "type":"scripthash",
                        "addresses":["2Mxh7iZ4QtajmS5zKtvwUVrJt9sajW2aMpS"]
                    }
                }
            ],
            "blockhash":"...",
            "confirmations":458,
            "time":1452645488,
            "blocktime":1452645488
        }
    },
    "code":200,
    "message":""
}

It looks like your transaction has 2 outputs:
  • 0.51540385 sent to 2MyRyi1EzM3onzv99gNLWqscQBzmPdd9qKy
  • 0.002 sent to 2Mxh7iZ4QtajmS5zKtvwUVrJt9sajW2aMpS

0.51540385 + 0.002 = total outputs 0.51740385

It looks like your transaction has 3 inputs:
  • Output number 1 from transaction 8589f593e1f9da61004a87e7dd6fc2c873cf9124edc90a91ee9f74528aadd236
  • Output number 0 from transaction 0ac8a4f8e7df98544e0bb4f39bf3916ca9b14dae17d3d5c5a02540002fc5376b
  • Output number 1 from transaction 0ac8a4f8e7df98544e0bb4f39bf3916ca9b14dae17d3d5c5a02540002fc5376b

Lets look at those three transaction outputs:

http://tbtc.blockr.io/api/v1/tx/raw/8589f593e1f9da61004a87e7dd6fc2c873cf9124edc90a91ee9f74528aadd236
Code:
- snip -
"vout":[
    - snip -
    {
        "value":0.001,
        "n":1,
        - snip -
        "addresses":["2N9yqoWM7epwB1QftTy7aFG7nvqJLv6cy5X"]
    }
]
- snip -
That looks like a 0.001 input.

http://tbtc.blockr.io/api/v1/tx/raw/0ac8a4f8e7df98544e0bb4f39bf3916ca9b14dae17d3d5c5a02540002fc5376b
Code:
- snip -
"vout":[
    {
        "value":0.001,
        "n":0,
        - snip -
        "addresses":["2MxbJa5LG6FrHDzVjnYmSnFJ1Zn93wdAubf"]
    },{
        "value":0.51596901,
        "n":1,
        - snip -
        "addresses":["2NB9X4bd8dGRnqqzxrhR973U9dZWwfteqvv"]
    }
]
- snip -

That looks like 2 outputs, one for 0.001 BTC and one for 0.51596901

0.001 + 0.001 + 0.51596901 = total inputs 0.51796901


Title: Re: Clarifications on this tx
Post by: supermoney on January 14, 2016, 05:39:46 PM
- snip -

It would be great if my bitcoind would get the same input values as the block explorer.
The following result contains outputs of ab6a33a6281bb9d9a98949e50ac875f1d550e02e030e28a8800f280e2192ac51 and inputs of 8589f593e1f9da61004a87e7dd6fc2c873cf9124edc90a91ee9f74528aadd236: tx-result (http://www.googledrive.com/host/0B-dhzfniY3D_XzhQalB6bTY5Uzg)
Raw transaction from bitcoind: tx-full (https://4f5dadd4a2267f08f70741b78ddd2e397d47acc6-www.googledrive.com/host/0B-dhzfniY3D_VnFqT0pjaHNpVDA)
As you can see inputs are different.

EDIT: I got the problem and figured it out... There are 3 inputs to calculate instead of 1 only as I used to do. Thanks for your time  :D


Title: Re: Clarifications on this tx
Post by: supermoney on January 14, 2016, 11:13:21 PM
Thank you DannyHamilton for helping me to figure out that my script was reading first input's value only.
I've updated my script with four nested foreach loops storing in a multidimensional array all values from each vout array of each vin of the original tx. The algorithm I studied and applied till now seems it didn't change hopefully.

Working script result: tx-result (http://www.googledrive.com/host/0B-dhzfniY3D_bDJNcmJrY2tNX00)

#closed.