github.com/onflow/flow-go@v0.33.17/fvm/evm/stdlib/abiOnlyContract.cdc (about) 1 access(all) 2 contract EVM { 3 4 /// EVMAddress is an EVM-compatible address 5 access(all) 6 struct EVMAddress { 7 8 /// Bytes of the address 9 access(all) 10 let bytes: [UInt8; 20] 11 12 /// Constructs a new EVM address from the given byte representation 13 init(bytes: [UInt8; 20]) { 14 self.bytes = bytes 15 } 16 17 } 18 19 access(all) 20 fun encodeABI(_ values: [AnyStruct]): [UInt8] { 21 return InternalEVM.encodeABI(values) 22 } 23 24 access(all) 25 fun decodeABI(types: [Type], data: [UInt8]): [AnyStruct] { 26 return InternalEVM.decodeABI(types: types, data: data) 27 } 28 29 access(all) 30 fun encodeABIWithSignature( 31 _ signature: String, 32 _ values: [AnyStruct] 33 ): [UInt8] { 34 let methodID = HashAlgorithm.KECCAK_256.hash( 35 signature.utf8 36 ).slice(from: 0, upTo: 4) 37 let arguments = InternalEVM.encodeABI(values) 38 39 return methodID.concat(arguments) 40 } 41 42 access(all) 43 fun decodeABIWithSignature( 44 _ signature: String, 45 types: [Type], 46 data: [UInt8] 47 ): [AnyStruct] { 48 let methodID = HashAlgorithm.KECCAK_256.hash( 49 signature.utf8 50 ).slice(from: 0, upTo: 4) 51 52 for byte in methodID { 53 if byte != data.removeFirst() { 54 panic("signature mismatch") 55 } 56 } 57 58 return InternalEVM.decodeABI(types: types, data: data) 59 } 60 }