diff --git a/liteapi/client.go b/liteapi/client.go index 047011e..23a991d 100644 --- a/liteapi/client.go +++ b/liteapi/client.go @@ -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 +} diff --git a/liteapi/client_test.go b/liteapi/client_test.go index 0aa7fb2..2051f78 100644 --- a/liteapi/client_test.go +++ b/liteapi/client_test.go @@ -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) +}