Skip to content

Commit

Permalink
rusk-wallet: Fix transaction direction and sign of amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 committed Dec 23, 2024
1 parent 3f4a486 commit d7047c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 1 addition & 3 deletions rusk-wallet/src/bin/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ use rusk_wallet::{
};
use wallet_core::BalanceInfo;

use crate::io::prompt::{self, create_password, request_transaction_model};
use crate::io::prompt::{self, create_password, TransactionModel};
use crate::settings::Settings;
use crate::{WalletFile, WalletPath};

use self::prompt::TransactionModel;

/// Commands that can be run against the Dusk wallet
#[allow(clippy::large_enum_variant)]
#[derive(PartialEq, Eq, Hash, Clone, Subcommand, Debug)]
Expand Down
29 changes: 21 additions & 8 deletions rusk-wallet/src/bin/command/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fmt::{self, Display};

use dusk_core::signatures::bls::PublicKey;
use dusk_core::transfer::Transaction;
use dusk_core::{dusk, from_dusk};
use rusk_wallet::{BlockTransaction, DecodedNote, GraphQL};
Expand Down Expand Up @@ -45,7 +44,7 @@ impl Display for TransactionHistory {
let fee = match self.direction {
TransactionDirection::In => "".into(),
TransactionDirection::Out => {
let fee = self.fee;
let fee: u64 = self.fee;
let fee = from_dusk(fee);
format!("{: >12.9}", fee)
}
Expand Down Expand Up @@ -160,7 +159,10 @@ pub(crate) async fn moonlight_history(
let gql =
GraphQL::new(settings.state.to_string(), io::status::interactive)?;

let history = gql.moonlight_history(address).await?.full_moonlight_history;
let history = gql
.moonlight_history(address.clone())
.await?
.full_moonlight_history;

let mut collected_history = Vec::new();

Expand All @@ -172,14 +174,25 @@ pub(crate) async fn moonlight_history(

for event in events {
let data = event.data;
let fee = data.gas_spent;
let amount = data.value;
let gas_spent = data.gas_spent;
let mut amount = data.value;
let sender = data.sender;

let direction: TransactionDirection =
match sender == address.to_string() {
true => {
amount = -amount;

TransactionDirection::Out
}
false => TransactionDirection::In,
};

collected_history.push(TransactionHistory {
direction: TransactionDirection::In,
direction,
height,
amount,
fee,
fee: gas_spent * tx.gas_price(),
tx: tx.clone(),
id: id.clone(),
})
Expand All @@ -189,7 +202,7 @@ pub(crate) async fn moonlight_history(
Ok(collected_history)
}

#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
enum TransactionDirection {
In,
Out,
Expand Down
6 changes: 0 additions & 6 deletions rusk-wallet/src/gql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ struct BlockResponse {
#[derive(Deserialize, Debug)]
pub struct BlockData {
pub gas_spent: u64,
pub receiver: String,
pub sender: String,
pub value: f64,
}
Expand Down Expand Up @@ -92,11 +91,6 @@ struct SpentTxResponse {
pub tx: Option<SpentTx>,
}

#[derive(Deserialize)]
struct RawTx {
tx: SpentTxResponse,
}

/// Transaction status
#[derive(Debug)]
pub enum TxStatus {
Expand Down

0 comments on commit d7047c8

Please sign in to comment.