From 755303a4702933eeaf4a00556334e76bb54a1208 Mon Sep 17 00:00:00 2001 From: Artur <33733651+Keeqler@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:25:39 -0300 Subject: [PATCH] Give tx fee in /transaction --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ca8fe7b..72f3d14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1948,6 +1948,7 @@ dependencies = [ "clap", "cuprate-blockchain", "cuprate-database", + "cuprate-helper", "cuprate-types", "derive_more", "hex", diff --git a/Cargo.toml b/Cargo.toml index f566c6b..6e87282 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" cuprate-blockchain = { path = "./external/cuprate/storage/blockchain", features = ["serde"] } cuprate-database = { path = "./external/cuprate/storage/database", features = ["serde"] } cuprate-types = { path = "./external/cuprate/types/types", features = ["serde"] } +cuprate-helper = { path = "./external/cuprate/helper", features = ["serde"] } monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "e6ae8c2", default-features = false } hex = "0.4.3" actix-web = "4.10.2" diff --git a/src/main.rs b/src/main.rs index 1341243..9a36a3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use cuprate_blockchain::{config::ConfigBuilder, ops, tables::{OpenTables, Tables}, types::PreRctOutputId} ; use cuprate_database::{ConcreteEnv, DatabaseRo, Env, EnvInner, RuntimeError}; +use cuprate_helper::tx::tx_fee; use cuprate_types::json::tx::Transaction; use hex::{FromHex, FromHexError}; use actix_web::{error, get, http::StatusCode, web::{self}, App, HttpResponse, HttpServer, Responder}; @@ -101,6 +102,7 @@ struct TransactionResponse { pub confirmation_height: usize, pub timestamp: u64, pub weight: usize, + pub fee: u64, pub inputs: Vec, pub outputs: Vec, pub extra: String, @@ -152,6 +154,7 @@ async fn get_tx( } )?; + let mixin_tx_block = new_tables.block_infos().get(&(output.height as usize))?; let mixin_tx_hash: [u8; 32] = if output.tx_idx == mixin_tx_block.mining_tx_index { let tx_blob = new_tables.tx_blobs().get(&output.tx_idx)?; @@ -195,6 +198,8 @@ async fn get_tx( }) } + let fee = tx_fee(&tx); + TransactionResponse { hash: tx_hash.clone(), version: prefix.version, @@ -203,6 +208,7 @@ async fn get_tx( confirmation_height: tx_height, timestamp: tx_block.timestamp, weight: tx.weight(), + fee, extra: hex::encode(prefix.extra), outputs, inputs: inputs?, @@ -268,6 +274,8 @@ async fn get_tx( }) } + let fee = tx_fee(&tx); + TransactionResponse { hash: tx_hash.clone(), version: prefix.version, @@ -276,6 +284,7 @@ async fn get_tx( confirmation_height: tx_height, timestamp: tx_block.timestamp, weight: tx.weight(), + fee, extra: hex::encode(prefix.extra), outputs, inputs: inputs?,