Use Rocket.toml

This commit is contained in:
Hanh 2022-06-10 19:14:21 +08:00
parent bd24633da7
commit 290715fa33
3 changed files with 27 additions and 18 deletions

View File

@ -13,16 +13,11 @@ Edit `Rocket.toml`
[default] [default]
allow_backup = true allow_backup = true
allow_send = true allow_send = true
yec = { db_path = "./yec.db", lwd_url = "https://lite.ycash.xyz:9067" }
zec = { db_path = "./zec.db", lwd_url = "https://mainnet.lightwalletd.com:9067" }
``` ```
Edit `.env`
```
ZEC_DB_PATH
ZEC_LWD_URL
YEC_DB_PATH
YEC_LWD_URL
```
# RPC # RPC

View File

@ -1,3 +1,6 @@
[default] [default]
allow_backup = true allow_backup = true
allow_send = true allow_send = true
yec = { db_path = "./yec.db", lwd_url = "https://lite.ycash.xyz:9067" }
zec = { db_path = "./zec.db", lwd_url = "https://mainnet.lightwalletd.com:9067" }

View File

@ -1,6 +1,7 @@
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
use std::collections::HashMap;
use anyhow::anyhow; use anyhow::anyhow;
use rocket::fairing::AdHoc; use rocket::fairing::AdHoc;
use rocket::response::Responder; use rocket::response::Responder;
@ -26,20 +27,30 @@ impl<'r> Responder<'r, 'static> for Error {
} }
} }
fn init(coin: u8, config: HashMap<String, String>) -> anyhow::Result<()> {
warp_api_ffi::init_coin(
coin,
config.get("db_path").ok_or(anyhow!("Missing configuration value"))?
)?;
warp_api_ffi::set_coin_lwd_url(
coin,
config.get("lwd_url").ok_or(anyhow!("Missing configuration value"))?
);
Ok(())
}
#[rocket::main] #[rocket::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
let _ = dotenv::dotenv(); let _ = dotenv::dotenv();
warp_api_ffi::init_coin(
0,
&dotenv::var("ZEC_DB_PATH").unwrap_or("./zec.db".to_string()),
)?;
warp_api_ffi::set_coin_lwd_url(
0,
&dotenv::var("ZEC_LWD_URL").unwrap_or("https://mainnet.lightwalletd.com:9067".to_string()),
);
let _ = rocket::build() let rocket = rocket::build();
.mount( let figment = rocket.figment();
let zec: HashMap<String, String> = figment.extract_inner("zec")?;
init(0, zec)?;
let yec: HashMap<String, String> = figment.extract_inner("yec")?;
init(1, yec)?;
let _ = rocket.mount(
"/", "/",
routes![ routes![
set_lwd, set_lwd,