-
Notifications
You must be signed in to change notification settings - Fork 8
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
Syscall Log & Event Automation #14
base: main
Are you sure you want to change the base?
Conversation
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! How should we do indexed logs in this model?
In the code, the first three arguments are automatically indexed in topics, while the rest go to data. This makes me think it would be interesting to do it like in Solidity and use the keyword indexed. What do you think? let mut topics = alloc::vec![topic0];
$(
let encoded = $arg.abi_encode();
if topics.len() < 3 {
topics.push(B256::from_slice(&encoded));
} else {
eth_riscv_runtime::emit_log(&encoded, &topics);
}
)* |
erc20/src/lib.rs
Outdated
@@ -29,16 +30,42 @@ impl ERC20 { | |||
|
|||
self.balance.write(from, from_balance - value); | |||
self.balance.write(to, to_balance + value); | |||
|
|||
emit!("Transfer", idx from, idx to, value); |
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.
Isn't it the case that in Solidity one defines which fields are indexed when declaring the event, not when using it? What will happen if another emit!
call doesn't do idx from
? Or change the (type) signature of the Transfer
event entirely.
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.
I completely understand what you're saying. We could do something more similar to what we have with Solidity and write it that way.
It's interesting to hear your opinions to define what would be most appropriate in this case. All of this is provisional. We could do something like this. What do you think?
#[event]
struct Transfer {
#[indexed]
from: Address,
#[indexed]
to: Address,
value: U256
}
pub fn transfer(&self, from: Address, to: Address, value: u64) -> bool {
...
emit!(Transfer, from, to, value);
}
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.
Yes, struct makes more sense.
As for emitting there a couple of options:
- What you did above.
- Construct a
Transfer
instance and pass that to theemit!
- Have
event
generate atransfer!
macro (named after the struct).
Although one might argue that 2&3 are just sugar in top of 1.
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.
I've just uploaded the update, would the structure be something like this?
Now I need to test everything byte by byte to ensure that everything matches 100% of the time
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.
That's awesome @scab24 , thanks for doing this.
Please, don't treat everything I write as a command :) I really appreciate jumping on this immediately but I don't want to add you work unnecessarily. Let's see what @gakonst and @leonardoalt think as well.
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.
@deuszx
Thank you for your comments, I'm glad to do it, it's a really interesting project 😀
Whenever I have some free time at work, I spend a bit on it
It'd be nice to have some tests showing byte-for-byte equality of events of the same signature between r55 and Solidity. That way indexers don't need to adapt in order to index contracts written with r55. |
Syscall Log & Event Automation