Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: ovanwijk on February 20, 2017, 04:13:07 PM



Title: Getting input addresses
Post by: ovanwijk on February 20, 2017, 04:13:07 PM
So I am building a tool to import bitcoin data to be used by a graph processing engine. (quite new to the whole blockchain technology)

Now I am using rpc getrawtransaction(I know this is going to take a while but I have 2 strong pc's set up with SSD's to speed the processes up) to get all transaction information.

This all works fine but I have some questions on how to interpret the data I get back.
What I want to achieve is something like this:
https://blockchain.info/tx/8a88f0b2169bb51680a8065a10c30722364db8c3224a37e69772aea6ae894033

Input addresses flowing to output addresses. However when I do [bitcoin-cli getrawtransaction 8a88f0b2169bb51680a8065a10c30722364db8c3224a37e69772aea6ae894033] I get:

Code:
{
"result": {
"hex": "removed",
"txid": "8a88f0b2169bb51680a8065a10c30722364db8c3224a37e69772aea6ae894033",
"hash": "8a88f0b2169bb51680a8065a10c30722364db8c3224a37e69772aea6ae894033",
"size": 1258,
"vsize": 1258,
"version": 1,
"locktime": 453863,
"vin": [{
"txid": "bdb40ce98ca596314f4585da9b48b38bef00120beb3cc7380b18a6ced248ac50",
"vout": 0,
"scriptSig": {
"asm": "304402207e62c036305e3d7333317c7ffb5fec47c33d7074a97a04bf89f12eeec63ba0380220576014410cd373d4259f6bdd3eeece401140d7de63f2228529e75aeb6de729cf[ALL] 0390fa7edcd0039b90d1939d97a30be396a6e859df4e96498af658b833d26bf716",
"hex": "47304402207e62c036305e3d7333317c7ffb5fec47c33d7074a97a04bf89f12eeec63ba0380220576014410cd373d4259f6bdd3eeece401140d7de63f2228529e75aeb6de729cf01210390fa7edcd0039b90d1939d97a30be396a6e859df4e96498af658b833d26bf716"
},
"sequence": 4294967294
},
{
"txid": "734f61837511aac0539bb65a3a5e7a795fdc5c27bf8207076b9c0fd15452e162",
"vout": 1,
"scriptSig": {
"asm": "30450221009092434431def6f1af029b0b6664670f9a3b90133c8201b63a93a17ff8a7057d02202fa6babc181a54ae7c27aea487e1aaa6018a30d4bb3cc0358ec97dd0e8ae56e5[ALL] 0298527d9c792ef0e6f2485a311bdd38449078431e847f0e7d7c43f0f1a8e65d52",
"hex": "4830450221009092434431def6f1af029b0b6664670f9a3b90133c8201b63a93a17ff8a7057d02202fa6babc181a54ae7c27aea487e1aaa6018a30d4bb3cc0358ec97dd0e8ae56e501210298527d9c792ef0e6f2485a311bdd38449078431e847f0e7d7c43f0f1a8e65d52"
},
"sequence": 4294967294
},
{
"txid": "f553c499f459ceb9df3c5e3e1dbe688e4cefb9b52203443a234e2bc89aca3336",
"vout": 1,
"scriptSig": {
"asm": "3045022100c61e38ff4cd46e2a7aa2e5c7e43c6f8422e448f6ee28500410b69192545ff9d9022006bd2756a5d4beca46f6c4ab8d7d7e66ca416ea57169c51f3ea0560280737539[ALL] 028923443b678efc0c6215a45b4983405366540ac4d1279524e3c17705fabb2ec5",
"hex": "483045022100c61e38ff4cd46e2a7aa2e5c7e43c6f8422e448f6ee28500410b69192545ff9d9022006bd2756a5d4beca46f6c4ab8d7d7e66ca416ea57169c51f3ea05602807375390121028923443b678efc0c6215a45b4983405366540ac4d1279524e3c17705fabb2ec5"
},
"sequence": 4294967294
},
{
"txid": "f913a18aae3cc2615c6f1a868929ac969d26accaea5fb300667802a391d7b1fb",
"vout": 1,
"scriptSig": {
"asm": "3044022019e9170dd348ad2d89b09e94203fefdc5152cb1658411ee46365b3e57c0f8f0b022029ffc6ac82a0ce9b094e094e076ce6bd155d7188593c052c5ab68e0506a6adb0[ALL] 02c156b615af42c437a995a53ebf001929a3d133ea5defa93062d86f0f00c686ad",
"hex": "473044022019e9170dd348ad2d89b09e94203fefdc5152cb1658411ee46365b3e57c0f8f0b022029ffc6ac82a0ce9b094e094e076ce6bd155d7188593c052c5ab68e0506a6adb0012102c156b615af42c437a995a53ebf001929a3d133ea5defa93062d86f0f00c686ad"
},
"sequence": 4294967294
},
{
"txid": "d78fe84a538daee8ecdba18ba893cb895c7cc704f2547d68a3a4d1956a6b3baa",
"vout": 0,
"scriptSig": {
"asm": "304402206e5986eedbfdb8fb20673f9f4c47a0e31f94ecb53014bf11db1838133d56499e02204370f16094559110fb8269bb561e1ddb1e9842c0829fd4801999a8c60edc5667[ALL] 0271566640fee4f013eb0d3e7dc72dcb9b5dca565efa1e7fd6fa288488e82d8c78",
"hex": "47304402206e5986eedbfdb8fb20673f9f4c47a0e31f94ecb53014bf11db1838133d56499e02204370f16094559110fb8269bb561e1ddb1e9842c0829fd4801999a8c60edc566701210271566640fee4f013eb0d3e7dc72dcb9b5dca565efa1e7fd6fa288488e82d8c78"
},
"sequence": 4294967294
},
{
"txid": "7b6395f74887c8364df0de640e7f0c09ea28b0f5e79b395a8726ae297803ea44",
"vout": 1,
"scriptSig": {
"asm": "30450221009b3ae04e106e7abc6aa843547f8415a8495bbdd6944f1b4a1991f6b68229bebb0220244c7c68e7796046f3c97677dd893d8d098d7c0e173b9ea1599e6f5432a33dbd[ALL] 03460ca67240146dd9f9b5052b9f4183cfb2ff043c20aa3190d1ced13867ec9fe7",
"hex": "4830450221009b3ae04e106e7abc6aa843547f8415a8495bbdd6944f1b4a1991f6b68229bebb0220244c7c68e7796046f3c97677dd893d8d098d7c0e173b9ea1599e6f5432a33dbd012103460ca67240146dd9f9b5052b9f4183cfb2ff043c20aa3190d1ced13867ec9fe7"
},
"sequence": 4294967294
},
{
"txid": "09088f8facb878147044f97fc8c27c5f48115df54980203d3515e40a89b46d41",
"vout": 1,
"scriptSig": {
"asm": "3044022069306ba81c03b76d2cebb10ec3009ba183f429c85f56c223b095cf7951cad46a0220371cdfa871d2793f2eb554db79848cce2ee401176ff4cf16f1dc120fb9b0296b[ALL] 024ce6e0082826172c22920aca9f085440b19fb1e094b74b15bcaeed1072c14777",
"hex": "473044022069306ba81c03b76d2cebb10ec3009ba183f429c85f56c223b095cf7951cad46a0220371cdfa871d2793f2eb554db79848cce2ee401176ff4cf16f1dc120fb9b0296b0121024ce6e0082826172c22920aca9f085440b19fb1e094b74b15bcaeed1072c14777"
},
"sequence": 4294967294
},
{
"txid": "e99f02458ed515c0693b486f2e5b21ec18464737c1ba5a6655cb30e9b1250064",
"vout": 0,
"scriptSig": {
"asm": "3045022100e328951012fd33193aea67f2b7de5d3003f6b7377d3e664955b45c18ce15fc7f02200b517ae588485fdf65c803eb025bc128a705142d6274102081cb69d1e89bafd9[ALL] 022e0fa1aed633e1fc324598a74ed8c6e2f6ce207ec6d4a78f1111d473e1282044",
"hex": "483045022100e328951012fd33193aea67f2b7de5d3003f6b7377d3e664955b45c18ce15fc7f02200b517ae588485fdf65c803eb025bc128a705142d6274102081cb69d1e89bafd90121022e0fa1aed633e1fc324598a74ed8c6e2f6ce207ec6d4a78f1111d473e1282044"
},
"sequence": 4294967294
}],
"vout": [{
"value": 0.01000010,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 7646f1733e37b4b12e6dfedd5823b5a8f884ac48 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a9147646f1733e37b4b12e6dfedd5823b5a8f884ac4888ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": ["1BnPirW8z4KPiQLzymCFqZpwUdhC6rVXBQ"]
}
},
{
"value": 9.01756051,
"n": 1,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 8d158e259f7cea7a5325d1dfcebea493ba7a5da8 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a9148d158e259f7cea7a5325d1dfcebea493ba7a5da888ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": ["1Drz6jZucDgMp2iusihq6YGzFeo95T7toh"]
}
}],
"blockhash": "000000000000000000c5960e3c9c13271189a57a7010049772d9e4e8d9f65c5a",
"confirmations": 42,
"time": 1487576190,
"blocktime": 1487576190
},
"error": null,
"id": null
}


