MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / ExampleClient_Update

Function ExampleClient_Update

light/example_test.go:24–89  ·  view source on GitHub ↗

Automatically getting new headers and verifying them.

()

Source from the content-addressed store, hash-verified

22
23// Automatically getting new headers and verifying them.
24func ExampleClient_Update() {
25 // give Tendermint time to generate some blocks
26 time.Sleep(5 * time.Second)
27
28 dbDir, err := os.MkdirTemp("", "light-client-example")
29 if err != nil {
30 stdlog.Fatal(err)
31 }
32 defer os.RemoveAll(dbDir)
33
34 var (
35 config = rpctest.GetConfig()
36 chainID = config.ChainID()
37 )
38
39 primary, err := httpp.New(chainID, config.RPC.ListenAddress)
40 if err != nil {
41 stdlog.Fatal(err)
42 }
43
44 block, err := primary.LightBlock(context.Background(), 2)
45 if err != nil {
46 stdlog.Fatal(err)
47 }
48
49 db, err := dbm.NewGoLevelDB("light-client-db", dbDir)
50 if err != nil {
51 stdlog.Fatal(err)
52 }
53
54 c, err := light.NewClient(
55 context.Background(),
56 chainID,
57 light.TrustOptions{
58 Period: 504 * time.Hour, // 21 days
59 Height: 2,
60 Hash: block.Hash(),
61 },
62 primary,
63 []provider.Provider{primary}, // NOTE: primary should not be used here
64 dbs.New(db, chainID),
65 light.Logger(log.TestingLogger()),
66 )
67 if err != nil {
68 stdlog.Fatal(err)
69 }
70 defer func() {
71 if err := c.Cleanup(); err != nil {
72 stdlog.Fatal(err)
73 }
74 }()
75
76 time.Sleep(2 * time.Second)
77
78 h, err := c.Update(context.Background(), time.Now())
79 if err != nil {
80 stdlog.Fatal(err)
81 }

Callers

nothing calls this directly

Calls 8

CleanupMethod · 0.95
UpdateMethod · 0.95
NewClientFunction · 0.92
LoggerFunction · 0.92
TestingLoggerFunction · 0.92
ChainIDMethod · 0.65
LightBlockMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected