evm_note/
state.rs

1use cosmwasm_std::Storage;
2use cw_storage_plus::{Item, Map};
3
4use crate::error::ContractError;
5
6/// (Connection-ID, Remote port) of this contract's pair.
7pub const CONNECTION_REMOTE_PORT: Item<(String, String)> = Item::new("a");
8
9/// Channel-ID of the channel currently connected. Holds no value when
10/// no channel is active.
11pub const CHANNEL: Item<String> = Item::new("b");
12
13/// Max gas usable in a single block.
14pub const BLOCK_MAX_GAS: Item<u64> = Item::new("bmg");
15
16/// (channel_id) -> sequence number. `u64` is the type used in the
17/// Cosmos SDK for sequence numbers:
18///
19/// <https://github.com/cosmos/ibc-go/blob/a25f0d421c32b3a2b7e8168c9f030849797ff2e8/modules/core/02-client/keeper/keeper.go#L116-L125>
20const SEQUENCE_NUMBER: Map<String, u64> = Map::new("sn");
21
22/// Increments and returns the next sequence number.
23pub(crate) fn increment_sequence_number(
24    storage: &mut dyn Storage,
25    channel_id: String,
26) -> Result<u64, ContractError> {
27    let seq = SEQUENCE_NUMBER
28        .may_load(storage, channel_id.clone())?
29        .unwrap_or_default()
30        .checked_add(1)
31        .ok_or(ContractError::SequenceOverflow)?;
32    SEQUENCE_NUMBER.save(storage, channel_id, &seq)?;
33    Ok(seq)
34}