I'm trying to determine the source address of transactions for automated refunding, but I'm seeing unexpected output from Bitcoin-QT
The transaction in question on blockexplorer: 8bc80f72d9cc6fecda77138e7364f95b48d652db404889deafd48158dc46387e
And below is the result of bitcoind gettransaction
for the same txid. Shouldn't I see the same thing? Or is there some issue with inter-wallet sending?
{
"amount" : 0.00000000,
"fee" : -0.00010000,
"confirmations" : 1,
"blockhash" : "0000000000941dab82b8f78596f93832104288c85e7951b5f505b8c1c30dd4ba",
"blockindex" : 1,
"blocktime" : 1377648593,
"txid" : "8bc80f72d9cc6fecda77138e7364f95b48d652db404889deafd48158dc46387e",
"time" : 1377648549,
"timereceived" : 1377648549,
"details" : [
{
"account" : "",
"address" : "n1SrgGXRGjK2gKcvSDRVUDPA1aVKBaG6PQ",
"category" : "send",
"amount" : -0.10000000,
"fee" : -0.00010000
},
{
"account" : "",
"address" : "mtjmGtkZet4Y7rzQrC8cweuJMYGZFpPw4d",
"category" : "send",
"amount" : -0.10000000,
"fee" : -0.00010000
},
{
"account" : "",
"address" : "n4N4hQZK1sgHv8z3ikHsuN98vGNhshQZSo",
"category" : "send",
"amount" : -0.10000000,
"fee" : -0.00010000
},
{
"account" : "",
"address" : "mvw4DVoSL7APFGdHb2RGYebzBKDBankTAM",
"category" : "send",
"amount" : -0.99950000,
"fee" : -0.00010000
},
{
"account" : "account1",
"address" : "n1SrgGXRGjK2gKcvSDRVUDPA1aVKBaG6PQ",
"category" : "receive",
"amount" : 0.10000000
},
{
"account" : "account2",
"address" : "mtjmGtkZet4Y7rzQrC8cweuJMYGZFpPw4d",
"category" : "receive",
"amount" : 0.10000000
},
{
"account" : "account3",
"address" : "n4N4hQZK1sgHv8z3ikHsuN98vGNhshQZSo",
"category" : "receive",
"amount" : 0.10000000
},
{
"account" : "account4",
"address" : "mvw4DVoSL7APFGdHb2RGYebzBKDBankTAM",
"category" : "receive",
"amount" : 0.99950000
}
]
}
Edit:
And here is the result of combining getrawtransaction
and decoderawtransaction
:
{
"txid" : "8bc80f72d9cc6fecda77138e7364f95b48d652db404889deafd48158dc46387e",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "f96590f6db1e8748f349e93ae5e1e335c57d55df9a26a70f99e7c06b32538f16",
"vout" : 0,
"scriptSig" : {
"asm" : "304502201d7a5a31936d9a4a0ff17f357dda13e87d7459a7663d127da783865858b552c5022100bac9edf373d42c578c92231cc096a620baa174d7bf141c519047b3ca5dc3577101 03f5fd9f5ad8f4a5ac11c9c8e6f6b094129dbc3d8a9f753dc8d415c5c42a5cccfa",
"hex" : "48304502201d7a5a31936d9a4a0ff17f357dda13e87d7459a7663d127da783865858b552c5022100bac9edf373d42c578c92231cc096a620baa174d7bf141c519047b3ca5dc35771012103f5fd9f5ad8f4a5ac11c9c8e6f6b094129dbc3d8a9f753dc8d415c5c42a5cccfa"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.10000000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 da9c29ba563c33688e8e1d85b84a634a271b5282 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914da9c29ba563c33688e8e1d85b84a634a271b528288ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"n1SrgGXRGjK2gKcvSDRVUDPA1aVKBaG6PQ"
]
}
},
{
"value" : 0.10000000,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 9105d7f92fd467f0035cd4b5b58bea1167647618 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a9149105d7f92fd467f0035cd4b5b58bea116764761888ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mtjmGtkZet4Y7rzQrC8cweuJMYGZFpPw4d"
]
}
},
{
"value" : 0.10000000,
"n" : 2,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 fa9c7e784bfae5e3d330cba28b73c804da71f213 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914fa9c7e784bfae5e3d330cba28b73c804da71f21388ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"n4N4hQZK1sgHv8z3ikHsuN98vGNhshQZSo"
]
}
},
{
"value" : 0.99950000,
"n" : 3,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 a918d01415a09ee82034f1dce3217741dcdf5849 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914a918d01415a09ee82034f1dce3217741dcdf584988ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mvw4DVoSL7APFGdHb2RGYebzBKDBankTAM"
]
}
}
]
}
Here's a reference stating the only way is to identify the output index of the previous transaction: https://bitcoin.stackexchange.com/a/12472/3413
If this is accurate, then to determine the "refund" address of a particular transaction, you would have to run the following pseudocode?:
txhex = getrawtransaction(targettxhash)
txjson = decoderawtransaction(txhex)
foreach txinput in txjson.vin:
txhexprev = getrawtransaction(txinput.txid)
txjsonprev = decoderawtransaction(txhexprev)
foreach txprevoutput in txjsonprev.vout:
txrefundarray[] += {'address':txprevoutput.scriptPubKey.addresses[0], 'amount':txprevout.value} // 0th address only doesn't support multi-sig