-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
searchrawtransactions -- vin does not include address. #485
Comments
I just noticed that the amount is not included in vin either, which I also need. |
Inputs do not have addresses... |
agreed that inputs do not have addresses. nor amounts. but the previous outputs that the inputs reference typically (always?) do have them. And applications sometimes need them. I suppose this is why most blockchain oracle type APIs I have looked at include both addresses and amounts for inputs. I provided a sample of toshi's output above. It is orders of magnitude more efficient for the API provider to lookup the previous outputs and return addresses and amount inline than for an application to make individual getrawtransaction queries to lookup each previous transaction and find the matching outputs. For my particular application, it is the difference between useful and too slow to use. Or if there is some other efficient way to obtain all coin in/out amounts for a particular address (all time) via the RPC API, please point me to it. My app is displaying a transaction history with running balance for one (or more) addresses. anyway, I have been hacking on the btcd code and I got something working. I plan to submit a pull request soon(ish). Hopefully it (or an improved version) can be integrated. One possibility: I could make the extra fields optional for: Another possibility would be to make it a separate API. We can continue the discussion in the pull request when it is ready. |
The address of an output that created a UTXO is not at all related to that UTXO's use as an input. |
|
As luke-jr pointed out, the "issue" here is that inputs do not have addresses. When a transaction creates an unspent transaction output (UTXO), it might be paying directly to a pubkey, to a pubkey-hash (Bitcoin) address, to a bare multi-sig addresses, to a pay-to-script-hash (P2SH) address, or any other number of nonstandard uses. So, when a transaction input consumes one of those UTXOs, there is no guarantee that it has an address associated with it. In practice it usually does, but therein lies the problem - it's not foolproof and thus your application needs to be extremely careful to avoid being exploitable as a result. When an address index is built, it is possible to track all of the funds coming in and out of a particular address, and that is what the APIs you mention are doing. @Roasbeef could probably speak to how difficult it would be for btcd to add that information when the address index is enabled since he's the most familiar with the address index format given he added the code for it. In the mean time, what will probably work for you is the rescan API in btcd's websocket API. That allows you to specify an address and it delivers all transactions which pay coins to that address and consume coins from it thereby letting your application manually create a balance. |
@dan-da Yes, anything presenting the previous sent-to address as a "from address" is wrong. The only solution is to use a unique address for each payment (which is the intended design in the first place). @davecgh Even when the UTXO script was created by sending to an address, that address is entirely unrelated to the UTXO itself or the transaction spending it. The address's lifetime necessarily ends when the transaction is received. |
Hi Dave, thanks for your comments. I understand that transaction outputs do not always pay directly to address(es). However, often/usually they do, and it can be useful to provide address info in those cases as well as the amount of each prev output. In the event that there is no address in the previous output then the addresses array can simply be empty or not present, or multiple addresses in the case of multisig -- as other APIs do. Here is a toshi multisig example. "inputs":[ { "previous_transaction_hash":"...", "output_index":0, "amount":50000000, "script":"...", "addresses":[ "1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq", "1AJbsFZ64EpEfS5UAjAfcUG8pH8Jn3rn1F", "1ETBbsHPvbydW7hGWXXKXZ3pxVh3VFoMaX" ] } ], The point that neither of the comments have addressed is that other blockchain APIs are already doing this because it is useful. I already provided a link and sample output from toshi.io. I'll provide some more at the bottom. Thanks for the link to the rescan API docs. I wasn't aware of that. Unfortunately I don't think it will help my use case for a couple reasons: 1) I am using the RPC API and changing to websockets isn't really an option at present. 2) rescan sounds very slow, and I need quick results. Hence my joy at finding the address index in btcd. The searchrawtransactions API only functions when the address index is enabled. I have already wrestled with the code enough that I have the desired new functionality. I just need to a bit of cleanup and some more testing before publishing a pull request. Perhaps @Roasbeef can review it. Since there seems to be resistance to this functionality, I'll go ahead and make the new behavior optional. As you can see below, the industry has already pretty much agreed on this. All these APIs include address and amount/value. btcd wouldn't exactly be breaking new ground here. Bitpay Insight: https://insight.bitpay.com/api/addrs/18xKdc2kXMJYCz12QpEqTZXUpJympcKchY/txs "vin": [ { "txid": "...", "vout": 1, "scriptSig": { "asm": "...", "hex": "..." }, "sequence": 4294967295, "n": 0, "addr": "16y6iQDD1a7uVm6UvWJ7KdhHjGCJ5deMSx", "valueSat": 849990000, "value": 8.4999, "doubleSpentTxID": null } ], blockchain.info: note: I like how they use a key named "prev_out" to make that clear. "inputs":[ { "sequence":4294967295, "prev_out":{ "spent":true, "tx_index":54282905, "type":0, "addr":"16y6iQDD1a7uVm6UvWJ7KdhHjGCJ5deMSx", "value":849990000, "n":1, "script":"76a9144174b1422c4ab89e1ce41ae4d71ffc78957cf53188ac" }, BlockCypher: http://dev.blockcypher.com/#address-full-endpoint "inputs": [ { "prev_hash": "729f6469b59fea5da7...", "output_index": 0, "script": "483045022100d06cdad1a...", "output_value": 3500000, "sequence": 4294967295, "addresses": [ "1VxsEDjo6ZLMT99dpcLu4RQonMDVEQQTG" ], "script_type": "pay-to-pubkey-hash" }, ... ], Blocktrail: https://www.blocktrail.com/api/docs#api_data "inputs": [ { "index": 0, "output_hash": "b0fc639ef699e8521dd4863fc9b8f6224d8aafb3e4fe52bb784150973c711523", "output_index": 1, "value": 105139900, "address": "1qMBuZnrmGoAc2MWyTnSgoLuWReDHNYyF", "type": "pubkeyhash", "multisig": null, "script_signature": "0x48 0x3045022100b7dcc897c7baadf693865818ea1fa7c544073936cad37f27fa402cb517989f7002201c56fb93e3acb3c016d394765f0a248cb85fa6ae290336fef88ca811dd6d6d0f01 0x41 0x04bc6b933acf9ff99e9c2946ecfe927a3813e0218bcfa58f3b5107a956a307055faa2609b879e51dda158820f93c8a22d12abfaa46c99d43e3ecc4c497c27fec5b" } ], |
Hey @dan-da, so it wouldn't be too difficult to add the functionality you desire to the current API for searchrawtransactions. However, you should be mindful of the comments made above by dave and luke-jr, although the API's you listed do indeed display "from addresses", the very existence of that terminology creates incorrect thought models which lead to people developing skewed models of the way Bitcoin actually works, which may directly lead to loss of user funds (eg: sending a refund to a "from address"). So back to the required changes. I'm unsure what you've done so far but, you shouldn't need to alter much concerning the address index itself. It's pretty minimal and just stores the info to identify the location of a particular Whatever changes you make concerning the addr index or the related EDIT: accidentally sent out this comment prematurely before I had finished drafting it |
@luke-jr: Agreed about the lifetime. I had already posted more about that on the mailing list in regards to this issue. I'll quote it here for reference:
|
This has been implemented by #487. |
vout includes an array of addresses but vin does not.
Other APIs I have used/evaluated include the address field whenever an address is present (ie non coinbase transactions). For example, here is output from toshi.io and btcd for the same address
https://bitcoin.toshi.io/api/v0/addresses/1GeBuz6M42h5mhWmSDFhmXsdNjdqNn6D76/transactions
And here is btcd output:
btcctl searchrawtransactions 1GeBuz6M42h5mhWmSDFhmXsdNjdqNn6D76
My application needs the address from vin when available. So the impact on myself is that I either must drag in a large external library to parse the vin script or fork btcd and implement it there.
The text was updated successfully, but these errors were encountered: