archid_registry/
state.rs

1use cosmwasm_std::{Addr, BlockInfo, Storage, Timestamp, Uint128};
2use cosmwasm_storage::{
3    bucket, bucket_read, singleton, singleton_read, Bucket, ReadonlyBucket, ReadonlySingleton,
4    Singleton,
5};
6use cw_utils::Expiration;
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9
10pub static NAME_RESOLVER_KEY: &[u8] = b"nameresolver";
11pub static SUBDOMAIN_MINTED: &[u8] = b"subdomain_minted";
12pub static CONFIG_KEY: &[u8] = b"config";
13
14#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
15pub struct Config {
16    pub admin: Addr,
17    pub wallet: Addr,
18    pub cw721: Addr,
19    pub base_cost: Uint128,
20    pub base_expiration: u64,
21}
22#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
23pub enum SubDomainStatus {
24    // if subdomain in acive mint domain owner can only extend expiration up to domain expiration
25    ExistingMintActive,
26    // if subdomain expired owner can remint which will first burn existing nft
27    ExistingMintExpired,
28    // if new subdomain owner can register and mint / not mint
29    NewSubdomain,
30}
31pub fn config(storage: &mut dyn Storage) -> Singleton<Config> {
32    singleton(storage, CONFIG_KEY)
33}
34
35pub fn config_read(storage: &dyn Storage) -> ReadonlySingleton<Config> {
36    singleton_read(storage, CONFIG_KEY)
37}
38
39/**
40    add expiration
41    and top level domain?
42**/
43#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
44pub struct NameRecord {
45    pub resolver: Addr,
46    pub created: u64,
47    pub expiration: u64,
48}
49impl NameRecord {
50    pub fn is_expired(&self, block: &BlockInfo) -> bool {
51        Expiration::AtTime(Timestamp::from_seconds(self.expiration)).is_expired(block)
52    }
53}
54pub fn resolver(storage: &mut dyn Storage) -> Bucket<NameRecord> {
55    bucket(storage, NAME_RESOLVER_KEY)
56}
57
58pub fn resolver_read(storage: &dyn Storage) -> ReadonlyBucket<NameRecord> {
59    bucket_read(storage, NAME_RESOLVER_KEY)
60}