Remove 'getaddressbalance' extension RPC.
Addresses do no have balances. In situations where a payment is required and just a single address was provided, it is better to track the unspent outputs themselves, rather than watching some artificial measure of payment.
This commit is contained in:
parent
49b15625b9
commit
cd1aebb68e
2 changed files with 0 additions and 62 deletions
27
rpcserver.go
27
rpcserver.go
|
@ -1316,7 +1316,6 @@ var rpcHandlers = map[string]requestHandler{
|
||||||
|
|
||||||
// Extensions to the reference client JSON-RPC API
|
// Extensions to the reference client JSON-RPC API
|
||||||
"exportwatchingwallet": ExportWatchingWallet,
|
"exportwatchingwallet": ExportWatchingWallet,
|
||||||
"getaddressbalance": GetAddressBalance,
|
|
||||||
// This was an extension but the reference implementation added it as
|
// This was an extension but the reference implementation added it as
|
||||||
// well, but with a different API (no account parameter). It's listed
|
// well, but with a different API (no account parameter). It's listed
|
||||||
// here because it hasn't been update to use the reference
|
// 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
|
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
|
// GetUnconfirmedBalance handles a getunconfirmedbalance extension request
|
||||||
// by returning the current unconfirmed balance of an account.
|
// by returning the current unconfirmed balance of an account.
|
||||||
func GetUnconfirmedBalance(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface{}, error) {
|
func GetUnconfirmedBalance(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface{}, error) {
|
||||||
|
|
35
wallet.go
35
wallet.go
|
@ -739,41 +739,6 @@ func (w *Wallet) CalculateBalance(confirms int) (btcutil.Amount, error) {
|
||||||
return w.TxStore.Balance(confirms, bs.Height)
|
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
|
// CurrentAddress gets the most recently requested Bitcoin payment address
|
||||||
// from a wallet. If the address has already been used (there is at least
|
// 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
|
// one transaction spending to it in the blockchain or btcd mempool), the next
|
||||||
|
|
Loading…
Reference in a new issue