github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/message/request.go (about) 1 // (c) 2019-2022, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package message 5 6 import ( 7 "context" 8 "fmt" 9 10 "github.com/MetalBlockchain/metalgo/codec" 11 "github.com/MetalBlockchain/metalgo/ids" 12 ) 13 14 // Request represents a Network request type 15 type Request interface { 16 // Requests should implement String() for logging. 17 fmt.Stringer 18 19 // Handle allows `Request` to call respective methods on handler to handle 20 // this particular request type 21 Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error) 22 } 23 24 // BytesToRequest unmarshals the given requestBytes into Request object 25 func BytesToRequest(codec codec.Manager, requestBytes []byte) (Request, error) { 26 var request Request 27 if _, err := codec.Unmarshal(requestBytes, &request); err != nil { 28 return nil, err 29 } 30 return request, nil 31 } 32 33 // RequestToBytes marshals the given request object into bytes 34 func RequestToBytes(codec codec.Manager, request Request) ([]byte, error) { 35 return codec.Marshal(Version, &request) 36 } 37 38 // CrossChainRequest represents the interface a cross chain request should implement 39 type CrossChainRequest interface { 40 // CrossChainRequest should implement String() for logging. 41 fmt.Stringer 42 43 // Handle allows [CrossChainRequest] to call respective methods on handler to handle 44 // this particular request type 45 Handle(ctx context.Context, requestingChainID ids.ID, requestID uint32, handler CrossChainRequestHandler) ([]byte, error) 46 }