From 5c09bfff480a9bd47af2bf4541580439bb2310fe Mon Sep 17 00:00:00 2001 From: Fernando Sobreira Date: Mon, 31 Aug 2020 09:19:51 -0300 Subject: [PATCH 1/2] Add rewwards into account allowance --- pkg/client/account.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/client/account.go b/pkg/client/account.go index 9688aa00..6d719de4 100644 --- a/pkg/client/account.go +++ b/pkg/client/account.go @@ -37,6 +37,23 @@ func (g *GrpcClient) GetAccount(addr string) (*core.Account, error) { return acc, nil } +// GetRewardsInfo from BASE58 address +func (g *GrpcClient) GetRewardsInfo(addr string) (int64, error) { + addrBytes, err := common.DecodeCheck(addr) + if err != nil { + return 0, err + } + + ctx, cancel := context.WithTimeout(context.Background(), g.grpcTimeout) + defer cancel() + + rewards, err := g.Client.GetRewardInfo(ctx, GetMessageBytes(addrBytes)) + if err != nil { + return 0, err + } + return rewards.Num, nil +} + // GetAccountNet return account resources from BASE58 address func (g *GrpcClient) GetAccountNet(addr string) (*api.AccountNetMessage, error) { account := new(core.Account) @@ -123,6 +140,11 @@ func (g *GrpcClient) GetAccountDetailed(addr string) (*account.Account, error) { return nil, err } + rewards, err := g.GetRewardsInfo(addr) + if err != nil { + return nil, err + } + // SUM Total freeze totalFrozen := int64(0) frozenList := make([]account.FrozenResource, 0) @@ -183,7 +205,7 @@ func (g *GrpcClient) GetAccountDetailed(addr string) (*account.Account, error) { Name: string(acc.GetAccountName()), ID: string(acc.GetAccountId()), Balance: acc.GetBalance(), - Allowance: acc.GetAllowance(), + Allowance: acc.GetAllowance() + rewards, LastWithdraw: acc.LatestWithdrawTime, IsWitness: acc.IsWitness, IsElected: acc.IsCommittee, From 4175a180571d4cac010ade000edea8426c065fa1 Mon Sep 17 00:00:00 2001 From: Fernando Sobreira Date: Mon, 31 Aug 2020 09:20:52 -0300 Subject: [PATCH 2/2] CLI add rewards to allowance --- cmd/subcommands/account.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/subcommands/account.go b/cmd/subcommands/account.go index 126eca8e..3918055e 100644 --- a/cmd/subcommands/account.go +++ b/cmd/subcommands/account.go @@ -42,11 +42,17 @@ func accountSub() []*cobra.Command { return nil } + rewards, err := conn.GetRewardsInfo(addr.String()) + if err != nil { + return err + } + result := make(map[string]interface{}) result["address"] = addr.String() result["type"] = acc.GetType() result["balance"] = float64(acc.GetBalance()) / 1000000 - result["allowance"] = float64(acc.GetAllowance()) / 1000000 + result["allowance"] = float64(acc.GetAllowance()+rewards) / 1000000 + result["rewards"] = float64(acc.GetAllowance()) / 1000000 asJSON, _ := json.Marshal(result) fmt.Println(common.JSONPrettyFormat(string(asJSON))) return nil