Skip to content

Commit

Permalink
Merge pull request #14 from kehiy/main
Browse files Browse the repository at this point in the history
fix: last blocktime logic
  • Loading branch information
kehiy authored Nov 21, 2023
2 parents c0d0d5b + 1147400 commit 0836216
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ func (c *Client) TransactionData(hash string) (*pactus.TransactionInfo, error) {
return data.GetTransaction(), nil
}

func (c *Client) LastBlockTime() (uint32, error) {
info, _ := c.blockchainClient.GetBlockchainInfo(context.Background(), &pactus.GetBlockchainInfoRequest{})
lastBlockTime, err := c.blockchainClient.GetBlock(context.Background(), &pactus.GetBlockRequest{Height: info.LastBlockHeight})

return lastBlockTime.BlockTime, err
}

func (c *Client) Close() error {
return c.conn.Close()
}
10 changes: 5 additions & 5 deletions client/client_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ func (cm *Mgr) GetBlockchainHeight() (uint32, error) {
}

func (cm *Mgr) GetLastBlockTime() uint32 {
var lastBlockHeight uint32 = 0
var lastBlockTime uint32 = 0
for _, c := range cm.clients {
info, err := c.GetBlockchainInfo()
t, err := c.LastBlockTime()
if err != nil {
continue
}
if info.LastBlockHeight > lastBlockHeight {
lastBlockHeight = info.LastBlockHeight
if t > lastBlockTime {
lastBlockTime = t
}
}

return lastBlockHeight
return lastBlockTime
}

func (cm *Mgr) GetNetworkInfo() (*pactus.GetNetworkInfoResponse, error) {
Expand Down

0 comments on commit 0836216

Please sign in to comment.