mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-23 00:21:38 +03:00
fix: format eth providers as set so they are never duplicated
This commit is contained in:
parent
8643f8e6c8
commit
ac408e6c2f
@ -63,18 +63,26 @@ impl ActiveProviders {
|
||||
kns_update,
|
||||
use_as_provider,
|
||||
} => {
|
||||
self.nodes.push(NodeProvider {
|
||||
trusted: new.trusted,
|
||||
usable: use_as_provider,
|
||||
kns_update,
|
||||
});
|
||||
self.remove_provider(&kns_update.name);
|
||||
self.nodes.insert(
|
||||
0,
|
||||
NodeProvider {
|
||||
trusted: new.trusted,
|
||||
usable: use_as_provider,
|
||||
kns_update,
|
||||
},
|
||||
);
|
||||
}
|
||||
NodeOrRpcUrl::RpcUrl(url) => {
|
||||
self.urls.push(UrlProvider {
|
||||
trusted: new.trusted,
|
||||
url,
|
||||
pubsub: None,
|
||||
});
|
||||
self.remove_provider(&url);
|
||||
self.urls.insert(
|
||||
0,
|
||||
UrlProvider {
|
||||
trusted: new.trusted,
|
||||
url,
|
||||
pubsub: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ async fn main() {
|
||||
Err(_) => serde_json::from_str(DEFAULT_ETH_PROVIDERS).unwrap(),
|
||||
};
|
||||
if let Some(rpc) = rpc {
|
||||
eth_provider_config.push(lib::eth::ProviderConfig {
|
||||
eth_provider_config.insert(lib::eth::ProviderConfig {
|
||||
chain_id: CHAIN_ID,
|
||||
trusted: true,
|
||||
provider: lib::eth::NodeOrRpcUrl::RpcUrl(rpc.to_string()),
|
||||
|
@ -125,8 +125,13 @@ pub async fn register(
|
||||
} else {
|
||||
"wss://optimism-rpc.publicnode.com".to_string()
|
||||
};
|
||||
let connector = WsConnect { url, auth: None };
|
||||
let Ok(client) = ClientBuilder::default().ws(connector).await else {
|
||||
println!("Connecting to Optimism RPC at {url}");
|
||||
// this fails occasionally in certain networking environments. i'm not sure why.
|
||||
// frustratingly, the exact same call does not fail in the eth module. more investigation needed.
|
||||
let Ok(client) = ClientBuilder::default()
|
||||
.ws(WsConnect { url, auth: None })
|
||||
.await
|
||||
else {
|
||||
panic!(
|
||||
"Error: runtime could not connect to ETH RPC.\n\
|
||||
This is necessary in order to verify node identity onchain.\n\
|
||||
@ -134,6 +139,7 @@ pub async fn register(
|
||||
the --rpc flag, and you are connected to the internet."
|
||||
);
|
||||
};
|
||||
println!("Connected to Optimism RPC");
|
||||
|
||||
let provider = Arc::new(Provider::new_with_client(client));
|
||||
|
||||
|
@ -1583,7 +1583,7 @@ pub enum NetResponse {
|
||||
Verified(bool),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
||||
pub struct KnsUpdate {
|
||||
pub name: String, // actual username / domain name
|
||||
pub owner: String,
|
||||
|
@ -141,17 +141,17 @@ pub struct AccessSettings {
|
||||
pub deny: HashSet<String>, // blacklist for access (always used)
|
||||
}
|
||||
|
||||
pub type SavedConfigs = Vec<ProviderConfig>;
|
||||
pub type SavedConfigs = HashSet<ProviderConfig>;
|
||||
|
||||
/// Provider config. Can currently be a node or a ws provider instance.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
|
||||
pub struct ProviderConfig {
|
||||
pub chain_id: u64,
|
||||
pub trusted: bool,
|
||||
pub provider: NodeOrRpcUrl,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
|
||||
pub enum NodeOrRpcUrl {
|
||||
Node {
|
||||
kns_update: crate::core::KnsUpdate,
|
||||
|
Loading…
Reference in New Issue
Block a user