Skip to content

Commit

Permalink
feat: Remove commented code and update SolanaClient's GetLastBlock me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
yusufyian committed Jul 7, 2024
1 parent e9bb885 commit 52e3273
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
8 changes: 8 additions & 0 deletions hypergrid-aide/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func main() {
log.Fatal(err)
}

// block, err := solana.GetLastBlock()
// if err != nil {
// log.Fatal(err)
// } else {
// println("Last block: ", block.Slot)

// }

last_sent_slot, err = tools.GetLastSentSlot()
if err != nil {
log.Fatal(err)
Expand Down
27 changes: 18 additions & 9 deletions hypergrid-aide/tools/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,24 @@ func (s *SolanaClient) GetFirstBlock() (uint64, error) {
return 0, nil
}

func (s *SolanaClient) GetLastBlock() (uint64, error) {
// resp, err := s.Client.GetBlock() .GetBlocksWithLimit(context.TODO(), 0, 1, rpc.CommitmentFinalized)
// if err != nil {
// return 0, err
// }
// if len(*resp) > 0 {
// return (*resp)[0], nil
// }
return 0, nil
func (s *SolanaClient) GetLastBlock() (SolanaBlock, error) {
resp, err := s.Client.GetBlockHeight(context.TODO(), rpc.CommitmentFinalized)
if err != nil {
return SolanaBlock{}, err
}
resp2, err := s.Client.GetBlock(context.TODO(), resp)
if err != nil {
return SolanaBlock{}, err
}

block := SolanaBlock{
Blockhash: resp2.Blockhash.String(),
Slot: resp,
BlockTime: resp2.BlockTime.Time().Second(),
}

return block, nil

}

func (s *SolanaClient) GetBlocks(start_slot uint64, limit uint64) ([]SolanaBlock, error) {
Expand Down

0 comments on commit 52e3273

Please sign in to comment.