Skip to content

Commit

Permalink
[client] extract print events method
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Jan 21, 2025
1 parent 1a50eac commit 74f75f3
Showing 1 changed file with 78 additions and 84 deletions.
162 changes: 78 additions & 84 deletions client/src/commands/encointer_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,94 +310,88 @@ async fn listen(matches: &ArgMatches<'_>) {
{
return;
};

let event_results = subscription.next_events::<RuntimeEvent, Hash>().await.unwrap();
blocks += 1;

match event_results {
Ok(evts) =>
for evr in evts {
debug!("decoded: phase {:?} event {:?}", evr.phase, evr.event);
match &evr.event {
RuntimeEvent::EncointerCeremonies(ee) => {
count += 1;
info!(">>>>>>>>>> ceremony event: {:?}", ee);
match &ee {
pallet_encointer_ceremonies::Event::ParticipantRegistered(
cid,
participant_type,
accountid,
) => {
println!(
"Participant registered as {participant_type:?}, for cid: {cid:?}, account: {accountid}, "
);
},
_ => println!("Unsupported EncointerCommunities event"),
}
},
RuntimeEvent::EncointerScheduler(ee) => {
count += 1;
info!(">>>>>>>>>> scheduler event: {:?}", ee);
match &ee {
pallet_encointer_scheduler::Event::PhaseChangedTo(phase) => {
println!("Phase changed to: {phase:?}");
},
pallet_encointer_scheduler::Event::CeremonySchedulePushedByOneDay => {
println!("Ceremony schedule was pushed by one day");
},
}
},
RuntimeEvent::EncointerCommunities(ee) => {
count += 1;
info!(">>>>>>>>>> community event: {:?}", ee);
match &ee {
pallet_encointer_communities::Event::CommunityRegistered(cid) => {
println!("Community registered: cid: {cid:?}");
},
pallet_encointer_communities::Event::MetadataUpdated(cid) => {
println!("Community metadata updated cid: {cid:?}");
},
pallet_encointer_communities::Event::NominalIncomeUpdated(
cid,
income,
) => {
println!(
"Community metadata updated cid: {cid:?}, value: {income:?}"
);
},
pallet_encointer_communities::Event::DemurrageUpdated(
cid,
demurrage,
) => {
println!(
"Community metadata updated cid: {cid:?}, value: {demurrage:?}"
);
},
_ => println!("Unsupported EncointerCommunities event"),
}
},
RuntimeEvent::EncointerBalances(ee) => {
count += 1;
println!(">>>>>>>>>> encointer balances event: {ee:?}");
},
RuntimeEvent::EncointerBazaar(ee) => {
count += 1;
println!(">>>>>>>>>> encointer bazaar event: {ee:?}");
},
RuntimeEvent::System(ee) => match ee {
frame_system::Event::ExtrinsicFailed {
dispatch_error: _,
dispatch_info: _,
} => {
error!("ExtrinsicFailed: {ee:?}");
},
frame_system::Event::ExtrinsicSuccess { dispatch_info } => {
println!("ExtrinsicSuccess: {dispatch_info:?}");
},
_ => debug!("ignoring unsupported system Event"),
},
_ => debug!("ignoring unsupported module event: {:?}", evr.event),
}
},
Ok(events) => {
print_events(events, &mut count);
},
Err(_) => error!("couldn't decode event record list"),
}
}
}

pub fn print_events(events: Vec<substrate_api_client::ac_node_api::EventRecord<RuntimeEvent, Hash>>, encointer_event_count: &mut u32) {
for evr in events {
debug!("decoded: phase {:?} event {:?}", evr.phase, evr.event);
match &evr.event {
RuntimeEvent::EncointerCeremonies(ee) => {
info!(">>>>>>>>>> ceremony event: {:?}", ee);
*encointer_event_count += 1;
match &ee {
pallet_encointer_ceremonies::Event::ParticipantRegistered(
cid,
participant_type,
accountid,
) => {
println!(
"Participant registered as {participant_type:?}, for cid: {cid:?}, account: {accountid}, "
);
},
_ => println!("Unsupported EncointerCommunities event"),
}
},
RuntimeEvent::EncointerScheduler(ee) => {
info!(">>>>>>>>>> scheduler event: {:?}", ee);
*encointer_event_count += 1;
match &ee {
pallet_encointer_scheduler::Event::PhaseChangedTo(phase) => {
println!("Phase changed to: {phase:?}");
},
pallet_encointer_scheduler::Event::CeremonySchedulePushedByOneDay => {
println!("Ceremony schedule was pushed by one day");
},
}
},
RuntimeEvent::EncointerCommunities(ee) => {
info!(">>>>>>>>>> community event: {:?}", ee);
*encointer_event_count += 1;
match &ee {
pallet_encointer_communities::Event::CommunityRegistered(cid) => {
println!("Community registered: cid: {cid:?}");
},
pallet_encointer_communities::Event::MetadataUpdated(cid) => {
println!("Community metadata updated cid: {cid:?}");
},
pallet_encointer_communities::Event::NominalIncomeUpdated(cid, income) => {
println!("Community metadata updated cid: {cid:?}, value: {income:?}");
},
pallet_encointer_communities::Event::DemurrageUpdated(cid, demurrage) => {
println!("Community metadata updated cid: {cid:?}, value: {demurrage:?}");
},
_ => println!("Unsupported EncointerCommunities event"),
}
},
RuntimeEvent::EncointerBalances(ee) => {
*encointer_event_count += 1;
println!(">>>>>>>>>> encointer balances event: {ee:?}");
},
RuntimeEvent::EncointerBazaar(ee) => {
*encointer_event_count += 1;
println!(">>>>>>>>>> encointer bazaar event: {ee:?}");
},
RuntimeEvent::System(ee) => match ee {
frame_system::Event::ExtrinsicFailed { dispatch_error: _, dispatch_info: _ } => {
error!("ExtrinsicFailed: {ee:?}");
},
frame_system::Event::ExtrinsicSuccess { dispatch_info } => {
println!("ExtrinsicSuccess: {dispatch_info:?}");
},
_ => debug!("ignoring unsupported system Event"),
},
_ => debug!("ignoring unsupported module event: {:?}", evr.event),
}
}
}

0 comments on commit 74f75f3

Please sign in to comment.