-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* explorer command explorer get -k <address> explorer get <label> * match cluster with cli config * newlines * /address
- Loading branch information
Showing
11 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,17 @@ | ||
use { | ||
crate::errors::CliError, | ||
crate::config::CliConfig, | ||
clockwork_utils::explorer::Explorer, | ||
|
||
}; | ||
|
||
pub fn thread_url<T: std::fmt::Display>(thread: T, config: CliConfig) -> Result<(), | ||
CliError> { | ||
println!("thread: {}", explorer(config).thread_url(thread, | ||
clockwork_client::thread::ID)); | ||
Ok(()) | ||
} | ||
|
||
fn explorer(config: CliConfig) -> Explorer { | ||
Explorer::from(config.json_rpc_url) | ||
} |
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
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
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,78 @@ | ||
const EXPLORER_URL: &str = "https://explorer.solana.com"; | ||
const CK_EXPLORER_URL: &str = "https://explorer.clockwork.xyz"; | ||
|
||
|
||
#[derive(Default)] | ||
pub struct Explorer { | ||
cluster: String, | ||
custom_rpc: Option<String>, | ||
} | ||
|
||
impl From<String> for Explorer { | ||
fn from(json_rpc_url: String) -> Self { | ||
match &json_rpc_url.to_lowercase() { | ||
url if url.contains("devnet") => Explorer::devnet(), | ||
url if url.contains("testnet") => Explorer::testnet(), | ||
url if url.contains("mainnet") => Explorer::mainnet(), | ||
_ => { | ||
Explorer::custom(json_rpc_url) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Explorer { | ||
pub fn mainnet() -> Self { | ||
Self { | ||
cluster: "mainnet-beta".into(), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn testnet() -> Self { | ||
Self { | ||
cluster: "testnet".into(), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn devnet() -> Self { | ||
Self { | ||
cluster: "devnet".into(), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn custom(custom_rpc: String) -> Self { | ||
Self { | ||
cluster: "custom".into(), | ||
custom_rpc: Some(custom_rpc), | ||
} | ||
} | ||
|
||
/// Ex: https://explorer.solana.com/tx/{tx} | ||
/// ?cluster=custom | ||
/// &customUrl=http://localhost:8899 | ||
pub fn tx_url<T: std::fmt::Display>(&self, tx: T) -> String { | ||
let url = format!("{}/tx/{}?cluster={}", EXPLORER_URL, tx, self.cluster); | ||
if self.cluster == "custom" { | ||
url + "&customUrl=" + self.custom_rpc.as_ref().unwrap() | ||
} else { | ||
url | ||
} | ||
} | ||
|
||
/// Ex: https://explorer.clockwork.xyz/thread/{thread} | ||
/// ?network=custom | ||
/// &customRPC=http://localhost:8899 | ||
pub fn thread_url<T: std::fmt::Display, U: std::fmt::Display>(&self, thread: T, program_id: U) -> String { | ||
let url = format!("{}/address/{}?programID={}&network={}", CK_EXPLORER_URL, | ||
thread, program_id, self | ||
.cluster); | ||
if self.cluster == "custom" { | ||
url + "&customRPC=" + self.custom_rpc.as_ref().unwrap() | ||
} else { | ||
url | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod explorer; | ||
|
||
use { | ||
anchor_lang::{ | ||
prelude::borsh::BorshSchema, | ||
|