1

I have probably misunderstood the meaning of bitcoind 'getbalance' command.

I am using bitcoind in regtest mode.

I am using imported multisig bitcoin watch-only addresses, which are the following:

mirko_180603243: 2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p
mirko_1169810029: 2N1DwxUDghdk2DRWee8PVLtcY9xxTM374Nj
mirko_1977534765: 2NANSy3VqQZmhQH36tNADVxEahLHJzQovdz

In the initial state I have no such transaction, as expected: listtransactions mirko_180603243 10 0 true: [] listtransactions mirko_1169810029 10 0 true: [] listtransactions mirko_1977534765 10 0 true: []

Then I send some money to the first account (mirko_180603243)

sendtoaddress 2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p 10 "Initial load"
setgenerate true 6

From the point of view of the balance, everything is right:

getbalance mirko_180603243 0 true: 10
listaccounts 1 true: "mirko_180603243" : 10.00000000

listunspent:
    {
        "txid" : "3c9970cda24b87ebf7080ff40d3be7cdded1afb6eafe3d9b7ade31f9c7fadc13",
        "vout" : 0,
        "address" : "2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p",
        "account" : "mirko_180603243",
        "scriptPubKey" : "a9142480ec8ccaea0328c6392c2ba4a4cd6fb0f6638b87",
        "amount" : 10.00000000,
        "confirmations" : 6,
        "spendable" : false
    }

From the point of view of the transactions, everything is consistent:

listtransactions "mirko_180603243" 10 0 true: 
    {
        "involvesWatchonly" : true,
        "account" : "mirko_180603243",
        "address" : "2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p",
        "category" : "receive",
        "amount" : 10.00000000,
        "vout" : 0,
        "confirmations" : 12,
        "blockhash" : "0000a083a8b0543d68059d9c3421b4ff681630601e80c3f4d4e58a05e228385d",
        "blockindex" : 1,
        "blocktime" : 1414401010,
        "txid" : "3c9970cda24b87ebf7080ff40d3be7cdded1afb6eafe3d9b7ade31f9c7fadc13",
        "walletconflicts" : [
    ],
        "time" : 1414400968,
        "timereceived" : 1414400968,
        "comment" : "Initial load"
    }

Then I send 3 BTC from the first account (mirko_180603243: 2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p) to the second one (mirko_1169810029: 2N1DwxUDghdk2DRWee8PVLtcY9xxTM374Nj). Since I only have 10 BTC in one block, I send back 7 BTC to myself.

This is the final transaction:

gettransaction 153c45f199eba376d43cad614c2cd410140d2c9597b0de8392fa71209f6e43a5
{
    "amount" : 10.00000000,
    "confirmations" : 6,
    "blockhash" : "0000da6254c04d050c93bb9949a5fdaec9256038edce3daa9798d2e0feca8199",
    "blockindex" : 1,
    "blocktime" : 1414401566,
    "txid" : "153c45f199eba376d43cad614c2cd410140d2c9597b0de8392fa71209f6e43a5",
    "walletconflicts" : [
],
    "time" : 1414401480,
    "timereceived" : 1414401480,
    "details" : [
],
    "hex" : "010000000113dcfac7f931de7a9b3dfeeab6afd1decde73b0df40f08f7eb874ba2cd70993c00000000fa0047304402205bb11653b7668488cf60a61c458bc729619b395d7b5d82c597d223956c0dc62d0220396fef209b3077b129648797ba72b9da0be94334dcebf067d1d5e31bb26ecf4a014730440220203dcdd4169db7c1259c14c7fe8ed0eb449b3f26a2732cbba3713779034afd9d022020c85a7ec67a8aaad642ff96b63b0c98ff9dedb35a68c3dfddd296ee7db08ac1014c67522102a880b200040eb0f4e3984263ce3fb86b39cb5ba4c9ea247bb2c4de4d36eec4ff4104abc0c6d83b138ff68b60ee11b5deb98da1bd4fe9d4894fe1041e436f5cebfb7be7cf886f15ea34a746302700008c88c1257b2f37128d764bc922940b2e01038752aeffffffff0200a3e1110000000017a914578335446ee73c6379c7cef95c4fc8c3c576e3a0870027b9290000000017a9142480ec8ccaea0328c6392c2ba4a4cd6fb0f6638b8700000000"
}

decoderawtransaction 010000000113dcfac...cd6fb0f6638b8700000000
{
    "txid" : "153c45f199eba376d43cad614c2cd410140d2c9597b0de8392fa71209f6e43a5",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "3c9970cda24b87ebf7080ff40d3be7cdded1afb6eafe3d9b7ade31f9c7fadc13",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "0 304402205bb11653b7668488cf60a61c458bc729619b395d7b5d82c597d223956c0dc62d0220396fef209b3077b129648797ba72b9da0be94334dcebf067d1d5e31bb26ecf4a01 30440220203dcdd4169db7c1259c14c7fe8ed0eb449b3f26a2732cbba3713779034afd9d022020c85a7ec67a8aaad642ff96b63b0c98ff9dedb35a68c3dfddd296ee7db08ac101 522102a880b200040eb0f4e3984263ce3fb86b39cb5ba4c9ea247bb2c4de4d36eec4ff4104abc0c6d83b138ff68b60ee11b5deb98da1bd4fe9d4894fe1041e436f5cebfb7be7cf886f15ea34a746302700008c88c1257b2f37128d764bc922940b2e01038752ae",
                "hex" : "0047304402205bb11653b7668488cf60a61c458bc729619b395d7b5d82c597d223956c0dc62d0220396fef209b3077b129648797ba72b9da0be94334dcebf067d1d5e31bb26ecf4a014730440220203dcdd4169db7c1259c14c7fe8ed0eb449b3f26a2732cbba3713779034afd9d022020c85a7ec67a8aaad642ff96b63b0c98ff9dedb35a68c3dfddd296ee7db08ac1014c67522102a880b200040eb0f4e3984263ce3fb86b39cb5ba4c9ea247bb2c4de4d36eec4ff4104abc0c6d83b138ff68b60ee11b5deb98da1bd4fe9d4894fe1041e436f5cebfb7be7cf886f15ea34a746302700008c88c1257b2f37128d764bc922940b2e01038752ae"
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 3.00000000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_HASH160 578335446ee73c6379c7cef95c4fc8c3c576e3a0 OP_EQUAL",
                "hex" : "a914578335446ee73c6379c7cef95c4fc8c3c576e3a087",
                "reqSigs" : 1,
                "type" : "scripthash",
                "addresses" : [
                    "2N1DwxUDghdk2DRWee8PVLtcY9xxTM374Nj"
                ]
            }
        },
        {
            "value" : 7.00000000,
            "n" : 1,
            "scriptPubKey" : {
                "asm" : "OP_HASH160 2480ec8ccaea0328c6392c2ba4a4cd6fb0f6638b OP_EQUAL",
                "hex" : "a9142480ec8ccaea0328c6392c2ba4a4cd6fb0f6638b87",
                "reqSigs" : 1,
                "type" : "scripthash",
                "addresses" : [
                    "2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p"
                ]
            }
        }
    ]
}

Everything is consistent with the unspent blocks:

{
    "txid" : "153c45f199eba376d43cad614c2cd410140d2c9597b0de8392fa71209f6e43a5",
    "vout" : 1,
    "address" : "2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p",
    "account" : "mirko_180603243",
    "scriptPubKey" : "a9142480ec8ccaea0328c6392c2ba4a4cd6fb0f6638b87",
    "amount" : 7.00000000,
    "confirmations" : 6,
    "spendable" : false
}
{
    "txid" : "153c45f199eba376d43cad614c2cd410140d2c9597b0de8392fa71209f6e43a5",
    "vout" : 0,
    "address" : "2N1DwxUDghdk2DRWee8PVLtcY9xxTM374Nj",
    "account" : "mirko_1169810029",
    "scriptPubKey" : "a914578335446ee73c6379c7cef95c4fc8c3c576e3a087",
    "amount" : 3.00000000,
    "confirmations" : 6,
    "spendable" : false
}

What I can not understand is the final balance:

getbalance mirko_180603243 1 true:
    17 instead of 7

getbalance mirko_1169810029 1 true:
    3

Basically, it seems to be that 'getbalance' sums up all the incoming transactions, ignoring the ones that go out.

Currently, I am computing the available amount summing up all the unspent blocks for each account. Unfortunately, though, that is not very user-friendly, as when you pay for 3 BTC and you have a single 10 BTC block, before the confirmations you see 0. I might include the 0 confirmations transactions as well, but the user may think that he could spend that money, which is false.

Sorry for the long message.

P.S. I was forgetting to mention that I have discovered that accounts are NOT used for debit: if you want to pay, you have to use 'move' or 'sendfrom', but I do want just to have watch-only addresses, as I do not want to keep the private keys.

For this reason, I can not rely on 'move' or 'sendfrom' commands but I have to manually create and multi-sign my transaction.

1

1 Answer 1

2

From the bitcoin "Accounts Explained" wiki page (https://en.bitcoin.it/wiki/Accounts_explained):

When you receive bitcoins, they are always assigned to one of your accounts, and you can change which account is credited based on which bitcoin address receives the coins, just like you tell a bank teller which account to credit when you deposit cash in your bank. However, sending bitcoins is like withdrawing cash from the bank; the coins that are sent out and debited from an account are almost always not the same coins that were deposited into that account.

So you can't really do what you said (below), sending from an account to another account. You can, however, move balances from an account to another account, with the move command, but this doesn't require a bitcoin transaction.

Then I send 3 BTC from the first account (mirko_180603243: 2MvaEkzFyw6EcQGR2vrFWQd4rDNSiP4Qn7p) to the second one (mirko_1169810029: 2N1DwxUDghdk2DRWee8PVLtcY9xxTM374Nj).

I think if you do:

./bitcoin-cli listaccounts

You will see some accounts with negative balances to account for the extra high balance you are seeing.

Note: The "fromaccount" in the sendfrom command just tells the client which account to debit when it sends to the address specified.

1
  • Hi Stephen, thank you for your answer. You are right, I have not been very clear: when I say I send 3 BTC from the first account to the second one, I mean that I create a raw transaction, multisign it and finally submit it. That tx has a p2ph script that corresponds to the multisig address of the second account. All in all, what I would like to do would be to find the balance without using the 'getbalance' rpc method. Thanks again for your help.
    – fcracker79
    Commented Oct 29, 2014 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.