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

fixed clippy warning #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"utils",
"wrapped-token",
]
resolver = "2"

[profile.release]
codegen-units = 1
Expand Down
23 changes: 9 additions & 14 deletions channel-escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Contract {
#[init]
pub fn new(near_ibc_account: AccountId) -> Self {
let account_id = String::from(env::current_account_id().as_str());
let parts = account_id.split(".").collect::<Vec<&str>>();
let parts = account_id.split('.').collect::<Vec<&str>>();
assert!(
parts.len() > 2,
"ERR_CONTRACT_MUST_BE_DEPLOYED_IN_SUB_ACCOUNT",
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Contract {
);
let msg = parse_result.unwrap();
let current_account_id = env::current_account_id();
let (channel_id, _) = current_account_id.as_str().split_once(".").unwrap();
let (channel_id, _) = current_account_id.as_str().split_once('.').unwrap();
let token_denom = token_denom.unwrap();
let transfer_request = Ics20TransferRequest {
port_on_a: PORT_ID_STR.to_string(),
Expand Down Expand Up @@ -132,17 +132,17 @@ impl Contract {
amount: U128,
) {
assert!(
self.pending_transfer_requests.contains_key(&account_id),
self.pending_transfer_requests.contains_key(account_id),
"ERR_NO_PENDING_TRANSFER_REQUEST"
);
let req = self.pending_transfer_requests.get(&account_id).unwrap();
let req = self.pending_transfer_requests.get(account_id).unwrap();
assert!(
req.amount == amount
&& req.token_denom.eq(base_denom)
&& req.token_trace_path.eq(trace_path),
"ERR_PENDING_TRANSFER_REQUEST_NOT_MATCHED"
);
self.pending_transfer_requests.remove(&account_id);
self.pending_transfer_requests.remove(account_id);
}
// Get token contract account id corresponding to the asset denom.
fn get_token_contract_by_asset_denom(&self, asset_denom: &AssetDenom) -> Option<AccountId> {
Expand Down Expand Up @@ -194,7 +194,7 @@ impl ChannelEscrow for Contract {
.with_attached_deposit(1)
.with_static_gas(utils::GAS_FOR_SIMPLE_FUNCTION_CALL * 2)
.with_unused_gas_weight(0)
.ft_transfer(receiver_id, amount.into(), None);
.ft_transfer(receiver_id, amount, None);
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ impl ProcessTransferRequestCallback for Contract {
.with_attached_deposit(1)
.with_static_gas(utils::GAS_FOR_SIMPLE_FUNCTION_CALL * 2)
.with_unused_gas_weight(0)
.ft_transfer(sender_id, amount.into(), None);
.ft_transfer(sender_id, amount, None);
}
}

Expand Down Expand Up @@ -290,19 +290,14 @@ impl Viewer for Contract {
}
///
fn get_pending_accounts(&self) -> Vec<AccountId> {
self.pending_transfer_requests
.keys()
.map(|account_id| account_id.clone())
.collect()
self.pending_transfer_requests.keys().cloned().collect()
}
///
fn get_pending_transfer_request_of(
&self,
account_id: AccountId,
) -> Option<Ics20TransferRequest> {
self.pending_transfer_requests
.get(&account_id)
.map(|req| req.clone())
self.pending_transfer_requests.get(&account_id).cloned()
}
}

Expand Down
4 changes: 2 additions & 2 deletions escrow-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Contract {
#[init]
pub fn new() -> Self {
let account_id = String::from(env::current_account_id().as_str());
let parts = account_id.split(".").collect::<Vec<&str>>();
let parts = account_id.split('.').collect::<Vec<&str>>();
assert!(
parts.len() > 2,
"ERR_CONTRACT_MUST_BE_DEPLOYED_IN_SUB_ACCOUNT",
Expand Down Expand Up @@ -107,7 +107,7 @@ pub trait Viewer {
#[near_bindgen]
impl Viewer for Contract {
fn get_channel_id_set(&self) -> Vec<ChannelId> {
self.channel_id_set.iter().map(|id| id.clone()).collect()
self.channel_id_set.iter().cloned().collect()
}
}

Expand Down
8 changes: 4 additions & 4 deletions near-ibc/src/collections/indexed_ascending_lookup_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ where
values.push(
self.index_map
.get(&index)
.map(|k| self.value_map.get(k).map(|v| v).unwrap()),
.map(|k| self.value_map.get(k).unwrap()),
);
}
values
Expand All @@ -208,7 +208,7 @@ where
pub fn get_value_by_index(&self, index: &u64) -> Option<&V> {
self.index_map
.get(index)
.map(|k| self.value_map.get(k).map(|v| v).unwrap())
.map(|k| self.value_map.get(k).unwrap())
}
/// Get value by key.
pub fn get_value_by_key(&self, key: &K) -> Option<&V> {
Expand All @@ -217,15 +217,15 @@ where
/// Get the value of the maximum key less than the given key.
pub fn get_previous_value_by_key(&self, key: &K) -> Option<&V> {
if let Some(key) = self.get_previous_key_by_key(key) {
self.get_value_by_key(&key)
self.get_value_by_key(key)
} else {
None
}
}
/// Get the value of the minimum key greater than the given key.
pub fn get_next_value_by_key(&self, key: &K) -> Option<&V> {
if let Some(key) = self.get_next_key_by_key(key) {
self.get_value_by_key(&key)
self.get_value_by_key(key)
} else {
None
}
Expand Down
14 changes: 6 additions & 8 deletions near-ibc/src/collections/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;

use core::cmp::Ordering;
pub use indexed_ascending_lookup_queue::IndexedAscendingLookupQueue;
pub use indexed_ascending_simple_queue::IndexedAscendingSimpleQueue;

Expand Down Expand Up @@ -33,7 +33,7 @@ where
/// Get current length of the queue.
fn len(&self) -> u64 {
if self.end_index() < self.start_index() {
return 0;
0
} else if self.end_index() == self.start_index() {
if self.get_key_by_index(&self.start_index()).is_some() {
return 1;
Expand Down Expand Up @@ -67,12 +67,10 @@ where
while start <= end {
let mid = start + (end - start) / 2;
if let Some(mid_key) = self.get_key_by_index(&mid) {
if mid_key == key {
return Some(mid);
} else if mid_key < key {
start = mid + 1;
} else {
end = mid - 1;
match mid_key.cmp(key) {
Ordering::Equal => return Some(mid),
Ordering::Less => start = mid + 1,
Ordering::Greater => end = mid - 1,
}
} else {
return None;
Expand Down
92 changes: 46 additions & 46 deletions near-ibc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ pub trait NearIbcStoreHost {
fn get_near_ibc_store() -> NearIbcStore {
let store =
near_sdk::env::storage_read(&StorageKey::NearIbcStore.try_to_vec().unwrap()).unwrap();
let store = NearIbcStore::try_from_slice(&store).unwrap();
store
NearIbcStore::try_from_slice(&store).unwrap()
}
///
fn set_near_ibc_store(store: &NearIbcStore) {
Expand All @@ -84,6 +83,12 @@ impl Debug for NearIbcStore {
}
}

impl Default for NearIbcStore {
fn default() -> Self {
Self::new()
}
}

impl NearIbcStore {
///
pub fn new() -> Self {
Expand Down Expand Up @@ -133,19 +138,17 @@ impl NearIbcStore {
.to_string()
.into_bytes(),
);
self.client_consensus_state_height_sets
.get(client_id)
.map(|heights| {
heights.keys().iter().for_each(|height| {
height.map(|height| {
env::storage_remove(
&ClientConsensusStatePath::new(client_id, height)
.to_string()
.into_bytes(),
)
});
})
});
if let Some(heights) = self.client_consensus_state_height_sets.get(client_id) {
heights.keys().iter().for_each(|height| {
height.map(|height| {
env::storage_remove(
&ClientConsensusStatePath::new(client_id, height)
.to_string()
.into_bytes(),
)
});
})
}
self.client_consensus_state_height_sets.remove(client_id);
self.client_consensus_state_height_sets.flush();
env::storage_remove(&ClientStatePath::new(client_id).to_string().into_bytes());
Expand All @@ -155,46 +158,43 @@ impl NearIbcStore {
}
///
pub fn remove_connection(&mut self, connection_id: &ConnectionId) {
env::storage_remove(&ConnectionPath::new(&connection_id).to_string().into_bytes());
env::storage_remove(&ConnectionPath::new(connection_id).to_string().into_bytes());
self.connection_id_set.remove(connection_id);
self.connection_id_set.flush();
log!("Connection '{}' has been removed.", connection_id);
}
///
pub fn remove_channel(&mut self, port_channel_id: &(PortId, ChannelId)) {
self.packet_commitment_sequence_sets
.get(port_channel_id)
.map(|set| {
set.iter().for_each(|sequence| {
env::storage_remove(
&CommitmentPath::new(&port_channel_id.0, &port_channel_id.1, *sequence)
.to_string()
.into_bytes(),
);
})
});
self.packet_receipt_sequence_sets
.get(port_channel_id)
.map(|set| {
set.iter().for_each(|sequence| {
env::storage_remove(
&ReceiptPath::new(&port_channel_id.0, &port_channel_id.1, *sequence)
.to_string()
.into_bytes(),
);
});
if let Some(set) = self.packet_commitment_sequence_sets.get(port_channel_id) {
set.iter().for_each(|sequence| {
env::storage_remove(
&CommitmentPath::new(&port_channel_id.0, &port_channel_id.1, *sequence)
.to_string()
.into_bytes(),
);
})
}
if let Some(set) = self.packet_receipt_sequence_sets.get(port_channel_id) {
set.iter().for_each(|sequence| {
env::storage_remove(
&ReceiptPath::new(&port_channel_id.0, &port_channel_id.1, *sequence)
.to_string()
.into_bytes(),
);
});
self.packet_acknowledgement_sequence_sets
}
if let Some(set) = self
.packet_acknowledgement_sequence_sets
.get(port_channel_id)
.map(|set| {
set.iter().for_each(|sequence| {
env::storage_remove(
&AckPath::new(&port_channel_id.0, &port_channel_id.1, *sequence)
.to_string()
.into_bytes(),
);
});
{
set.iter().for_each(|sequence| {
env::storage_remove(
&AckPath::new(&port_channel_id.0, &port_channel_id.1, *sequence)
.to_string()
.into_bytes(),
);
});
}
env::storage_remove(
&SeqSendPath(port_channel_id.0.clone(), port_channel_id.1.clone())
.to_string()
Expand Down
Loading