-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solana-ibc: refactor events handling
Firstly, remove ibc_events_history from the storage. The field only ever grows which isn’t sustainable. The contract has no use for the field and off-chain customers should look at history of Solana logs rather than looking at the field. Secondly, encode the IBC event directly in an event struct rather than first borsh serialising it and then emitting that. Since emitting causes another borsh serialisation this leads to somewhat awkward and unnecessary double serialisation. Lastly, use Solana logging directly rather than using Anchor’s logging infrastructure. Anchor really doesn’t give us much as far as I can tell and having an enum with all possible events which is serialised is just as if not more convenient.
- Loading branch information
Showing
5 changed files
with
33 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use anchor_lang::prelude::borsh; | ||
use anchor_lang::solana_program; | ||
|
||
/// Possible events emitted by the smart contract. | ||
/// | ||
/// The events are logged in their borsh-serialised form. | ||
#[derive( | ||
Clone, | ||
PartialEq, | ||
Eq, | ||
borsh::BorshSerialize, | ||
borsh::BorshDeserialize, | ||
derive_more::From, | ||
)] | ||
pub enum Event { | ||
IBCEvent(ibc::core::events::IbcEvent), | ||
} | ||
|
||
impl Event { | ||
pub fn emit(&self) -> Result<(), String> { | ||
borsh::BorshSerialize::try_to_vec(self) | ||
.map(|data| solana_program::log::sol_log_data(&[data.as_slice()])) | ||
.map_err(|err| err.to_string()) | ||
} | ||
} | ||
|
||
pub fn emit(event: impl Into<Event>) -> Result<(), String> { | ||
event.into().emit() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters