MCPcopy
hub / github.com/canopy-network/canopy / StateDiff

Method StateDiff

cmd/rpc/query.go:491–518  ·  view source on GitHub ↗

StateDiff returns the different between the state at two block heights

(w http.ResponseWriter, r *http.Request, p httprouter.Params)

Source from the content-addressed store, hash-verified

489
490// StateDiff returns the different between the state at two block heights
491func (s *Server) StateDiff(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
492 sm1, sm2, opts, ok := s.getDoubleStateMachineFromHeightParams(w, r, p)
493 if !ok {
494 return
495 }
496 defer sm1.Discard()
497 defer sm2.Discard()
498 state1, e := sm1.ExportState()
499 if e != nil {
500 write(w, e.Error(), http.StatusInternalServerError)
501 return
502 }
503 state2, e := sm2.ExportState()
504 if e != nil {
505 write(w, e.Error(), http.StatusInternalServerError)
506 return
507 }
508 j1, _ := json.Marshal(state1)
509 j2, _ := json.Marshal(state2)
510 _, differ := jsondiff.Compare(j1, j2, opts)
511 if r.Method == http.MethodGet {
512 w.Header().Set("Content-Type", "text/html; charset=utf-8")
513 differ = "<pre>" + differ + "</pre>"
514 }
515 if _, err := w.Write([]byte(differ)); err != nil {
516 s.logger.Error(err.Error())
517 }
518}
519
520// TransactionsBySender returns transactions for the specified sender address
521func (s *Server) TransactionsBySender(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {

Callers 1

query.goFile · 0.45

Calls 8

writeFunction · 0.85
ExportStateMethod · 0.80
WriteMethod · 0.80
DiscardMethod · 0.65
ErrorMethod · 0.65
MarshalMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected