Skip to content
Snippets Groups Projects
Commit d3b02a3a authored by Éloïs's avatar Éloïs
Browse files

[feat] bca: add req Identities

parent 8cfc82d2
Branches
Tags
1 merge request!1368[feat] bca: add req Identities
...@@ -69,5 +69,26 @@ pub(super) async fn execute_req_type( ...@@ -69,5 +69,26 @@ pub(super) async fn execute_req_type(
}), }),
BcaReqTypeV0::Ping => Ok(BcaRespTypeV0::Pong), BcaReqTypeV0::Ping => Ok(BcaRespTypeV0::Pong),
BcaReqTypeV0::SendTxs(txs) => send_txs::send_txs(bca_executor, txs).await, 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??,
))
}
} }
} }
...@@ -37,8 +37,8 @@ use async_io_stream::IoStream; ...@@ -37,8 +37,8 @@ use async_io_stream::IoStream;
use bincode::Options as _; use bincode::Options as _;
use dubp::crypto::keys::{ed25519::Ed25519KeyPair, Signator}; use dubp::crypto::keys::{ed25519::Ed25519KeyPair, Signator};
use duniter_bca_types::{ use duniter_bca_types::{
amount::Amount, bincode_opts, BcaReq, BcaReqExecError, BcaReqTypeV0, BcaResp, BcaRespTypeV0, amount::Amount, bincode_opts, identity::Identity, BcaReq, BcaReqExecError, BcaReqTypeV0,
BcaRespV0, BcaResp, BcaRespTypeV0, BcaRespV0,
}; };
pub use duniter_dbs::kv_typed::prelude::*; pub use duniter_dbs::kv_typed::prelude::*;
use duniter_dbs::{FileBackend, SharedDbs}; use duniter_dbs::{FileBackend, SharedDbs};
......
// 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,
}
...@@ -23,11 +23,13 @@ ...@@ -23,11 +23,13 @@
)] )]
pub mod amount; pub mod amount;
pub mod identity;
pub mod prepare_payment; pub mod prepare_payment;
pub mod rejected_tx; pub mod rejected_tx;
pub mod utxo; pub mod utxo;
use crate::amount::Amount; use crate::amount::Amount;
use crate::identity::Identity;
use crate::prepare_payment::{PrepareSimplePayment, PrepareSimplePaymentResp}; use crate::prepare_payment::{PrepareSimplePayment, PrepareSimplePaymentResp};
use crate::utxo::Utxo; use crate::utxo::Utxo;
...@@ -74,6 +76,7 @@ pub enum BcaReqTypeV0 { ...@@ -74,6 +76,7 @@ pub enum BcaReqTypeV0 {
}, },
Ping, Ping,
SendTxs(Txs), SendTxs(Txs),
Identities(ArrayVec<[PublicKey; 16]>),
} }
// Request types helpers // Request types helpers
...@@ -110,6 +113,7 @@ pub enum BcaRespTypeV0 { ...@@ -110,6 +113,7 @@ pub enum BcaRespTypeV0 {
PrepareSimplePayment(PrepareSimplePaymentResp), PrepareSimplePayment(PrepareSimplePaymentResp),
Pong, Pong,
RejectedTxs(Vec<rejected_tx::RejectedTx>), RejectedTxs(Vec<rejected_tx::RejectedTx>),
Identities(ArrayVec<[Option<Identity>; 16]>),
} }
// Result and error // Result and error
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment