added rpc support to cashierd

This commit is contained in:
lunar-mining
2021-08-26 14:02:35 +02:00
parent 51bc448a1d
commit 231d09b8d3
4 changed files with 20 additions and 6 deletions

View File

@@ -12,12 +12,14 @@ use drk::service::GatewayClient;
use drk::util::join_config_path;
use drk::wallet::CashierDb;
use drk::{Error, Result};
use drk::rpc::jsonserver;
use log::*;
use async_executor::Executor;
use easy_parallel::Parallel;
async fn start(executor: Arc<Executor<'_>>, config: Arc<&CashierdConfig>) -> Result<()> {
async fn start(executor: Arc<Executor<'_>>, config: Arc<CashierdConfig>) -> Result<()> {
let ex = executor.clone();
let accept_addr: SocketAddr = config.accept_url.parse()?;
let gateway_addr: SocketAddr = config.gateway_url.parse()?;
@@ -38,9 +40,13 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<&CashierdConfig>) -> Res
debug!(target: "cashierd", "starting cashier service");
let cashier = CashierService::new(accept_addr, btc_endpoint, wallet.clone(), gateway)?;
cashier.start(executor.clone()).await?;
cashier.start(ex.clone()).await?;
let rpc_url: std::net::SocketAddr = config.rpc_url.parse()?;
let adapter = Arc::new(CashierAdapter::new(wallet.clone())?);
let io = Arc::new(adapter.handle_input()?);
jsonserver::start(ex, rpc_url, io).await?;
let _adapter = Arc::new(CashierAdapter::new(wallet.clone())?);
Ok(())
}
@@ -56,7 +62,7 @@ fn main() -> Result<()> {
Config::<CashierdConfig>::load_default(path)?
};
let config_ptr = Arc::new(&config);
let config = Arc::new(config);
let options = CashierdCli::load()?;
@@ -90,7 +96,7 @@ fn main() -> Result<()> {
// Run the main future on the current thread.
.finish(|| {
smol::future::block_on(async move {
start(ex2, config_ptr).await?;
start(ex2, config).await?;
drop(signal);
Ok::<(), Error>(())
})

View File

@@ -187,6 +187,10 @@ pub struct CashierdConfig {
#[serde(rename = "accept_url")]
pub accept_url: String,
#[serde(default)]
#[serde(rename = "rpc_url")]
pub rpc_url: String,
#[serde(default)]
#[serde(rename = "database_path")]
pub database_path: String,
@@ -211,6 +215,7 @@ pub struct CashierdConfig {
impl Default for CashierdConfig {
fn default() -> Self {
let accept_url = String::from("127.0.0.1:7777");
let rpc_url = String::from("http://127.0.0.1:8000");
let gateway_url = String::from("127.0.0.1:3333");
let database_path = String::from("cashierd.db");
let btc_endpoint = String::from("tcp://electrum.blockstream.info:50001");
@@ -222,6 +227,7 @@ impl Default for CashierdConfig {
let password = String::new();
Self {
accept_url,
rpc_url,
database_path,
btc_endpoint,
gateway_url,

View File

@@ -14,8 +14,8 @@ impl CashierAdapter {
pub fn handle_input(
self: Arc<Self>,
mut io: jsonrpc_core::IoHandler,
) -> Result<jsonrpc_core::IoHandler> {
let mut io = jsonrpc_core::IoHandler::new();
io.add_sync_method("cashier_hello", |_| {
Ok(jsonrpc_core::Value::String("hello world!".into()))
});

View File

@@ -84,6 +84,8 @@ impl CashierService {
let _ = handle_request_task.cancel().await;
//let rpc_url: std::net::SocketAddr = config.rpc_url.parse()?;
Ok(())
}