-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a GetAllUnspentTxOuts API call to mobilecoind (#3663)
* Add a GetAllUnspentTxOuts API call to mobilecoind Currently, there is no easy way to get all of the unspent tx outs associated to a given monitor id. This is a very normal thing to want to do if you are managing a wallet with many subaddresses, because you have no way to subscribe to updates when payments come in, so you would like to be able to poll for them efficiently. The GetUnspentTxOutList API call exists, but it only allows you to search for UTXOs one subaddress and token id at a time. You get use the GetProcessedBlock API call, which allows you to be more efficient, but it still creates a lot of extra work on the caller side, because now you have to think about blocks and keep track of a cursor as you advance through the chain. There are other things about this API that are annoying -- the ProcessedTxOut tells you that you sent or received a TxOut in a particular block, but not whether you still have it. And many of the other calls, like GenerateTx, require you to provide an UnspentTxOut for the InputList argument, but you can't get an UnspentTxOut from a ProcessedTxOut, so you will have to make another call to GetUnspentTxOutList if you want to do that. --- By making a version of GetUnspentTxOutList that doesn't impose any filtering, and just gives me all UTXOs that exist against my monitor, it becomes much easier to determine if there was new activity on my monitor. I don't have to think about blocks anymore. If I'm building an exchange, my loop can be like: * Check if I got any new UTXOs * If I got UTXOs on subaddress > 0, then that's a deposit * Report the deposit, using part of the UTXO as the inbound tx id. * Remote services can ignore it if it was a duplicate * Sweep it to subaddress zero * Now I won't pick it up again and report it again if I get restarted * Maybe make an optimization tx if subaddress 0 has many UTXOs. This feels much simpler to me conceptually and much closer to how I intuitively want an exchange integration to work, compared to the GetProcessedBlock based approach. --- Fortunately, it was extremely easy to implement this API and did not require any changes to the mobilecoind database. This is because of properties of how lmdb orders keys and how lmdb cursors work. I was able to implement this in the time that I had to wait for either of mobilecoind or full-service to finish downloading and syncing the ledger, so that I can test other things. If this PR is accepted, it will allow me to simplify a bunch of other code that I had to write. * fix clippies
- Loading branch information
Showing
4 changed files
with
236 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters