diff --git a/rust-libs/modules/gva/bca/src/exec_req_type.rs b/rust-libs/modules/gva/bca/src/exec_req_type.rs index b5b75d083e41bc6d27cb82633f75b506468e566a..6a4b226c71e8006d7b395f1b3f24ee025380ec24 100644 --- a/rust-libs/modules/gva/bca/src/exec_req_type.rs +++ b/rust-libs/modules/gva/bca/src/exec_req_type.rs @@ -69,5 +69,26 @@ pub(super) async fn execute_req_type( }), BcaReqTypeV0::Ping => Ok(BcaRespTypeV0::Pong), BcaReqTypeV0::SendTxs(txs) => send_txs::send_txs(bca_executor, txs).await, + BcaReqTypeV0::Identities(pubkeys) => { + let dbs_reader = bca_executor.dbs_reader(); + Ok(BcaRespTypeV0::Identities( + bca_executor + .dbs_pool + .execute(move |dbs| { + pubkeys + .into_iter() + .map(|pubkey| { + dbs_reader.idty(&dbs.bc_db_ro, pubkey).map(|idty_opt| { + idty_opt.map(|idty| Identity { + is_member: idty.is_member, + username: idty.username, + }) + }) + }) + .collect::<KvResult<ArrayVec<_>>>() + }) + .await??, + )) + } } } diff --git a/rust-libs/modules/gva/bca/src/lib.rs b/rust-libs/modules/gva/bca/src/lib.rs index b1a1dc1a502fe5cc19f67a409b6c9e8b10aab917..0ac1a1c9f7db726ed1e88c84644f78a32aef7f58 100644 --- a/rust-libs/modules/gva/bca/src/lib.rs +++ b/rust-libs/modules/gva/bca/src/lib.rs @@ -37,8 +37,8 @@ use async_io_stream::IoStream; use bincode::Options as _; use dubp::crypto::keys::{ed25519::Ed25519KeyPair, Signator}; use duniter_bca_types::{ - amount::Amount, bincode_opts, BcaReq, BcaReqExecError, BcaReqTypeV0, BcaResp, BcaRespTypeV0, - BcaRespV0, + amount::Amount, bincode_opts, identity::Identity, BcaReq, BcaReqExecError, BcaReqTypeV0, + BcaResp, BcaRespTypeV0, BcaRespV0, }; pub use duniter_dbs::kv_typed::prelude::*; use duniter_dbs::{FileBackend, SharedDbs}; diff --git a/rust-libs/modules/gva/bca/types/src/identity.rs b/rust-libs/modules/gva/bca/types/src/identity.rs new file mode 100644 index 0000000000000000000000000000000000000000..e2302a9bfa7d9520b4a5b41831ff987276776ed8 --- /dev/null +++ b/rust-libs/modules/gva/bca/types/src/identity.rs @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Éloïs SANCHEZ. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +use crate::*; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct Identity { + pub is_member: bool, + pub username: String, +} diff --git a/rust-libs/modules/gva/bca/types/src/lib.rs b/rust-libs/modules/gva/bca/types/src/lib.rs index 8c9f84501b69ce562c1c7403904c01c2df29959c..4182fb555e9fae5c6c3095c59660a50500d8bd78 100644 --- a/rust-libs/modules/gva/bca/types/src/lib.rs +++ b/rust-libs/modules/gva/bca/types/src/lib.rs @@ -23,11 +23,13 @@ )] pub mod amount; +pub mod identity; pub mod prepare_payment; pub mod rejected_tx; pub mod utxo; use crate::amount::Amount; +use crate::identity::Identity; use crate::prepare_payment::{PrepareSimplePayment, PrepareSimplePaymentResp}; use crate::utxo::Utxo; @@ -74,6 +76,7 @@ pub enum BcaReqTypeV0 { }, Ping, SendTxs(Txs), + Identities(ArrayVec<[PublicKey; 16]>), } // Request types helpers @@ -110,6 +113,7 @@ pub enum BcaRespTypeV0 { PrepareSimplePayment(PrepareSimplePaymentResp), Pong, RejectedTxs(Vec<rejected_tx::RejectedTx>), + Identities(ArrayVec<[Option<Identity>; 16]>), } // Result and error