Title: bitcoind RPC calls: get fee amount of received transaction Post by: binaryFate on July 07, 2013, 10:40:12 PM Dear all,
I don't find a convenient way with bitcoind rpc calls, to determine the fee amount of a transaction I receive. I found the information on the wiki to be wrong or outdated on this: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list#Common_operations 'gettransaction' is said to return the fee, but I found that it is true only for transaction of type "send", not "receive". Maybe there is another place where I can find more reliable info on the bitcoind RPC calls? To get this fee amount, I would like to avoid looping over vin and vouts to compute the difference of the sums, there must be something easier! Am I missing something? Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: grue on July 07, 2013, 10:56:14 PM there is no reliable to determine what fees the client will use. patches are welcome, but the preferred solution is to set the tx fee to 0.0001 BTC by default, and deduct that from your customer.
Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: binaryFate on July 07, 2013, 11:14:51 PM there is no reliable to determine what fees the client will use. patches are welcome, but the preferred solution is to set the tx fee to 0.0001 BTC by default, and deduct that from your customer. Either I didn't explain my question properly, or you read it a bit fast :) I don't want to know what fee will be used, but to know the fee included in a transaction I received from somebody else. Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: btc4ever on July 07, 2013, 11:19:39 PM The OP was asking how a recipient could determine what fees were paid by sender. I'm not sure that's possible. anyone?
there is no reliable to determine what fees the client will use. patches are welcome, but the preferred solution is to set the tx fee to 0.0001 BTC by default, and deduct that from your customer. Somehow the bitcoin-qt UI is able to display the required fee amount to the user with a proceed/cancel dialog. So it seems like the same thing should be possible via RPC api, by hooking into the code the UI uses. I envision something like: send_handle = rpc.prepareSend(); meta = rpc.getMeta(send_handle); if( meta.fee > limit ) abort(); else rpc.send( send_handle ); This is a serious pain point for developers trying to use bitcoind for anything real. Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: kjj on July 08, 2013, 03:03:15 AM I'm sure you could puzzle it out by using the raw transaction decoder.
But why would you do that? Unless you are also the miner of the block that included that transaction, you don't care about the fee: It isn't yours. Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: binaryFate on July 08, 2013, 10:47:04 AM I'm sure you could puzzle it out by using the raw transaction decoder. Yes I could, by doing this: To get this fee amount, I would like to avoid looping over vin and vouts to compute the difference of the sums But I'm surprised I cannot get this piece of information as an explicit field from bitcoind.For instance I can get the amount of the transaction with gettransaction or getrawtransaction, I don't have to sum all the vout myself. I'm asking if there's an equivalent for fees. But why would you do that? Unless you are also the miner of the block that included that transaction, you don't care about the fee: It isn't yours. I know it's not mine, but I'd like to know this anyway. For instance, I could check how much the transaction complies with 0.8.2+ rules, or I could estimate the time to be included in a block. I don't think the "why?" is relevant to my question anyway. :)Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: binaryFate on July 09, 2013, 11:52:46 AM Bump
Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: DannyHamilton on July 09, 2013, 12:39:25 PM Perhaps a future version will add an additional API for this, but at the moment the only way you can find the information is by "looping over vin and vouts to compute the difference of the sums."
Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: binaryFate on July 09, 2013, 03:17:49 PM Perhaps a future version will add an additional API for this, but at the moment the only way you can find the information is by "looping over vin and vouts to compute the difference of the sums." Gosh! :( Thanks Danny for the clarity. I'm not sure how I can loop over the vins actually. They don't include amounts, just a reference to which vouts of other transactions they refer. Even with "txindex=1", how can I query bitcoind about these transactions as they have nothing to do with my wallet addresses?... I'll try, but I have doubt I can get info about them. Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: kjj on July 09, 2013, 05:49:49 PM Code: bitcoind getrawtransaction 946a49aca6fad0cc95792d70fd189ff4f3ca2e113da89c7780a2c2e9a73df41d 1 Replace that txid with the txid you want to see. Basically, you look up the transaction you want to see. Loop through the vouts and add up the values. Then, loop through the vins and do another lookup on each of them, add up those values.* Subtract the second value from the first value, and you have the fee. * When something is a vin here, it was a vout in a previous transaction. You look up that previous transaction by txid using the same call as above, then just ignore everything except the vout that you need. Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: binaryFate on July 09, 2013, 05:56:57 PM That's what I had in mind, thanks for writing this down precisely.
My latest concern is that when I'll do this: Then, loop through the vins and do another lookup on each of them bitcoind might complain that it cannot find the transaction (as it is not linked to my wallet addresses in any way) I couldn't test yet if it works, if it works only with "txindex=1", if does not work at all (I fear once all outputs are spent the information won't remain anywhere locally)... I'll try soon. Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: NielDLR on July 10, 2013, 03:10:48 AM That's what I had in mind, thanks for writing this down precisely. My latest concern is that when I'll do this: Then, loop through the vins and do another lookup on each of them bitcoind might complain that it cannot find the transaction (as it is not linked to my wallet addresses in any way) I couldn't test yet if it works, if it works only with "txindex=1", if does not work at all (I fear once all outputs are spent the information won't remain anywhere locally)... I'll try soon. I've recently done a similar thing for a bitcoin project. You'll have to set txindex=1 and then run bitcoind again with the -reindex flag. When you use getrawtransaction again, it will work on all possible transactions, regardless if all the outputs have been spent or not. Then, as kjj mentioned, loop through vouts (add them up) and then lookup each vin using getrawtransaction on the txid. However, you might be confused on how to find the exact output amount for your vin. The vout parameter in the vin is a reference to which output it refers to from your input. Look below: Code: "vin": [ The vout is 1. Now if you run a getrawtransaction on that txid you'll see this in the vout: Code: "vout": [ n:1 is the one you're looking for. Thus the value is 4.7305. Now add up all the values for all the vins of the original transaction and minus the vouts = fee. Title: Re: bitcoind RPC calls: get fee amount of received transaction Post by: binaryFate on July 10, 2013, 11:13:14 AM Thanks a lot NielDLR! :)
Make a pull request. Don't bitch about it, this is open source software, either code it yourself or shut up. I presume you're "answer" is for me. I perfectly know how an open source project works and would never "bitch" about it. Where did you see that I complained? I asked this question because among all possible API calls I may have missed one that suits my need. I don't thank you sir for your useless post and your harsh tone out of nowhere. |