use crate::client::types::{Balance, InternalTransaction, Transaction};
use crate::client::BscScanClient;
use crate::error::Result;
pub trait AccountEndpoints {
async fn get_balance(&self, address: &str) -> Result<Balance>;
async fn get_transactions(
&self,
address: &str,
start_block: u64,
end_block: u64,
page: u32,
offset: u32,
sort: &str,
) -> Result<Vec<Transaction>>;
async fn get_internal_transactions(
&self,
address: &str,
start_block: u64,
end_block: u64,
page: u32,
offset: u32,
sort: &str,
) -> Result<Vec<InternalTransaction>>;
}
impl AccountEndpoints for BscScanClient {
async fn get_balance(&self, address: &str) -> Result<Balance> {
let params = [("address", address), ("tag", "latest")];
let balance_str: String = self.request_simple("account", "balance", ¶ms).await?;
Ok(Balance { wei: balance_str })
}
async fn get_transactions(
&self,
address: &str,
start_block: u64,
end_block: u64,
page: u32,
offset: u32,
sort: &str,
) -> Result<Vec<Transaction>> {
let params = [
("address", address),
("startblock", &start_block.to_string()),
("endblock", &end_block.to_string()),
("page", &page.to_string()),
("offset", &offset.to_string()),
("sort", sort),
];
self.request("account", "txlist", ¶ms).await
}
async fn get_internal_transactions(
&self,
address: &str,
start_block: u64,
end_block: u64,
page: u32,
offset: u32,
sort: &str,
) -> Result<Vec<InternalTransaction>> {
let params = [
("address", address),
("startblock", &start_block.to_string()),
("endblock", &end_block.to_string()),
("page", &page.to_string()),
("offset", &offset.to_string()),
("sort", sort),
];
self.request("account", "txlistinternal", ¶ms).await
}
}