-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into yahya-revert-pr4978
- Loading branch information
Showing
7 changed files
with
279 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
access(all) | ||
contract EVM { | ||
|
||
/// EVMAddress is an EVM-compatible address | ||
access(all) | ||
struct EVMAddress { | ||
|
||
/// Bytes of the address | ||
access(all) | ||
let bytes: [UInt8; 20] | ||
|
||
/// Constructs a new EVM address from the given byte representation | ||
init(bytes: [UInt8; 20]) { | ||
self.bytes = bytes | ||
} | ||
|
||
} | ||
|
||
access(all) | ||
fun encodeABI(_ values: [AnyStruct]): [UInt8] { | ||
return InternalEVM.encodeABI(values) | ||
} | ||
|
||
access(all) | ||
fun decodeABI(types: [Type], data: [UInt8]): [AnyStruct] { | ||
return InternalEVM.decodeABI(types: types, data: data) | ||
} | ||
|
||
access(all) | ||
fun encodeABIWithSignature( | ||
_ signature: String, | ||
_ values: [AnyStruct] | ||
): [UInt8] { | ||
let methodID = HashAlgorithm.KECCAK_256.hash( | ||
signature.utf8 | ||
).slice(from: 0, upTo: 4) | ||
let arguments = InternalEVM.encodeABI(values) | ||
|
||
return methodID.concat(arguments) | ||
} | ||
|
||
access(all) | ||
fun decodeABIWithSignature( | ||
_ signature: String, | ||
types: [Type], | ||
data: [UInt8] | ||
): [AnyStruct] { | ||
let methodID = HashAlgorithm.KECCAK_256.hash( | ||
signature.utf8 | ||
).slice(from: 0, upTo: 4) | ||
|
||
for byte in methodID { | ||
if byte != data.removeFirst() { | ||
panic("signature mismatch") | ||
} | ||
} | ||
|
||
return InternalEVM.decodeABI(types: types, data: data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.