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

Restore and update listaccounts #11

Merged
merged 2 commits into from
Jun 19, 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
6 changes: 3 additions & 3 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use json::bitcoin::Txid;
use jsonrpc_async;
use log::Level::{Debug, Trace, Warn};
use serde::{self, Serialize};
use serde_json::{self, json, Map};
use serde_json::{self, Map};

use crate::error::*;
use crate::json;
Expand Down Expand Up @@ -892,7 +892,7 @@ pub trait RpcApi: Sized {
) -> Result<Vec<json::TestMempoolAcceptResult>> {
let hexes: Vec<serde_json::Value> =
rawtxs.to_vec().into_iter().map(|r| r.raw_hex().into()).collect();
let mut args = [into_json(hexes)?, opt_into_json(max_fee_rate)?];
let args = [into_json(hexes)?, opt_into_json(max_fee_rate)?];
self.call("testmempoolaccept", &args).await
}

Expand Down Expand Up @@ -1121,7 +1121,7 @@ pub trait RpcApi: Sized {
tx: R,
max_fee_rate: Option<u64>,
) -> Result<bitcoin::Txid> {
let mut args = [into_json(tx.raw_hex())?, opt_into_json(max_fee_rate)?];
let args = [into_json(tx.raw_hex())?, opt_into_json(max_fee_rate)?];
self.call("sendrawtransaction", &args).await
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use json::bitcoin::consensus::{Decodable, ReadExt};
use json::bitcoin::hex::HexToBytesIter;

mod client;
mod error;
pub mod error;
mod queryable;
mod traits;

Expand Down
43 changes: 25 additions & 18 deletions client/src/traits/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ pub trait AccountRPC: RpcApi {
owner: Option<String>,
options: AccountHistoryOptions,
) -> Result<Vec<AccountHistory>>;
// TODO handle AccountResult enum type
// async fn list_accounts(
// &self,
// pagination: Option<ListAccountPagination>,
// verbose: Option<bool>,
// options: Option<ListAccountOptions>,
// ) -> Result<Vec<AccountResult<String, String>>>;
async fn list_accounts(
&self,
pagination: Option<ListAccountsPagination>,
verbose: Option<bool>,
indexed_amounts: Option<bool>,
is_mine_only: Option<bool>,
) -> Result<Vec<AccountsResult<AccountsResultOwner, String>>>;
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 @@ -157,17 +157,24 @@ impl AccountRPC for Client {
) -> Result<Vec<AccountHistory>> {
self.call("listaccounthistory", &[into_json(owner)?, into_json(options)?]).await
}
// async fn list_accounts(
// &self,
// pagination: Option<ListAccountPagination>,
// verbose: Option<bool>,
// options: Option<ListAccountOptions>,
// ) -> Result<Vec<AccountResult<String, String>>> {
// self.call(
// "listaccounts",
// &[into_json(pagination)?, into_json(verbose)?, into_json(options)?],
// )
// }
async fn list_accounts(
&self,
pagination: Option<ListAccountsPagination>,
verbose: Option<bool>,
indexed_amounts: Option<bool>,
is_mine_only: Option<bool>,
) -> Result<Vec<AccountsResult<AccountsResultOwner, String>>> {
self.call(
"listaccounts",
&[
into_json(pagination)?,
into_json(verbose)?,
into_json(indexed_amounts)?,
into_json(is_mine_only)?,
],
)
.await
}
async fn list_burn_history(&self, options: BurnHistoryOptions) -> Result<Vec<BurnHistory>> {
self.call("listburnhistory", &[into_json(options)?]).await
}
Expand Down
38 changes: 20 additions & 18 deletions json/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum OwnerType {
All,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Format {
Id,
Expand All @@ -30,48 +30,50 @@ pub enum TransferDomainType {
Evm = 3,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ListAccountPagination {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ListAccountsPagination {
start: Option<String>,
including_start: Option<bool>,
limit: Option<u64>,
}

impl ListAccountsPagination {
pub fn new(start: Option<String>, including_start: Option<bool>, limit: Option<u64>) -> Self {
Self {
start,
including_start,
limit,
}
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetAccountPagination {
start: Option<u32>,
including_start: Option<bool>,
limit: Option<u64>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountResult<T, U> {
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct AccountsResult<T, U> {
key: String,
owner: T,
amount: U,
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct AccountAmount(pub HashMap<String, f64>);

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ListAccountOptions {
indexed_amounts: Option<bool>,
is_mine_only: Option<bool>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetAccountOptions {
Expand Down Expand Up @@ -107,7 +109,7 @@ pub struct AccountHistory {
pub amounts: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountHistoryOptions {
max_block_height: Option<u64>,
Expand Down
Loading