mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
merged rpc options into ClientProgramOptions and moved dfi.rs to bin/old
This commit is contained in:
@@ -84,10 +84,6 @@ path = "lisp/lisp.rs"
|
||||
name = "zkvm"
|
||||
path = "src/bin/zkvm.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "dfi"
|
||||
path = "src/bin/dfi.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "mimc"
|
||||
path = "src/old/mimc.rs"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use async_std::sync::Arc;
|
||||
use drk::rpc::adapter::RpcAdapter;
|
||||
use drk::rpc::jsonserver;
|
||||
use drk::rpc::options::ProgramOptions;
|
||||
//use drk::rpc::options::ProgramOptions;
|
||||
use rand::rngs::OsRng;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
@@ -27,6 +27,7 @@ use bellman::groth16;
|
||||
use bls12_381::Bls12;
|
||||
use easy_parallel::Parallel;
|
||||
use ff::Field;
|
||||
use log::*;
|
||||
use std::path::Path;
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -157,7 +158,7 @@ pub async fn subscribe(gateway_slabs_sub: GatewaySlabsSubscriber, mut state: Sta
|
||||
}
|
||||
}
|
||||
|
||||
async fn start(executor: Arc<Executor<'_>>, options: ClientProgramOptions) -> Result<()> {
|
||||
async fn start(executor: Arc<Executor<'_>>, options: Arc<ClientProgramOptions>) -> Result<()> {
|
||||
let connect_addr: SocketAddr = setup_addr(options.connect_addr, "127.0.0.1:3333".parse()?);
|
||||
let sub_addr: SocketAddr = setup_addr(options.sub_addr, "127.0.0.1:4444".parse()?);
|
||||
let database_path = options.database_path.as_path();
|
||||
@@ -223,9 +224,7 @@ fn main() -> Result<()> {
|
||||
let ex = Arc::new(Executor::new());
|
||||
let (signal, shutdown) = async_channel::unbounded::<()>();
|
||||
|
||||
let rpc_options = ProgramOptions::load()?;
|
||||
|
||||
let options = ClientProgramOptions::load()?;
|
||||
let options = Arc::new(ClientProgramOptions::load()?);
|
||||
|
||||
let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build();
|
||||
|
||||
@@ -254,7 +253,7 @@ fn main() -> Result<()> {
|
||||
// Run the main future on the current thread.
|
||||
.finish(|| {
|
||||
smol::future::block_on(async move {
|
||||
jsonserver::start(ex2.clone(), rpc_options, adapter).await?;
|
||||
jsonserver::start(ex2.clone(), options.clone(), adapter).await?;
|
||||
start(ex2, options).await?;
|
||||
drop(signal);
|
||||
Ok::<(), drk::Error>(())
|
||||
|
||||
213
src/bin/dfi.rs
213
src/bin/dfi.rs
@@ -1,213 +0,0 @@
|
||||
extern crate clap;
|
||||
use async_executor::Executor;
|
||||
use drk::rpc::adapter::RpcAdapter;
|
||||
use drk::rpc::jsonserver;
|
||||
use drk::rpc::options::ProgramOptions;
|
||||
use drk::Result;
|
||||
use easy_parallel::Parallel;
|
||||
use std::sync::Arc;
|
||||
|
||||
/*
|
||||
async fn start2(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<()> {
|
||||
let connections = Arc::new(Mutex::new(HashMap::new()));
|
||||
|
||||
let stored_addrs = Arc::new(Mutex::new(Vec::new()));
|
||||
|
||||
let executor2 = executor.clone();
|
||||
let stored_addrs2 = stored_addrs.clone();
|
||||
|
||||
let mut server_task = None;
|
||||
if let Some(accept_addr) = options.accept_addr {
|
||||
let accept_addr = accept_addr.clone();
|
||||
|
||||
let protocol = ServerProtocol::new(connections.clone(), accept_addr, stored_addrs2);
|
||||
server_task = Some(executor.spawn(async move {
|
||||
protocol.start(executor2).await?;
|
||||
Ok::<(), drk::Error>(())
|
||||
}));
|
||||
// }
|
||||
|
||||
let mut seed_protocols = Vec::with_capacity(options.seed_addrs.len());
|
||||
|
||||
// Normally we query this from a server
|
||||
let accept_addr = options.accept_addr.clone();
|
||||
|
||||
for seed_addr in options.seed_addrs.iter() {
|
||||
let protocol = SeedProtocol::new(seed_addr.clone(), accept_addr, stored_addrs.clone());
|
||||
protocol.clone().start(executor.clone()).await;
|
||||
seed_protocols.push(protocol);
|
||||
}
|
||||
|
||||
debug!("Waiting for seed node queries to finish...");
|
||||
|
||||
for seed_protocol in seed_protocols {
|
||||
seed_protocol.await_finish().await;
|
||||
}
|
||||
|
||||
debug!("Seed nodes queried.");
|
||||
|
||||
let mut client_slots = vec![];
|
||||
for i in 0..options.connection_slots {
|
||||
debug!("Starting connection slot {}", i);
|
||||
|
||||
let client = Channel::new(
|
||||
connections.clone(),
|
||||
accept_addr.clone(),
|
||||
stored_addrs.clone(),
|
||||
);
|
||||
client.clone().start(executor.clone()).await;
|
||||
client_slots.push(client);
|
||||
}
|
||||
|
||||
for remote_addr in options.manual_connects {
|
||||
debug!("Starting connection (manual) to {}", remote_addr);
|
||||
|
||||
let client = Channel::new(
|
||||
connections.clone(),
|
||||
accept_addr.clone(),
|
||||
stored_addrs.clone(),
|
||||
);
|
||||
client
|
||||
.clone()
|
||||
.start_manual(remote_addr, executor.clone())
|
||||
.await;
|
||||
client_slots.push(client);
|
||||
}
|
||||
|
||||
let rpc = RpcInterface::new();
|
||||
let http = listen(
|
||||
executor.clone(),
|
||||
rpc.clone(),
|
||||
Async::<TcpListener>::bind(([127, 0, 0, 1], 8000))?,
|
||||
None,
|
||||
);
|
||||
|
||||
let http_task = executor.spawn(http);
|
||||
|
||||
rpc.stop_recv.recv().await?;
|
||||
|
||||
http_task.cancel().await;
|
||||
|
||||
match server_task {
|
||||
None => {}
|
||||
Some(server_task) => {
|
||||
server_task.cancel().await;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
*/
|
||||
|
||||
//struct ProgramOptions {
|
||||
// network_settings: net::Settings,
|
||||
// log_path: Box<std::path::PathBuf>,
|
||||
// rpc_port: u16,
|
||||
//}
|
||||
//
|
||||
//impl ProgramOptions {
|
||||
// fn load() -> Result<ProgramOptions> {
|
||||
// let app = clap_app!(dfi =>
|
||||
// (version: "0.1.0")
|
||||
// (author: "Amir Taaki <amir@dyne.org>")
|
||||
// (about: "Dark node")
|
||||
// (@arg ACCEPT: -a --accept +takes_value "Accept address")
|
||||
// (@arg SEED_NODES: -s --seeds ... "Seed nodes")
|
||||
// (@arg CONNECTS: -c --connect ... "Manual connections")
|
||||
// (@arg CONNECT_SLOTS: --slots +takes_value "Connection slots")
|
||||
// (@arg LOG_PATH: --log +takes_value "Logfile path")
|
||||
// (@arg RPC_PORT: -r --rpc +takes_value "RPC port")
|
||||
// )
|
||||
// .get_matches();
|
||||
//
|
||||
// let accept_addr = if let Some(accept_addr) = app.value_of("ACCEPT") {
|
||||
// Some(accept_addr.parse()?)
|
||||
// } else {
|
||||
// None
|
||||
// };
|
||||
//
|
||||
// let mut seed_addrs: Vec<SocketAddr> = vec![];
|
||||
// if let Some(seeds) = app.values_of("SEED_NODES") {
|
||||
// for seed in seeds {
|
||||
// seed_addrs.push(seed.parse()?);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let mut manual_connects: Vec<SocketAddr> = vec![];
|
||||
// if let Some(connections) = app.values_of("CONNECTS") {
|
||||
// for connect in connections {
|
||||
// manual_connects.push(connect.parse()?);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let connection_slots = if let Some(connection_slots) =
|
||||
// app.value_of("CONNECT_SLOTS") { connection_slots.parse()?
|
||||
// } else {
|
||||
// 0
|
||||
// };
|
||||
//
|
||||
// let log_path = Box::new(
|
||||
// if let Some(log_path) = app.value_of("LOG_PATH") {
|
||||
// std::path::Path::new(log_path)
|
||||
// } else {
|
||||
// std::path::Path::new("/tmp/darkfid.log")
|
||||
// }
|
||||
// .to_path_buf(),
|
||||
// );
|
||||
//
|
||||
// let rpc_port = if let Some(rpc_port) = app.value_of("RPC_PORT") {
|
||||
// rpc_port.parse()?
|
||||
// } else {
|
||||
// 8000
|
||||
// };
|
||||
//
|
||||
// Ok(ProgramOptions {
|
||||
// network_settings: net::Settings {
|
||||
// inbound: accept_addr,
|
||||
// outbound_connections: connection_slots,
|
||||
// external_addr: accept_addr,
|
||||
// peers: manual_connects,
|
||||
// seeds: seed_addrs,
|
||||
// ..Default::default()
|
||||
// },
|
||||
// log_path,
|
||||
// rpc_port,
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
use simplelog::*;
|
||||
|
||||
let options = ProgramOptions::load()?;
|
||||
|
||||
let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build();
|
||||
|
||||
CombinedLogger::init(vec![
|
||||
TermLogger::new(LevelFilter::Debug, logger_config, TerminalMode::Mixed).unwrap(),
|
||||
WriteLogger::new(
|
||||
LevelFilter::Debug,
|
||||
Config::default(),
|
||||
std::fs::File::create(options.log_path.as_path()).unwrap(),
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let adapter = RpcAdapter::new("wallet.db")?;
|
||||
let ex = Arc::new(Executor::new());
|
||||
let (signal, shutdown) = async_channel::unbounded::<()>();
|
||||
let ex2 = ex.clone();
|
||||
|
||||
let (_, result) = Parallel::new()
|
||||
// Run four executor threads.
|
||||
.each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
|
||||
// Run the main future on the current thread.
|
||||
.finish(|| {
|
||||
smol::future::block_on(async move {
|
||||
jsonserver::start(ex2, options, adapter).await?;
|
||||
drop(signal);
|
||||
Ok::<(), drk::Error>(())
|
||||
})
|
||||
});
|
||||
|
||||
result
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::rpc::adapter::RpcAdapter;
|
||||
use crate::rpc::options::ProgramOptions;
|
||||
use crate::service::ClientProgramOptions;
|
||||
use crate::{net, Error, Result};
|
||||
use async_executor::Executor;
|
||||
use async_native_tls::TlsAcceptor;
|
||||
@@ -73,12 +73,10 @@ pub async fn listen(
|
||||
|
||||
pub async fn start(
|
||||
executor: Arc<Executor<'_>>,
|
||||
options: ProgramOptions,
|
||||
options: Arc<ClientProgramOptions>,
|
||||
_adapter: RpcAdapter,
|
||||
) -> Result<()> {
|
||||
let p2p = net::P2p::new(options.network_settings);
|
||||
|
||||
let rpc = RpcInterface::new(p2p.clone())?;
|
||||
let rpc = RpcInterface::new()?;
|
||||
let http = listen(
|
||||
executor.clone(),
|
||||
rpc.clone(),
|
||||
@@ -90,10 +88,6 @@ pub async fn start(
|
||||
|
||||
*rpc.started.lock().await = true;
|
||||
|
||||
p2p.clone().start(executor.clone()).await?;
|
||||
|
||||
p2p.run(executor).await?;
|
||||
|
||||
rpc.wait_for_quit().await?;
|
||||
|
||||
http_task.cancel().await;
|
||||
@@ -103,7 +97,6 @@ pub async fn start(
|
||||
// json RPC server goes here
|
||||
#[allow(dead_code)]
|
||||
pub struct RpcInterface {
|
||||
p2p: Arc<net::P2p>,
|
||||
pub started: Mutex<bool>,
|
||||
stop_send: async_channel::Sender<()>,
|
||||
stop_recv: async_channel::Receiver<()>,
|
||||
@@ -111,11 +104,11 @@ pub struct RpcInterface {
|
||||
}
|
||||
|
||||
impl RpcInterface {
|
||||
pub fn new(p2p: Arc<net::P2p>) -> Result<Arc<Self>> {
|
||||
pub fn new() -> Result<Arc<Self>> {
|
||||
let (stop_send, stop_recv) = async_channel::unbounded::<()>();
|
||||
let adapter = RpcAdapter::new("wallet.db")?;
|
||||
Ok(Arc::new(Self {
|
||||
p2p,
|
||||
//p2p,
|
||||
started: Mutex::new(false),
|
||||
stop_send,
|
||||
stop_recv,
|
||||
@@ -180,7 +173,7 @@ impl RpcInterface {
|
||||
"Attempted wallet generation".into(),
|
||||
))
|
||||
});
|
||||
let self3 = self.clone();
|
||||
//let self3 = self.clone();
|
||||
//io.add_method("key_gen", move |_| {
|
||||
// let self4 = self3.clone();
|
||||
// async move {
|
||||
@@ -192,7 +185,7 @@ impl RpcInterface {
|
||||
// ))
|
||||
// }
|
||||
//});
|
||||
let self5 = self.clone();
|
||||
//let self5 = self.clone();
|
||||
//io.add_method("cash_key_gen", move |_| {
|
||||
// let self6 = self5.clone();
|
||||
// async move {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod adapter;
|
||||
pub mod jsonserver;
|
||||
pub mod options;
|
||||
pub mod test;
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
use crate::{net, Result};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub struct ProgramOptions {
|
||||
pub network_settings: net::Settings,
|
||||
pub log_path: Box<std::path::PathBuf>,
|
||||
pub rpc_port: u16,
|
||||
}
|
||||
|
||||
impl ProgramOptions {
|
||||
pub fn load() -> Result<ProgramOptions> {
|
||||
let app = clap_app!(dfi =>
|
||||
(version: "0.1.0")
|
||||
(author: "Amir Taaki <amir@dyne.org>")
|
||||
(about: "Dark node")
|
||||
(@arg ACCEPT: -a --accept +takes_value "Accept add//ress")
|
||||
(@arg SEED_NODES: -s --seeds ... "Seed nodes")
|
||||
(@arg CONNECTS: -c --connect ... "Manual connections")
|
||||
(@arg CONNECT_SLOTS: --slots +takes_value "Connection slots")
|
||||
(@arg LOG_PATH: --log +takes_value "Logfile path")
|
||||
(@arg RPC_PORT: -r --rpc +takes_value "RPC port")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let accept_addr = if let Some(accept_addr) = app.value_of("ACCEPT") {
|
||||
Some(accept_addr.parse()?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut seed_addrs: Vec<SocketAddr> = vec![];
|
||||
if let Some(seeds) = app.values_of("SEED_NODES") {
|
||||
for seed in seeds {
|
||||
seed_addrs.push(seed.parse()?);
|
||||
}
|
||||
}
|
||||
|
||||
let mut manual_connects: Vec<SocketAddr> = vec![];
|
||||
if let Some(connections) = app.values_of("CONNECTS") {
|
||||
for connect in connections {
|
||||
manual_connects.push(connect.parse()?);
|
||||
}
|
||||
}
|
||||
|
||||
let connection_slots = if let Some(connection_slots) = app.value_of("CONNECT_SLOTS") {
|
||||
connection_slots.parse()?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let log_path = Box::new(
|
||||
if let Some(log_path) = app.value_of("LOG_PATH") {
|
||||
std::path::Path::new(log_path)
|
||||
} else {
|
||||
std::path::Path::new("/tmp/darkfid.log")
|
||||
}
|
||||
.to_path_buf(),
|
||||
);
|
||||
|
||||
let rpc_port = if let Some(rpc_port) = app.value_of("RPC_PORT") {
|
||||
rpc_port.parse()?
|
||||
} else {
|
||||
8000
|
||||
};
|
||||
|
||||
Ok(ProgramOptions {
|
||||
network_settings: net::Settings {
|
||||
inbound: accept_addr,
|
||||
outbound_connections: connection_slots,
|
||||
external_addr: accept_addr,
|
||||
peers: manual_connects,
|
||||
seeds: seed_addrs,
|
||||
..Default::default()
|
||||
},
|
||||
log_path,
|
||||
rpc_port,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,7 @@ pub struct ClientProgramOptions {
|
||||
pub verbose: bool,
|
||||
pub database_path: Box<std::path::PathBuf>,
|
||||
pub log_path: Box<std::path::PathBuf>,
|
||||
pub rpc_port: u16,
|
||||
}
|
||||
|
||||
impl ClientProgramOptions {
|
||||
@@ -84,6 +85,7 @@ impl ClientProgramOptions {
|
||||
(@arg VERBOSE: -v --verbose "Increase verbosity")
|
||||
(@arg DATABASE_PATH: --database +takes_value "database path")
|
||||
(@arg LOG_PATH: --log +takes_value "Logfile path")
|
||||
(@arg RPC_PORT: -r --rpc +takes_value "RPC port")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
@@ -119,12 +121,19 @@ impl ClientProgramOptions {
|
||||
.to_path_buf(),
|
||||
);
|
||||
|
||||
let rpc_port = if let Some(rpc_port) = app.value_of("RPC_PORT") {
|
||||
rpc_port.parse()?
|
||||
} else {
|
||||
8000
|
||||
};
|
||||
|
||||
Ok(ClientProgramOptions {
|
||||
connect_addr,
|
||||
sub_addr,
|
||||
verbose,
|
||||
database_path,
|
||||
log_path,
|
||||
rpc_port,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,10 @@ pub struct WalletDB {
|
||||
|
||||
impl WalletDB {
|
||||
pub fn new(wallet: &str) -> Result<Self> {
|
||||
debug!(target: "walletdb", "new() Constructor called");
|
||||
let path = Self::create_path(wallet)?;
|
||||
let conn = Connection::open(&path)?;
|
||||
debug!(target: "walletdb", "OPENED CONNECTION AT PATH {:?}", path);
|
||||
let contents = include_str!("../../res/schema.sql");
|
||||
let cashier_secret = jubjub::Fr::random(&mut OsRng);
|
||||
let secret = jubjub::Fr::random(&mut OsRng);
|
||||
@@ -32,6 +34,7 @@ impl WalletDB {
|
||||
Ok(v) => println!("Database initalized successfully {:?}", v),
|
||||
Err(err) => println!("Error: {}", err),
|
||||
};
|
||||
debug!(target: "walletdb", "new(): inititalized wallet");
|
||||
Ok(Self {
|
||||
path,
|
||||
own_coins: vec![],
|
||||
|
||||
Reference in New Issue
Block a user