diff --git a/rpcserver.go b/rpcserver.go index 65e6478..3765c1b 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1316,7 +1316,6 @@ var rpcHandlers = map[string]requestHandler{ // Extensions to the reference client JSON-RPC API "exportwatchingwallet": ExportWatchingWallet, - "getaddressbalance": GetAddressBalance, // This was an extension but the reference implementation added it as // well, but with a different API (no account parameter). It's listed // here because it hasn't been update to use the reference @@ -1705,32 +1704,6 @@ func GetAccountAddress(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (int return addr.EncodeAddress(), err } -// GetAddressBalance handles a getaddressbalance extension request by -// returning the current balance (sum of unspent transaction output amounts) -// for a single address. -func GetAddressBalance(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface{}, error) { - cmd := icmd.(*btcws.GetAddressBalanceCmd) - - // Is address valid? - addr, err := btcutil.DecodeAddress(cmd.Address, activeNet.Params) - if err != nil { - return nil, btcjson.ErrInvalidAddressOrKey - } - - // Check if address is managed by this wallet. - _, err = w.KeyStore.Address(addr) - if err != nil { - return nil, ErrAddressNotInWallet - } - - bal, err := w.CalculateAddressBalance(addr, int(cmd.Minconf)) - if err != nil { - return nil, err - } - - return bal.ToUnit(btcutil.AmountBTC), nil -} - // GetUnconfirmedBalance handles a getunconfirmedbalance extension request // by returning the current unconfirmed balance of an account. func GetUnconfirmedBalance(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface{}, error) { diff --git a/wallet.go b/wallet.go index 3995959..80b17ba 100644 --- a/wallet.go +++ b/wallet.go @@ -739,41 +739,6 @@ func (w *Wallet) CalculateBalance(confirms int) (btcutil.Amount, error) { return w.TxStore.Balance(confirms, bs.Height) } -// CalculateAddressBalance sums the amounts of all unspent transaction -// outputs to a single address's pubkey hash and returns the balance. -// -// If confirmations is 0, all UTXOs, even those not present in a -// block (height -1), will be used to get the balance. Otherwise, -// a UTXO must be in a block. If confirmations is 1 or greater, -// the balance will be calculated based on how many how many blocks -// include a UTXO. -func (w *Wallet) CalculateAddressBalance(addr btcutil.Address, confirms int) (btcutil.Amount, error) { - bs, err := w.SyncedChainTip() - if err != nil { - return 0, err - } - - var bal btcutil.Amount - unspent, err := w.TxStore.UnspentOutputs() - if err != nil { - return 0, err - } - for _, credit := range unspent { - if credit.Confirmed(confirms, bs.Height) { - // We only care about the case where len(addrs) == 1, and err - // will never be non-nil in that case - _, addrs, _, _ := credit.Addresses(activeNet.Params) - if len(addrs) != 1 { - continue - } - if addrs[0].EncodeAddress() == addr.EncodeAddress() { - bal += credit.Amount() - } - } - } - return bal, nil -} - // CurrentAddress gets the most recently requested Bitcoin payment address // from a wallet. If the address has already been used (there is at least // one transaction spending to it in the blockchain or btcd mempool), the next