/
update.go
39 lines (36 loc) · 918 Bytes
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package config
import (
"context"
"fmt"
"time"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)
func (c *Config) UpdateTrust() error {
client, err := rpchttp.New(c.Katzenmint.PrimaryAddress, "/websocket")
if err != nil {
return err
}
info, err := client.ABCIInfo(context.Background())
if err != nil {
return err
}
genesis, err := client.Genesis(context.Background())
if err != nil {
return err
}
blockHeight := info.Response.LastBlockHeight
block, err := client.Block(context.Background(), &blockHeight)
if err != nil {
return err
}
if block == nil {
return fmt.Errorf("couldn't find block: %d", blockHeight)
}
if genesis.Genesis.ChainID != c.Katzenmint.ChainID {
return fmt.Errorf("wrong chain ID")
}
c.Katzenmint.TrustOptions.Period = 10 * time.Minute
c.Katzenmint.TrustOptions.Height = blockHeight
c.Katzenmint.TrustOptions.Hash = block.BlockID.Hash
return nil
}