Skip to content

Commit

Permalink
Support different RPC results
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Jun 20, 2024
1 parent 4d1d15b commit 73fb6db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
4 changes: 2 additions & 2 deletions client/src/traits/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub trait AccountRPC: RpcApi {
verbose: Option<bool>,
indexed_amounts: Option<bool>,
is_mine_only: Option<bool>,
) -> Result<Vec<AccountsResult<AccountsResultOwner, String>>>;
) -> Result<Vec<AccountsResult>>;
async fn list_burn_history(&self, options: BurnHistoryOptions) -> Result<Vec<BurnHistory>>;
async fn list_community_balances(&self) -> Result<CommunityBalanceData>;
async fn list_pending_dusd_swaps(&self) -> Result<Vec<DusdSwapsInfo>>;
Expand Down Expand Up @@ -163,7 +163,7 @@ impl AccountRPC for Client {
verbose: Option<bool>,
indexed_amounts: Option<bool>,
is_mine_only: Option<bool>,
) -> Result<Vec<AccountsResult<AccountsResultOwner, String>>> {
) -> Result<Vec<AccountsResult>> {
self.call(
"listaccounts",
&[
Expand Down
46 changes: 32 additions & 14 deletions json/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,40 @@ pub struct GetAccountPagination {
limit: Option<u64>,
}

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct AccountsResult<T, U> {
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct AccountsResult {
key: String,
owner: T,
amount: U,
owner: AccountsResultOwner,
amount: AccountsResultAmount,
}

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AccountsResultOwner {
asm: String,
hex: String,
req_sigs: Option<u64>,
r#type: String,
addresses: Option<Vec<String>>,
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum AccountsResultOwner {
#[serde(rename_all = "camelCase")]
Detailed {
asm: String,
hex: String,
req_sigs: Option<u64>,
r#type: String,
addresses: Option<Vec<String>>,
},
Simple(String),
}

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct AccountAmount(pub Vec<String>);
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum AccountsResultAmount {
Map(HashMap<String, f64>),
String(String),
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum AccountAmount {
List(Vec<String>),
Map(HashMap<String, f64>),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -104,6 +119,9 @@ pub struct AccountHistory {
block_hash: Option<String>,
block_time: Option<u64>,
r#type: String,
reward_type: Option<String>,
#[serde(rename = "poolID")]
pool_id: Option<String>,
txn: Option<u64>,
txid: Option<String>,
pub amounts: Vec<String>,
Expand Down

0 comments on commit 73fb6db

Please sign in to comment.