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

rusk-wallet: Implement history pagenation and search #3298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions rusk-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Change dependency declaration to not require strict equal [#3405]

### Add

- Add pagenation for transaction history to not pollute the stdout [#3292]

### Fix

- Fix wrong lower limit for stake operation when performing topup [#3394]
Expand Down Expand Up @@ -68,6 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2396]: https://github.com/dusk-network/rusk/issues/2396
[#2340]: https://github.com/dusk-network/rusk/issues/2340
[#2288]: https://github.com/dusk-network/rusk/issues/2288
[#3292]: https://github.com/dusk-network/rusk/issues/3292
[#3394]: https://github.com/dusk-network/rusk/issues/3394

<!-- Releases -->
Expand Down
17 changes: 8 additions & 9 deletions rusk-wallet/src/bin/command/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct TransactionHistory {
impl TransactionHistory {
pub fn header() -> String {
format!(
"{: ^9} | {: ^64} | {: ^8} | {: ^17} | {: ^12} | {: ^8}",
"{: ^9} | {: ^64} | {: ^8} | {: ^17} | {: ^12} | {: ^8}\n",
"BLOCK", "TX_ID", "METHOD", "AMOUNT", "FEE", "TRANSACTION_TYPE"
)
}
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Display for TransactionHistory {
Transaction::Phoenix(_) => dusk_core::transfer::PHOENIX_TOPIC,
};

write!(
writeln!(
f,
"{height: >9} | {tx_id} | {contract: ^8} | {dusk: >+17.9} | {fee} | {tx_type}",
)
Expand Down Expand Up @@ -141,15 +141,14 @@ pub(crate) async fn transaction_from_notes(
&& th.height == decoded_note.block_height
});

match outgoing_tx {
// Outgoing txs found, this should be the change or any
// other output created by the tx result
// (like withdraw or unstake)
Some(th) => th.amount += note_amount,
// If outgoing txs found, this should be the change or any
// other output created by the tx result
// (like withdraw or unstake)
if let Some(th) = outgoing_tx {
th.amount += note_amount

// No outgoing txs found, this note should belong to a
// If no outgoing txs found, this note should belong to a
// preconfigured genesis state
None => println!("??? val {}", note_amount),
}
}
}
Expand Down
41 changes: 24 additions & 17 deletions rusk-wallet/src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,33 @@ pub(crate) async fn run_loop(
// run command
prompt::hide_cursor()?;
let res = cmd.run(wallet, settings).await?;

prompt::show_cursor()?;

// output results
println!("\r{}", res);
if let RunResult::Tx(hash) = res {
let tx_id = hex::encode(hash.to_bytes());

// Wait for transaction confirmation
// from network
let gql = GraphQL::new(
settings.state.to_string(),
io::status::interactive,
)?;
gql.wait_for(&tx_id).await?;

if let Some(explorer) = &settings.explorer {
let url = format!("{explorer}{tx_id}");
println!("> URL: {url}");
prompt::launch_explorer(url)?;
match res {
RunResult::Tx(hash) => {
let tx_id = hex::encode(hash.to_bytes());

// Wait for transaction confirmation
// from network
let gql = GraphQL::new(
settings.state.to_string(),
io::status::interactive,
)?;
gql.wait_for(&tx_id).await?;

if let Some(explorer) = &settings.explorer {
let url = format!("{explorer}{tx_id}");
println!("> URL: {url}");
prompt::launch_explorer(url)?;
}
}
RunResult::History(ref history) => {
let _ = crate::prompt::tx_history_list(history);

println!();
}
_ => println!("\r{}", res),
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions rusk-wallet/src/bin/io/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use rusk_wallet::{
};
use sha2::{Digest, Sha256};

use crate::command::TransactionHistory;

pub(crate) fn ask_pwd(msg: &str) -> Result<String, InquireError> {
let pwd = Password::new(msg)
.with_display_toggle_enabled()
Expand Down Expand Up @@ -368,6 +370,16 @@ pub(crate) fn request_address(
.prompt()?)
}

pub(crate) fn tx_history_list(
history: &[TransactionHistory],
) -> anyhow::Result<String> {
let header = TransactionHistory::header();
let history_str: Vec<String> =
history.iter().map(|history| history.to_string()).collect();

Ok(Select::new(header.as_str(), history_str).prompt()?)
}

/// Request contract WASM file location
pub(crate) fn request_contract_code() -> anyhow::Result<PathBuf> {
let validator = |path_str: &str| {
Expand Down
Loading