mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-01-20 19:11:09 +03:00
add doctest exercising advanced query JSON API
This commit is contained in:
parent
13b1fc8e01
commit
1188f3287d
4 changed files with 90 additions and 3 deletions
|
@ -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();
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -203,8 +203,12 @@ pub struct RetrieveTxQueryArgs {
|
|||
/// whether to only consider reverted transactions
|
||||
pub include_reverted_only: Option<bool>,
|
||||
/// 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<u64>,
|
||||
/// 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<u64>,
|
||||
/// lower bound on the creation timestamp, inclusive
|
||||
pub min_creation_timestamp_inc: Option<DateTime<Utc>>,
|
||||
|
|
|
@ -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<TxLogEntry> = 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() {
|
||||
|
|
Loading…
Reference in a new issue