-
Notifications
You must be signed in to change notification settings - Fork 10
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
Implement the eth_estimateGas
JSON-RPC endpoint
#81
Conversation
|
||
access(all) | ||
fun main(encodedTx: [UInt8]): [UInt64; 2] { | ||
let coa <- EVM.createCadenceOwnedAccount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use evm account resource:
let account = getAuthAccount<auth(Storage) &Account>(Address(0xCOA))
let coa = account.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm)
?? panic("Could not borrow reference to the COA!")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👍 Fixed in eeea98e
I didn't use any entitlements, because EVM.run
does not have any. It is simply defined as:
access(all) fun run(
data = *args.Data | ||
} else if args.Input != nil { | ||
data = *args.Input | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if neither, have another else with error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the TX can also be a value transfer, so it is legit to not provide the input
or data
fields.
api/eoa_test_account.go
Outdated
) | ||
|
||
// address: 658bdf435d810c91414ec09147daa6db62406379 | ||
const eoaTestAccount1KeyHex = "9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better to use the configured evm account, better than have random keys hardcoded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea 👍
Updated in fac85cb
integration/helpers.go
Outdated
func (r *rpcTest) estimateGas( | ||
from common.Address, | ||
data []byte, | ||
gas uint64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is gas here? gas limit or gas price? better to rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point 👍
Updated in fac85cb
@@ -128,6 +140,9 @@ func (e *EVM) SendRawTransaction(ctx context.Context, data []byte) (common.Hash, | |||
uint64(len(data)), | |||
), | |||
) | |||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏅
e.logger.Panic().Msg(fmt.Sprintf("failed to convert value to array: %v", value)) | ||
} | ||
|
||
result := value.(cadence.Array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a todo here, to have a decoder for EVM.Result. For now this is ok but in future I would want to have unified decoder from EVM.Result back to Go type so we can reuse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I think we might need it for the other scripts/transactions that use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added TODO in fac85cb
@@ -319,3 +366,82 @@ func bytesFromCadenceArray(value cadence.Value) ([]byte, error) { | |||
|
|||
return res, nil | |||
} | |||
|
|||
func getErrorForCode(errorCode uint64) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth adding a todo that this would make sense to live inside flow-go/evm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I will probably move it there, in the errors
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added TODO in fac85cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some more comments, but otherwise looks good.
Residual from: #9
Description
Utilizes the new interface of
EVM.run
inside a Cadence script, to run an EVM transaction in order to retrieve the gas consumption and any possible failures. No state change occurs.For contributor use:
master
branchFiles changed
in the Github PR explorer