MCPcopy Create free account
hub / github.com/tendermint/tendermint / ExampleClient

Function ExampleClient

light/example_test.go:22–110  ·  view source on GitHub ↗

Manually getting light blocks and verifying them.

()

Source from the content-addressed store, hash-verified

20
21// Manually getting light blocks and verifying them.
22func ExampleClient() {
23 ctx, cancel := context.WithCancel(context.Background())
24 defer cancel()
25 conf, err := rpctest.CreateConfig("ExampleClient_VerifyLightBlockAtHeight")
26 if err != nil {
27 stdlog.Fatal(err)
28 }
29
30 logger := log.TestingLogger()
31
32 // Start a test application
33 app := kvstore.NewApplication()
34
35 _, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
36 if err != nil {
37 stdlog.Fatal(err)
38 }
39 defer func() { _ = closer(ctx) }()
40
41 dbDir, err := ioutil.TempDir("", "light-client-example")
42 if err != nil {
43 stdlog.Fatal(err)
44 }
45 defer os.RemoveAll(dbDir)
46
47 chainID := conf.ChainID()
48
49 primary, err := httpp.New(chainID, conf.RPC.ListenAddress)
50 if err != nil {
51 stdlog.Fatal(err)
52 }
53
54 // give Tendermint time to generate some blocks
55 time.Sleep(5 * time.Second)
56
57 block, err := primary.LightBlock(ctx, 2)
58 if err != nil {
59 stdlog.Fatal(err)
60 }
61
62 db, err := dbm.NewGoLevelDB("light-client-db", dbDir)
63 if err != nil {
64 stdlog.Fatal(err)
65 }
66
67 c, err := light.NewClient(ctx,
68 chainID,
69 light.TrustOptions{
70 Period: 504 * time.Hour, // 21 days
71 Height: 2,
72 Hash: block.Hash(),
73 },
74 primary,
75 []provider.Provider{primary}, // NOTE: primary should not be used here
76 dbs.New(db),
77 light.Logger(logger),
78 )
79 if err != nil {

Callers

nothing calls this directly

Calls 14

CleanupMethod · 0.95
TrustedLightBlockMethod · 0.95
UpdateMethod · 0.95
TestingLoggerFunction · 0.92
NewApplicationFunction · 0.92
NewClientFunction · 0.92
LoggerFunction · 0.92
SleepMethod · 0.80
ChainIDMethod · 0.65
LightBlockMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…