Skip to content

Commit

Permalink
Merge pull request #16 from octopus-network/patch/v1.0.3
Browse files Browse the repository at this point in the history
Revise a view function.
  • Loading branch information
riversyang authored Jan 30, 2024
2 parents 093a5cd + 2b8e480 commit 2b30af4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion near-ibc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near-ibc"
version = "1.0.2"
version = "1.0.3"
edition = "2021"

[lib]
Expand Down
42 changes: 30 additions & 12 deletions near-ibc/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ibc::{
clients::tendermint::context::CommonContext,
core::{
channel::types::{
channel::{ChannelEnd, IdentifiedChannelEnd},
channel::{ChannelEnd, IdentifiedChannelEnd, Order},
commitment::{AcknowledgementCommitment, PacketCommitment},
},
client::types::Height,
Expand Down Expand Up @@ -61,7 +61,7 @@ pub trait Viewer {
/// Get the packet receipt associated with the given port, channel, and sequence.
fn get_packet_receipt(&self, port_id: PortId, channel_id: ChannelId, seq: Sequence) -> Vec<u8>;
/// Get the unreceived packet sequences associated with the given port and channel.
fn get_unreceipt_packet(
fn get_unreceived_packets(
&self,
port_id: PortId,
channel_id: ChannelId,
Expand Down Expand Up @@ -221,22 +221,40 @@ impl Viewer for NearIbcContract {
.map_or(vec![], |receipt| borsh::to_vec(&receipt).unwrap())
}
//
fn get_unreceipt_packet(
fn get_unreceived_packets(
&self,
port_id: PortId,
channel_id: ChannelId,
sequences: Vec<Sequence>,
) -> Vec<Sequence> {
let near_ibc_store = self.near_ibc_store.get().unwrap();
let stored_sequences = near_ibc_store
.packet_receipt_sequence_sets
.get(&(port_id, channel_id))
.map_or_else(|| vec![], |receipts| receipts.iter().collect());
sequences
.iter()
.filter(|sequence| !stored_sequences.contains(&sequence))
.cloned()
.collect()
if let Some(channel_end) = near_ibc_store
.channel_end(&ChannelEndPath::new(&port_id, &channel_id))
.map_or(None, |ce| Some(ce))
{
if *channel_end.ordering() == Order::Ordered {
let next_sequence_recv = near_ibc_store
.get_next_sequence_recv(&SeqRecvPath::new(&port_id, &channel_id))
.map_or(Sequence::default(), |sq| sq);
sequences
.iter()
.filter(|sequence| sequence >= &&next_sequence_recv)
.cloned()
.collect()
} else {
let stored_sequences = near_ibc_store
.packet_receipt_sequence_sets
.get(&(port_id, channel_id))
.map_or_else(|| vec![], |receipts| receipts.iter().collect());
sequences
.iter()
.filter(|sequence| !stored_sequences.contains(&sequence))
.cloned()
.collect()
}
} else {
panic!("Channel not found");
}
}
//
fn get_clients(&self) -> Vec<(ClientId, Vec<u8>)> {
Expand Down

0 comments on commit 2b30af4

Please sign in to comment.