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

Method OnDataHandle

http/websocket/websocket/server.go:304–360  ·  view source on GitHub ↗
(curSession *session.Session, bysMsg []byte, r *http.Request)

Source from the content-addressed store, hash-verified

302 return true
303}
304func (self *WsServer) OnDataHandle(curSession *session.Session, bysMsg []byte, r *http.Request) bool {
305
306 var req = make(map[string]interface{})
307
308 if err := json.Unmarshal(bysMsg, &req); err != nil {
309 resp := rest.ResponsePack(Err.ILLEGAL_DATAFORMAT)
310 curSession.Send(marshalResp(resp))
311 log.Infof("websocket OnDataHandle:", err)
312 return false
313 }
314 actionName, ok := req["Action"].(string)
315 if !ok {
316 resp := rest.ResponsePack(Err.INVALID_METHOD)
317 curSession.Send(marshalResp(resp))
318 return false
319 }
320 action, ok := self.ActionMap[actionName]
321 if !ok {
322 resp := rest.ResponsePack(Err.INVALID_METHOD)
323 curSession.Send(marshalResp(resp))
324 return false
325 }
326 if !self.IsValidMsg(req) {
327 resp := rest.ResponsePack(Err.INVALID_PARAMS)
328 curSession.Send(marshalResp(resp))
329 return true
330 }
331 if height, ok := req["Height"].(float64); ok {
332 req["Height"] = strconv.FormatInt(int64(height), 10)
333 }
334 if raw, ok := req["Raw"].(float64); ok {
335 req["Raw"] = strconv.FormatInt(int64(raw), 10)
336 }
337 req["SessionId"] = curSession.GetSessionId()
338 resp := action.handler(req)
339 resp["Action"] = actionName
340 resp["Id"] = req["Id"]
341 if action.pushFlag {
342 if error, _ := resp["Error"].(int64); ok && error == 0 {
343 if txHash, ok := resp["Result"].(string); ok && len(txHash) == common.UINT256_SIZE*2 {
344 //delete timeover txhashs
345 txhashs := curSession.RemoveTimeoverTxHashes()
346 self.Lock()
347 defer self.Unlock()
348 for _, v := range txhashs {
349 delete(self.TxHashMap, v.TxHash)
350 }
351 //add new txhash
352 self.TxHashMap[txHash] = curSession.GetSessionId()
353 curSession.AppendTxHash(txHash)
354 }
355 }
356 }
357 curSession.Send(marshalResp(resp))
358
359 return true
360}
361func (self *WsServer) InsertTxHashMap(txhash string, sessionid string) {

Callers 1

webSocketHandlerMethod · 0.95

Calls 8

IsValidMsgMethod · 0.95
ResponsePackFunction · 0.92
InfofFunction · 0.92
marshalRespFunction · 0.85
GetSessionIdMethod · 0.80
AppendTxHashMethod · 0.80
SendMethod · 0.65

Tested by

no test coverage detected