Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1478 from irisnet/develop
Browse files Browse the repository at this point in the history
R4R:merge master from develop branch
  • Loading branch information
kaifei Hu authored Jul 17, 2020
2 parents b91ae6a + 962b8a3 commit 7a6266a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions backend/task/update_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,20 @@ func (task UpdateAccount) DoTask(fn func(string) chan bool) error {
}

func updateAccount(account *document.Account) error {
if res, err := updateAccountInfo(account); err == nil {
if res, err := getAccountInfo(account); err == nil {
account = res
} else {
logger.Warn("get AccountInfo failed", logger.String("err", err.Error()))
}
_, _, rewards, err := lcd.GetDistributionRewardsByValidatorAcc(account.Address)
if err == nil {
if len(rewards) > 0 {
newrewards := loadRewards(rewards)
subvalue := newrewards.Amount - account.Rewards.Amount
account.Total.Amount += subvalue
account.Rewards = newrewards
} else {
account.Rewards = utils.Coin{Denom: account.Rewards.Denom}
}
}

if err := account.Update(*account); err != nil {
logger.Warn("Account Update Rewards failed", logger.String("err", err.Error()))
return err
}
return nil
}

func updateAccountInfo(account *document.Account) (*document.Account, error) {
func getAccountInfo(account *document.Account) (*document.Account, error) {
balance, res, err := getBalance(account)
if err != nil {
logger.Error("lcd getBalance Info have error", logger.String("err", err.Error()))
Expand All @@ -93,6 +83,19 @@ func updateAccountInfo(account *document.Account) (*document.Account, error) {
if err != nil {
logger.Warn("update UnbondingDelegation Info have error", logger.String("err", err.Error()))
}
//rewards
_, _, rewards, err := lcd.GetDistributionRewardsByValidatorAcc(account.Address)
if err != nil {
logger.Warn("update GetDistributionRewards Info have error", logger.String("err", err.Error()))
}

if len(rewards) > 0 {
newrewards := loadRewards(rewards)
account.Rewards = newrewards
//account.Total.Amount += account.Rewards.Amount
} else {
account.Rewards = utils.Coin{Denom: account.Rewards.Denom}
}

account.Delegation = utils.Coin{
Denom: balance.Denom,
Expand All @@ -110,8 +113,9 @@ func updateAccountInfo(account *document.Account) (*document.Account, error) {

account.Total = utils.Coin{
Denom: balance.Denom,
Amount: balance.Amount + delegation + unbondingDelegation,
Amount: balance.Amount + delegation + unbondingDelegation + account.Rewards.Amount,
}

return account, nil
}

Expand Down
2 changes: 1 addition & 1 deletion backend/task/update_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestUpdateAccount_DoTask(t *testing.T) {
}

func TestUpdateAccount_updateAccountInfo(t *testing.T) {
account, _ := updateAccountInfo(&account)
account, _ := getAccountInfo(&account)
bytedata, _ := json.Marshal(account)
t.Log(string(bytedata))
}
Expand Down

0 comments on commit 7a6266a

Please sign in to comment.