Now here I cannot find the address of the sender as I can see on blockchain info. However if I follow the transaction I can see the output address and interpret it as the input address for the transaction above:

Code:
{
"result": {
"hex": "0100000001691d0c9d88ea66b96256d11f22750db04e9a224762a09bb48c45cd76782d19ab000000006a473044022069750c2f0d7311819144253c80795206c25e7c9cf0f3cd73cf32c02be7c94fd70220786d225e21b5a01a622d76c39af9a6e46e15fe799b7e575dcb1ff5641d4325880121025133df09ec939b1db2b034b8ebfa16c9e476468a9e205d68fa716596520167c4ffffffff0260538000000000001976a914380241a7ba4bd6e7a533a51d6da46171dc13a0c588ace7234917000000001976a914fdcc8441475f86950f56254c233a4ffa5a98d08088ac00000000",
"txid": "bdb40ce98ca596314f4585da9b48b38bef00120beb3cc7380b18a6ced248ac50",
"hash": "bdb40ce98ca596314f4585da9b48b38bef00120beb3cc7380b18a6ced248ac50",
"size": 225,
"vsize": 225,
"version": 1,
"locktime": 0,
"vin": [{
"txid": "ab192d7876cd458cb49ba06247229a4eb00d75221fd15662b966ea889d0c1d69",
"vout": 0,
"scriptSig": {
"asm": "3044022069750c2f0d7311819144253c80795206c25e7c9cf0f3cd73cf32c02be7c94fd70220786d225e21b5a01a622d76c39af9a6e46e15fe799b7e575dcb1ff5641d432588[ALL] 025133df09ec939b1db2b034b8ebfa16c9e476468a9e205d68fa716596520167c4",
"hex": "473044022069750c2f0d7311819144253c80795206c25e7c9cf0f3cd73cf32c02be7c94fd70220786d225e21b5a01a622d76c39af9a6e46e15fe799b7e575dcb1ff5641d4325880121025133df09ec939b1db2b034b8ebfa16c9e476468a9e205d68fa716596520167c4"
},
"sequence": 4294967295
}],
"vout": [{
"value": 0.08409952,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 380241a7ba4bd6e7a533a51d6da46171dc13a0c5 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914380241a7ba4bd6e7a533a51d6da46171dc13a0c588ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": ["1679YXRMLue2qn61QhhsqueJiuaKnT7u5b"]
}
},
{
"value": 3.90669287,
"n": 1,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 fdcc8441475f86950f56254c233a4ffa5a98d080 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914fdcc8441475f86950f56254c233a4ffa5a98d08088ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": ["1Q8xxbdUAJPAEo3vmf5RXcTi2efijYKuVu"]
}
}],
"blockhash": "000000000000000000aac995e14fe22637c1955e09631d36d5c33afbe0e571fc",
"confirmations": 373,
"time": 1487379731,
"blocktime": 1487379731
},
"error": null,
"id": null
}




Now my question is: Is this the only way to get the 'input address' of a transaction or can I find the address also by somehow decoding the scriptSig?
Same question is obviously for the input amount and to what output it contributes.


Also I see: "addresses": ["1Q8xxbdUAJPAEo3vmf5RXcTi2efijYKuVu"] as being an array, is this ever empty or has more then 1 value? If so why and when does this happen (perhaps a transaction ID that I can follow?)


Thanks in advance!




Title: Re: Getting input addresses
Post by: achow101 on February 20, 2017, 06:25:20 PM
Now my question is: Is this the only way to get the 'input address' of a transaction or
That is the only way you are guaranteed to get the right address.

can I find the address also by somehow decoding the scriptSig?
You can try, but this may not necessarily work. Most transactions' scriptsigs will either be for a p2pkh or a p2sh multisig output. For p2pkh, there is a signature and then the pubkey. You can convert the pubkey to an address. For p2sh multisig, there are multiple signatures followed by the redeemscript. You can take the redeemscript and convert that to an address. However there is no easy way to do this in Bitcoin Core (that I know of).

Same question is obviously for the input amount and to what output it contributes.
The only way to get the amounts is to lookup the referenced transaction and figure it out from there.

Also I see: "addresses": ["1Q8xxbdUAJPAEo3vmf5RXcTi2efijYKuVu"] as being an array, is this ever empty or has more then 1 value? If so why and when does this happen (perhaps a transaction ID that I can follow?)
It can be empty if the output is non-standard or OP_RETURN. I think it will return multiple addresses for bare multisig outputs too.


Title: Re: Getting input addresses
Post by: ovanwijk on February 20, 2017, 09:59:15 PM
Thanks for your reply!

On the multiple outputs:

As far as I understand is that in case of multiple outputs any of the addresses can spend the coins (but only 1 can do it naturally).

So to figure out where it actually 'went' I have to follow up on all outputs.

Found an example: https://blockchain.info/tx/055f9c6dc094cf21fa224e1eb4a54ee3cc44ae9daa8aa47f98df5c73c48997f9


But when it is empty what should I do with it? I do I interpret OP_RETURN/non-standard? Should I ignore it? Are they bounced/invalidated transactions? or especially interesting?


Also another question: I always hear about IP address being registered with transactions and all (like it is on blockchain.info) but is this information actually stored inside the blockchain? And if yes how can I can find it. Doesn's seem to be inside 'getrawtransaction'?


Title: Re: Getting input addresses
Post by: DannyHamilton on February 20, 2017, 10:22:16 PM
As far as I understand is that in case of multiple outputs any of the addresses can spend the coins (but only 1 can do it naturally).

That depends on how the transaction is set up.

It is possible to require owners of ALL addresses to sign the transaction that spends the output, or some subset of owners of addresses, or just one.

You would need to look at the output script to see how the transaction was set up, and then you would need to look at the input script to see how the signature was handled.

So to figure out where it actually 'went' I have to follow up on all outputs.

One output.  Multiple addresses.  You would have to follow up on the output script to see what was required, and the input script to see what happened.

when it is empty what should I do with it?

Whatever you want to do with it.

do I interpret OP_RETURN/non-standard?

OP_RETURN is standard as long as there is only 1 OP_RETURN in the transaction.

Should I ignore it?

If you want to.  That's up to you and what you are trying to accomplish.

Are they bounced/invalidated transactions?

No.  They are valid, standard transactions.

or especially interesting?

OP_RETURN allows the sender to store some data in the transaction.  I can't say whether or not that data is interesting to you.

Also another question: I always hear about IP address being registered with transactions and all (like it is on blockchain.info) but is this information actually stored inside the blockchain?

