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

chore: rename bca->bda & externalize bda-types

parent dc22ce63
No related branches found
No related tags found
No related merge requests found
Pipeline #12503 passed
Showing
with 160 additions and 436 deletions
......@@ -694,23 +694,25 @@ checksum = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d"
[[package]]
name = "dubp"
version = "0.54.1"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5dca084e135ee5ea38d64e5e665cac6fc23570a66ed22ce5021b5d14c4f9443"
checksum = "c30ebc00a1c88df81a8f15d35fb785a934bafb81bdb53e0a50a77531b79d01ff"
dependencies = [
"dubp-block",
"dubp-common",
"dubp-documents",
"dubp-documents-parser",
"dubp-wallet",
"duniter-bda-types",
"duniter-peer",
"dup-crypto",
]
[[package]]
name = "dubp-block"
version = "0.54.1"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fa8e2b1d9728832dd4696f9eff1348085d162d5f98fe025e9c9a2caeffd9c89"
checksum = "3608ef622ea82856b2dfdef0bb8c1da7ef25e125279aa4f3b672d24729ef2b18"
dependencies = [
"dubp-documents",
"dubp-documents-parser",
......@@ -723,9 +725,9 @@ dependencies = [
[[package]]
name = "dubp-common"
version = "0.54.1"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49a12c0842c7c4e61e75755476b782d09e282275cab187376b3cc0da405b6afb"
checksum = "196cce73d8ae0cff80bdd9d8d95f6f33f6af0103aeaac1e87fa70e12748c79d7"
dependencies = [
"dup-crypto",
"serde",
......@@ -736,9 +738,9 @@ dependencies = [
[[package]]
name = "dubp-documents"
version = "0.54.1"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "450f2b268c979264ef098f00532faf0015d281d9c8ebabf227f57ecc35d0076c"
checksum = "78bb43886be2293ecae9abc5a709869a8a828a2ddc471c478e407aa450e436ea"
dependencies = [
"beef",
"dubp-wallet",
......@@ -750,9 +752,9 @@ dependencies = [
[[package]]
name = "dubp-documents-parser"
version = "0.54.1"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "067bba5a1e34566871128b7157642a643264e4aeaba1db5034634ef6461f797b"
checksum = "8dcc86531972ec0c17cafa069691f40ea5e2bd3060592bbf257b661d4d885116"
dependencies = [
"dubp-documents",
"json-pest-parser",
......@@ -764,9 +766,9 @@ dependencies = [
[[package]]
name = "dubp-wallet"
version = "0.54.1"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7552a1c1cca8498dc9266fdb6b10ee98ef841e363a1e3c0cd319ead3fa2aeef4"
checksum = "081ac73321da67f2de891cc26126f539ea336d84abb16e8fe47592b1adaf3fe2"
dependencies = [
"byteorder",
"dubp-common",
......@@ -779,7 +781,7 @@ dependencies = [
[[package]]
name = "dubp-wot"
version = "0.11.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"log",
"once_cell",
......@@ -791,7 +793,7 @@ dependencies = [
[[package]]
name = "duniter-bc-reader"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"anyhow",
"dubp",
......@@ -800,7 +802,7 @@ dependencies = [
]
[[package]]
name = "duniter-bca"
name = "duniter-bda"
version = "0.1.0"
dependencies = [
"anyhow",
......@@ -809,7 +811,6 @@ dependencies = [
"async_io_stream",
"bincode",
"dubp",
"duniter-bca-types",
"duniter-core",
"duniter-gva-db",
"duniter-gva-dbs-reader",
......@@ -823,12 +824,15 @@ dependencies = [
]
[[package]]
name = "duniter-bca-types"
version = "0.1.0"
name = "duniter-bda-types"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f80e789db68f1831ca51ed27f9568c3e1750b9cd95d97a3b6096e492024f7a"
dependencies = [
"arrayvec 0.7.0",
"bincode",
"dubp",
"dubp-documents",
"duniter-peer",
"serde",
"smallvec",
"thiserror",
......@@ -837,7 +841,7 @@ dependencies = [
[[package]]
name = "duniter-conf"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"anyhow",
"dubp",
......@@ -851,8 +855,9 @@ dependencies = [
[[package]]
name = "duniter-core"
version = "1.8.1"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"dubp",
"dubp-wot",
"duniter-bc-reader",
"duniter-conf",
......@@ -865,7 +870,7 @@ dependencies = [
[[package]]
name = "duniter-dbs"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"arrayvec 0.7.0",
"bincode",
......@@ -888,7 +893,7 @@ dependencies = [
[[package]]
name = "duniter-dbs-write-ops"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"chrono",
"dubp",
......@@ -903,7 +908,7 @@ dependencies = [
[[package]]
name = "duniter-global"
version = "1.8.1"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"async-rwlock",
"dubp",
......@@ -925,7 +930,7 @@ dependencies = [
"async-trait",
"bytes 1.0.1",
"dubp",
"duniter-bca",
"duniter-bda",
"duniter-core",
"duniter-gva-conf",
"duniter-gva-db",
......@@ -983,12 +988,12 @@ dependencies = [
"anyhow",
"arrayvec 0.7.0",
"dubp",
"duniter-bca-types",
"duniter-core",
"duniter-gva-db",
"flate2",
"maplit",
"mockall",
"rand 0.8.3",
"resiter",
"smallvec",
"unwrap",
......@@ -1003,7 +1008,6 @@ dependencies = [
"async-graphql",
"async-trait",
"dubp",
"duniter-bca-types",
"duniter-core",
"duniter-gva-db",
"duniter-gva-dbs-reader",
......@@ -1042,7 +1046,7 @@ dependencies = [
[[package]]
name = "duniter-mempools"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"dubp",
"duniter-bc-reader",
......@@ -1055,7 +1059,7 @@ dependencies = [
[[package]]
name = "duniter-module"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"anyhow",
"async-mutex",
......@@ -1072,22 +1076,34 @@ dependencies = [
"serde",
]
[[package]]
name = "duniter-peer"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2ece2a69df5cc4ef0a3460b8e5159ae4d8c6acd3b57ddae1e9c5b6b083a647c"
dependencies = [
"beef",
"dubp-common",
"log",
"serde",
"serde_json",
"smallvec",
"thiserror",
]
[[package]]
name = "dup-crypto"
version = "0.54.1"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4b9746489f2564086fffce1cc67de3b867a098eaf4dbcce15dc85f85542c9c"
checksum = "e9fbff8a0a8449f195a9d41f89043a54eb0d0d3b6f97ae2ef32de5378aa4ffc7"
dependencies = [
"arrayvec 0.5.2",
"base64",
"blake3",
"bs58",
"byteorder",
"cryptoxide",
"ed25519-bip32",
"getrandom 0.2.2",
"hex",
"once_cell",
"ring",
"serde",
"thiserror",
......@@ -1095,15 +1111,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "ed25519-bip32"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8827180a2b511141fbe49141e50b31a8d542465e0fb572f81f36feea2addfe92"
dependencies = [
"cryptoxide",
]
[[package]]
name = "either"
version = "1.6.1"
......@@ -1639,7 +1646,7 @@ dependencies = [
[[package]]
name = "kv_typed"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#5f6d6b1a4a6f3da9e87f511b3967dc19fe5c4076"
dependencies = [
"byteorder",
"cfg-if 0.1.10",
......
......@@ -13,8 +13,8 @@ async-graphql = { version = "2.8", features = ["log"] }
async-mutex = "1.4.0"
async-trait = "0.1.41"
bytes = "1.0"
dubp = { version = "0.54.1", features = ["duniter"] }
duniter-bca = { path = "./bca" }
dubp = { version = "0.55.1", features = ["duniter"] }
duniter-bda = { path = "./bda" }
duniter-core = { git = "https://git.duniter.org/nodes/rust/duniter-core" }
duniter-gva-conf = { path = "./conf" }
duniter-gva-db = { path = "./db" }
......@@ -43,7 +43,7 @@ unwrap = "1.2.1"
[workspace]
members = [
"bca",
"bda",
"conf",
"db",
"dbs-reader",
......
[package]
name = "duniter-bca-types"
version = "0.1.0"
authors = ["librelois <elois@duniter.org>"]
license = "AGPL-3.0"
edition = "2018"
[dependencies]
arrayvec = { version = "0.7", features = ["serde"] }
bincode = "1.3"
dubp = { version = "0.54.1" }
serde = { version = "1.0.105", features = ["derive"] }
smallvec = { version = "1.4.0", features = ["serde"] }
thiserror = "1.0.20"
[features]
default = ["duniter"]
client = ["dubp/client"]
duniter = ["dubp/duniter"]
// 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, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum Amount {
Cents(SourceAmount),
Uds(f64),
}
impl Default for Amount {
fn default() -> Self {
Self::Cents(SourceAmount::ZERO)
}
}
impl Amount {
pub fn to_cents(self, ud_amount: SourceAmount) -> SourceAmount {
match self {
Amount::Cents(sa) => sa,
Amount::Uds(f64_) => {
if !f64_.is_finite() || f64_ <= 0f64 {
SourceAmount::ZERO
} else {
SourceAmount::new(
f64::round(ud_amount.amount() as f64 * f64_) as i64,
ud_amount.base(),
)
}
}
}
}
}
// 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,
}
// 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/>.
#![deny(
clippy::unwrap_used,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unstable_features,
unused_import_braces
)]
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;
use arrayvec::ArrayVec;
use bincode::Options as _;
use dubp::crypto::keys::ed25519::{PublicKey, Signature};
use dubp::wallet::prelude::*;
use dubp::{common::prelude::Blockstamp, crypto::hashs::Hash};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use thiserror::Error;
// Constants
pub const MAX_FIRST_UTXOS: usize = 40;
// Request
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum BcaReq {
V0(BcaReqV0),
_V1,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct BcaReqV0 {
pub req_id: usize,
pub req_type: BcaReqTypeV0,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum BcaReqTypeV0 {
BalancesOfPubkeys(ArrayVec<PublicKey, 16>),
FirstUtxosOfPubkeys {
amount_target_opt: Option<Amount>,
pubkeys: ArrayVec<PublicKey, 16>,
},
LastBlockstampOutOfForkWindow,
MembersCount,
PrepareSimplePayment(PrepareSimplePayment),
ProofServerPubkey {
challenge: [u8; 16],
},
Ping,
SendTxs(Txs),
Identities(ArrayVec<PublicKey, 16>),
CurrentUd,
BalancesOfScripts(ArrayVec<WalletScriptV10, 16>),
}
// Request types helpers
pub type Txs = SmallVec<[dubp::documents::transaction::TransactionDocumentV10; 1]>;
// Response
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
pub enum BcaResp {
V0(BcaRespV0),
UnsupportedVersion,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
pub struct BcaRespV0 {
pub req_id: usize,
pub resp_type: BcaRespTypeV0,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
pub enum BcaRespTypeV0 {
Error(String),
Balances(ArrayVec<Option<SourceAmount>, 16>),
FirstUtxosOfPubkeys(Vec<ArrayVec<Utxo, MAX_FIRST_UTXOS>>),
ProofServerPubkey {
challenge: [u8; 16],
server_pubkey: PublicKey,
sig: Signature,
},
LastBlockstampOutOfForkWindow(Blockstamp),
MembersCount(u64),
PrepareSimplePayment(PrepareSimplePaymentResp),
Pong,
RejectedTxs(Vec<rejected_tx::RejectedTx>),
Identities(ArrayVec<Option<Identity>, 16>),
CurrentUd(SourceAmount),
}
// Result and error
pub type BcaResult = Result<BcaResp, BcaReqExecError>;
#[derive(Clone, Debug, Deserialize, Error, PartialEq, Eq, Serialize)]
pub enum BcaReqExecError {
#[error("task cancelled")]
Cancelled,
#[error("Invalid request: {0}")]
InvalidReq(String),
#[error("task panicked")]
Panic,
#[error("Unknown error")]
Unknown,
}
// Bincode configuration
pub fn bincode_opts() -> impl bincode::Options {
bincode::options()
.with_limit(u32::max_value() as u64)
.allow_trailing_bytes()
}
// 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::*;
use dubp::documents::transaction::TransactionInputV10;
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct PrepareSimplePayment {
pub issuer: PublicKey,
pub amount: Amount,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
pub struct PrepareSimplePaymentResp {
pub current_block_number: u32,
pub current_block_hash: Hash,
pub current_ud: SourceAmount,
pub inputs: Vec<TransactionInputV10>,
pub inputs_sum: SourceAmount,
}
// 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, Copy, Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
pub struct Utxo {
pub amount: SourceAmount,
pub tx_hash: Hash,
pub output_index: u8,
}
[package]
name = "duniter-bca"
name = "duniter-bda"
version = "0.1.0"
authors = ["librelois <elois@duniter.org>"]
license = "AGPL-3.0"
......@@ -11,8 +11,7 @@ arrayvec = { version = "0.7", features = ["serde"] }
async-bincode = "0.6.1"
async_io_stream = { version = "0.3.1", features = [ "tokio_io"] }
bincode = "1.3"
dubp = { version = "0.54.1", features = ["duniter"] }
duniter-bca-types = { path = "types", features = ["duniter"] }
dubp = { version = "0.55.1", features = ["duniter"] }
duniter-core = { git = "https://git.duniter.org/nodes/rust/duniter-core" }
duniter-gva-db = { path = "../db" }
duniter-gva-dbs-reader = { path = "../dbs-reader" }
......
......@@ -17,6 +17,7 @@ mod balances;
mod current_ud;
mod last_blockstamp_out_of_fork_window;
mod members_count;
mod peers;
mod prepare_simple_payment;
mod send_txs;
mod utxos;
......@@ -38,42 +39,42 @@ where
}
pub(super) async fn execute_req_type(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
req_type: BcaReqTypeV0,
_is_whitelisted: bool,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
match req_type {
BcaReqTypeV0::BalancesOfPubkeys(pubkeys) => {
balances::exec_req_balances_of_pubkeys(bca_executor, pubkeys).await
balances::exec_req_balances_of_pubkeys(bda_executor, pubkeys).await
}
BcaReqTypeV0::FirstUtxosOfPubkeys {
amount_target_opt,
pubkeys,
} => utxos::exec_req_first_utxos_of_pubkeys(bca_executor, amount_target_opt, pubkeys).await,
} => utxos::exec_req_first_utxos_of_pubkeys(bda_executor, amount_target_opt, pubkeys).await,
BcaReqTypeV0::LastBlockstampOutOfForkWindow => {
last_blockstamp_out_of_fork_window::exec_req_last_blockstamp_out_of_fork_window(
bca_executor,
bda_executor,
)
.await
}
BcaReqTypeV0::MembersCount => members_count::exec_req_members_count(bca_executor).await,
BcaReqTypeV0::MembersCount => members_count::exec_req_members_count(bda_executor).await,
BcaReqTypeV0::PrepareSimplePayment(params) => {
prepare_simple_payment::exec_req_prepare_simple_payment(bca_executor, params).await
prepare_simple_payment::exec_req_prepare_simple_payment(bda_executor, params).await
}
BcaReqTypeV0::ProofServerPubkey { challenge } => Ok(BcaRespTypeV0::ProofServerPubkey {
challenge,
server_pubkey: bca_executor.self_keypair.public_key(),
sig: bca_executor
server_pubkey: bda_executor.self_keypair.public_key(),
sig: bda_executor
.self_keypair
.generate_signator()
.sign(&challenge),
}),
BcaReqTypeV0::Ping => Ok(BcaRespTypeV0::Pong),
BcaReqTypeV0::SendTxs(txs) => send_txs::send_txs(bca_executor, txs).await,
BcaReqTypeV0::SendTxs(txs) => send_txs::send_txs(bda_executor, txs).await,
BcaReqTypeV0::Identities(pubkeys) => {
let dbs_reader = bca_executor.dbs_reader();
let dbs_reader = bda_executor.dbs_reader();
Ok(BcaRespTypeV0::Identities(
bca_executor
bda_executor
.dbs_pool
.execute(move |dbs| {
pubkeys
......@@ -91,9 +92,10 @@ pub(super) async fn execute_req_type(
.await??,
))
}
BcaReqTypeV0::CurrentUd => current_ud::exec_req_current_ud(bca_executor).await,
BcaReqTypeV0::CurrentUd => current_ud::exec_req_current_ud(bda_executor).await,
BcaReqTypeV0::BalancesOfScripts(scripts) => {
balances::exec_req_balances_of_scripts(bca_executor, scripts).await
balances::exec_req_balances_of_scripts(bda_executor, scripts).await
}
BcaReqTypeV0::PeersV10 { n } => peers::exec_req_peers_v1(bda_executor, n).await,
}
}
......@@ -17,12 +17,12 @@ use crate::*;
use dubp::{crypto::keys::ed25519::PublicKey, wallet::prelude::WalletScriptV10};
pub(super) async fn exec_req_balances_of_pubkeys(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
pubkeys: ArrayVec<PublicKey, 16>,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
let dbs_reader = bca_executor.dbs_reader();
let dbs_reader = bda_executor.dbs_reader();
Ok(BcaRespTypeV0::Balances(
bca_executor
bda_executor
.dbs_pool
.execute(move |_| {
pubkeys
......@@ -39,12 +39,12 @@ pub(super) async fn exec_req_balances_of_pubkeys(
}
pub(super) async fn exec_req_balances_of_scripts(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
scripts: ArrayVec<WalletScriptV10, 16>,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
let dbs_reader = bca_executor.dbs_reader();
let dbs_reader = bda_executor.dbs_reader();
Ok(BcaRespTypeV0::Balances(
bca_executor
bda_executor
.dbs_pool
.execute(move |_| {
scripts
......
......@@ -16,9 +16,9 @@
use crate::*;
pub(super) async fn exec_req_current_ud(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
if let Some(current_ud) = bca_executor
if let Some(current_ud) = bda_executor
.cm_accessor
.get_current_meta(|cm| cm.current_ud)
.await
......
......@@ -17,15 +17,15 @@ use crate::*;
use dubp::common::prelude::*;
pub(super) async fn exec_req_last_blockstamp_out_of_fork_window(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
if let Some(current_block_number) = bca_executor
if let Some(current_block_number) = bda_executor
.cm_accessor
.get_current_meta(|cm| cm.current_block_meta.number)
.await
{
let dbs_reader = bca_executor.dbs_reader();
bca_executor
let dbs_reader = bda_executor.dbs_reader();
bda_executor
.dbs_pool
.execute(move |dbs| {
let block_ref_number = if current_block_number < 101 {
......@@ -63,10 +63,10 @@ mod tests {
.times(1)
.returning(|_| None);
let dbs_reader = MockDbsReader::new();
let bca_executor =
create_bca_executor(cm_mock, dbs_reader).expect("fail to create bca executor");
let bda_executor =
create_bda_executor(cm_mock, dbs_reader).expect("fail to create bca executor");
let resp_res = exec_req_last_blockstamp_out_of_fork_window(&bca_executor).await;
let resp_res = exec_req_last_blockstamp_out_of_fork_window(&bda_executor).await;
assert_eq!(resp_res, Err(ExecReqTypeError("no blockchain".into())));
}
......@@ -84,10 +84,10 @@ mod tests {
.times(1)
.returning(|_, _| Ok(Some(BlockMetaV2::default())));
let bca_executor =
create_bca_executor(cm_mock, dbs_reader).expect("fail to create bca executor");
let bda_executor =
create_bda_executor(cm_mock, dbs_reader).expect("fail to create bca executor");
let resp = exec_req_last_blockstamp_out_of_fork_window(&bca_executor).await?;
let resp = exec_req_last_blockstamp_out_of_fork_window(&bda_executor).await?;
assert_eq!(
resp,
......
......@@ -16,9 +16,9 @@
use crate::*;
pub(super) async fn exec_req_members_count(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
if let Some(members_count) = bca_executor
if let Some(members_count) = bda_executor
.cm_accessor
.get_current_meta(|cm| cm.current_block_meta.members_count)
.await
......@@ -42,10 +42,10 @@ mod tests {
.times(1)
.returning(|f| Some(f(&CurrentMeta::default())));
let dbs_reader = MockDbsReader::new();
let bca_executor =
create_bca_executor(cm_mock, dbs_reader).expect("fail to create bca executor");
let bda_executor =
create_bda_executor(cm_mock, dbs_reader).expect("fail to create bca executor");
let resp_res = exec_req_members_count(&bca_executor).await;
let resp_res = exec_req_members_count(&bda_executor).await;
assert_eq!(resp_res, Ok(BcaRespTypeV0::MembersCount(0)));
}
......
......@@ -15,16 +15,19 @@
use crate::*;
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
pub struct RejectedTx {
pub tx_index: u16,
pub reason: RejectedTxReason,
}
pub(super) async fn exec_req_peers_v1(
bda_executor: &BdaExecutor,
n: usize,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
let dbs_reader = bda_executor.dbs_reader();
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
pub enum RejectedTxReason {
DbError(String),
InvalidTx(String),
MempoolFull,
TxAlreadyWritten,
Ok(BcaRespTypeV0::PeersV10(
bda_executor
.dbs_pool
.execute(move |shared_dbs| dbs_reader.get_some_peers(&shared_dbs.dunp_db, n))
.await??
.into_iter()
.map(|peer_db| peer_db.peer)
.collect(),
))
}
......@@ -14,20 +14,20 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use dubp::bda_types::prepare_payment::{PrepareSimplePayment, PrepareSimplePaymentResp};
use dubp::wallet::prelude::*;
use duniter_bca_types::prepare_payment::{PrepareSimplePayment, PrepareSimplePaymentResp};
pub(super) async fn exec_req_prepare_simple_payment(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
params: PrepareSimplePayment,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
let issuer = params.issuer;
if let Some(current_meta) = bca_executor.cm_accessor.get_current_meta(|cm| *cm).await {
if let Some(current_meta) = bda_executor.cm_accessor.get_current_meta(|cm| *cm).await {
let current_block_meta = current_meta.current_block_meta;
let current_ud = current_meta.current_ud;
let dbs_reader = bca_executor.dbs_reader();
let (amount, block_ref_number, block_ref_hash, (inputs, inputs_sum)) = bca_executor
let dbs_reader = bda_executor.dbs_reader();
let (amount, block_ref_number, block_ref_hash, (inputs, inputs_sum)) = bda_executor
.dbs_pool
.execute(move |dbs| {
let mut amount = params.amount.to_cents(current_ud);
......@@ -95,11 +95,11 @@ mod tests {
.times(1)
.returning(|_| None);
let dbs_reader = MockDbsReader::new();
let bca_executor =
create_bca_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let bda_executor =
create_bda_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let resp_res = exec_req_prepare_simple_payment(
&bca_executor,
&bda_executor,
PrepareSimplePayment {
issuer: PublicKey::default(),
amount: Amount::Cents(SourceAmount::new(42, 0)),
......@@ -122,11 +122,11 @@ mod tests {
.expect_block()
.times(1)
.returning(|_, _| Ok(Some(BlockMetaV2::default())));
let bca_executor =
create_bca_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let bda_executor =
create_bda_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let resp_res = exec_req_prepare_simple_payment(
&bca_executor,
&bda_executor,
PrepareSimplePayment {
issuer: PublicKey::default(),
amount: Amount::Cents(SourceAmount::new(42, 1)),
......@@ -153,11 +153,11 @@ mod tests {
.expect_find_inputs::<TxsMpV2Db<FileBackend>>()
.times(1)
.returning(|_, _, _, _, _| Ok((vec![], SourceAmount::default())));
let bca_executor =
create_bca_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let bda_executor =
create_bda_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let resp_res = exec_req_prepare_simple_payment(
&bca_executor,
&bda_executor,
PrepareSimplePayment {
issuer: PublicKey::default(),
amount: Amount::Cents(SourceAmount::new(42, 0)),
......@@ -195,11 +195,11 @@ mod tests {
.expect_find_inputs::<TxsMpV2Db<FileBackend>>()
.times(1)
.returning(move |_, _, _, _, _| Ok((vec![input], SourceAmount::with_base0(57))));
let bca_executor =
create_bca_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let bda_executor =
create_bda_executor(mock_cm, dbs_reader).expect("fail to create bca executor");
let resp = exec_req_prepare_simple_payment(
&bca_executor,
&bda_executor,
PrepareSimplePayment {
issuer: PublicKey::default(),
amount: Amount::Cents(SourceAmount::new(42, 0)),
......
......@@ -14,20 +14,20 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use dubp::{crypto::keys::KeyPair, documents::transaction::TransactionDocumentTrait};
use duniter_bca_types::{
use dubp::bda_types::{
rejected_tx::{RejectedTx, RejectedTxReason},
Txs,
};
use dubp::{crypto::keys::KeyPair, documents::transaction::TransactionDocumentTrait};
pub(super) async fn send_txs(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
txs: Txs,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
let expected_currency = bca_executor.currency.clone();
let expected_currency = bda_executor.currency.clone();
let server_pubkey = bca_executor.self_keypair.public_key();
let txs_mempool = bca_executor.txs_mempool;
let server_pubkey = bda_executor.self_keypair.public_key();
let txs_mempool = bda_executor.txs_mempool;
let mut rejected_txs = Vec::new();
for (i, tx) in txs.into_iter().enumerate() {
......@@ -36,7 +36,7 @@ pub(super) async fn send_txs(
tx_index: i as u16,
reason: RejectedTxReason::InvalidTx(e.to_string()),
});
} else if let Err(rejected_tx) = bca_executor
} else if let Err(rejected_tx) = bda_executor
.dbs_pool
.execute(move |dbs| {
txs_mempool
......
......@@ -17,23 +17,23 @@ use crate::*;
use dubp::{crypto::keys::ed25519::PublicKey, wallet::prelude::WalletScriptV10};
pub(super) async fn exec_req_first_utxos_of_pubkeys(
bca_executor: &BcaExecutor,
bda_executor: &BdaExecutor,
amount_target_opt: Option<Amount>,
pubkeys: ArrayVec<PublicKey, 16>,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
if let Some(current_ud) = bca_executor
if let Some(current_ud) = bda_executor
.cm_accessor
.get_current_meta(|cm| cm.current_ud)
.await
{
let dbs_reader = bca_executor.dbs_reader();
let dbs_reader = bda_executor.dbs_reader();
let scripts: ArrayVec<WalletScriptV10, 16> = pubkeys
.into_iter()
.map(WalletScriptV10::single_sig)
.collect();
if let Some(amount_target) = amount_target_opt {
Ok(BcaRespTypeV0::FirstUtxosOfPubkeys(
bca_executor
bda_executor
.dbs_pool
.execute(move |_| {
Ok::<_, ExecReqTypeError>(dbs_reader.first_scripts_utxos(
......@@ -46,7 +46,7 @@ pub(super) async fn exec_req_first_utxos_of_pubkeys(
))
} else {
Ok(BcaRespTypeV0::FirstUtxosOfPubkeys(
bca_executor
bda_executor
.dbs_pool
.execute(move |_| dbs_reader.first_scripts_utxos(None, 40, &scripts))
.await??,
......
......@@ -35,11 +35,11 @@ use arrayvec::ArrayVec;
use async_bincode::AsyncBincodeReader;
use async_io_stream::IoStream;
use bincode::Options as _;
use dubp::crypto::keys::{ed25519::Ed25519KeyPair, Signator};
use duniter_bca_types::{
use dubp::bda_types::{
amount::Amount, bincode_opts, identity::Identity, BcaReq, BcaReqExecError, BcaReqTypeV0,
BcaResp, BcaRespTypeV0, BcaRespV0,
};
use dubp::crypto::keys::{ed25519::Ed25519KeyPair, Signator};
pub use duniter_core::dbs::kv_typed::prelude::*;
use duniter_core::dbs::{FileBackend, SharedDbs};
#[cfg(not(test))]
......@@ -56,9 +56,9 @@ use crate::tests::DbsReaderImpl;
#[cfg(not(test))]
use duniter_gva_dbs_reader::DbsReaderImpl;
static BCA_EXECUTOR: OnceCell<BcaExecutor> = OnceCell::new();
static BDA_EXECUTOR: OnceCell<BdaExecutor> = OnceCell::new();
pub fn set_bca_executor(
pub fn set_bda_executor(
currency: String,
cm_accessor: AsyncAccessor,
dbs_pool: fast_threadpool::ThreadPoolAsyncHandler<SharedDbs<FileBackend>>,
......@@ -67,8 +67,8 @@ pub fn set_bca_executor(
software_version: &'static str,
txs_mempool: duniter_core::mempools::TxsMempool,
) {
BCA_EXECUTOR
.set(BcaExecutor {
BDA_EXECUTOR
.set(BdaExecutor {
currency,
cm_accessor,
dbs_pool,
......@@ -77,7 +77,7 @@ pub fn set_bca_executor(
software_version,
txs_mempool,
})
.unwrap_or_else(|_| panic!("BCA_EXECUTOR already set !"))
.unwrap_or_else(|_| panic!("bda_executor already set !"))
}
#[cfg(not(test))]
......@@ -87,7 +87,7 @@ where
S: 'static + TryStream<Ok = B, Error = std::io::Error> + Send + Unpin,
{
unsafe {
BCA_EXECUTOR
BDA_EXECUTOR
.get_unchecked()
.execute(query_body_stream, is_whitelisted)
.await
......@@ -95,7 +95,7 @@ where
}
#[derive(Clone)]
struct BcaExecutor {
struct BdaExecutor {
cm_accessor: AsyncAccessor,
currency: String,
dbs_pool: fast_threadpool::ThreadPoolAsyncHandler<SharedDbs<FileBackend>>,
......@@ -105,7 +105,7 @@ struct BcaExecutor {
txs_mempool: duniter_core::mempools::TxsMempool,
}
use uninit::extension_traits::VecCapacity;
impl BcaExecutor {
impl BdaExecutor {
pub async fn execute<B, S>(&self, query_body_stream: S, is_whitelisted: bool) -> Vec<u8>
where
B: AsRef<[u8]>,
......@@ -214,7 +214,7 @@ impl BcaExecutor {
}
#[cfg(not(test))]
impl BcaExecutor {
impl BdaExecutor {
#[inline(always)]
pub fn dbs_reader(&self) -> DbsReaderImpl {
self.dbs_reader
......@@ -224,6 +224,7 @@ impl BcaExecutor {
#[cfg(test)]
mod tests {
use super::*;
pub use dubp::bda_types::BcaReqV0;
pub use dubp::{
block::prelude::*,
crypto::{
......@@ -233,7 +234,6 @@ mod tests {
documents::transaction::TransactionInputV10,
wallet::prelude::*,
};
pub use duniter_bca_types::BcaReqV0;
pub use duniter_core::dbs::databases::bc_v2::{BcV2DbReadable, BcV2DbRo};
pub use duniter_core::dbs::databases::cm_v1::{CmV1Db, CmV1DbReadable};
pub use duniter_core::dbs::databases::txs_mp_v2::{TxsMpV2Db, TxsMpV2DbReadable};
......@@ -245,21 +245,21 @@ mod tests {
pub type AsyncAccessor = duniter_core::dbs::kv_typed::prelude::Arc<MockAsyncAccessor>;
pub type DbsReaderImpl = duniter_core::dbs::kv_typed::prelude::Arc<MockDbsReader>;
impl BcaExecutor {
impl BdaExecutor {
#[inline(always)]
pub fn dbs_reader(&self) -> DbsReaderImpl {
self.dbs_reader.clone()
}
}
pub(crate) fn create_bca_executor(
pub(crate) fn create_bda_executor(
mock_cm: MockAsyncAccessor,
mock_dbs_reader: MockDbsReader,
) -> KvResult<BcaExecutor> {
) -> KvResult<BdaExecutor> {
let dbs = SharedDbs::mem()?;
let threadpool =
fast_threadpool::ThreadPool::start(fast_threadpool::ThreadPoolConfig::low(), dbs);
Ok(BcaExecutor {
Ok(BdaExecutor {
cm_accessor: duniter_core::dbs::kv_typed::prelude::Arc::new(mock_cm),
currency: "g1".to_owned(),
dbs_pool: threadpool.into_async_handler(),
......@@ -299,11 +299,11 @@ mod tests {
.expect_get_current_meta::<u64>()
.times(1)
.returning(|f| Some(f(&CurrentMeta::default())));
let bca_executor = create_bca_executor(mock_cm, MockDbsReader::new())
let bda_executor = create_bda_executor(mock_cm, MockDbsReader::new())
.expect("fail to create bca executor");
//println!("bytes={:?}", bytes);
let bytes_res = bca_executor.execute(io_stream(bytes), false).await;
let bytes_res = bda_executor.execute(io_stream(bytes), false).await;
//println!("bytes_res={:?}", bytes_res);
let bca_res: Vec<Result<BcaResp, BcaReqExecError>> =
AsyncBincodeReader::<_, Result<BcaResp, BcaReqExecError>>::from(&bytes_res[..])
......@@ -337,11 +337,11 @@ mod tests {
//println!("bytes_for_bincode={:?}", &bytes[4..]);
assert_eq!(req, bincode_opts().deserialize(&bytes[4..])?);
let bca_executor = create_bca_executor(MockAsyncAccessor::new(), MockDbsReader::new())
let bda_executor = create_bda_executor(MockAsyncAccessor::new(), MockDbsReader::new())
.expect("fail to create bca executor");
//println!("bytes={:?}", bytes);
let bytes_res = bca_executor.execute(io_stream(bytes), false).await;
let bytes_res = bda_executor.execute(io_stream(bytes), false).await;
//println!("bytes_res={:?}", bytes_res);
let bca_res: Vec<Result<BcaResp, BcaReqExecError>> =
AsyncBincodeReader::<_, Result<BcaResp, BcaReqExecError>>::from(&bytes_res[..])
......@@ -382,11 +382,11 @@ mod tests {
.expect_get_current_meta::<u64>()
.times(1)
.returning(|f| Some(f(&CurrentMeta::default())));
let bca_executor = create_bca_executor(mock_cm, MockDbsReader::new())
let bda_executor = create_bda_executor(mock_cm, MockDbsReader::new())
.expect("fail to create bca executor");
//println!("bytes={:?}", bytes);
let bytes_res = bca_executor.execute(io_stream(bytes), false).await;
let bytes_res = bda_executor.execute(io_stream(bytes), false).await;
//println!("bytes_res={:?}", bytes_res);
let bca_res: Vec<Result<BcaResp, BcaReqExecError>> =
AsyncBincodeReader::<_, Result<BcaResp, BcaReqExecError>>::from(&bytes_res[..])
......
......@@ -14,7 +14,7 @@ path = "src/lib.rs"
bincode = "1.3"
chrono = { version = "0.4.15", optional = true }
duniter-core = { git = "https://git.duniter.org/nodes/rust/duniter-core" }
dubp = { version = "0.54.1", features = ["duniter"] }
dubp = { version = "0.55.1", features = ["duniter"] }
parking_lot = "0.11.0"
paste = "1.0.2"
serde = { version = "1.0.105", features = ["derive"] }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment