Skip to content
Open
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
10 changes: 8 additions & 2 deletions api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ where
/// the transaction log entry of id `i`.
/// * `tx_slate_id` - If `Some(uuid)`, only return transactions associated with
/// the given [`Slate`](../grin_wallet_libwallet/slate/struct.Slate.html) uuid.
/// * `confirmed_height` - If `Some(block_height)`, only return transactions confirmed at
/// the given block height.
///
/// # Returns
/// * `(bool, Vec<TxLogEntry)` - A tuple:
Expand All @@ -464,9 +466,10 @@ where
/// let update_from_node = true;
/// let tx_id = None;
/// let tx_slate_id = None;
/// let confirmed_height = 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, confirmed_height);
///
/// if let Ok((was_updated, tx_log_entries)) = result {
/// //...
Expand All @@ -479,6 +482,7 @@ where
refresh_from_node: bool,
tx_id: Option<u32>,
tx_slate_id: Option<Uuid>,
confirmed_height: Option<u64>,
) -> Result<(bool, Vec<TxLogEntry>), Error> {
let tx = {
let t = self.status_tx.lock();
Expand All @@ -495,6 +499,7 @@ where
refresh_from_node,
tx_id,
tx_slate_id,
confirmed_height,
)?;
if self.doctest_mode {
res.1 = res
Expand Down Expand Up @@ -1158,9 +1163,10 @@ where
/// let update_from_node = true;
/// let tx_id = None;
/// let tx_slate_id = None;
/// let confirmed_height = 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, confirmed_height);
///
/// 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();
Expand Down
8 changes: 7 additions & 1 deletion api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ pub trait OwnerRpc {
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"refresh_from_node": true,
"tx_id": null,
"tx_slate_id": null
"tx_slate_id": null,
"confirmed_height": null
},
"id": 1
}
Expand All @@ -255,6 +256,7 @@ pub trait OwnerRpc {
"amount_debited": "0",
"confirmation_ts": "2019-01-15T16:01:26Z",
"confirmed": true,
"confirmed_height": 1,
"creation_ts": "2019-01-15T16:01:26Z",
"fee": null,
"id": 0,
Expand All @@ -275,6 +277,7 @@ pub trait OwnerRpc {
"amount_debited": "0",
"confirmation_ts": "2019-01-15T16:01:26Z",
"confirmed": true,
"confirmed_height": 2,
"creation_ts": "2019-01-15T16:01:26Z",
"fee": null,
"id": 1,
Expand Down Expand Up @@ -305,6 +308,7 @@ pub trait OwnerRpc {
refresh_from_node: bool,
tx_id: Option<u32>,
tx_slate_id: Option<Uuid>,
confirmed_height: Option<u64>,
) -> Result<(bool, Vec<TxLogEntry>), ErrorKind>;

/**
Expand Down Expand Up @@ -1767,13 +1771,15 @@ where
refresh_from_node: bool,
tx_id: Option<u32>,
tx_slate_id: Option<Uuid>,
confirmed_height: Option<u64>,
) -> Result<(bool, Vec<TxLogEntry>), ErrorKind> {
Owner::retrieve_txs(
self,
(&token.keychain_mask).as_ref(),
refresh_from_node,
tx_id,
tx_slate_id,
confirmed_height,
)
.map_err(|e| e.kind())
}
Expand Down
16 changes: 13 additions & 3 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ where
pub struct TxsArgs {
pub id: Option<u32>,
pub tx_slate_id: Option<Uuid>,
pub confirmed_height: Option<u64>,
}

pub fn txs<L, C, K>(
Expand All @@ -1004,8 +1005,10 @@ where
let updater_running = owner_api.updater_running.load(Ordering::Relaxed);
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
let res = api.node_height(m)?;
let (validated, txs) = api.retrieve_txs(m, true, args.id, args.tx_slate_id)?;
let include_status = !args.id.is_some() && !args.tx_slate_id.is_some();
let (validated, txs) =
api.retrieve_txs(m, true, args.id, args.tx_slate_id, args.confirmed_height)?;
let include_status =
!args.id.is_some() && !args.tx_slate_id.is_some() && !args.confirmed_height.is_some();
display::txs(
&g_args.account,
res.height,
Expand All @@ -1030,6 +1033,13 @@ where
None
};

if args.confirmed_height.is_some() && txs.is_empty() {
println!(
"Could not find any transactions confirmed at the block height {}.\n",
args.confirmed_height.unwrap()
)
}

if id.is_some() {
let (_, outputs) = api.retrieve_outputs(m, true, false, id)?;
display::outputs(
Expand Down Expand Up @@ -1112,7 +1122,7 @@ where
}
Some(s) => s,
};
let (_, txs) = api.retrieve_txs(m, true, Some(args.id), None)?;
let (_, txs) = api.retrieve_txs(m, true, Some(args.id), None, None)?;
match args.dump_file {
None => {
if txs[0].confirmed {
Expand Down
8 changes: 8 additions & 0 deletions controller/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn txs(
bMG->"Creation Time",
bMG->"TTL Cutoff Height",
bMG->"Confirmed?",
bMG->"Confirmed Height",
bMG->"Confirmation Time",
bMG->"Num. \nInputs",
bMG->"Num. \nOutputs",
Expand Down Expand Up @@ -186,6 +187,10 @@ pub fn txs(
None => "None".to_owned(),
};
let confirmed = format!("{}", t.confirmed);
let confirmed_height = match t.confirmed_height {
Some(ch) => format!("{}", ch),
None => "None".to_owned(),
};
let num_inputs = format!("{}", t.num_inputs);
let num_outputs = format!("{}", t.num_outputs);
let amount_debited_str = core::amount_to_hr_string(t.amount_debited, true);
Expand Down Expand Up @@ -225,6 +230,7 @@ pub fn txs(
bFB->creation_ts,
bFB->ttl_cutoff_height,
bFC->confirmed,
bFC->confirmed_height,
bFB->confirmation_ts,
bFC->num_inputs,
bFC->num_outputs,
Expand All @@ -244,6 +250,7 @@ pub fn txs(
bFD->slate_id,
bFB->creation_ts,
bFg->confirmed,
bFg->confirmed_height,
bFB->confirmation_ts,
bFD->num_inputs,
bFD->num_outputs,
Expand All @@ -262,6 +269,7 @@ pub fn txs(
bFD->slate_id,
bFB->creation_ts,
bFR->confirmed,
bFR->confirmed_height,
bFB->confirmation_ts,
bFD->num_inputs,
bFD->num_outputs,
Expand Down
14 changes: 7 additions & 7 deletions controller/tests/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
assert_eq!(wallet1_info.total, 5 * reward);
assert_eq!(wallet1_info.amount_currently_spendable, (5 - cm) * reward);
// check tx log as well
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert_eq!(txs.len(), 5);
Ok(())
})?;
Expand All @@ -159,7 +159,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
assert_eq!(wallet1_info.total, 7 * reward);
assert_eq!(wallet1_info.amount_currently_spendable, 7 * reward);
// check tx log as well
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert_eq!(txs.len(), 7);
Ok(())
})?;
Expand All @@ -178,7 +178,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
assert_eq!(wallet1_info.total, 0,);
assert_eq!(wallet1_info.amount_currently_spendable, 0,);
// check tx log as well
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert_eq!(txs.len(), 0);
Ok(())
})?;
Expand Down Expand Up @@ -210,7 +210,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, 13);
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert_eq!(txs.len(), 9);
Ok(())
})?;
Expand All @@ -225,7 +225,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
assert_eq!(wallet1_info.last_confirmed_height, 12);
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
assert_eq!(wallet1_info.last_confirmed_height, 13);
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
println!("{:?}", txs);
assert_eq!(txs.len(), 5);
Ok(())
Expand All @@ -236,7 +236,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
assert!(wallet2_refreshed);
assert_eq!(wallet2_info.last_confirmed_height, 13);
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert_eq!(txs.len(), 1);
Ok(())
})?;
Expand All @@ -254,7 +254,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
assert_eq!(wallet2_info.total, 0,);
assert_eq!(wallet2_info.amount_currently_spendable, 0,);
// check tx log as well
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert_eq!(txs.len(), 0);
Ok(())
})?;
Expand Down
4 changes: 2 additions & 2 deletions controller/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
assert_eq!(wallet1_info.total, bh * reward);
assert_eq!(wallet1_info.amount_currently_spendable, (bh - cm) * reward);
// check tx log as well
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
assert_eq!(wallet1_info.total, c);
assert_eq!(txs.len(), bh as usize);
Expand Down Expand Up @@ -150,7 +150,7 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// check we have a problem now
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
assert!(wallet1_info.total != c);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions controller/tests/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Check transaction log for wallet 2
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
let (_, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert!(refreshed);
assert!(txs.len() == 1);
println!(
Expand All @@ -161,7 +161,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// exists
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None, None)?;
assert!(refreshed);
assert_eq!(txs.len() as u64, bh + 1);
println!(
Expand Down
8 changes: 4 additions & 4 deletions controller/tests/no_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {

// Refresh and check transaction log for wallet 1
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
assert!(refreshed);
let tx = txs[0].clone();
println!("SIMPLE SEND - SENDING WALLET");
Expand All @@ -117,7 +117,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {

// Refresh and check transaction log for wallet 2
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
assert!(refreshed);
let tx = txs[0].clone();
println!("SIMPLE SEND - RECEIVING WALLET");
Expand Down Expand Up @@ -170,7 +170,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {

// check wallet 2's version
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
assert!(refreshed);
for tx in txs {
stored_excess = tx.kernel_excess;
Expand All @@ -184,7 +184,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {

// Refresh and check transaction log for wallet 1
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
assert!(refreshed);
for tx in txs {
println!("Wallet 1: {:?}", tx);
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/payment_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
sender_api.tx_lock_outputs(m, &slate)?;

// Ensure what's stored in TX log for payment proof is correct
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id))?;
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id), None)?;
assert!(txs[0].payment_proof.is_some());
let pp = txs[0].clone().payment_proof.unwrap();
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions controller/tests/repost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>

// Now repost from cached
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
println!("TXS[0]: {:?}", txs[0]);
let stored_tx = api.get_stored_tx(m, None, Some(&txs[0].tx_slate_id.unwrap()))?;
println!("Stored tx: {:?}", stored_tx);
Expand Down Expand Up @@ -224,7 +224,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>

// Now repost from cached
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
let stored_tx_slate = api.get_stored_tx(m, Some(txs[0].id), None)?.unwrap();
api.post_tx(m, &stored_tx_slate, false)?;
bh += 1;
Expand Down
Loading