Skip to content

Commit

Permalink
fix: dynamic chain support (#182)
Browse files Browse the repository at this point in the history
* fix: dynamic chain support

* chore: use tagged version
  • Loading branch information
chris13524 authored Mar 11, 2024
1 parent d449220 commit 4f17a6a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 22 deletions.
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 36 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,48 @@ authors = [
"Derek Rein <derek@walletconnect.com>",
"Szymon Rząd <szymon@walletconnect.com>",
"Xavier Basty-Kjellberg <xavier@walletconnect.com>",
"Maciej Rak <raku@walletconnect.com>"
"Maciej Rak <raku@walletconnect.com>",
]
build = "build.rs"

[dependencies]
wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.0", features = ["geoip", "geoblock"] }
relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.28.0", features = ["cacao"] }
wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.0", features = [
"geoip",
"geoblock",
] }
relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.2", features = [
"cacao",
] }
blockchain_api = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.2" }

aws-config = "0.56"
aws-sdk-s3 = "0.31"

axum = "0.6.1"
axum-macros = "0.3.0"
tokio = { version = "1.0", features = ["full"] }
tower = { version = "0.4", features = ["util", "timeout", "load-shed", "limit"] }
tower-http = { version = "0.3.0", features = ["add-extension", "auth", "compression-full", "trace", "cors", "request-id", "util"] }
tower = { version = "0.4", features = [
"util",
"timeout",
"load-shed",
"limit",
] }
tower-http = { version = "0.3.0", features = [
"add-extension",
"auth",
"compression-full",
"trace",
"cors",
"request-id",
"util",
] }
hyper = "0.14"
http = "0.2.8"

# Database
wither = { git = "https://github.com/WalletConnect/wither.git", rev = "6a70e74", features = ["bson-chrono-0_4"] }
wither = { git = "https://github.com/WalletConnect/wither.git", rev = "6a70e74", features = [
"bson-chrono-0_4",
] }
wither_derive = { git = "https://github.com/WalletConnect/wither.git", rev = "6a70e74" }

# Seralisation
Expand All @@ -48,7 +69,10 @@ opentelemetry-otlp = "0.11"

# Logging
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "parking_lot"] }
tracing-subscriber = { version = "0.3", features = [
"env-filter",
"parking_lot",
] }
tracing-appender = "0.2"
tracing-opentelemetry = "0.18"
atty = "0.2"
Expand All @@ -71,3 +95,8 @@ hex = "0.4.3"

[build-dependencies]
build-info-build = "0.0.29"

# [patch.'https://github.com/WalletConnect/WalletConnectRust.git']
# relay_rpc = { path = "../WalletConnectRust/relay_rpc" }
# relay_client = { path = "../WalletConnectRust/relay_client" }
# blockchain_api = { path = "../WalletConnectRust/blockchain_api" }
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub struct Configuration {
pub database_url: String,
pub project_id: ProjectId,

#[serde(default = "default_blockchain_api_endpoint")]
pub blockchain_api_endpoint: Option<String>,

// Telemetry
pub telemetry_enabled: Option<bool>,
pub telemetry_grpc_url: Option<String>,
Expand Down Expand Up @@ -43,3 +46,7 @@ fn default_port() -> u16 {
fn default_log_level() -> String {
"WARN".to_string()
}

fn default_blockchain_api_endpoint() -> Option<String> {
Some("https://rpc.walletconnect.com".to_string())
}
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub enum Error {

#[error(transparent)]
Cacao(#[from] CacaoError),

#[error("Blockchain API error: {0}")]
BlockchainApi(blockchain_api::Error),
}

impl IntoResponse for Error {
Expand Down
19 changes: 11 additions & 8 deletions src/handlers/identity/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ pub async fn handler(
payload.cacao
);

cacao.verify(&state.provider).await.map_err(|error| {
increment_counter!(state.metrics, invalid_identity_register_cacao);
info!(
"Failure - Register identity with cacao: {:?}, error: {:?}",
payload.cacao, error
);
error
})?;
cacao
.verify(state.provider.as_ref())
.await
.map_err(|error| {
increment_counter!(state.metrics, invalid_identity_register_cacao);
info!(
"Failure - Register identity with cacao: {:?}, error: {:?}",
payload.cacao, error
);
error
})?;

let identity_key = cacao.p.identity_key()?;
let account = cacao.p.caip_10_address()?;
Expand Down
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use {
crate::{config::Configuration, log::prelude::*, state::AppState},
crate::{config::Configuration, error::Error, log::prelude::*, state::AppState},
aws_config::meta::region::RegionProviderChain,
aws_sdk_s3::{config::Region, Client as S3Client},
axum::{
routing::{get, post},
Router,
},
blockchain_api::BlockchainApiProvider,
http::{HeaderValue, Method},
opentelemetry::{sdk::Resource, KeyValue},
relay_rpc::auth::cacao::signature::eip1271::blockchain_api::BlockchainApiProvider,
std::{net::SocketAddr, sync::Arc},
stores::keys::MongoPersistentStorage,
tokio::{select, sync::broadcast},
Expand Down Expand Up @@ -46,7 +46,20 @@ pub async fn bootstrap(
let s3_client = get_s3_client(&config).await;
let geoip_resolver = get_geoip_resolver(&config, &s3_client).await;

let provider = BlockchainApiProvider::new(config.project_id.clone());
let provider = if let Some(blockchain_api_endpoint) = &config.blockchain_api_endpoint {
Some(
BlockchainApiProvider::new(
config.project_id.clone(),
blockchain_api_endpoint
.parse()
.expect("Error parsing blockchain_api_endpoint"),
)
.await
.map_err(Error::BlockchainApi)?,
)
} else {
None
};
let mut state = AppState::new(config, keys_persistent_storage, provider)?;

if let Some(prometheus_port) = state.config.telemetry_prometheus_port {
Expand Down
6 changes: 3 additions & 3 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
crate::{config::Configuration, metrics::Metrics, stores::keys::KeysPersistentStorageArc},
blockchain_api::BlockchainApiProvider,
build_info::BuildInfo,
relay_rpc::auth::cacao::signature::eip1271::blockchain_api::BlockchainApiProvider,
};

#[derive(Clone)]
Expand All @@ -10,7 +10,7 @@ pub struct AppState {
pub build_info: BuildInfo,
pub metrics: Option<Metrics>,
pub keys_persitent_storage: KeysPersistentStorageArc,
pub provider: BlockchainApiProvider,
pub provider: Option<BlockchainApiProvider>,
}

build_info::build_info!(fn build_info);
Expand All @@ -19,7 +19,7 @@ impl AppState {
pub fn new(
config: Configuration,
keys_persitent_storage: KeysPersistentStorageArc,
provider: BlockchainApiProvider,
provider: Option<BlockchainApiProvider>,
) -> crate::error::Result<AppState> {
let build_info: &BuildInfo = build_info();

Expand Down

0 comments on commit 4f17a6a

Please sign in to comment.