mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
multi-account: update listreceivedbyaccount
This commit is contained in:
parent
93b33edbcd
commit
b34aa61e4d
1 changed files with 31 additions and 10 deletions
|
@ -1299,21 +1299,42 @@ func listLockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
|
||||||
func listReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
|
func listReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
|
||||||
cmd := icmd.(*btcjson.ListReceivedByAccountCmd)
|
cmd := icmd.(*btcjson.ListReceivedByAccountCmd)
|
||||||
|
|
||||||
results, err := w.TotalReceivedForAccounts(
|
accounts := map[uint32]*wallet.AccountTotalReceivedResult{}
|
||||||
waddrmgr.KeyScopeBIP0044, int32(*cmd.MinConf),
|
err := forEachKeyScope(func(scope waddrmgr.KeyScope) error {
|
||||||
)
|
results, err := w.TotalReceivedForAccounts(
|
||||||
|
scope, int32(*cmd.MinConf),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, result := range results {
|
||||||
|
account := accounts[result.AccountNumber]
|
||||||
|
if account == nil {
|
||||||
|
dup := result
|
||||||
|
account = &dup
|
||||||
|
accounts[result.AccountNumber] = account
|
||||||
|
}
|
||||||
|
account.TotalReceived += result.TotalReceived
|
||||||
|
if account.LastConfirmation < result.LastConfirmation {
|
||||||
|
account.LastConfirmation = result.LastConfirmation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonResults := make([]btcjson.ListReceivedByAccountResult, 0, len(results))
|
jsonResults := make([]btcjson.ListReceivedByAccountResult, 0, len(accounts))
|
||||||
for _, result := range results {
|
for _, account := range accounts {
|
||||||
jsonResults = append(jsonResults, btcjson.ListReceivedByAccountResult{
|
jsonResult := btcjson.ListReceivedByAccountResult{
|
||||||
Account: result.AccountName,
|
Account: account.AccountName,
|
||||||
Amount: result.TotalReceived.ToBTC(),
|
Amount: account.TotalReceived.ToBTC(),
|
||||||
Confirmations: uint64(result.LastConfirmation),
|
Confirmations: uint64(account.LastConfirmation),
|
||||||
})
|
}
|
||||||
|
jsonResults = append(jsonResults, jsonResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonResults, nil
|
return jsonResults, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue