Commit 949b2a3f authored by Éloïs's avatar Éloïs
Browse files

[feat] gva:bca: add server meta data in BcaExecutor

parent 02a24c84
......@@ -41,7 +41,7 @@ declare_types! {
let gva_conf = rust_server_conf_stringified.gva;
let currency = rust_server_conf_stringified.currency;
let server_pubkey = if let Some(self_keypair_str) = rust_server_conf_stringified.self_keypair {
let self_key_pair = if let Some(self_keypair_str) = rust_server_conf_stringified.self_keypair {
into_neon_res(&mut cx, crate::crypto::keypair_from_expanded_base58_secret_key(&self_keypair_str))?
} else {
Ed25519KeyPair::generate_random().expect("fail to gen random keyypair")
......@@ -49,7 +49,7 @@ declare_types! {
let txs_mempool_size = rust_server_conf_stringified.txs_mempool_size as usize;
let conf = DuniterConf {
gva: gva_conf,
self_key_pair: server_pubkey,
self_key_pair,
txs_mempool_size
};
......
......@@ -32,6 +32,7 @@ use crate::exec_req_type::ExecReqTypeError;
use crate::utils::AsyncReader;
use async_bincode::AsyncBincodeReader;
use bincode::Options as _;
use dubp::crypto::keys::ed25519::Ed25519KeyPair;
use duniter_bca_types::{BcaReq, BcaReqTypeV0, BcaResp, BcaRespTypeV0, BcaRespV0, ReqExecError};
use duniter_dbs::{FileBackend, SharedDbs};
use futures::{prelude::stream::FuturesUnordered, StreamExt, TryStream, TryStreamExt};
......@@ -47,13 +48,19 @@ use duniter_gva_dbs_reader::DbsReader;
static BCA_EXECUTOR: OnceCell<BcaExecutor> = OnceCell::new();
pub fn set_bca_executor(
currency: String,
dbs_pool: fast_threadpool::ThreadPoolAsyncHandler<SharedDbs<FileBackend>>,
dbs_reader: DbsReader,
self_keypair: Ed25519KeyPair,
software_version: &'static str,
) {
BCA_EXECUTOR
.set(BcaExecutor {
currency,
dbs_pool,
dbs_reader,
self_keypair,
software_version,
})
.unwrap_or_else(|_| panic!("BCA_EXECUTOR already set !"))
}
......@@ -73,8 +80,11 @@ pub async fn execute<R: 'static + futures::AsyncRead + Send + Unpin>(
#[derive(Clone)]
struct BcaExecutor {
currency: String,
dbs_pool: fast_threadpool::ThreadPoolAsyncHandler<SharedDbs<FileBackend>>,
dbs_reader: DbsReader,
self_keypair: Ed25519KeyPair,
software_version: &'static str,
}
use uninit::extension_traits::VecCapacity;
impl BcaExecutor {
......@@ -200,11 +210,15 @@ pub(crate) fn bincode_opts() -> impl bincode::Options {
#[cfg(test)]
mod tests {
use super::*;
pub use dubp::block::prelude::*;
pub use dubp::crypto::hashs::Hash;
pub use dubp::crypto::keys::ed25519::PublicKey;
pub use dubp::documents::transaction::TransactionInputV10;
pub use dubp::wallet::prelude::*;
pub use dubp::{
block::prelude::*,
crypto::{
hashs::Hash,
keys::{ed25519::PublicKey, KeyPair, Seed32},
},
documents::transaction::TransactionInputV10,
wallet::prelude::*,
};
pub use duniter_bca_types::BcaReqV0;
pub use duniter_dbs::databases::bc_v2::{BcV2DbReadable, BcV2DbRo};
pub use duniter_dbs::databases::cm_v1::{CmV1Db, CmV1DbReadable};
......@@ -248,8 +262,13 @@ mod tests {
let threadpool =
fast_threadpool::ThreadPool::start(fast_threadpool::ThreadPoolConfig::low(), dbs);
Ok(BcaExecutor {
currency: "g1".to_owned(),
dbs_pool: threadpool.into_async_handler(),
dbs_reader: duniter_dbs::kv_typed::prelude::Arc::new(mock_dbs_reader),
self_keypair: Ed25519KeyPair::from_seed(
Seed32::random().expect("fail to gen random seed"),
),
software_version: "test",
})
}
......
......@@ -28,10 +28,13 @@ mod warp_;
pub use duniter_conf::gva_conf::GvaConf;
use async_graphql::http::GraphQLPlaygroundConfig;
use dubp::common::crypto::keys::{ed25519::PublicKey, KeyPair as _};
use dubp::common::prelude::*;
use dubp::documents::transaction::TransactionDocumentV10;
use dubp::{block::DubpBlockV10, crypto::hashs::Hash};
use dubp::{
common::crypto::keys::{ed25519::PublicKey, KeyPair as _},
crypto::keys::ed25519::Ed25519KeyPair,
};
use duniter_conf::DuniterMode;
use duniter_dbs::databases::txs_mp_v2::TxsMpV2DbReadable;
use duniter_dbs::prelude::*;
......@@ -52,7 +55,7 @@ pub struct GvaModule {
gva_db_ro: &'static GvaV1DbRo<FileBackend>,
mempools: Mempools,
mode: DuniterMode,
self_pubkey: PublicKey,
self_keypair: Ed25519KeyPair,
software_version: &'static str,
}
......@@ -119,7 +122,7 @@ impl duniter_module::DuniterModule for GvaModule {
gva_db_ro: get_gva_db_ro(profile_path_opt),
mempools,
mode,
self_pubkey: conf.self_key_pair.public_key(),
self_keypair: conf.self_key_pair.clone(),
software_version,
},
endpoints,
......@@ -136,7 +139,7 @@ impl duniter_module::DuniterModule for GvaModule {
gva_db_ro,
mempools,
mode,
self_pubkey,
self_keypair,
software_version,
} = self;
......@@ -148,7 +151,7 @@ impl duniter_module::DuniterModule for GvaModule {
dbs_pool,
gva_db_ro,
mempools,
self_pubkey,
self_keypair,
software_version,
)
.await
......@@ -231,13 +234,17 @@ impl GvaModule {
dbs_pool: fast_threadpool::ThreadPoolAsyncHandler<SharedDbs<FileBackend>>,
gva_db_ro: &'static GvaV1DbRo<FileBackend>,
mempools: Mempools,
self_pubkey: PublicKey,
self_keypair: Ed25519KeyPair,
software_version: &'static str,
) {
log::info!("GvaServer::start: conf={:?}", conf);
let self_pubkey = self_keypair.public_key();
duniter_bca::set_bca_executor(
currency.clone(),
dbs_pool.clone(),
duniter_gva_dbs_reader::create_dbs_reader(gva_db_ro),
self_keypair,
software_version,
);
let gva_schema = duniter_gva_gql::build_schema_with_data(
duniter_gva_gql::GvaSchemaData {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment