Commit d3b02a3a authored by Éloïs's avatar Éloïs
Browse files

[feat] bca: add req Identities

parent 8cfc82d2
......@@ -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??,
))
}
}
}
......@@ -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};
......
// 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 @@
)]
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
......
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