diff --git a/assets/schema.json b/assets/schema.json index 4235e36..c72a138 100644 --- a/assets/schema.json +++ b/assets/schema.json @@ -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", @@ -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" diff --git a/src/compat/tx.rs b/src/compat/tx.rs index b31aa50..78a587a 100644 --- a/src/compat/tx.rs +++ b/src/compat/tx.rs @@ -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, @@ -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), }), } @@ -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( diff --git a/src/types.rs b/src/types.rs index 9486f97..07148e9 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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)]