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

Function ExampleClient_VerifyLightBlockAtHeight

light/example_test.go:92–156  ·  view source on GitHub ↗

Manually getting light blocks and verifying them.

()

Source from the content-addressed store, hash-verified

90
91// Manually getting light blocks and verifying them.
92func ExampleClient_VerifyLightBlockAtHeight() {
93 // give Tendermint time to generate some blocks
94 time.Sleep(5 * time.Second)
95
96 dbDir, err := os.MkdirTemp("", "light-client-example")
97 if err != nil {
98 stdlog.Fatal(err)
99 }
100 defer os.RemoveAll(dbDir)
101
102 var (
103 config = rpctest.GetConfig()
104 chainID = config.ChainID()
105 )
106
107 primary, err := httpp.New(chainID, config.RPC.ListenAddress)
108 if err != nil {
109 stdlog.Fatal(err)
110 }
111
112 block, err := primary.LightBlock(context.Background(), 2)
113 if err != nil {
114 stdlog.Fatal(err)
115 }
116
117 db, err := dbm.NewGoLevelDB("light-client-db", dbDir)
118 if err != nil {
119 stdlog.Fatal(err)
120 }
121
122 c, err := light.NewClient(
123 context.Background(),
124 chainID,
125 light.TrustOptions{
126 Period: 504 * time.Hour, // 21 days
127 Height: 2,
128 Hash: block.Hash(),
129 },
130 primary,
131 []provider.Provider{primary}, // NOTE: primary should not be used here
132 dbs.New(db, chainID),
133 light.Logger(log.TestingLogger()),
134 )
135 if err != nil {
136 stdlog.Fatal(err)
137 }
138 defer func() {
139 if err := c.Cleanup(); err != nil {
140 stdlog.Fatal(err)
141 }
142 }()
143
144 _, err = c.VerifyLightBlockAtHeight(context.Background(), 3, time.Now())
145 if err != nil {
146 stdlog.Fatal(err)
147 }
148
149 h, err := c.TrustedLightBlock(3)

Callers

nothing calls this directly

Calls 9

CleanupMethod · 0.95
TrustedLightBlockMethod · 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