Skip to content
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

Transaction.getFee() returning 0.0 #82

Open
rafa-js opened this issue Dec 6, 2018 · 4 comments
Open

Transaction.getFee() returning 0.0 #82

rafa-js opened this issue Dec 6, 2018 · 4 comments

Comments

@rafa-js
Copy link

rafa-js commented Dec 6, 2018

I'm experiencing problems with the tx.getFee() method. Some times works fine but others just returns 0.0 when actually the fees are higher than that.

I haven't been able to find a pattern with the transactions causing the issues. Some examples:

Any hypothesis about what could be causing the this random issue?

@HashEngineering
Copy link
Collaborator

https://github.com/bitcoinj-cash/bitcoinj/blob/cash-0.14/core/src/main/java/org/bitcoinj/core/Transaction.java#L429

Perhaps there is a difference between sent and received transactions. For received transactions, there is no way to calculate the fee, unless they had zero confirmations, and even then, maybe not.

@rafa-js
Copy link
Author

rafa-js commented Dec 8, 2018

Oh, didn't see the comment. What's the best way to solve this problem in your opinion?

Thanks @HashEngineering

@HashEngineering
Copy link
Collaborator

HashEngineering commented Dec 9, 2018

Since bitcoinj doesn't store the entire blockchain, it is not possible to determine the fee on received transactions without an external data source such as a block explorer or an electrum server. There is no p2p message (such as getdata) to query for a transaction that is in the blockchain.

Transactions store the inputs, which are references to previous transactions, only with the transaction id and an index of the output. To determine the fee, bitcoinj would need to look back in the blockchain for that transaction and it would find the amount of coins that were in that input. bitcoinj does not store the blockchain and therefore cannot get the information of this input.

There are some cases where bitcoinj can get the inputs:

  1. It is a sent transaction and bitcoinj stores the transaction input in the wallet. The input was a previously received transaction.
  2. The received transaction A is spending coins from another transaction B in the mempool (a 0-conf transaction). bitcoinj will download the other transaction B. After that bitcoinj can determine the fee of A, but not of B.

@rafa-js
Copy link
Author

rafa-js commented Dec 10, 2018

@HashEngineering Thanks for the details! So basically the workarounds I see are:

  • Downloading the tx dependencies to know the output values.
  • Using an external explorer to directly know the tx fees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants