From fd4a3f83e9b8c6d9800fd45d76895ee19208f07d Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Fri, 2 Apr 2021 16:19:14 +0200 Subject: [PATCH] [feat] bca: add current ud --- .../modules/gva/bca/src/exec_req_type.rs | 2 ++ .../gva/bca/src/exec_req_type/current_ud.rs | 30 +++++++++++++++++++ rust-libs/modules/gva/bca/types/src/lib.rs | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 rust-libs/modules/gva/bca/src/exec_req_type/current_ud.rs 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 6a4b226c7..fc6c92749 100644 --- a/rust-libs/modules/gva/bca/src/exec_req_type.rs +++ b/rust-libs/modules/gva/bca/src/exec_req_type.rs @@ -14,6 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. mod balances; +mod current_ud; mod last_blockstamp_out_of_fork_window; mod members_count; mod prepare_simple_payment; @@ -90,5 +91,6 @@ pub(super) async fn execute_req_type( .await??, )) } + BcaReqTypeV0::CurrentUd => current_ud::exec_req_current_ud(bca_executor).await, } } diff --git a/rust-libs/modules/gva/bca/src/exec_req_type/current_ud.rs b/rust-libs/modules/gva/bca/src/exec_req_type/current_ud.rs new file mode 100644 index 000000000..02823dbba --- /dev/null +++ b/rust-libs/modules/gva/bca/src/exec_req_type/current_ud.rs @@ -0,0 +1,30 @@ +// 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::*; + +pub(super) async fn exec_req_current_ud( + bca_executor: &BcaExecutor, +) -> Result<BcaRespTypeV0, ExecReqTypeError> { + if let Some(current_ud) = bca_executor + .cm_accessor + .get_current_meta(|cm| cm.current_ud) + .await + { + Ok(BcaRespTypeV0::CurrentUd(current_ud)) + } else { + Err("no blockchain".into()) + } +} diff --git a/rust-libs/modules/gva/bca/types/src/lib.rs b/rust-libs/modules/gva/bca/types/src/lib.rs index 4182fb555..4cc715f05 100644 --- a/rust-libs/modules/gva/bca/types/src/lib.rs +++ b/rust-libs/modules/gva/bca/types/src/lib.rs @@ -77,6 +77,7 @@ pub enum BcaReqTypeV0 { Ping, SendTxs(Txs), Identities(ArrayVec<[PublicKey; 16]>), + CurrentUd, } // Request types helpers @@ -114,6 +115,7 @@ pub enum BcaRespTypeV0 { Pong, RejectedTxs(Vec<rejected_tx::RejectedTx>), Identities(ArrayVec<[Option<Identity>; 16]>), + CurrentUd(SourceAmount), } // Result and error -- GitLab