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
pub mod blocking;
pub use blocking::*;
use snarkvm_console::program::Network;
use anyhow::{ensure, Result};
use std::marker::PhantomData;
#[derive(Clone, Debug)]
pub struct AleoAPIClient<N: Network> {
client: ureq::Agent,
base_url: String,
network_id: String,
_network: PhantomData<N>,
}
impl<N: Network> AleoAPIClient<N> {
pub fn new(base_url: &str, chain: &str) -> Result<Self> {
let client = ureq::Agent::new();
ensure!(
base_url.starts_with("http://") || base_url.starts_with("https://"),
"specified url {base_url} invalid, the base url must start with or https:// (or http:// if doing local development)"
);
Ok(AleoAPIClient {
client,
base_url: base_url.to_string(),
network_id: chain.to_string(),
_network: PhantomData,
})
}
pub fn testnet3() -> Self {
Self::new("https://vm.aleo.org/api", "testnet3").unwrap()
}
pub fn local_testnet3(port: &str) -> Self {
Self::new(&format!("http://localhost:{}", port), "testnet3").unwrap()
}
pub fn base_url(&self) -> &str {
&self.base_url
}
pub fn network_id(&self) -> &str {
&self.network_id
}
}