MCPcopy Create free account
hub / github.com/DNAProject/DNA / registryMethod

Method registryMethod

http/websocket/websocket/server.go:131–211  ·  view source on GitHub ↗

registry handler method

()

Source from the content-addressed store, hash-verified

129
130//registry handler method
131func (self *WsServer) registryMethod() {
132
133 heartbeat := func(cmd map[string]interface{}) map[string]interface{} {
134 resp := rest.ResponsePack(Err.SUCCESS)
135 self.Lock()
136 defer self.Unlock()
137
138 sessionId, _ := cmd["SessionId"].(string)
139 sub := self.SubscribeMap[sessionId]
140 resp["Action"] = "heartbeat"
141 resp["Result"] = sub
142 return resp
143 }
144 subscribe := func(cmd map[string]interface{}) map[string]interface{} {
145 resp := rest.ResponsePack(Err.SUCCESS)
146 self.Lock()
147 defer self.Unlock()
148
149 sessionId, _ := cmd["SessionId"].(string)
150 sub := self.SubscribeMap[sessionId]
151 if b, ok := cmd["SubscribeEvent"].(bool); ok {
152 sub.SubscribeEvent = b
153 }
154 if b, ok := cmd["SubscribeJsonBlock"].(bool); ok {
155 sub.SubscribeJsonBlock = b
156 }
157 if b, ok := cmd["SubscribeRawBlock"].(bool); ok {
158 sub.SubscribeRawBlock = b
159 }
160 if b, ok := cmd["SubscribeBlockTxHashs"].(bool); ok {
161 sub.SubscribeBlockTxHashs = b
162 }
163 if ctsf, ok := cmd["ContractsFilter"].([]interface{}); ok {
164 sub.ContractsFilter = []string{}
165 for _, v := range ctsf {
166 if addr, k := v.(string); k {
167 sub.ContractsFilter = append(sub.ContractsFilter, addr)
168 }
169 }
170 }
171 self.SubscribeMap[sessionId] = sub
172
173 resp["Action"] = "subscribe"
174 resp["Result"] = sub
175 return resp
176 }
177 getsessioncount := func(cmd map[string]interface{}) map[string]interface{} {
178 resp := rest.ResponsePack(Err.SUCCESS)
179 resp["Action"] = "getsessioncount"
180 resp["Result"] = self.SessionList.GetSessionCount()
181 return resp
182 }
183 actionMap := map[string]Handler{
184 "getblockheightbytxhash": {handler: rest.GetBlockHeightByTxHash},
185 "getsmartcodeeventbyhash": {handler: rest.GetSmartCodeEventByTxHash},
186 "getsmartcodeeventbyheight": {handler: rest.GetSmartCodeEventTxsByHeight},
187 "getcontract": {handler: rest.GetContractState},
188 "getbalance": {handler: rest.GetBalance},

Callers 1

StartMethod · 0.95

Calls 2

ResponsePackFunction · 0.92
GetSessionCountMethod · 0.80

Tested by

no test coverage detected