Skip to content

Commit

Permalink
Merge pull request #3510 from dusk-network/neotamandua/serde_on_genes…
Browse files Browse the repository at this point in the history
…is_events

rusk: serialize genesis events as json on gql
  • Loading branch information
Neotamandua authored Feb 20, 2025
2 parents 8b88a89 + c89f7cc commit 0704645
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 228 deletions.
21 changes: 9 additions & 12 deletions node/src/archive/moonlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ pub enum Order {
Descending,
}

/// Group of events belonging to a single Moonlight **transaction** and
/// Group of events belonging to a single **transaction** and
/// additional metadata.
///
/// One Moonlight transaction can contain multiple events and multiple transfers
/// One transaction can contain multiple events and multiple transfers
/// of assets. The underlying Vec<ContractEvent> contains at least one event
/// that relates to a moonlight in- or outflow.
///
/// This can be a "moonlight" event or
/// a "withdraw", "mint", or "convert" event, where there is a Moonlight
/// address as WithdrawReceiver.
/// a "withdraw", "contract_to_account", "mint", or "convert" event
#[serde_with::serde_as]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MoonlightGroup {
Expand Down Expand Up @@ -165,7 +164,7 @@ impl Archive {
&self,
grouped_events: BTreeMap<EventIdentifier, Vec<ContractEvent>>,
) -> Result<()> {
debug!("Loading moonlight transaction events into the moonlight db");
debug!("Loading transaction events into the moonlight db");

let transformer::TransormerResult {
address_outflow_mappings,
Expand All @@ -174,10 +173,7 @@ impl Archive {
moonlight_tx_mappings,
} = transformer::filter_and_convert(grouped_events);

debug!(
"Found {} moonlight transactions",
moonlight_tx_mappings.len()
);
debug!("Found {} moonlight transfers", moonlight_tx_mappings.len());

let address_inflow_mappings =
util::check_duplicates(address_inflow_mappings);
Expand Down Expand Up @@ -246,9 +242,10 @@ impl Archive {
self.append_moonlight_tx(self.cf_memo_tx()?, &memo, moonlight_tx)
}

/// Get the full moonlight transaction history of a given AccountPublicKey.
/// Get the full moonlight transfer history of a given AccountPublicKey.
///
/// Returns all finalized moonlight events for the given public key
/// Returns all finalized moonlight events affecting the balance of the
/// given public key
pub fn full_moonlight_history(
&self,
pk: AccountPublicKey,
Expand Down Expand Up @@ -743,7 +740,7 @@ mod util {
}

if len_before != deduped.len() {
warn!("Found duplicates in address mappings for moonlight transactions. Duplicates have been removed. This is a bug.");
warn!("Found duplicates in address mappings for transactions. Duplicates have been removed. This is a bug.");
}

deduped
Expand Down
2 changes: 2 additions & 0 deletions rusk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Change plonk verification to use embed verification data by default [#3507]
- Change responses for moonlight gql endpoints (archive node) [#3512]

## [1.1.0] - 2025-02-14

Expand Down Expand Up @@ -347,6 +348,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add build system that generates keys for circuits and caches them.

<!-- Issues -->
[#3512]: https://github.com/dusk-network/rusk/issues/3512
[#3507]: https://github.com/dusk-network/rusk/issues/3507
[#3494]: https://github.com/dusk-network/rusk/issues/3494
[#3481]: https://github.com/dusk-network/rusk/issues/3481
Expand Down
2 changes: 1 addition & 1 deletion rusk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ recovery-keys = ["rusk-recovery/keys"]
prover = ["dep:rusk-prover"]
testwallet = ["dep:futures"]
chain = ["dep:node", "dep:dusk-consensus", "dep:node-data"]
archive = ["chain", "node/archive"]
archive = ["chain", "node/archive", "dusk-core/serde"]
network-trace = ["node/network-trace"]
http-wasm = []
dynamic-verifier = []
Expand Down
13 changes: 10 additions & 3 deletions rusk/src/lib/http/chain/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use node::database::{Ledger, DB};
use node_data::ledger::Label;
#[cfg(feature = "archive")]
use {
archive::data::deserialized_archive_data::DeserializedMoonlightGroups,
archive::data::*,
archive::events::*,
archive::finalized_block::*,
Expand Down Expand Up @@ -180,16 +179,24 @@ impl Query {
})
}

/// Retrieves the events of all historical transactions that have been
/// affecting the moonlight balance of the given address.
#[cfg(feature = "archive")]
async fn full_moonlight_history(
&self,
ctx: &Context<'_>,
address: String,
ord: Option<String>,
) -> OptResult<DeserializedMoonlightGroups> {
) -> OptResult<MoonlightTransfers> {
full_moonlight_history(ctx, address, ord).await
}

/// Retrieves raw events from transactions where at least one event within a
/// transaction indicates a transfer of funds.
///
/// Filter by topic="moonlight" and target=TRANSFER_CONTRACT on events for a
/// tx, to get only events from moonlight transactions. (Instead of both
/// phoenix or moonlight transactions)
#[allow(clippy::too_many_arguments)]
#[cfg(feature = "archive")]
async fn moonlight_history(
Expand Down Expand Up @@ -223,7 +230,7 @@ impl Query {
moonlight_tx_by_memo(ctx, memo).await
}

/// Get contract events by height or hash.
/// Get contract events by block height or hash.
#[cfg(feature = "archive")]
async fn contract_events(
&self,
Expand Down
Loading

0 comments on commit 0704645

Please sign in to comment.