Skip to content

Add rpc command 'getunconfirmedbalance'... - #3369

Merged
laanwj merged 1 commit into
bitcoin:masterfrom
TripleSpeeder:master
Dec 20, 2013
Merged

laanwj merged 1 commit into
bitcoin:masterfrom
TripleSpeeder:master

Conversation

@TripleSpeeder

Copy link
Copy Markdown
Contributor

...to obtain total unconfirmed balance.

I am needing this frequently, so this might be useful for other people, too.

@BitcoinPullTester

Copy link
Copy Markdown

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/6027b460e40e7769930d0e89f18f011fa0f6c262 for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

@gavinandresen

Copy link
Copy Markdown
Contributor

What do you need this for?

Unconfirmed balances are very dangerous things.....

@TripleSpeeder

Copy link
Copy Markdown
Contributor Author

In one project that is working both with unconfirmed and raw transactions I need to monitor the unconfirmed funds in the hot wallet. First I tried approaches like

confirmed = bitcoind_api.getbalance('*', 1)
inc_unconfirmed = bitcoind_api.getbalance('*', 0)
unconfirmed = inc_unconfirmed - confirmed

and several variations. But this was not working like intended. If I remember correctly the problem was that outgoing transactions, while being unconfirmed, are still taken into account with the getbalance methods, leading to wrong results.
Compared with messing around with the getbalance method (including the non-intuitive account handling...) the new "getunconfirmedbalance" method seems quite straightforward and does exactly what it says.

@gavinandresen

Copy link
Copy Markdown
Contributor

I still don't understand what, at a high level, you were trying to accomplish. It sounds like maybe you should be using -walletnotify instead of polling getbalance.

@laanwj

laanwj commented Dec 10, 2013

Copy link
Copy Markdown
Member

The unconfirmed balance is shown in the GUI, so in a way it makes sense to expose it on the RPC as well.

And this looks like a pretty sane and minimal code addition as these things go.

But indeed, relying on it to see if funds have arrived is dangerous.

@TripleSpeeder

Copy link
Copy Markdown
Contributor Author

Thanks for your comments. I am running a site that works a lot with unconfirmed transactions, raw transactions and a very custom coin control implementation, so I am aware of the risks involved.
The highlevel usecase i need this for is very simple. I have a job running every few minutes that collects from bitcoind both confirmed and unconfirmed balance. If any of the values is outside a certain threshhold I am getting notified to investigate or take measures. I just could not get the unconfirmed balance reliable with the existing rpc "getbalance" command, while this pull request makes it very easy :)

@gavinandresen

Copy link
Copy Markdown
Contributor

I've got a feeling I'm going to regret this... but ACK.

@jgarzik

jgarzik commented Dec 12, 2013

Copy link
Copy Markdown
Contributor

ACK

laanwj added a commit that referenced this pull request Dec 20, 2013
6027b46 Add rpc command 'getunconfirmedbalance' to obtain total unconfirmed balance (Michael Bauer)
@laanwj
laanwj merged commit 6027b46 into bitcoin:master Dec 20, 2013
Bushstar pushed a commit to Bushstar/omnicore that referenced this pull request Apr 8, 2020
* Introduce SynchronousUpdatedBlockTip signal

This version of UpdatedBlockTip mirrors the asynchronous behavior that we
had before the introduction of asynchronous signal handling.

* Fix tab spacing in validationinterface.cpp

* Invoke CDeterministicMNManager::UpdatedBlockTip from validation thread

It must be invoked synchronously as otherwise things become inconsistent.

* Call CActiveMasternodeManager::Init with block index

pindexNew in UpdatedBlockTip is not necessarily the current tip, so we
shouldn't rely on it in Init(). This is due to the async nature of the
UpdatedBlockTip invocation.
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants