dtr-org / unit-e

A digital currency for a new era of decentralized trust
https://unit-e.io
MIT License
45 stars 15 forks source link

Validate deposit prior adding to the wallet #1040

Closed frolosofsky closed 5 years ago

frolosofsky commented 5 years ago

At the moment, when a user prepares deposit, the node creates a transaction and adds it to the wallet. It, in turn, tries to accept it to the memory pool and could fail when the deposit is invalid (for example validator is blacklisted). That leads to disappearing of the deposit from the balance.

This commit fixes that by validating deposit before adding transaction to the wallet.

Fixes #996.

scravy commented 5 years ago

This code change looks alright to me, but I am wondering:

The whole balance thing is a tricky thing, once I spend some UTXO they are deduced from my balance. Yet they might not be included in the blockchain actually yet, so they are not really spend. So I am wondering it there should be some sort of "in flight balance", like something which one owns but which has not been included in the blockchain yet.

The thoughts that led me here are: It strikes me as odd that anything which has not been confirmed yet (included in the blockchain, possibly even finalized) alters any numbers; but of course it makes sense for the wallet as a user should not create a transaction form balance which she already attempted to spend, true. So maybe some "there but not really there" would be appropriate.

Gnappuraz commented 5 years ago

This code change looks alright to me, but I am wondering:

The whole balance thing is a tricky thing, once I spend some UTXO they are deduced from my balance. Yet they might not be included in the blockchain actually yet, so they are not really spend. So I am wondering it there should be some sort of "in flight balance", like something which one owns but which has not been included in the blockchain yet.

The thoughts that led me here are: It strikes me as odd that anything which has not been confirmed yet (included in the blockchain, possibly even finalized) alters any numbers; but of course it makes sense for the wallet as a user should not create a transaction form balance which she already attempted to spend, true. So maybe some "there but not really there" would be appropriate.

There is a getunconfirmedbalance rpc that I think does what you ask, returns the balance that is coming from txs with 0 confs or in the mempool.