-
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.
- Loading branch information
Showing
20 changed files
with
460 additions
and
60 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
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,88 @@ | ||
use std::{str::FromStr, string::ToString}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum NetworkType { | ||
Main, | ||
Test, | ||
Dev, | ||
} | ||
|
||
impl FromStr for NetworkType { | ||
type Err = String; | ||
|
||
fn from_str(ty: &str) -> Result<Self, Self::Err> { | ||
let ty = match ty.to_lowercase().as_str() { | ||
"main" => NetworkType::Main, | ||
"test" => NetworkType::Test, | ||
"dev" => NetworkType::Dev, | ||
_ => return Err(format!("Unknown Rpc type {ty}")), | ||
}; | ||
|
||
Ok(ty) | ||
} | ||
} | ||
|
||
impl ToString for NetworkType { | ||
fn to_string(&self) -> String { | ||
String::from(match self { | ||
NetworkType::Main => "Main", | ||
NetworkType::Test => "Test", | ||
NetworkType::Dev => "Dev", | ||
}) | ||
} | ||
} | ||
|
||
impl NetworkType { | ||
pub fn address_detail_url(&self, address: &str) -> String { | ||
let url = "https://explorer.solana.com/address"; | ||
match *self { | ||
NetworkType::Main => format!("{url}/{address}"), | ||
NetworkType::Test => format!("{url}/{address}?cluster=testnet"), | ||
NetworkType::Dev => format!("{url}/{address}?cluster=devnet"), | ||
} | ||
} | ||
|
||
pub fn tx_detail_url(&self, hash: &str) -> String { | ||
let url = "https://explorer.solana.com/tx"; | ||
match *self { | ||
NetworkType::Main => format!("{url}/{hash}"), | ||
NetworkType::Test => format!("{url}/{hash}?cluster=testnet"), | ||
NetworkType::Dev => format!("{url}/{hash}?cluster=devnet"), | ||
} | ||
|
||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum RpcUrlType { | ||
Main, | ||
Test, | ||
Dev, | ||
} | ||
|
||
impl ToString for RpcUrlType { | ||
fn to_string(&self) -> String { | ||
String::from(match self { | ||
RpcUrlType::Main => "https://api.mainnet-beta.solana.com", | ||
RpcUrlType::Test => "https://api.testnet.solana.com", | ||
RpcUrlType::Dev => "https://api.devnet.solana.com", | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum WssUrlType { | ||
Main, | ||
Test, | ||
Dev, | ||
} | ||
|
||
impl ToString for WssUrlType { | ||
fn to_string(&self) -> String { | ||
String::from(match self { | ||
WssUrlType::Main => "wss://api.mainnet-beta.solana.com", | ||
WssUrlType::Test => "wss://api.testnet.solana.com", | ||
WssUrlType::Dev => "wss://api.devnet.solana.com", | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod conf; | ||
mod data; | ||
|
||
pub use conf::{all, db_path, init, is_first_run, save, ui}; | ||
pub use conf::{all, db_path, init, is_first_run, save, ui, network}; |
Oops, something went wrong.