Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Hack jsonrpsee, substrate-subxt, Workround For #7 (#78)
Browse files Browse the repository at this point in the history
* hack: jsonrpsee, substrate-subxt, workround for #7

* suppress: clippy

* remove: async std
  • Loading branch information
aurexav authored Nov 2, 2020
1 parent 8ee8cb7 commit d70d76c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 24 deletions.
40 changes: 31 additions & 9 deletions Cargo.lock

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

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ name = "bridger"
path = "src/bin/bridger.rs"

[dependencies]
async-macros = "2.0.0"
async-trait = "0.1.40"
dirs = "3.0.1"
env_logger = "0.7.1"
Expand Down Expand Up @@ -58,3 +59,14 @@ features = ["runtime", "rpc"]
package = "serde"
version = "1"
features = ["derive"]

[patch.crates-io]
# jsonrpsee = { path = "../jsonrpsee", features = ["ws"] }
# substrate-subxt = { path = "../substrate-subxt" }
jsonrpsee = { git = "https://github.com/AurevoirXavier/jsonrpsee", branch = "xavier-send-error", features = ["ws"] }
substrate-subxt = { git = "https://github.com/AurevoirXavier/substrate-subxt", branch = "xavier-send-error" }
[patch.'https://github.com/paritytech/jsonrpsee']
# jsonrpsee = { path = "../jsonrpsee", features = ["ws"] }
# substrate-subxt = { path = "../substrate-subxt" }
jsonrpsee = { git = "https://github.com/AurevoirXavier/jsonrpsee", branch = "xavier-send-error", features = ["ws"] }
substrate-subxt = { git = "https://github.com/AurevoirXavier/substrate-subxt", branch = "xavier-send-error" }
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

17 changes: 16 additions & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use crate::result::Result;
use std::path::PathBuf;
use structopt::{clap::AppSettings, StructOpt};
use std::time::Duration;
use tokio::time;

mod confirm;
mod run;
Expand Down Expand Up @@ -63,7 +65,20 @@ enum Opt {
pub async fn exec() -> Result<()> {
let opt = Opt::from_args();
match opt {
Opt::Run { config, verbose } => run::exec(config, verbose).await?,
Opt::Run { config, verbose } => {
if std::env::var("RUST_LOG").is_err() {
if verbose {
std::env::set_var("RUST_LOG", "info,darwinia_bridger");
} else {
std::env::set_var("RUST_LOG", "info");
}
}
env_logger::init();

while run::exec(config.clone()).await.is_err() {
time::delay_for(Duration::from_secs(5)).await;
}
}
Opt::Confirm { block } => confirm::exec(block).await?,
Opt::Affirm { block} => affirm::exec(block).await?,
Opt::AffirmRaw { json } => affirm_raw::exec(json).await?,
Expand Down
32 changes: 19 additions & 13 deletions src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@ use crate::{
result::{Error, Result},
Config,
};
use async_macros::select;
use futures::StreamExt;
use std::path::PathBuf;
use std::sync::Arc;
use web3::transports::http::Http;

/// Run the bridger
pub async fn exec(path: Option<PathBuf>, verbose: bool) -> Result<()> {
if std::env::var("RUST_LOG").is_err() {
if verbose {
std::env::set_var("RUST_LOG", "info,darwinia_bridger");
} else {
std::env::set_var("RUST_LOG", "info");
}
}
env_logger::init();

pub async fn exec(path: Option<PathBuf>) -> Result<()> {
// config
let config = Config::new(path)?;
let config = Config::new(path.clone())?;
if config.eth.rpc.starts_with("ws") {
return Err(Error::Bridger(
"Bridger currently doesn't support ethereum websocket transport".to_string(),
Expand All @@ -33,6 +26,7 @@ pub async fn exec(path: Option<PathBuf>, verbose: bool) -> Result<()> {
// APIs
let shadow = Arc::new(Shadow::new(&config));
let darwinia = Arc::new(Darwinia::new(&config).await?);
let killer = darwinia.client.rpc.client.killer.clone();

// Services
let ethereum = <EthereumService<Http>>::new_http(&config)?;
Expand Down Expand Up @@ -70,7 +64,19 @@ pub async fn exec(path: Option<PathBuf>, verbose: bool) -> Result<()> {
} else {
listener.register(guard)?;
}
listener.start(config.eth.start).await?;

Ok(())
let never_exit = async {
listener.start(config.eth.start).await?;

Ok::<(), Error>(())
};
let exit_on_ws_close = async {
loop {
if killer.lock().await.next().await.is_some() {
return Err(Error::Bridger("WS Closed".into()));
}
}
};

select!(never_exit, exit_on_ws_close).await
}

0 comments on commit d70d76c

Please sign in to comment.