-
Notifications
You must be signed in to change notification settings - Fork 447
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
About Event storage codec #759
Comments
Another strange place is that self.env() will take the ownership: pub trait Env {
/// The access wrapper.
type EnvAccess;
/// Accesses the environment with predefined environmental types.
fn env(self) -> Self::EnvAccess;
} Why the following erc20 example code works ? #[ink(message)]
pub fn transfer_from(
&mut self,
from: AccountId,
to: AccountId,
value: Balance,
) -> Result<()> {
let caller = self.env().caller();
let allowance = self.allowance(from, caller);
if allowance < value {
return Err(Error::InsufficientAllowance);
}
self.transfer_from_to(from, to, value)?;
self.allowances.insert((from, caller), allowance - value);
Ok(())
} |
Self::env().emit_event
and self.env()
About
Should this hash appear in metadata.json ? We now only know that some fields are indexd but do not know any other infos. The generated code have the following infos: builder
.build::<Self>()
.push_topic::<::ink_env::topics::PrefixedValue<[u8; 15usize]>>(
&::ink_env::topics::PrefixedValue {
value: b"Erc20::Transfer",
prefix: b"",
},
)
.push_topic::<::ink_env::topics::PrefixedValue<Option<AccountId>>>(
&::ink_env::topics::PrefixedValue {
value: &self.from,
prefix: b"Erc20::Transfer::from",
},
)
.push_topic::<::ink_env::topics::PrefixedValue<Option<AccountId>>>(
&::ink_env::topics::PrefixedValue {
value: &self.to,
prefix: b"Erc20::Transfer::to",
},
)
.push_topic::<::ink_env::topics::PrefixedValue<Balance>>(
&::ink_env::topics::PrefixedValue {
value: &self.value,
prefix: b"Erc20::Transfer::value",
},
)
.finish()
} How to use the information of |
We think if change the events type define from for exmaple we think a standard like "ERC20" should include the event. Then if the standard define some event in an "interface" crate, then the impl crate should know the event type which defined in the "interface" crate. Then the impl crate also may define self event. The currently event module could not do this thing. So we think the define of event should be marked as id, then it could be composable. |
It works since we implement the trait for references of the contract. E.g. impl<'a> Env for &'a MyContract {
type EnvAccess = ...;
fn env(self) -> Self::EnvAccess { ... }
} Then |
You can access the generated base event type definition using |
But not all users know the detailed generate rule. This makes the cost of using some generated types very high. |
We already had discussions about adding yet another way to specify events in the form of an enum directly which would probably resolve your problems. Not implemented, yet though. |
@Robbepop is this in an issue somewhere? If so, I think we should probably close this in favour of that |
There is no issues for that yet from what I can tell. It is a pretty recent idea due to the ideas that came up for library-like contracts. |
Closing the issue due to inactivity |
I find
erc20
example expanded code is:Ink! users do not perceive the coding process, but the design has a lot of influence on the combination of different contracts. Other contracts cannot access the generated
__ink_EventBase
. Contract A may have trouble handling the events of contract B.Other rust users can only rely on the events type on
metadata.json
and implement the corresponding event type again to decode the event.Is it necessary to automatically generate a
__ink_EventBase
and implement various traits for it? What effect does this have on the mode of event storage ?Would it be better if the user manually specify the
id
of the event? Just likeselector
. In this way, cross-contract events can be resolved more easily.Example:
User choose a
id
for contract event. In this way, other contract can reuse these contract events.However, this method should not encode the event to the enumeration of scale, because the enumeration of scale is very limited (only 1 byte is used), so there will be new problems soon.
The text was updated successfully, but these errors were encountered: