mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
multi-account: update getreceivedbyaccount
This commit is contained in:
parent
678379ce45
commit
03256c049b
1 changed files with 25 additions and 14 deletions
|
@ -928,27 +928,38 @@ func getRawChangeAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error
|
||||||
// getReceivedByAccount handles a getreceivedbyaccount request by returning
|
// getReceivedByAccount handles a getreceivedbyaccount request by returning
|
||||||
// the total amount received by addresses of an account.
|
// the total amount received by addresses of an account.
|
||||||
func getReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
|
func getReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
|
||||||
|
|
||||||
cmd := icmd.(*btcjson.GetReceivedByAccountCmd)
|
cmd := icmd.(*btcjson.GetReceivedByAccountCmd)
|
||||||
|
|
||||||
account, err := w.AccountNumber(waddrmgr.KeyScopeBIP0044, cmd.Account)
|
account, err := w.AccountNumber(*cmd.Account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This is more inefficient that it could be, but the entire
|
totalReceived := 0.0
|
||||||
// algorithm is already dominated by reading every transaction in the
|
|
||||||
// wallet's history.
|
var results []wallet.AccountTotalReceivedResult
|
||||||
results, err := w.TotalReceivedForAccounts(
|
|
||||||
waddrmgr.KeyScopeBIP0044, int32(*cmd.MinConf),
|
fn := func(scope waddrmgr.KeyScope) error {
|
||||||
)
|
|
||||||
|
results, err = w.TotalReceivedForAccounts(
|
||||||
|
scope, int32(*cmd.MinConf))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
acctIndex := int(account)
|
acctIndex := int(account)
|
||||||
if account == waddrmgr.ImportedAddrAccount {
|
if account == waddrmgr.ImportedAddrAccount {
|
||||||
acctIndex = len(results) - 1
|
acctIndex = len(results) - 1
|
||||||
}
|
}
|
||||||
return results[acctIndex].TotalReceived.ToBTC(), nil
|
|
||||||
|
totalReceived += results[acctIndex].TotalReceived.ToBTC()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err = forEachKeyScope(fn)
|
||||||
|
|
||||||
|
return totalReceived, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// getReceivedByAddress handles a getreceivedbyaddress request by returning
|
// getReceivedByAddress handles a getreceivedbyaddress request by returning
|
||||||
|
|
Loading…
Add table
Reference in a new issue