generated from PoCInnovation/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PoCInnovation/wallet
[ADD] wallet commands
- Loading branch information
Showing
5 changed files
with
347 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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,76 @@ | ||
use crate::utils::get; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use serde_json::Value; | ||
|
||
/// CLI arguments for `kermit events`. | ||
#[derive(Parser)] | ||
pub enum EventsSubcommands { | ||
/// Get events for a contract within a counter range. | ||
#[command(visible_alias = "ec")] | ||
ContractEvents { | ||
contract_address: String, | ||
start: i32, | ||
limit: Option<i32>, | ||
group: Option<i32>, | ||
}, | ||
|
||
/// Get the current value of the events counter for a contract. | ||
#[command(visible_alias = "cc")] | ||
ContractCurrentCount { contract_address: String }, | ||
|
||
/// Get contract events for a transaction. | ||
#[command(visible_alias = "etc")] | ||
TxContractEvents { tx_id: String, group: Option<i32> }, | ||
|
||
/// Get contract events for a block. | ||
#[command(visible_alias = "ebh")] | ||
BlockContractEvents { | ||
block_hash: String, | ||
group: Option<i32>, | ||
}, | ||
} | ||
|
||
impl EventsSubcommands { | ||
pub async fn run(self, url: &str) -> Result<()> { | ||
let value: Value = match self { | ||
Self::ContractEvents { | ||
contract_address, | ||
start, | ||
limit, | ||
group, | ||
} => { | ||
let mut endpoint = format!("/events/contract/{}?start={}", contract_address, start); | ||
if let Some(limit) = limit { | ||
endpoint.push_str(&format!("&limit={}", limit)); | ||
} | ||
if let Some(group) = group { | ||
endpoint.push_str(&format!("&limit={}", group)); | ||
} | ||
get(url, &endpoint).await? | ||
}, | ||
Self::ContractCurrentCount { contract_address } => { | ||
let endpoint = format!("/events/contract/{}/current-count", contract_address); | ||
get(url, &endpoint).await? | ||
}, | ||
Self::TxContractEvents { tx_id, group } => { | ||
let mut endpoint = format!("/events/tx-id/{}", tx_id); | ||
if let Some(group) = group { | ||
endpoint.push_str(&format!("&limit={}", group)); | ||
} | ||
get(url, &endpoint).await? | ||
}, | ||
Self::BlockContractEvents { block_hash, group } => { | ||
let mut endpoint = format!("/events/block-hash/{}", block_hash); | ||
if let Some(group) = group { | ||
endpoint.push_str(&format!("&limit={}", group)); | ||
} | ||
get(url, &endpoint).await? | ||
}, | ||
}; | ||
|
||
serde_json::to_writer_pretty(std::io::stdout(), &value)?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.