-
Notifications
You must be signed in to change notification settings - Fork 133
Add stellar tx fetch events cmd #2157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
fbb9f7b
Add stellar tx fetch events cmd
elizabethengelman 43e6d92
Merge branch 'main' into feat/tx-events
elizabethengelman 2f00a23
Fix fmt and remove println
elizabethengelman 69e2163
Merge branch 'main' into feat/tx-events
elizabethengelman f90e750
Merge branch 'main' into feat/tx-events
elizabethengelman 976dce6
Add integration test
elizabethengelman ca9a2e2
Merge branch 'main' into feat/tx-events
elizabethengelman 885bd2c
Merge branch 'main' into feat/tx-events
elizabethengelman f99001d
Merge branch 'main' into feat/tx-events
elizabethengelman 5978d79
Generated docs & fmt
elizabethengelman 49d8ce8
Merge branch 'main' into feat/tx-events
elizabethengelman 31dc988
Merge branch 'main' into feat/tx-events
elizabethengelman 5a100e9
Merge branch 'main' into feat/tx-events
elizabethengelman de48e84
Merge branch 'main' into feat/tx-events
elizabethengelman 6c92f78
Merge branch 'main' into feat/tx-events
elizabethengelman f9877ae
Add text output options for tx events
elizabethengelman ed909ba
Clippy
elizabethengelman b790f4e
Cargo fmt
elizabethengelman 4a82a74
Generated docs
elizabethengelman ef58612
Merge branch 'main' into feat/tx-events
elizabethengelman 127fa37
Merge branch 'main' into feat/tx-events
fnando 4b112f5
Merge branch 'main' into feat/tx-events
elizabethengelman d956189
Merge branch 'main' into feat/tx-events
elizabethengelman e198b3d
Merge branch 'main' into feat/tx-events
elizabethengelman 9e686d5
Merge branch 'main' into feat/tx-events
elizabethengelman 7b05bb8
Fix code issues in gen docs
elizabethengelman c371eef
Merge branch 'main' into feat/tx-events
janewang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| use crate::{commands::global, xdr}; | ||
| use clap::{command, Parser}; | ||
|
|
||
| use super::args; | ||
|
|
||
| #[derive(Parser, Debug, Clone)] | ||
| #[group(skip)] | ||
| pub struct Cmd { | ||
| #[command(flatten)] | ||
| args: args::Args, | ||
|
|
||
| /// Format of the output | ||
| #[arg(long, default_value = "json")] | ||
| output: EventsOutputFormat, | ||
| } | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum Error { | ||
| #[error(transparent)] | ||
| Serde(#[from] serde_json::Error), | ||
| #[error(transparent)] | ||
| Xdr(#[from] xdr::Error), | ||
| #[error(transparent)] | ||
| Args(#[from] args::Error), | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum, Default)] | ||
| pub enum EventsOutputFormat { | ||
| /// JSON output of the events with parsed XDRs (one line, not formatted) | ||
| Json, | ||
| /// Formatted (multiline) JSON output of events with parsed XDRs | ||
| JsonFormatted, | ||
| /// Human readable event output with parsed XDRs | ||
| #[default] | ||
| Text, | ||
| } | ||
|
|
||
| impl Cmd { | ||
| pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { | ||
| let resp = self.args.fetch_transaction(global_args).await?; | ||
| let events = &resp.events; | ||
| let contract_events: &Vec<Vec<xdr::ContractEvent>> = &events.contract_events; | ||
| let diagnostic_events = &events.diagnostic_events; | ||
| let transaction_events = &events.transaction_events; | ||
| match self.output { | ||
| EventsOutputFormat::Text => { | ||
| args::Args::print_tx_summary(&resp); | ||
| Self::print_contract_events(contract_events); | ||
| Self::print_transaction_events(transaction_events); | ||
| Self::print_diagnostic_events(diagnostic_events); | ||
| } | ||
| EventsOutputFormat::JsonFormatted => { | ||
| args::Args::print_tx_summary(&resp); | ||
| println!("{}", serde_json::to_string_pretty(&events)?); | ||
| } | ||
| EventsOutputFormat::Json => { | ||
| println!("{}", serde_json::to_string(&events)?); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn get_sc_val_string(val: &xdr::ScVal) -> String { | ||
| match val { | ||
| xdr::ScVal::Symbol(sym) => { | ||
| format!("Symbol: {:?}", sym.to_string()) | ||
| } | ||
| xdr::ScVal::Address(addr) => { | ||
| format!("Address: {:?}", addr.to_string()) | ||
| } | ||
| xdr::ScVal::I128(val) => { | ||
| format!("I128: {:?}", val.to_string()) | ||
| } | ||
| other => { | ||
| format!("Other: {other:?}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn print_contract_event(event: &xdr::ContractEvent) { | ||
| if let Some(id) = event.contract_id.as_ref() { | ||
| println!(" Contract Id: {id}"); | ||
| } | ||
|
|
||
| match &event.body { | ||
| xdr::ContractEventBody::V0(body) => { | ||
| for (i, topic) in body.topics.iter().enumerate() { | ||
| println!(" Topic[{i}]: {}", Self::get_sc_val_string(topic)); | ||
| } | ||
| println!(" Data: {}", Self::get_sc_val_string(&body.data)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn print_contract_events(events: &[Vec<xdr::ContractEvent>]) { | ||
| if events.is_empty() { | ||
| println!("Contract Events: None"); | ||
| return; | ||
| } | ||
| println!("Contract Events:"); | ||
| for event in events.iter().flatten() { | ||
| Self::print_contract_event(event); | ||
| println!(); | ||
| } | ||
| } | ||
|
|
||
| fn print_transaction_events(events: &Vec<xdr::TransactionEvent>) { | ||
| if events.is_empty() { | ||
| println!("Transaction Events: None"); | ||
| return; | ||
| } | ||
| println!("Transaction Events:"); | ||
| for event in events { | ||
| println!(" Transaction State: {:?}", event.stage); | ||
| Self::print_contract_event(&event.event); | ||
| println!(); | ||
| } | ||
| } | ||
|
|
||
| fn print_diagnostic_events(events: &Vec<xdr::DiagnosticEvent>) { | ||
| if events.is_empty() { | ||
| println!("Diagnostic Events: None"); | ||
| return; | ||
| } | ||
|
|
||
| println!("Diagnostic Events:"); | ||
| for event in events { | ||
| println!( | ||
| " In Successful Contract Call: {:?}", | ||
| event.in_successful_contract_call | ||
| ); | ||
| Self::print_contract_event(&event.event); | ||
| println!(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.