Skip to content

Commit

Permalink
rusk: GQL - use transaction serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Aug 9, 2024
1 parent 38f94bd commit 1d80e91
Showing 1 changed file with 1 addition and 93 deletions.
94 changes: 1 addition & 93 deletions rusk/src/lib/http/chain/graphql/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,99 +242,7 @@ impl Transaction<'_> {
}

pub async fn json(&self) -> String {
use dusk_bytes::Serializable;
use serde::Serialize;
use serde_json::{json, Map, Value};

let tx = &self.0.inner;

let mut map = Map::new();

if let Some(root) = tx.root() {
map.insert("root".into(), json!(hex::encode(root.to_bytes())));
}

if let Some(from) = tx.from() {
map.insert("from".into(), json!(hex::encode(from.to_bytes())));
}
if let Some(to) = tx.to() {
map.insert("to".into(), json!(hex::encode(to.to_bytes())));
}
if let Some(value) = tx.value() {
map.insert("value".into(), json!(hex::encode(value.to_bytes())));
}

let nullifiers: Vec<_> = tx
.nullifiers()
.iter()
.map(|n| hex::encode(n.to_bytes()))
.collect();
map.insert("nullifiers".into(), json!(nullifiers));
map.insert(
"deposit".into(),
json!(hex::encode(tx.deposit().to_bytes())),
);
let notes: Vec<_> = tx
.outputs()
.iter()
.map(|n| {
let mut map = Map::new();
map.insert("note_type".into(), json!(n.note_type() as u8));
map.insert(
"value_commitment".into(),
json!([
hex::encode(n.value_commitment().get_u().to_bytes()),
hex::encode(n.value_commitment().get_v().to_bytes())
]),
);
map.insert(
"stealth_address".into(),
json!(bs58::encode(n.stealth_address().to_bytes())
.into_string()),
);
map.insert(
"value_enc".into(),
json!(n
.value_enc()
.iter()
.map(|c| hex::encode(c.to_bytes()))
.collect::<Vec<_>>()),
);
map.insert(
"sender".into(),
json!(hex::encode(n.sender().to_bytes())),
);
map
})
.collect();
map.insert("notes".into(), json!(notes));

let mut fee = Map::new();

fee.insert("gas_limit".into(), json!(tx.gas_limit()));
fee.insert("gas_price".into(), json!(tx.gas_price()));

if let Some(stealth_address) = tx.stealth_address() {
fee.insert(
"stealth_address".into(),
json!(bs58::encode(stealth_address.to_bytes()).into_string()),
);
}
if let Some(sender) = tx.sender() {
fee.insert("sender".into(), json!(hex::encode(sender.to_bytes())));
}

map.insert("fee".into(), json!(fee));

if let Some(c) = tx.call() {
let mut call = Map::new();
call.insert("contract".into(), json!(hex::encode(c.contract)));
call.insert("fn_name".into(), json!(&c.fn_name));
call.insert("fn_args".into(), json!(hex::encode(&c.fn_args)));
map.insert("call".into(), json!(call));
}

json!(map).to_string()
self.0.to_json().to_string()
}

pub async fn id(&self) -> String {
Expand Down

0 comments on commit 1d80e91

Please sign in to comment.