Skip to content

Commit

Permalink
rusk: remove WrappedContractId usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Neotamandua committed Feb 14, 2025
1 parent 2e326e0 commit cdf99cf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
18 changes: 7 additions & 11 deletions rusk/src/lib/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,7 @@ mod tests {
use super::*;

use dusk_core::abi::ContractId;
use node_data::events::contract::{
ContractEvent, ContractTxEvent, WrappedContractId,
};
use node_data::events::contract::{ContractEvent, ContractTxEvent};
use std::net::TcpStream;
use tungstenite::client;

Expand Down Expand Up @@ -848,17 +846,15 @@ mod tests {
)
.expect("Session ID should be parsed");

const SUB_CONTRACT_ID: WrappedContractId =
WrappedContractId(ContractId::from_bytes([1; 32]));
const MAYBE_SUB_CONTRACT_ID: WrappedContractId =
WrappedContractId(ContractId::from_bytes([2; 32]));
const NON_SUB_CONTRACT_ID: WrappedContractId =
WrappedContractId(ContractId::from_bytes([3; 32]));
const SUB_CONTRACT_ID: ContractId = ContractId::from_bytes([1; 32]);
const MAYBE_SUB_CONTRACT_ID: ContractId =
ContractId::from_bytes([2; 32]);
const NON_SUB_CONTRACT_ID: ContractId = ContractId::from_bytes([3; 32]);

const TOPIC: &str = "topic";

let sub_contract_id_hex = hex::encode(SUB_CONTRACT_ID.0);
let maybe_sub_contract_id_hex = hex::encode(MAYBE_SUB_CONTRACT_ID.0);
let sub_contract_id_hex = hex::encode(SUB_CONTRACT_ID);
let maybe_sub_contract_id_hex = hex::encode(MAYBE_SUB_CONTRACT_ID);

let client = reqwest::Client::new();

Expand Down
20 changes: 7 additions & 13 deletions rusk/src/lib/http/chain/graphql/archive/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ impl ContractEvents {
/// TODO: #2773 add serde feature to dusk-core
pub mod deserialized_archive_data {
use super::*;

use dusk_core::abi::ContractId;
use dusk_core::stake::STAKE_CONTRACT;
use dusk_core::transfer::withdraw::WithdrawReceiver;
use dusk_core::transfer::{
ConvertEvent, DepositEvent, MoonlightTransactionEvent, WithdrawEvent,
CONVERT_TOPIC, DEPOSIT_TOPIC, MINT_TOPIC, MOONLIGHT_TOPIC,
TRANSFER_CONTRACT, WITHDRAW_TOPIC,
};
use node_data::events::contract::{
ContractEvent, OriginHash, WrappedContractId,
};
use node_data::events::contract::{ContractEvent, OriginHash};
use serde::ser::SerializeStruct;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -128,10 +128,7 @@ pub mod deserialized_archive_data {
{
let withdraw_event = &self.0;
let mut state = serializer.serialize_struct("WithdrawEvent", 3)?;
state.serialize_field(
"sender",
&WrappedContractId(withdraw_event.sender),
)?;
state.serialize_field("sender", &withdraw_event.sender)?;
state.serialize_field(
"receiver",
&match withdraw_event.receiver {
Expand Down Expand Up @@ -197,10 +194,7 @@ pub mod deserialized_archive_data {
.sender
.map(|pk| bs58::encode(pk.to_bytes()).into_string()),
)?;
state.serialize_field(
"receiver",
&WrappedContractId(deposit_event.receiver),
)?;
state.serialize_field("receiver", &deposit_event.receiver)?;
state.serialize_field("value", &deposit_event.value)?;

state.end()
Expand All @@ -209,14 +203,14 @@ pub mod deserialized_archive_data {

#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct DeserializedContractEvent {
pub target: WrappedContractId,
pub target: ContractId,
pub topic: String,
pub data: serde_json::Value,
}

impl From<ContractEvent> for DeserializedContractEvent {
fn from(event: ContractEvent) -> Self {
let deserialized_data = if event.target.0 == TRANSFER_CONTRACT {
let deserialized_data = if event.target == TRANSFER_CONTRACT {
match event.topic.as_str() {
MOONLIGHT_TOPIC => rkyv::from_bytes::<
MoonlightTransactionEvent,
Expand Down
6 changes: 2 additions & 4 deletions rusk/src/lib/http/chain/graphql/archive/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

//! Module for GraphQL that relates to stored events in the archive.
use async_graphql::{Context, FieldError, FieldResult, Object};
use dusk_core::abi::CONTRACT_ID_BYTES;
use node_data::events::contract::WrappedContractId;

use super::data::ContractEvents;
use crate::http::chain::graphql::{DBContext, OptResult};
use async_graphql::{Context, FieldError, FieldResult, Object};
use dusk_core::abi::{ContractId, CONTRACT_ID_BYTES};

pub async fn events_by_height(
ctx: &Context<'_>,
Expand Down
2 changes: 1 addition & 1 deletion rusk/src/lib/http/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ impl From<node_data::events::contract::ContractTxEvent> for RuesEvent {
Self {
uri: RuesEventUri {
component: "contracts".into(),
entity: Some(hex::encode(event.target.0)),
entity: Some(hex::encode(event.target.to_bytes())),
topic: event.topic,
},
data: event.data.into(),
Expand Down

0 comments on commit cdf99cf

Please sign in to comment.