pub mod response;
use response::*;
pub const MAINNET_URL: &str = "https://nodes.wavesnodes.com";
pub const TESTNET_URL: &str = "https://nodes-testnet.wavesnodes.com";
pub const STAGENET_URL: &str = "https://nodes-stagenet.wavesnodes.com";
pub const LOCAL_URL: &str = "http://127.0.0.1:6869";
pub struct Node<'a> {
url: &'a str,
}
impl<'a> Default for Node<'a> {
fn default() -> Self {
Node { url: MAINNET_URL }
}
}
impl<'a> Node<'a> {
pub fn from_url(url: &'a str) -> Self {
Node { url }
}
pub async fn get_balance(
&self,
address: &str,
) -> Result<ResponseBalance, Box<dyn std::error::Error>> {
let url = format!("{}/addresses/balance/{}", self.url, address);
let res = reqwest::get(url).await?.json::<ResponseBalance>().await?;
Ok(res)
}
pub async fn get_balance_details(
&self,
address: &str,
) -> Result<ResponseBalanceDetails, Box<dyn std::error::Error>> {
let url = format!("{}/addresses/balance/details/{}", self.url, address);
let res = reqwest::get(url)
.await?
.json::<ResponseBalanceDetails>()
.await?;
Ok(res)
}
pub async fn get_address_by_alias(
&self,
alias: &str,
) -> Result<ResponseAddress, Box<dyn std::error::Error>> {
let url = format!("{}/alias/by-alias/{}", self.url, alias);
let res = reqwest::get(url).await?.json::<ResponseAddress>().await?;
Ok(res)
}
pub async fn get_assets_details(
&self,
asset_id: &str,
) -> Result<ResponseAsset, Box<dyn std::error::Error>> {
let url = format!("{}/assets/details/{}", self.url, asset_id);
let res = reqwest::get(url).await?.json::<ResponseAsset>().await?;
Ok(res)
}
pub async fn get_blocks_headers(
&self,
id: &str,
) -> Result<ResponseBlock, Box<dyn std::error::Error>> {
let url = format!("{}/blocks/headers/{}", self.url, id);
let res = reqwest::get(url).await?.json::<ResponseBlock>().await?;
Ok(res)
}
pub async fn get_blocks_headers_at_height(
&self,
height: u64,
) -> Result<ResponseBlock, Box<dyn std::error::Error>> {
let url = format!("{}/blocks/headers/at/{}", self.url, height);
let res = reqwest::get(url).await?.json::<ResponseBlock>().await?;
Ok(res)
}
pub async fn get_blocks_last(&self) -> Result<ResponseBlock, Box<dyn std::error::Error>> {
let url = format!("{}/blocks/last", self.url);
let res = reqwest::get(url).await?.json::<ResponseBlock>().await?;
Ok(res)
}
pub async fn get_leasing_info(
&self,
id: &str,
) -> Result<ResponseLease, Box<dyn std::error::Error>> {
let url = format!("{}/leasing/info/{}", self.url, id);
let res = reqwest::get(url).await?.json::<ResponseLease>().await?;
Ok(res)
}
pub async fn get_node_version(
&self,
) -> Result<ResponseNodeVersion, Box<dyn std::error::Error>> {
let url = format!("{}/node/version", self.url);
let res = reqwest::get(url)
.await?
.json::<ResponseNodeVersion>()
.await?;
Ok(res)
}
pub async fn get_transactions_info(
&self,
id: &str,
) -> Result<ResponseTransaction, Box<dyn std::error::Error>> {
let url = format!("{}/transactions/info/{}", self.url, id);
let res = reqwest::get(url)
.await?
.json::<ResponseTransaction>()
.await?;
Ok(res)
}
pub async fn get_transactions_status(
&self,
id: &str,
) -> Result<ResponseTransactionStatus, Box<dyn std::error::Error>> {
let url = format!("{}/transactions/status/{}", self.url, id);
let res = reqwest::get(url)
.await?
.json::<ResponseTransactionStatus>()
.await?;
Ok(res)
}
}