1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#[macro_use]
extern crate lazy_static;

use std::fmt;
use std::sync::Mutex;

use reqwest::header::HeaderMap;

pub const STAGING_REQUEST_URL: &str = "https://api-staging.mirrorworld.fun";
pub const RELEASE_REQUEST_URL: &str = "https://api.mirrorworld.fun";

pub const SSO_STAGING: &str = "https://mirrorworld-sso-staging.mirrorworld.fun";
pub const SSO_RELEASE: &str = "https://mirrorworld-sso.mirrorworld.fun";


pub const DEVNET_ENV: &str = "devnet";
pub const MAINNET_ENV: &str = "mainnet";

pub struct Config {
    api_key: String,
    auth: String,
    net: String,
}
impl Config {
    fn new() -> Config {
        Config {
            api_key: "".to_string(),
            auth: "".to_string(),
            net: "devnet".to_string(),
        }
    }
}

lazy_static! {
    static ref API_KEY: Mutex<String> = Mutex::new("".to_string());
    static ref AUTH: Mutex<String> = Mutex::new("".to_string());
    static ref CACHE: Mutex<Config> = Mutex::new(Config::new());
}

pub fn set_config(auth_str: &str, key_str: &str) {
    CACHE.lock().unwrap().api_key = key_str.to_string();
    CACHE.lock().unwrap().auth = auth_str.to_string();
}

pub fn set_auth(auth_str: &str) {
    CACHE.lock().unwrap().auth = auth_str.to_string();
}
pub fn set_apikey(key_str: &str) {
    CACHE.lock().unwrap().api_key = key_str.to_string();
}
pub fn set_network(net: &str) {
    CACHE.lock().unwrap().net = net.to_string();
}
pub fn get_network() -> String {
    return CACHE.lock().unwrap().net.to_string();
}

pub fn get_auth() -> String {
    return CACHE.lock().unwrap().auth.to_string();
}

pub fn get_apikey() -> String {
    return CACHE.lock().unwrap().api_key.to_string();
}

#[derive(Copy, Clone)]
pub enum NetEnv {
    DEVNET,
    MAINNET,
}

pub fn get_env_name(net: NetEnv) -> String {
    let s = match net {
        NetEnv::DEVNET => DEVNET_ENV.to_string(),
        NetEnv::MAINNET => MAINNET_ENV.to_string(),
        // _ => "".to_string(),
    };
    s
}

pub fn get_basic_url(net: NetEnv) -> String {
    let s = match net {
        NetEnv::DEVNET => STAGING_REQUEST_URL.to_string(),
        NetEnv::MAINNET => RELEASE_REQUEST_URL.to_string(),
        // _ => "".to_string(),
    };
    s
}

pub fn get_sso_basic_url(net: NetEnv) -> String {
    let s = match net {
        NetEnv::DEVNET => SSO_STAGING.to_string(),
        NetEnv::MAINNET => SSO_RELEASE.to_string(),
    };
    s
}

pub fn get_request_header(api: String, token: String) -> HeaderMap {
    let mut headers = HeaderMap::new();
    headers.insert("Content-Type", "application/json".parse().unwrap());
    headers.insert("x-api-key", api.parse().unwrap());
    let authentication: String = "Bearer ".to_string() + &token;
    headers.insert("Authorization", authentication.parse().unwrap());

    headers
}

pub mod authentication;
pub mod marketplace;
pub mod wallet;

pub enum ActionType {
    MINT_NFT,
    UPDATE_NFT,
    TRANSFER_SOL,
    TRANSFER_SPL_TOKEN,
    CREATE_COLLECTION,
    CREATE_SUB_COLLECTION,
    LIST_NFT,
    BUY_NFT,
    CANCEL_LISTING,
    UPDATE_LISTING,
    TRANSFER_NFT,
    INTERACTION,
    CREATE_MARKETPLACE,
    UPDATE_MARKETPLACE
}


impl fmt::Display for ActionType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            ActionType::MINT_NFT => write!(f, "mint_nft"),
            ActionType::UPDATE_NFT => write!(f, "update_nft"),
            ActionType::TRANSFER_SOL => write!(f, "transfer_sol"),
            ActionType::TRANSFER_SPL_TOKEN => write!(f, "transfer_spl_token"),
            ActionType::CREATE_COLLECTION => write!(f, "create_collection"),
            ActionType::CREATE_SUB_COLLECTION => write!(f, "create_sub_collection"),
            ActionType::LIST_NFT => write!(f, "list_nft"),
            ActionType::BUY_NFT => write!(f, "buy_nft"),
            ActionType::CANCEL_LISTING => write!(f, "cancel_listing"),
            ActionType::UPDATE_LISTING => write!(f, "update_listing"),
            ActionType::TRANSFER_NFT => write!(f, "transfer_nft"),
            ActionType::INTERACTION => write!(f, "interaction"),
            ActionType::CREATE_MARKETPLACE => write!(f, "create_marketplace"),
            ActionType::UPDATE_MARKETPLACE => write!(f, "update_marketplace"),
        }
    }
}