diff --git a/api/src/owner.rs b/api/src/owner.rs index 01fbdd09..ac80d787 100644 --- a/api/src/owner.rs +++ b/api/src/owner.rs @@ -1167,7 +1167,7 @@ where /// let tx_slate_id = None; /// /// // Return all TxLogEntries - /// let result = api_owner.retrieve_txs(None, update_from_node, tx_id, tx_slate_id); + /// let result = api_owner.retrieve_txs(None, update_from_node, tx_id, tx_slate_id, None); /// /// if let Ok((was_updated, tx_log_entries)) = result { /// let stored_tx = api_owner.get_stored_tx(None, Some(tx_log_entries[0].id), None).unwrap(); diff --git a/api/src/owner_rpc.rs b/api/src/owner_rpc.rs index beeb6a66..8ce8a5f6 100644 --- a/api/src/owner_rpc.rs +++ b/api/src/owner_rpc.rs @@ -300,6 +300,89 @@ pub trait OwnerRpc { # "# # , 2, false, false, false, false); ``` + + # JSON-RPC Example, with advanced query arguments - See (../grin_wallet_libwallet/types.struct.RetrieveTxQueryArgs.html) + + ``` + # grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!( + # r#" + { + "jsonrpc": "2.0", + "method": "retrieve_txs", + "params": { + "token": "d202964900000000d302964900000000d402964900000000d502964900000000", + "refresh_from_node": true, + "tx_id": null, + "tx_slate_id": null, + "tx_query_args": { + "min_id_inc": 0, + "max_id_inc": 100, + "min_amount_inc": "0", + "max_amount_inc": "6000000000", + "sort_field": "Id", + "sort_order": "Desc" + } + }, + "id": 1 + } + # "# + # , + # r#" + { + "id": 1, + "jsonrpc": "2.0", + "result": { + "Ok": [ + true, + [ + { + "amount_credited": "60000000000", + "amount_debited": "0", + "confirmation_ts": "2019-01-15T16:01:26Z", + "confirmed": true, + "creation_ts": "2019-01-15T16:01:26Z", + "fee": null, + "id": 0, + "kernel_excess": "0838e19c490038b10f051c9c190a9b1f96d59bbd242f5d3143f50630deb74342ed", + "kernel_lookup_min_height": 1, + "num_inputs": 0, + "num_outputs": 1, + "parent_key_id": "0200000000000000000000000000000000", + "stored_tx": null, + "ttl_cutoff_height": null, + "tx_slate_id": null, + "payment_proof": null, + "reverted_after": null, + "tx_type": "ConfirmedCoinbase" + }, + { + "amount_credited": "60000000000", + "amount_debited": "0", + "confirmation_ts": "2019-01-15T16:01:26Z", + "confirmed": true, + "creation_ts": "2019-01-15T16:01:26Z", + "fee": null, + "id": 1, + "kernel_excess": "08cd9d890c0b6a004f700aa5939a1ce0488fe2a11fa33cf096b50732ceab0be1df", + "kernel_lookup_min_height": 2, + "num_inputs": 0, + "num_outputs": 1, + "parent_key_id": "0200000000000000000000000000000000", + "stored_tx": null, + "ttl_cutoff_height": null, + "payment_proof": null, + "reverted_after": null, + "tx_slate_id": null, + "tx_type": "ConfirmedCoinbase" + } + ] + ] + } + } + # "# + # , 2, false, false, false, false); + ``` + */ fn retrieve_txs( diff --git a/libwallet/src/api_impl/types.rs b/libwallet/src/api_impl/types.rs index 213700e1..2c35cc43 100644 --- a/libwallet/src/api_impl/types.rs +++ b/libwallet/src/api_impl/types.rs @@ -203,8 +203,12 @@ pub struct RetrieveTxQueryArgs { /// whether to only consider reverted transactions pub include_reverted_only: Option, /// lower bound on the total amount (amount_credited - amount_debited), inclusive + #[serde(with = "secp_ser::opt_string_or_u64")] + #[serde(default)] pub min_amount_inc: Option, /// higher bound on the total amount (amount_credited - amount_debited), inclusive + #[serde(with = "secp_ser::opt_string_or_u64")] + #[serde(default)] pub max_amount_inc: Option, /// lower bound on the creation timestamp, inclusive pub min_creation_timestamp_inc: Option>, diff --git a/libwallet/src/internal/updater.rs b/libwallet/src/internal/updater.rs index e9aea59d..ad5ada1d 100644 --- a/libwallet/src/internal/updater.rs +++ b/libwallet/src/internal/updater.rs @@ -25,6 +25,7 @@ use crate::grin_core::global; use crate::grin_core::libtx::proof::ProofBuilder; use crate::grin_core::libtx::reward; use crate::grin_keychain::{Identifier, Keychain, SwitchCommitmentType}; +use crate::grin_util as util; use crate::grin_util::secp::key::SecretKey; use crate::grin_util::secp::pedersen; use crate::grin_util::static_secp_instance; @@ -32,7 +33,6 @@ use crate::internal::keys; use crate::types::{ NodeClient, OutputData, OutputStatus, TxLogEntry, TxLogEntryType, WalletBackend, WalletInfo, }; -use crate::{grin_util as util, Amount}; use crate::{ BlockFees, CbData, OutputCommitMapping, RetrieveTxQueryArgs, RetrieveTxQuerySortField, RetrieveTxQuerySortOrder, @@ -339,7 +339,7 @@ where C: NodeClient + 'a, K: Keychain + 'a, { - let mut txs: Vec = vec![]; + let mut txs; // Adding in new tranasction list query logic. If `tx_id` or `tx_slate_id` // is provided, then `query_args` is ignored and old logic is followed. if query_args.is_some() && tx_id.is_none() && tx_slate_id.is_none() {