From b7fb1ca16d7b761eca393e7fd455edcb669e1b5a Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Fri, 29 Nov 2024 15:07:44 +0300 Subject: [PATCH] wait masterchain block --- liteapi/client.go | 13 +++++++++++++ liteapi/client_test.go | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/liteapi/client.go b/liteapi/client.go index 047011ef..23a991dc 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 0aa7fb28..2051f78b 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) +}