Skip to content

Conversation

@BonelessImpl
Copy link
Contributor

No description provided.

ft_withdraw: &FtWithdraw,
intent_hash: CryptoHash,
) -> Result<()>;
fn emit_event(&mut self, event: DefuseEvent<'_>);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to implementation whether to emit event, store it somewhere internally or handle it in some another way:

Suggested change
fn emit_event(&mut self, event: DefuseEvent<'_>);
fn on_event(&mut self, event: DefuseEvent<'_>);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way it will only be possible to emit dip4 events, but not nep245 and others...
Can you make it accept all possible events that we might have in some structured way? E.g. by accepting Event enum as parameter:

#[serde(untagged)]
 pub enum Event<'a> {
    Dip4(DefuseEvent<'a>),
    Nep245(MtEvent<'a>),
    // ...
}

impl Event<'_> {
    pub fn emit(&self) {
        match self {
            Self::Dip4(event) => event.emit(),
            Self::Nep245(event) => event.emit(),
        }
    }
}

The complex part will be to re-write Contract::deposit() and Contract::withdraw methods, so that they become Inspector-aware, or, in general, intent-aware... Or maybe you have other suggestions?

pub ft_withdrawals: Option<Vec<FtWithdraw>>,
pub nft_withdrawals: Option<Vec<NftWithdraw>>,
pub mt_withdrawals: Option<Vec<MtWithdraw>>,
pub events_emitted: Vec<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it more convenient for callers to avoid parsing strings as JSON:

Suggested change
pub events_emitted: Vec<String>,
pub events: Vec<serde_json::Value>,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it would be even better if we don't bind to JSON specifically, but use strongly-typed Event struct/enum...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push event objects presents a challenge because the values are mostly references. In fact, I changed some Cow::Borrow to Owned to make this work. If we get rid of references, then this is easily doable.

pub nft_withdrawals: Option<Vec<NftWithdraw>>,
pub mt_withdrawals: Option<Vec<MtWithdraw>>,
pub events_emitted: Vec<String>,
pub events_emitted: Vec<serde_json::Value>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub events_emitted: Vec<serde_json::Value>,
pub events: Vec<serde_json::Value>,

@BonelessImpl
Copy link
Contributor Author

Closed in favor of #91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants