Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support different results for account history RPC calls #12

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 33 additions & 15 deletions json/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};

use crate::common::UTXO;

Expand Down 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)]
pub struct AccountAmount(pub HashMap<String, f64>);
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum AccountsResultAmount {
Map(BTreeMap<String, f64>),
String(String),
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum AccountAmount {
List(Vec<String>),
Map(BTreeMap<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
Loading