-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix channel closure and account tracking in callback package.
Before this change: 1. The account map wasn't populated if no callback was requested during execution. 2. Sequence number wasn't namespaced by channel_id, which would cause incorrect callbacks to be sent in the event of a channel closing.
- Loading branch information
Showing
11 changed files
with
185 additions
and
86 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
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
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,48 @@ | ||
use cosmwasm_std::{Addr, StdResult, Storage}; | ||
use cw_storage_plus::Map; | ||
|
||
/// (channel_id, sequence_number) -> sender | ||
/// | ||
/// Maps packets to the address that sent them. | ||
const PENDING: Map<(String, u64), Addr> = Map::new("polytone-accounts-pending"); | ||
|
||
/// (local_account) -> remote_account | ||
/// | ||
/// Maps local addresses to their remote counterparts. | ||
const LOCAL_TO_REMOTE_ACCOUNT: Map<Addr, String> = Map::new("polytone-account-map"); | ||
|
||
pub fn on_send_packet( | ||
storage: &mut dyn Storage, | ||
channel_id: String, | ||
sequence_number: u64, | ||
sender: &Addr, | ||
) -> StdResult<()> { | ||
PENDING.save(storage, (channel_id, sequence_number), sender) | ||
} | ||
|
||
pub fn on_ack( | ||
storage: &mut dyn Storage, | ||
channel_id: String, | ||
sequence_number: u64, | ||
executor: Option<String>, | ||
) { | ||
let local_account = PENDING | ||
.load(storage, (channel_id.clone(), sequence_number)) | ||
.expect("pending was set when sending packet"); | ||
|
||
PENDING.remove(storage, (channel_id, sequence_number)); | ||
|
||
if let Some(executor) = executor { | ||
LOCAL_TO_REMOTE_ACCOUNT | ||
.save(storage, local_account, &executor) | ||
.expect("strings were loaded from storage, so should serialize"); | ||
} | ||
} | ||
|
||
pub fn on_timeout(storage: &mut dyn Storage, channel_id: String, sequence_number: u64) { | ||
PENDING.remove(storage, (channel_id, sequence_number)) | ||
} | ||
|
||
pub fn query_account(storage: &dyn Storage, local_address: Addr) -> StdResult<Option<String>> { | ||
LOCAL_TO_REMOTE_ACCOUNT.may_load(storage, local_address) | ||
} |
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
Oops, something went wrong.