Skip to content

Commit

Permalink
Merge pull request #102 from dusk-network/tx_history_type
Browse files Browse the repository at this point in the history
Add tx type in tx history
  • Loading branch information
Daksh14 authored Dec 30, 2023
2 parents e09e3e7 + 5d259ab commit ada88e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion assets/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@
"TransactionHistoryType": {
"description": "The type of the transaction history",
"type": "object",
"required": ["direction", "block_height", "fee", "amount", "id"],
"required": ["direction", "block_height", "fee", "amount", "id", "tx_type"],
"properties": {
"direction": {
"description": "The direction of the transaction, in or out",
Expand All @@ -1405,6 +1405,10 @@
"type": "number",
"format": "uint64"
},
"tx_type": {
"description": "The type of the transaction",
"type": "string"
},
"id": {
"description": "The hash of the transaction",
"type": "string"
Expand Down
10 changes: 10 additions & 0 deletions src/compat/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ pub fn get_history(args: i32, len: i32) -> i64 {
true => types::TransactionDirectionType::Out,
false => types::TransactionDirectionType::In,
};
let transaction_type =
transaction_type(t.call.as_ref().map(|(_, x, _)| x.as_str()));
let hash_to_find = Hasher::digest(t.to_hash_input_bytes());
match ret.iter_mut().find(|th| th.id == hash_to_find.to_string()) {
Some(tx) => tx.amount += note_amount,
Expand All @@ -226,6 +228,7 @@ pub fn get_history(args: i32, len: i32) -> i64 {
block_height: note_data.block_height,
amount: note_amount - inputs_amount,
fee: gas_spent * t.fee().gas_price,
tx_type: transaction_type,
id: transaction_hash(hash_to_find),
}),
}
Expand Down Expand Up @@ -269,6 +272,13 @@ fn transaction_hash(hash: BlsScalar) -> String {
f
}

fn transaction_type(method: Option<&str>) -> String {
match method {
None => String::from("TRANSFER"),
Some(x) => x.to_uppercase(),
}
}

/// Serialize a unprovenTx we recieved from the wallet-core
/// this is copied from old wallet-core (0.20.0-piecrust.0.6)
fn utx_to_var_bytes(
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ pub struct TransactionHistoryType {
pub fee: u64,
#[doc = " The hash of the transaction"]
pub id: String,
#[doc = " The type of the transaction"]
pub tx_type: String,
}
#[doc = " Metadata of the transaction, used in calculating history"]
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
Expand Down

0 comments on commit ada88e3

Please sign in to comment.