Skip to content
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

Store packets #64

Merged
merged 14 commits into from
Nov 1, 2023
30 changes: 29 additions & 1 deletion solana/solana-ibc/programs/solana-ibc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use anchor_lang::prelude::*;
use borsh::{BorshDeserialize, BorshSerialize};
use ibc::core::ics04_channel::msgs::PacketMsg;

Check failure on line 12 in solana/solana-ibc/programs/solana-ibc/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `ibc::core::ics04_channel::msgs::PacketMsg`

error: unused import: `ibc::core::ics04_channel::msgs::PacketMsg` --> solana/solana-ibc/programs/solana-ibc/src/lib.rs:12:5 | 12 | use ibc::core::ics04_channel::msgs::PacketMsg; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]`
use ibc::core::ics04_channel::packet::Sequence;
use ibc::core::ics24_host::identifier::PortId;
use ibc::core::router::{Module, ModuleId, Router};
Expand All @@ -33,6 +34,8 @@

#[anchor_lang::program]
pub mod solana_ibc {
use ibc::core::MsgEnvelope;

use super::*;

pub fn deliver(
Expand Down Expand Up @@ -63,7 +66,30 @@
value: msg.value,
};
let res = ibc::core::MsgEnvelope::try_from(msg).and_then(|msg| {
ibc::core::dispatch(&mut store, &mut router, msg)
let result =
ibc::core::dispatch(&mut store, &mut router, msg.clone());
match msg {
MsgEnvelope::Packet(packet) => {
// store the packet if not exists
let mut inner_store = store.0.borrow_mut();
let serialized_packet = borsh::to_vec(&packet).unwrap();
// Find if the packet already exists
match inner_store
.private
.packets
.iter()
.find(|&pack| pack == &serialized_packet)
{
Some(_) => (),
None => inner_store
.private
.packets
.push(serialized_packet),
}
}
_ => (),
}

Check failure on line 91 in solana/solana-ibc/programs/solana-ibc/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> solana/solana-ibc/programs/solana-ibc/src/lib.rs:71:17 | 71 | / match msg { 72 | | MsgEnvelope::Packet(packet) => { 73 | | // store the packet if not exists 74 | | let mut inner_store = store.0.borrow_mut(); ... | 90 | | _ => (), 91 | | } | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `-D clippy::single-match` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::single_match)]` help: try | 71 ~ if let MsgEnvelope::Packet(packet) = msg { 72 + // store the packet if not exists 73 + let mut inner_store = store.0.borrow_mut(); 74 + let serialized_packet = borsh::to_vec(&packet).unwrap(); 75 + // Find if the packet already exists 76 + match inner_store 77 + .private 78 + .packets 79 + .iter() 80 + .find(|&pack| pack == &serialized_packet) 81 + { 82 + Some(_) => (), 83 + None => inner_store 84 + .private 85 + .packets 86 + .push(serialized_packet), 87 + } 88 + } |
result
});
if let Err(err) = res {
errors.push(err);
Expand Down Expand Up @@ -122,6 +148,7 @@
pub type InnerConnectionEnd = String; // Serialized
pub type InnerChannelEnd = String; // Serialized
pub type InnerConsensusState = String; // Serialized
pub type InnerPacketMsg = Vec<u8>;
dhruvja marked this conversation as resolved.
Show resolved Hide resolved

/// A triple of send, receive and acknowledge sequences.
#[derive(
Expand Down Expand Up @@ -225,6 +252,7 @@
BTreeMap<(InnerPortId, InnerChannelId), Vec<InnerSequence>>,
/// The history of IBC events.
pub ibc_events_history: BTreeMap<InnerHeight, Vec<InnerIbcEvent>>,
pub packets: Vec<InnerPacketMsg>,
}

/// All the structs from IBC are stored as String since they dont implement AnchorSerialize and AnchorDeserialize
Expand Down
Loading