Skip to content

Commit

Permalink
Merge pull request #2359 from dusk-network/json-fields
Browse files Browse the repository at this point in the history
rusk: Add new graphql fields
  • Loading branch information
herr-seppia authored Sep 12, 2024
2 parents 281ba55 + c62a587 commit 48e147f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions node-data/src/events/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ impl Serialize for Transaction {
call
});
state.serialize_field("call", &call)?;

state.serialize_field("is_deploy", &tx.deploy().is_some())?;
state.serialize_field("memo", &tx.memo().map(hex::encode))?;
state.end()
}
}
Expand Down
20 changes: 20 additions & 0 deletions rusk/src/lib/http/chain/graphql/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl Header<'_> {
pub async fn iteration(&self) -> u8 {
self.0.iteration
}

pub async fn json(&self) -> String {
serde_json::to_string(self.0).unwrap_or_default()
}
}

#[Object]
Expand Down Expand Up @@ -258,13 +262,29 @@ impl Transaction<'_> {
self.0.inner.gas_price()
}

pub async fn tx_type(&self) -> String {
match self.0.inner {
execution_core::transfer::Transaction::Phoenix(_) => "Phoenix",
execution_core::transfer::Transaction::Moonlight(_) => "Moonlight",
}
.into()
}

pub async fn call_data(&self) -> Option<CallData> {
self.0.inner.call().map(|call| CallData {
contract_id: hex::encode(call.contract),
fn_name: call.fn_name.clone(),
data: hex::encode(&call.fn_args),
})
}

pub async fn is_deploy(&self) -> bool {
self.0.inner.deploy().is_some()
}

pub async fn memo(&self) -> Option<String> {
self.0.inner.memo().map(hex::encode)
}
}

#[derive(SimpleObject)]
Expand Down

0 comments on commit 48e147f

Please sign in to comment.