use crate::prelude::*;
use crate::deserialize::{de_string_to_numeric,
de_string_to_U256,
de_string_to_bool,
de_constructor_arguments_string_to_vec_string};
pub enum BSCApiResponseType {
NormalTransaction,
InternalTransaction
}
#[derive(Debug, Clone, serde::Deserialize)]
#[serde(rename_all = "camelCase")] pub struct BSCNormalTransactionResponseSuccessVariantResult {
#[serde(deserialize_with = "de_string_to_numeric")]
pub block_number: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
#[serde(rename = "timeStamp")]
pub timestamp: u64,
pub hash: String,
#[serde(deserialize_with = "de_string_to_numeric")]
pub nonce: u32,
#[serde(deserialize_with = "de_string_to_numeric")]
pub transaction_index: u64,
pub from: String,
pub to: String,
#[serde(deserialize_with = "de_string_to_U256")]
pub value: U256,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas_price: u64,
#[serde(deserialize_with = "de_string_to_bool")]
pub is_error: bool,
#[serde(rename = "txreceipt_status")]
pub txreceipt_status: String,
pub input: String,
pub contract_address: String,
#[serde(deserialize_with = "de_string_to_numeric")]
pub cumulative_gas_used: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas_used: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub confirmations: u32,
}
#[derive(Debug, Clone, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BSCInternalTransactionResponseSuccessVariantResult {
#[serde(deserialize_with = "de_string_to_numeric")]
pub block_number: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
#[serde(rename = "timeStamp")]
pub timestamp: u64,
pub hash: String,
pub from: String,
pub to: String,
#[serde(deserialize_with = "de_string_to_U256")]
pub value: U256,
pub contract_address: String,
pub input: String,
pub r#type: Option<String>,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas_used: u64,
pub trace_id: Option<String>,
#[serde(deserialize_with = "de_string_to_bool")]
pub is_error: bool,
pub err_code: Option<String>
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCBnbBalanceResponse {
pub status: String,
pub message: String,
pub result: GenericBSCBnbBalanceResponseResult,
}
#[derive(Debug, serde::Deserialize)]
#[serde(untagged)]
pub enum GenericBSCBnbBalanceResponseResult {
#[serde(deserialize_with = "de_string_to_U256")]
Success(U256),
Failed(String),
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCBnbBalanceMultiResponse {
pub status: String,
pub message: String,
pub result: GenericBSCBnbBalanceMultiResponseResult,
}
#[derive(Debug, serde::Deserialize)]
#[serde(untagged)]
pub enum GenericBSCBnbBalanceMultiResponseResult {
Success(Vec<BSCBnbBalanceMulti>),
Failed(String),
}
#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BSCBnbBalanceMulti {
pub account: String,
#[serde(deserialize_with = "de_string_to_U256")]
pub balance: U256,
}
#[derive(Debug, Clone, serde::Deserialize)]
#[serde(untagged)]
pub enum GenericBSCTransactionResponseResult<T> {
Success(Vec::<T>),
Failed(Option<String>)
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCTransactionResponse<T> {
pub status: String,
pub message: String,
pub result: GenericBSCTransactionResponseResult::<T>,
}
pub trait CompatibleTransactionResponse<T> {
fn status(&self) -> &str;
fn message(&self) -> &str;
fn result(&self) -> GenericBSCTransactionResponseResult::<T>;
}
impl CompatibleTransactionResponse<BSCNormalTransactionResponseSuccessVariantResult> for BSCTransactionResponse<BSCNormalTransactionResponseSuccessVariantResult>
{
fn status(&self) -> &str {
&self.status
}
fn message(&self) -> &str {
&self.message
}
fn result(&self) -> GenericBSCTransactionResponseResult::<BSCNormalTransactionResponseSuccessVariantResult> {
self.result.clone()
}
}
impl CompatibleTransactionResponse<BSCInternalTransactionResponseSuccessVariantResult> for BSCTransactionResponse<BSCInternalTransactionResponseSuccessVariantResult>
{
fn status(&self) -> &str {
&self.status
}
fn message(&self) -> &str {
&self.message
}
fn result(&self) -> GenericBSCTransactionResponseResult::<BSCInternalTransactionResponseSuccessVariantResult> {
self.result.clone()
}
}
#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BSCBep20TokenTransferEventResponseSuccessVariantResult {
#[serde(deserialize_with = "de_string_to_numeric")]
pub block_number: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
#[serde(rename = "timeStamp")]
pub timestamp: u64,
pub hash: String,
#[serde(deserialize_with = "de_string_to_numeric")]
pub nonce: u32,
pub block_hash: String,
pub from: String,
pub contract_address: String,
pub to: String,
#[serde(deserialize_with = "de_string_to_U256")]
pub value: U256,
pub token_name: String,
pub token_symbol: String,
#[serde(deserialize_with = "de_string_to_numeric")]
pub token_decimal: u8,
#[serde(deserialize_with = "de_string_to_numeric")]
pub transaction_index: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas_price: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub gas_used: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub cumulative_gas_used: u64,
pub input: String,
#[serde(deserialize_with = "de_string_to_numeric")]
pub confirmations: u32,
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCBep20TokenTransferEventResponse {
pub status: String,
pub message: String,
pub result: GenericBSCBep20TokenTransferEventResponseResult,
}
#[derive(Debug, serde::Deserialize)]
#[serde(untagged)]
pub enum GenericBSCBep20TokenTransferEventResponseResult {
Success(Vec::<BSCBep20TokenTransferEventResponseSuccessVariantResult>),
Failed(String)
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCBnbLastPriceResponse {
pub status: String,
pub message: String,
pub result: BSCBnbLastPriceResult,
}
#[derive(Debug, serde::Deserialize)]
#[serde(untagged)]
pub enum BSCBnbLastPriceResult {
Success(BSCBnbLastPrice),
Failed(String)
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCBnbLastPrice {
#[serde(deserialize_with = "de_string_to_numeric")]
pub ethbtc: f64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub ethbtc_timestamp: u64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub ethusd: f64,
#[serde(deserialize_with = "de_string_to_numeric")]
pub ethusd_timestamp: u64,
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCContractABIResponse {
pub status: String,
pub message: String,
pub result: String,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct BSCContractABIItem {
#[serde(skip_serializing_if = "Option::is_none")]
pub anonymous: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub inputs: Option<Vec<BSCContractABIItemType>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub outputs: Option<Vec<BSCContractABIItemType>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub state_mutability: Option<String>,
pub r#type: String
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct BSCContractABIItemType {
#[serde(skip_serializing_if = "Option::is_none")]
pub indexed: Option<bool>,
pub internal_type: String,
pub name: String,
pub r#type: String,
}
#[derive(Debug, serde::Deserialize)]
pub struct BSCContractSourceCodeResponse {
pub status: String,
pub message: String,
pub result: BSCContractSourceCodeResult,
}
#[derive(Debug, serde::Deserialize)]
#[serde(untagged)]
pub enum BSCContractSourceCodeResult {
Success(Vec<BSCContractSourceCode>),
Failed(String),
}
#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BSCContractSourceCode {
#[serde(rename = "SourceCode")]
pub source_code: String,
#[serde(rename = "ABI")]
pub abi: String,
#[serde(rename = "ContractName")]
pub contract_name: String,
#[serde(rename = "CompilerVersion")]
pub compiler_version: String,
#[serde(deserialize_with = "de_string_to_bool")]
#[serde(rename = "OptimizationUsed")]
pub optimization_used: bool,
#[serde(deserialize_with = "de_string_to_numeric")]
#[serde(rename = "Runs")]
pub runs: u32,
#[serde(deserialize_with = "de_constructor_arguments_string_to_vec_string")]
#[serde(rename = "ConstructorArguments")]
pub constructor_arguments: Vec<String>,
#[serde(rename = "EVMVersion")]
pub evm_version: String,
#[serde(rename = "Library")]
pub library: String,
#[serde(rename = "LicenseType")]
pub license_type: String,
#[serde(deserialize_with = "de_string_to_bool")]
#[serde(rename = "Proxy")]
pub proxy: bool,
#[serde(rename = "Implementation")]
pub implementation: String,
#[serde(rename = "SwarmSource")]
pub swarm_source: String,
}