MCPcopy Create free account
hub / github.com/33cn/chain33 / SetQueueClient

Method SetQueueClient

common/crypto/client/client.go:43–79  ·  view source on GitHub ↗

SetQueueClient set queue client

(cli queue.Client)

Source from the content-addressed store, hash-verified

41
42// SetQueueClient set queue client
43func (m module) SetQueueClient(cli queue.Client) {
44
45 crypto.Init(cli.GetConfig().GetModuleConfig().Crypto, cli.GetConfig().GetSubConfig().Crypto)
46 api, err := client.New(cli, nil)
47 if err != nil {
48 panic("crypto SetQueueClient, new client api err:" + err.Error())
49 }
50 SetQueueAPI(api)
51 cli.Sub("crypto")
52 ticker := time.NewTicker(time.Second)
53 go func() {
54
55 for {
56
57 select {
58 case msg := <-cli.Recv():
59 if msg.Ty == types.EventAddBlock {
60 if header, ok := msg.Data.(*types.Header); ok {
61 SetCurrentBlock(header.GetHeight(), header.GetBlockTime())
62 }
63
64 }
65 case <-ticker.C:
66 // 首次启动, 需要主动获取依次区块头信息
67 h, err := api.GetLastHeader()
68 if err == nil {
69 SetCurrentBlock(h.GetHeight(), h.GetBlockTime())
70 ticker.Stop()
71 }
72 case <-m.done:
73 return
74 }
75
76 }
77 }()
78
79}
80
81// Close close
82func (m module) Close() {

Callers

nothing calls this directly

Calls 13

InitFunction · 0.92
NewFunction · 0.92
SetQueueAPIFunction · 0.85
SetCurrentBlockFunction · 0.85
GetModuleConfigMethod · 0.80
GetSubConfigMethod · 0.80
GetConfigMethod · 0.65
ErrorMethod · 0.65
SubMethod · 0.65
RecvMethod · 0.65
GetLastHeaderMethod · 0.65
GetHeightMethod · 0.45

Tested by

no test coverage detected