Skip to content

Commit

Permalink
multi-scope: update getbalance
Browse files Browse the repository at this point in the history
  • Loading branch information
roylee17 committed Sep 26, 2022
1 parent 8cadd74 commit d54e539
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/rpchelp/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var Methods = []struct {
{"getaccountaddress", returnsString},
{"getaddressesbyaccount", returnsStringArray},
{"getaddressinfo", []interface{}{(*btcjson.GetAddressInfoResult)(nil)}},
{"getbalance", append(returnsNumber, returnsNumber[0])},
{"getbalance", returnsNumber},
{"getbestblockhash", returnsString},
{"getblockcount", returnsNumber},
{"getinfo", []interface{}{(*btcjson.InfoWalletResult)(nil)}},
Expand Down
32 changes: 12 additions & 20 deletions rpc/legacyrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,30 +582,22 @@ func getAddressInfo(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
func getBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetBalanceCmd)

var balance btcutil.Amount
var err error
accountName := "*"
if cmd.Account != nil {
accountName = *cmd.Account
}
if accountName == "*" {
balance, _, err = w.CalculateBalance(int32(*cmd.MinConf))
if err != nil {
return nil, err
}
} else {
var account uint32
account, err = w.AccountNumber(waddrmgr.KeyScopeBIP0044, accountName)
if err != nil {
return nil, err
}
bals, err := w.CalculateAccountBalances(account, int32(*cmd.MinConf))
if *cmd.Account == "*" {
balance, _, err := w.CalculateBalance(int32(*cmd.MinConf))
if err != nil {
return nil, err
}
balance = bals.Spendable
return balance.ToBTC(), nil
}

account, err := w.AccountNumber(*cmd.Account)
if err != nil {
return nil, err
}
return balance.ToBTC(), nil

bals, err := w.CalculateAccountBalances(account, int32(*cmd.MinConf))

return bals.Spendable.ToBTC(), err
}

// getBestBlock handles a getbestblock request by returning a JSON object
Expand Down

0 comments on commit d54e539

Please sign in to comment.