provwasm_tutorial/
state.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Addr, Decimal, Storage};
5use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
6
7pub static CONFIG_KEY: &[u8] = b"config";
8
9/// Fields that comprise the smart contract state
10#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
11pub struct State {
12    // The required purchase denomination
13    pub purchase_denom: String,
14    // The merchant account
15    pub merchant_address: Addr,
16    // The fee collection account
17    pub fee_collection_address: Addr,
18    // The percentage to collect on transfers
19    pub fee_percent: Decimal,
20}
21
22pub fn config(storage: &mut dyn Storage) -> Singleton<State> {
23    singleton(storage, CONFIG_KEY)
24}
25
26pub fn config_read(storage: &dyn Storage) -> ReadonlySingleton<State> {
27    singleton_read(storage, CONFIG_KEY)
28}