MCPcopy Create free account
hub / github.com/CPChain/chain / exec

Method exec

api/rpc/server.go:327–345  ·  view source on GitHub ↗

exec executes the given request and writes the result back using the codec.

(ctx context.Context, codec ServerCodec, req *serverRequest)

Source from the content-addressed store, hash-verified

325
326// exec executes the given request and writes the result back using the codec.
327func (s *Server) exec(ctx context.Context, codec ServerCodec, req *serverRequest) {
328 var response interface{}
329 var callback func()
330 if req.err != nil {
331 response = codec.CreateErrorResponse(&req.id, req.err)
332 } else {
333 response, callback = s.handle(ctx, codec, req)
334 }
335
336 if err := codec.Write(response); err != nil {
337 log.Error(fmt.Sprintf("%v\n", err))
338 codec.Close()
339 }
340
341 // when request was a subscribe request this allows these subscriptions to be actived
342 if callback != nil {
343 callback()
344 }
345}
346
347// execBatch executes the given requests and writes the result back using the codec.
348// It will only write the response back when the last request is processed.

Callers 1

serveRequestMethod · 0.95

Calls 6

handleMethod · 0.95
callbackStruct · 0.85
CreateErrorResponseMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected