Skip to content

Commit

Permalink
Merge pull request #322 from tonkeeper/wait-mc-block
Browse files Browse the repository at this point in the history
wait masterchain block
  • Loading branch information
mr-tron authored Dec 1, 2024
2 parents 40dcba5 + b7fb1ca commit 0ed51ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions liteapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,3 +1089,16 @@ func (c *Client) GetNetworkGlobalID(ctx context.Context) (int32, error) {
c.networkGlobalID = &block.GlobalId
return block.GlobalId, nil
}

func (c *Client) WaitMasterchainBlock(ctx context.Context, seqno uint32, timeout time.Duration) (ton.BlockIDExt, error) {
t := uint32(timeout.Milliseconds())
client, _, err := c.pool.BestMasterchainClient(ctx)
if err != nil {
return ton.BlockIDExt{}, err
}
res, err := client.WaitMasterchainBlock(ctx, seqno, t)
if err != nil {
return ton.BlockIDExt{}, err
}
return res.Id.ToBlockIdExt(), nil
}
21 changes: 21 additions & 0 deletions liteapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,24 @@ func TestFromEnvs(t *testing.T) {
t.Fatal("expected 0 lite server")
}
}

func TestWaitMasterchainBlock(t *testing.T) {
api, err := NewClient(Mainnet(), FromEnvs())
if err != nil {
t.Fatal(err)
}
info, err := api.GetMasterchainInfo(context.Background())
if err != nil {
t.Fatal(err)
}
fmt.Printf("Current block seqno : %v\n", info.Last.Seqno)
nextSeqno := info.Last.Seqno + 1
bl, err := api.WaitMasterchainBlock(context.TODO(), nextSeqno, time.Second*15)
if err != nil {
t.Fatal(err)
}
if bl.Seqno != nextSeqno {
t.Fatal("wrong block seqno")
}
fmt.Printf("Next block seqno : %v\n", bl.Seqno)
}

0 comments on commit 0ed51ad

Please sign in to comment.