Skip to content

Commit 0b0a15d

Browse files
authored
Merge pull request #3622 from dusk-network/neotamandua/3613
rusk: add from_block, to_block params to gql `fullMoonlightHistory`
2 parents bf5f0d9 + e41e9e9 commit 0b0a15d

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

node/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add transaction serialization check
1313
- Add max transaction size check
14+
- Add from_block & to_block params to `full_moonlight_history` in archive [#3613]
1415

1516
## [1.2.0] - 2025-03-20
1617

@@ -48,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4849
- First `dusk-node` release
4950

5051
<!-- Issues -->
52+
[#3613]: https://github.com/dusk-network/rusk/issues/3613
5153
[#3491]: https://github.com/dusk-network/rusk/issues/3491
5254
[#3359]: https://github.com/dusk-network/rusk/issues/3359
5355
[#3407]: https://github.com/dusk-network/rusk/issues/3407

node/src/archive/moonlight.rs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,24 @@ impl Archive {
250250
&self,
251251
pk: AccountPublicKey,
252252
ord: Option<Order>,
253+
from_block: Option<u64>,
254+
to_block: Option<u64>,
253255
) -> Result<Option<Vec<MoonlightGroup>>> {
254256
let order = ord.unwrap_or(Order::Ascending);
255257

256258
let inflows = self.fetch_moonlight_history(
257259
Some(pk),
258260
None,
259-
None,
260-
None,
261+
from_block,
262+
to_block,
261263
None,
262264
None,
263265
)?;
264266
let outflows = self.fetch_moonlight_history(
265267
None,
266268
Some(pk),
267-
None,
268-
None,
269+
from_block,
270+
to_block,
269271
None,
270272
None,
271273
)?;
@@ -1039,7 +1041,10 @@ mod tests {
10391041
let archive = Archive::create_or_open(path).await;
10401042

10411043
let pk = AccountPublicKey::default();
1042-
assert!(archive.full_moonlight_history(pk, None).unwrap().is_none());
1044+
assert!(archive
1045+
.full_moonlight_history(pk, None, None, None, None)
1046+
.unwrap()
1047+
.is_none());
10431048

10441049
let block_events = block_events();
10451050

@@ -1064,8 +1069,10 @@ mod tests {
10641069
fetched_moonlight_tx.dedup();
10651070
assert_eq!(fetched_moonlight_tx.len(), 6);
10661071

1067-
let fetched_events =
1068-
archive.full_moonlight_history(pk, None).unwrap().unwrap();
1072+
let fetched_events = archive
1073+
.full_moonlight_history(pk, None, None, None, None)
1074+
.unwrap()
1075+
.unwrap();
10691076
assert_eq!(fetched_events.len(), 6);
10701077

10711078
for moonlight_events in fetched_events {
@@ -1123,7 +1130,10 @@ mod tests {
11231130
let path = test_dir();
11241131
let archive = Archive::create_or_open(path).await;
11251132
let pk = AccountPublicKey::default();
1126-
assert!(archive.full_moonlight_history(pk, None).unwrap().is_none());
1133+
assert!(archive
1134+
.full_moonlight_history(pk, None, None, None, None)
1135+
.unwrap()
1136+
.is_none());
11271137

11281138
let block_events = block_events();
11291139
let event_groups = transformer::group_by_origins(block_events, 1);
@@ -1173,7 +1183,7 @@ mod tests {
11731183
assert_eq!(fetched_tx1[0].origin(), &[4; 32]);
11741184
fetched_tx1[0].events().iter().for_each(|e| {
11751185
assert_eq!(e.topic, "moonlight");
1176-
assert_eq!(e.target, usk_core::transfer::TRANSFER_CONTRACT);
1186+
assert_eq!(e.target, dusk_core::transfer::TRANSFER_CONTRACT);
11771187

11781188
let moonlight_event =
11791189
rkyv::from_bytes::<MoonlightTransactionEvent>(&e.data).unwrap();
@@ -1458,7 +1468,10 @@ mod tests {
14581468
let archive = Archive::create_or_open(path).await;
14591469

14601470
let pk = AccountPublicKey::default();
1461-
assert!(archive.full_moonlight_history(pk, None).unwrap().is_none());
1471+
assert!(archive
1472+
.full_moonlight_history(pk, None, None, None, None)
1473+
.unwrap()
1474+
.is_none());
14621475

14631476
let block_events = block_events();
14641477

@@ -1483,12 +1496,20 @@ mod tests {
14831496
fetched_moonlight_tx.dedup();
14841497
assert_eq!(fetched_moonlight_tx.len(), 6);
14851498

1486-
let mut fetched_events =
1487-
archive.full_moonlight_history(pk, None).unwrap().unwrap();
1499+
let mut fetched_events = archive
1500+
.full_moonlight_history(pk, None, None, None, None)
1501+
.unwrap()
1502+
.unwrap();
14881503
assert_eq!(fetched_events.len(), 6);
14891504

14901505
let fetched_events_reverse_order = archive
1491-
.full_moonlight_history(pk, Some(super::Order::Descending))
1506+
.full_moonlight_history(
1507+
pk,
1508+
Some(super::Order::Descending),
1509+
None,
1510+
None,
1511+
None,
1512+
)
14921513
.unwrap()
14931514
.unwrap();
14941515

rusk/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Add transaction serialization check
1414
- Add max transaction size check
1515
- Add `/on/driver:<contract>/<method>:<target>` endpoint
16+
- Add from_block & to_block params to `full_moonlight_history` in gql [#3613]
1617

1718
### Changed
1819

@@ -369,6 +370,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
369370
- Add build system that generates keys for circuits and caches them.
370371

371372
<!-- Issues -->
373+
[#3613]: https://github.com/dusk-network/rusk/issues/3613
372374
[#3512]: https://github.com/dusk-network/rusk/issues/3512
373375
[#3507]: https://github.com/dusk-network/rusk/issues/3507
374376
[#3494]: https://github.com/dusk-network/rusk/issues/3494

rusk/src/lib/http/chain/graphql.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ impl Query {
184184
ctx: &Context<'_>,
185185
address: String,
186186
ord: Option<String>,
187+
from_block: Option<u64>,
188+
to_block: Option<u64>,
187189
) -> OptResult<MoonlightTransfers> {
188-
full_moonlight_history(ctx, address, ord).await
190+
full_moonlight_history(ctx, address, ord, from_block, to_block).await
189191
}
190192

191193
/// Retrieves raw events from transactions where at least one event within a

rusk/src/lib/http/chain/graphql/archive/moonlight.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub async fn full_moonlight_history(
1919
ctx: &Context<'_>,
2020
address: String,
2121
ordering: Option<String>,
22+
from_block: Option<u64>,
23+
to_block: Option<u64>,
2224
) -> OptResult<MoonlightTransfers> {
2325
let (_, archive) = ctx.data::<DBContext>()?;
2426
let v = bs58::decode(address).into_vec()?;
@@ -36,7 +38,9 @@ pub async fn full_moonlight_history(
3638
_ => None,
3739
};
3840

39-
if let Some(moonlight_events) = archive.full_moonlight_history(pk, ord)? {
41+
if let Some(moonlight_events) =
42+
archive.full_moonlight_history(pk, ord, from_block, to_block)?
43+
{
4044
Ok(Some(MoonlightTransfers(moonlight_events)))
4145
} else {
4246
Ok(None)

0 commit comments

Comments
 (0)