Skip to content

removed check forward & forward channel mapping #17

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

Merged
merged 1 commit into from
Oct 3, 2023
Merged
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
9 changes: 1 addition & 8 deletions contracts/cw-ics20-latest/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ pub fn reply(deps: DepsMut, _env: Env, reply: Reply) -> Result<Response, Contrac
&reply_args.channel,
&reply_args.denom,
reply_args.amount,
false,
)?;

let sub_msg = handle_packet_refund(
Expand Down Expand Up @@ -1066,13 +1065,7 @@ fn on_packet_failure(

let sub_msg = handle_packet_refund(deps.storage, &msg.sender, &msg.denom, msg.amount)?;
// since we reduce the channel's balance optimistically when transferring back, we undo reduce it again when receiving failed ack
undo_reduce_channel_balance(
deps.storage,
&packet.src.channel_id,
&msg.denom,
msg.amount,
false,
)?;
undo_reduce_channel_balance(deps.storage, &packet.src.channel_id, &msg.denom, msg.amount)?;

let res = IbcBasicResponse::new()
.add_submessage(sub_msg)
Expand Down
20 changes: 6 additions & 14 deletions contracts/cw-ics20-latest/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub const CHANNEL_REVERSE_STATE: Map<(&str, &str), ChannelState> =
Map::new("channel_reverse_state");

/// Reverse channel state is used when LOCAL chain initiates ibc transfer to remote chain
pub const CHANNEL_FORWARD_STATE: Map<(&str, &str), ChannelState> =
Map::new("channel_forward_state");
// pub const CHANNEL_FORWARD_STATE: Map<(&str, &str), ChannelState> =
// Map::new("channel_forward_state");

/// Every cw20 contract we allow to be sent is stored here, possibly with a gas_limit
pub const ALLOW_LIST: Map<&Addr, AllowInfo> = Map::new("allow_list");
Expand Down Expand Up @@ -143,8 +143,7 @@ pub fn increase_channel_balance(
denom: &str, // should be ibc denom
amount: Uint128,
) -> Result<(), ContractError> {
let state = CHANNEL_REVERSE_STATE;
state.update(storage, (channel, denom), |orig| -> StdResult<_> {
CHANNEL_REVERSE_STATE.update(storage, (channel, denom), |orig| -> StdResult<_> {
let mut state = orig.unwrap_or_default();
state.outstanding += amount;
state.total_sent += amount;
Expand All @@ -159,8 +158,7 @@ pub fn reduce_channel_balance(
denom: &str, // should be ibc denom
amount: Uint128,
) -> Result<(), ContractError> {
let state = CHANNEL_REVERSE_STATE;
state.update(
CHANNEL_REVERSE_STATE.update(
storage,
(channel, denom),
|orig| -> Result<_, ContractError> {
Expand Down Expand Up @@ -190,8 +188,7 @@ pub fn override_channel_balance(
outstanding: Uint128,
total_sent: Option<Uint128>,
) -> Result<(), ContractError> {
let state = CHANNEL_REVERSE_STATE;
state.update(storage, (channel, denom), |orig| -> StdResult<_> {
CHANNEL_REVERSE_STATE.update(storage, (channel, denom), |orig| -> StdResult<_> {
let mut state = orig.unwrap_or_default();
state.outstanding = outstanding;
if let Some(total_sent) = total_sent {
Expand All @@ -209,13 +206,8 @@ pub fn undo_reduce_channel_balance(
channel: &str,
denom: &str,
amount: Uint128,
forward: bool,
) -> Result<(), ContractError> {
let mut state = CHANNEL_REVERSE_STATE;
if forward {
state = CHANNEL_FORWARD_STATE;
}
state.update(storage, (channel, denom), |orig| -> StdResult<_> {
CHANNEL_REVERSE_STATE.update(storage, (channel, denom), |orig| -> StdResult<_> {
let mut state = orig.unwrap_or_default();
state.outstanding += amount;
Ok(state)
Expand Down