No.  There are no IP addresses stored in transactions or the blockchain.  The IP addresses reported by blockchain.info are NOT the IP addresses of the user that sent the bitcoins.  The IP addresses reported by blockchain.info are the IP addresses of the peer node that first relayed the transaction to one of blockchain.info's nodes.

And if yes how can I can find it.

You can't.  All you can do is keep track of which of the nodes that you are connected to sent the transaction to you, and record that node's IP address as the node that relayed the transaction to you.

Doesn's seem to be inside 'getrawtransaction'?

Doesn't exist in a transaction.


Title: Re: Getting input addresses
Post by: achow101 on February 20, 2017, 10:28:03 PM
Thanks for your reply!

On the multiple outputs:

As far as I understand is that in case of multiple outputs any of the addresses can spend the coins (but only 1 can do it naturally).
They are multisig outputs, not multiple outputs. What you just said is incorrect. They have the exact same requirements as a normal p2sh multisig address for spending. WIth the example transaction that you linked, 1 out of the 2 public keys in a bare multisig output need to sign the spending transaction in order to spend. If that were in the traditional 2-of-3 multisig format, then there would still need to be two signatures which correspond to two different public keys specified in the output.

But when it is empty what should I do with it? I do I interpret OP_RETURN/non-standard? Should I ignore it? Are they bounced/invalidated transactions? or especially interesting?
Look at the other data in the output. It will say what type the output is. Generally anything that is not pubkey, pubkeyhash, or scripthash should be shown as non-standard. If it is an OP_RETURN output, the type is nulldata and you can get the data after the OP_RETURN and display that. Usually those can be interpreted as strings, but they can really be any arbitrary data.

Also another question: I always hear about IP address being registered with transactions and all (like it is on blockchain.info) but is this information actually stored inside the blockchain? And if yes how can I can find it. Doesn's seem to be inside 'getrawtransaction'?
No. IP addresses are not part of anything to do with blocks or transactions. They would ruin privacy and there is no use for an IP address. The IP addresses you see in block explorers are simply the IP address of the node that relayed the transaction to the block explorer's node. Those IPs are not the IP address of the node that sent the transaction.


Title: Re: Getting input addresses
Post by: amaclin on February 21, 2017, 07:58:32 AM
Found an example: https://blockchain.info/tx/055f9c6dc094cf21fa224e1eb4a54ee3cc44ae9daa8aa47f98df5c73c48997f9
But when it is empty what should I do with it? I do I interpret OP_RETURN/non-standard?
These are bare multisig outputs. They are standard
The blockchain.info can not decode them because their programmers are dumb.


Title: Re: Getting input addresses
Post by: ovanwijk on February 27, 2017, 11:53:44 AM
Thanks all, it makes more sense now. However I do have another question in line with my previous question, or more something I want confirmation on.

There is no way -within a transaction- to know what input contributed to which exact output?

As in: I have 4 Vin that each contribute 2.5 btc with a total of 10 btc then I have 10 output of each 1 btc (no fees considered). That would mean each input contributed 10% to each output?


Title: Re: Getting input addresses
Post by: DannyHamilton on February 27, 2017, 01:29:32 PM
Thanks all, it makes more sense now. However I do have another question in line with my previous question, or more something I want confirmation on.

There is no way -within a transaction- to know what input contributed to which exact output?

As in: I have 4 Vin that each contribute 2.5 btc with a total of 10 btc then I have 10 output of each 1 btc (no fees considered). That would mean each input contributed 10% to each output?

It's up to you how you want to handle that.  Your suggestion is what I would do.

As an analogy, think about the transaction as a crucible in which gold nuggets are melted as inputs, and then poured out into new nuggets as outputs.

If you contribute 4 nuggets of gold each with a mass of 2.5 grams with a total of 10 grams of gold, then melt it all into a liquid and pour out 10 new nuggets with a mass of 1 gram each (no leftovers in the crucible considered). Is there a way to know exactly how much gold each individual input contributed to any specific output?  Or do you just assume that each input contributed 10% to each output?