-
Notifications
You must be signed in to change notification settings - Fork 18
Adapt encoding to ethereum #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
b32602e
9de5a8c
eb25271
48bc0c1
94aac8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| {.push raises: [].} | ||
|
|
||
| import | ||
| std/[macros, math], | ||
| stint, | ||
| ./primitives | ||
|
|
||
|
|
@@ -299,6 +300,37 @@ func payload*(args: TransactionArgs): seq[byte] = | |
| func isEIP4844*(args: TransactionArgs): bool = | ||
| args.maxFeePerBlobGas.isSome or args.blobVersionedHashes.isSome | ||
|
|
||
| macro makeEthereumTypeEnum(): untyped = | ||
| ## This macro creates all the various types of Solidity contracts and maps | ||
| ## them to the type used for their encoding. It also creates an enum to | ||
| ## identify these types in the contract signatures, along with encoder | ||
| ## functions used in the generated procedures. | ||
| result = newStmtList() | ||
| var lastpow2: int | ||
| for i in countdown(256, 8, 8): | ||
| let | ||
| identUint = newIdentNode("EthereumUint" & $i) | ||
| identInt = newIdentNode("EthereumInt" & $i) | ||
| if ceil(log2(i.float)) == floor(log2(i.float)): | ||
tersec marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lastpow2 = i | ||
|
|
||
| result.add quote do: | ||
| type | ||
| `identUint`* = StUint[`lastpow2`] | ||
|
||
| `identInt`* = StInt[`lastpow2`] | ||
|
|
||
| let | ||
| identUint = ident("EthereumUint") | ||
| identInt = ident("EthereumInt") | ||
| identBool = ident("EthereumBool") | ||
| result.add quote do: | ||
| type | ||
| `identUint`* = UInt256 | ||
| `identInt`* = Int256 | ||
| `identBool`* = distinct Int256 | ||
|
|
||
| makeEthereumTypeEnum() | ||
|
|
||
| # Backwards compatibility | ||
|
|
||
| type | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.