Skip to content

Commit b94c4fb

Browse files
committed
refactor: streamline query handling in pallas_observer.rs
- refactor imports in `pallas_observer.rs` - update code references to `localstate::queries_v16` to now use the module specifiers directly - consolidate initialization and usage of `stakes` struct in tests - adjust stake values and pools in test data - rename `localstate::queries_v16::stakesnapshot` to `stakesnapshot` - refactor matching logic in `match` block for query handling
1 parent b8342c2 commit b94c4fb

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

mithril-common/src/chain_observer/pallas_observer.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ mod tests {
335335

336336
use pallas_codec::utils::{AnyCbor, AnyUInt, KeyValuePairs, TagWrap};
337337
use pallas_crypto::hash::Hash;
338-
use pallas_network::miniprotocols::localstate::{self, queries_v16::Value, ClientQueryRequest};
338+
use pallas_network::miniprotocols::localstate::{
339+
queries_v16::{
340+
BlockQuery, HardForkQuery, LedgerQuery, Request, Snapshots, StakeSnapshot, Value,
341+
},
342+
ClientQueryRequest,
343+
};
339344
use tokio::net::UnixListener;
340345

341346
use super::*;
@@ -380,7 +385,7 @@ mod tests {
380385
hex::decode("00000036d515e12e18cd3c88c74f09a67984c2c279a5296aa96efe89")
381386
.unwrap(),
382387
),
383-
localstate::queries_v16::Stakes {
388+
Stakes {
384389
snapshot_mark_pool: 300000000001,
385390
snapshot_set_pool: 300000000002,
386391
snapshot_go_pool: 300000000000,
@@ -391,7 +396,7 @@ mod tests {
391396
hex::decode("000000f66e28b0f18aef20555f4c4954234e3270dfbbdcc13f54e799")
392397
.unwrap(),
393398
),
394-
localstate::queries_v16::Stakes {
399+
Stakes {
395400
snapshot_mark_pool: 600000000001,
396401
snapshot_set_pool: 600000000002,
397402
snapshot_go_pool: 600000000000,
@@ -402,7 +407,7 @@ mod tests {
402407
hex::decode("00000110093effbf3ce788aebd3e7506b80322bd3995ad432e61fad5")
403408
.unwrap(),
404409
),
405-
localstate::queries_v16::Stakes {
410+
Stakes {
406411
snapshot_mark_pool: 1200000000001,
407412
snapshot_set_pool: 1200000000002,
408413
snapshot_go_pool: 1200000000000,
@@ -413,16 +418,16 @@ mod tests {
413418
hex::decode("00000ffff93effbf3ce788aebd3e7506b80322bd3995ad432e61fad5")
414419
.unwrap(),
415420
),
416-
localstate::queries_v16::Stakes {
421+
Stakes {
417422
snapshot_mark_pool: 0,
418423
snapshot_set_pool: 1300000000002,
419424
snapshot_go_pool: 0,
420425
},
421426
),
422427
]);
423428

424-
localstate::queries_v16::StakeSnapshot {
425-
snapshots: localstate::queries_v16::Snapshots {
429+
StakeSnapshot {
430+
snapshots: Snapshots {
426431
stake_snapshots,
427432
snapshot_stake_mark_total: 2100000000003,
428433
snapshot_stake_set_total: 2100000000006,
@@ -440,29 +445,18 @@ mod tests {
440445
};
441446

442447
match query {
443-
localstate::queries_v16::Request::LedgerQuery(
444-
localstate::queries_v16::LedgerQuery::HardForkQuery(
445-
localstate::queries_v16::HardForkQuery::GetCurrentEra,
446-
),
447-
) => AnyCbor::from_encode(4),
448-
localstate::queries_v16::Request::LedgerQuery(
449-
localstate::queries_v16::LedgerQuery::BlockQuery(
450-
_,
451-
localstate::queries_v16::BlockQuery::GetEpochNo,
452-
),
453-
) => AnyCbor::from_encode([8]),
454-
localstate::queries_v16::Request::LedgerQuery(
455-
localstate::queries_v16::LedgerQuery::BlockQuery(
456-
_,
457-
localstate::queries_v16::BlockQuery::GetUTxOByAddress(_),
458-
),
459-
) => AnyCbor::from_encode(get_fake_utxo_by_address()),
460-
localstate::queries_v16::Request::LedgerQuery(
461-
localstate::queries_v16::LedgerQuery::BlockQuery(
462-
_,
463-
localstate::queries_v16::BlockQuery::GetStakeSnapshots(_),
464-
),
465-
) => AnyCbor::from_encode(get_fake_stake_snapshot()),
448+
Request::LedgerQuery(LedgerQuery::HardForkQuery(HardForkQuery::GetCurrentEra)) => {
449+
AnyCbor::from_encode(4)
450+
}
451+
Request::LedgerQuery(LedgerQuery::BlockQuery(_, BlockQuery::GetEpochNo)) => {
452+
AnyCbor::from_encode([8])
453+
}
454+
Request::LedgerQuery(LedgerQuery::BlockQuery(_, BlockQuery::GetUTxOByAddress(_))) => {
455+
AnyCbor::from_encode(get_fake_utxo_by_address())
456+
}
457+
Request::LedgerQuery(LedgerQuery::BlockQuery(_, BlockQuery::GetStakeSnapshots(_))) => {
458+
AnyCbor::from_encode(get_fake_stake_snapshot())
459+
}
466460
_ => panic!("unexpected query from client: {query:?}"),
467461
}
468462
}

0 commit comments

Comments
 (0)