github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/message/code_request.go (about) 1 // (c) 2021-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 "strings" 10 11 "github.com/MetalBlockchain/metalgo/ids" 12 "github.com/ethereum/go-ethereum/common" 13 ) 14 15 var _ Request = CodeRequest{} 16 17 // CodeRequest is a request to retrieve a contract code with specified Hash 18 type CodeRequest struct { 19 // Hashes is a list of contract code hashes 20 Hashes []common.Hash `serialize:"true"` 21 } 22 23 func (c CodeRequest) String() string { 24 hashStrs := make([]string, len(c.Hashes)) 25 for i, hash := range c.Hashes { 26 hashStrs[i] = hash.String() 27 } 28 return fmt.Sprintf("CodeRequest(Hashes=%s)", strings.Join(hashStrs, ", ")) 29 } 30 31 func (c CodeRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error) { 32 return handler.HandleCodeRequest(ctx, nodeID, requestID, c) 33 } 34 35 func NewCodeRequest(hashes []common.Hash) CodeRequest { 36 return CodeRequest{ 37 Hashes: hashes, 38 } 39 } 40 41 // CodeResponse is a response to a CodeRequest 42 // crypto.Keccak256Hash of each element in Data is expected to equal 43 // the corresponding element in CodeRequest.Hashes 44 // handler: handlers.CodeRequestHandler 45 type CodeResponse struct { 46 Data [][]byte `serialize:"true"` 47 }