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
#[macro_use]
extern crate lazy_static;
use std::sync::Mutex;
use reqwest::header::HeaderMap;
pub const STAGING_REQUEST_URL: &str = "https://api.mirrorworld.fun";
pub const RELEASE_REQUEST_URL: &str = "https://api.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(),
};
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(),
};
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("authentication", authentication.parse().unwrap());
headers
}
pub mod authentication;
pub mod marketplace;
pub mod wallet;