diff --git a/client/client.go b/client/client.go index 805d4558..803702cb 100644 --- a/client/client.go +++ b/client/client.go @@ -138,6 +138,17 @@ func (c *Client) GetTransactionData(txID string) (*pactus.GetTransactionResponse }) } +func (c *Client) GetBalance(address string) (int64, error) { + account, err := c.blockchainClient.GetAccount(context.Background(), &pactus.GetAccountRequest{ + Address: address, + }) + if err != nil { + return 0, err + } + + return account.Account.Balance, nil +} + func (c *Client) Close() error { return c.conn.Close() } diff --git a/client/client_mgr.go b/client/client_mgr.go index dc6cebf8..0cc38156 100644 --- a/client/client_mgr.go +++ b/client/client_mgr.go @@ -146,6 +146,45 @@ func (cm *Mgr) GetTransactionData(txID string) (*pactus.GetTransactionResponse, return txData, nil } +func (cm *Mgr) GetCirculatingSupply() (int64, error) { + localClient := cm.getLocalClient() + + height, err := localClient.GetBlockchainInfo() + if err != nil { + return 0, err + } + minted := float64(height.LastBlockHeight) * 1e9 + staked := height.TotalPower + + var addr1Out int64 = 0 + var addr2Out int64 = 0 + var addr3Out int64 = 0 + var addr4Out int64 = 0 + + balance1, err := localClient.GetBalance("pc1z2r0fmu8sg2ffa0tgrr08gnefcxl2kq7wvquf8z") + if err == nil { + addr1Out = 8_400_000_000_000_000 - balance1 + } + + balance2, err := localClient.GetBalance("pc1zprhnvcsy3pthekdcu28cw8muw4f432hkwgfasv") + if err == nil { + addr2Out = 6_300_000_000_000_000 - balance2 + } + + balance3, err := localClient.GetBalance("pc1znn2qxsugfrt7j4608zvtnxf8dnz8skrxguyf45") + if err == nil { + addr3Out = 4_200_000_000_000_000 - balance3 + } + + balance4, err := localClient.GetBalance("pc1zs64vdggjcshumjwzaskhfn0j9gfpkvche3kxd3") + if err == nil { + addr4Out = 2_100_000_000_000_000 - balance4 + } + + circulating := (addr1Out + addr2Out + addr3Out + addr4Out + int64(minted)) - staked + return circulating, nil +} + func (cm *Mgr) Stop() { for addr, c := range cm.clients { if err := c.Close(); err != nil { diff --git a/client/interface.go b/client/interface.go index 2f83cd11..54a895b0 100644 --- a/client/interface.go +++ b/client/interface.go @@ -12,5 +12,6 @@ type IClient interface { GetValidatorInfo(string) (*pactus.GetValidatorResponse, error) GetValidatorInfoByNumber(int32) (*pactus.GetValidatorResponse, error) GetTransactionData(string) (*pactus.GetTransactionResponse, error) + GetBalance(string) (int64, error) Close() error } diff --git a/client/mock.go b/client/mock.go index b0a2dd42..f27de08a 100644 --- a/client/mock.go +++ b/client/mock.go @@ -53,6 +53,21 @@ func (mr *MockIClientMockRecorder) Close() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockIClient)(nil).Close)) } +// GetBalance mocks base method. +func (m *MockIClient) GetBalance(arg0 string) (int64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBalance", arg0) + ret0, _ := ret[0].(int64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBalance indicates an expected call of GetBalance. +func (mr *MockIClientMockRecorder) GetBalance(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBalance", reflect.TypeOf((*MockIClient)(nil).GetBalance), arg0) +} + // GetBlockchainHeight mocks base method. func (m *MockIClient) GetBlockchainHeight() (uint32, error) { m.ctrl.T.Helper() diff --git a/discord/embeds.go b/discord/embeds.go index 6cea8daf..dfbc60dc 100644 --- a/discord/embeds.go +++ b/discord/embeds.go @@ -85,7 +85,7 @@ func claimStatusEmbed(s *discordgo.Session, i *discordgo.InteractionCreate, resu func rewardCalcEmbed(s *discordgo.Session, i *discordgo.InteractionCreate, result string) *discordgo.MessageEmbed { return &discordgo.MessageEmbed{ - Title: "Vlidator reward calculationš§®", + Title: "Validator reward calculationš§®", Description: result, Color: PACTUS, } diff --git a/discord/handlers.go b/discord/handlers.go index 43a653cc..f6fdba35 100644 --- a/discord/handlers.go +++ b/discord/handlers.go @@ -219,7 +219,7 @@ func walletCommandHandler(db *DiscordBot, s *discordgo.Session, i *discordgo.Int return } - result, _ := db.BotEngine.Run("bot-wallet") + result, _ := db.BotEngine.Run("wallet") embed := botWalletEmbed(s, i, result) response := &discordgo.InteractionResponse{ diff --git a/engine/engine.go b/engine/engine.go index 62f3ed00..7f7b0c00 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -115,6 +115,11 @@ func (be *BotEngine) NetworkStatus() (*NetStatus, error) { return nil, err } + cs, err := be.Cm.GetCirculatingSupply() + if err != nil { + cs = 0 + } + return &NetStatus{ ConnectedPeersCount: netInfo.ConnectedPeersCount, ValidatorsCount: chainInfo.TotalValidators, @@ -125,6 +130,7 @@ func (be *BotEngine) NetworkStatus() (*NetStatus, error) { TotalCommitteePower: chainInfo.CommitteePower, NetworkName: netInfo.NetworkName, TotalAccounts: chainInfo.TotalAccounts, + CirculatingSupply: cs, }, nil } diff --git a/engine/run.go b/engine/run.go index a9316578..4c3f7ee6 100644 --- a/engine/run.go +++ b/engine/run.go @@ -99,10 +99,10 @@ func (be *BotEngine) Run(input string) (string, error) { } return fmt.Sprintf("Network Name: %s\nConnected Peers: %v\n"+ - "Validators Count: %v\nAccounts Count: %v\nCurrent Block Height: %v\nTotal Power: %v PAC's\nTotal Committee Power: %v PAC's\n"+ + "Validators Count: %v\nAccounts Count: %v\nCurrent Block Height: %v\nTotal Power: %v PAC\nTotal Committee Power: %v PAC\nCirculating Supply: %v PAC\n"+ "\n> Noteš: This info is from one random network node. Non-blockchain data may not be consistent.", net.NetworkName, net.ConnectedPeersCount, net.ValidatorsCount, net.TotalAccounts, net.CurrentBlockHeight, util.ChangeToString(net.TotalNetworkPower), - util.ChangeToString(net.TotalCommitteePower)), nil + util.ChangeToString(net.TotalCommitteePower), util.ChangeToString(net.CirculatingSupply)), nil case CmdBotWallet: addr, blnc := be.BotWallet() @@ -128,7 +128,7 @@ func (be *BotEngine) Run(input string) (string, error) { return "", err } - return fmt.Sprintf("Approximately you earn %v PAC's reward, with %v stake š on your validator in one %s ā° with %v PAC total power ā” of committee."+ + return fmt.Sprintf("Approximately you earn %v PAC reward, with %v PAC stake š on your validator in one %s ā° with %v PAC total power ā” of committee."+ "\n\n> Noteš: This is an estimation and the number can get changed by changes of your stake amount, total power and ...", reward, stake, time, totalPower), nil diff --git a/engine/structs.go b/engine/structs.go index 442c6d41..805c1471 100644 --- a/engine/structs.go +++ b/engine/structs.go @@ -11,6 +11,7 @@ type NetHealthResponse struct { } type NetStatus struct { + NetworkName string ConnectedPeersCount uint32 ValidatorsCount int32 TotalBytesSent uint32 @@ -18,8 +19,8 @@ type NetStatus struct { CurrentBlockHeight uint32 TotalNetworkPower int64 TotalCommitteePower int64 - NetworkName string TotalAccounts int32 + CirculatingSupply int64 } type NodeInfo struct {