commit 6d2599c1b1ed11109b6a7c012167608eca00145e parent 0abc24d093a9208333932c38b377e9e78bb2deaa Author: Antoine A <> Date: Thu, 3 Feb 2022 16:15:52 +0100 Rename taler_common to common as it is less taler specific Diffstat:
40 files changed, 103 insertions(+), 103 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock @@ -154,12 +154,12 @@ dependencies = [ "base64", "bech32", "bitcoin", + "common", "criterion", "rust-ini", "serde", "serde_json", "serde_repr", - "taler-common", "thiserror", "uri-pack", ] @@ -227,6 +227,24 @@ dependencies = [ ] [[package]] +name = "common" +version = "0.1.0" +dependencies = [ + "base32", + "flexi_logger", + "log", + "postgres", + "rand", + "rust-ini", + "serde", + "serde_json", + "serde_with", + "thiserror", + "time", + "url", +] + +[[package]] name = "cpufeatures" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -462,12 +480,12 @@ name = "eth-wire" version = "0.1.0" dependencies = [ "argh", + "common", "ethereum-types", "hex", "serde", "serde_json", "serde_repr", - "taler-common", "thiserror", "uri-pack", ] @@ -1567,24 +1585,6 @@ dependencies = [ ] [[package]] -name = "taler-common" -version = "0.1.0" -dependencies = [ - "base32", - "flexi_logger", - "log", - "postgres", - "rand", - "rust-ini", - "serde", - "serde_json", - "serde_with", - "thiserror", - "time", - "url", -] - -[[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1978,6 +1978,7 @@ name = "wire-gateway" version = "0.1.0" dependencies = [ "bitcoin", + "common", "deadpool-postgres", "ethereum-types", "hyper", @@ -1988,7 +1989,6 @@ dependencies = [ "serde_json", "serde_urlencoded", "serde_with", - "taler-common", "thiserror", "tokio", "tokio-postgres", diff --git a/Cargo.toml b/Cargo.toml @@ -4,5 +4,5 @@ members = [ "btc-wire", "eth-wire", "uri-pack", - "taler-common", + "common", ] diff --git a/btc-wire/Cargo.toml b/btc-wire/Cargo.toml @@ -27,8 +27,8 @@ thiserror = "1.0.30" # Optimized uri binary format uri-pack = { path = "../uri-pack" } base64 = "0.13.0" -# Taler libs -taler-common = { path = "../taler-common" } +# Common lib +common = { path = "../common" } # Ini parser rust-ini = "0.17.0" diff --git a/btc-wire/benches/metadata.rs b/btc-wire/benches/metadata.rs @@ -15,7 +15,7 @@ */ use btc_wire::segwit::{decode_segwit_msg, encode_segwit_key, rand_addresses}; use criterion::{criterion_group, criterion_main, Criterion}; -use taler_common::rand_slice; +use common::rand_slice; fn criterion_benchmark(c: &mut Criterion) { let mut group = c.benchmark_group("SegWit addresses"); diff --git a/btc-wire/src/bin/btc-wire-cli.rs b/btc-wire/src/bin/btc-wire-cli.rs @@ -18,7 +18,7 @@ use btc_wire::{ rpc::{Rpc, Error, ErrorCode}, rpc_utils::default_data_dir, }; -use taler_common::{ +use common::{ config::{Config, CoreConfig}, postgres::{Client, NoTls}, }; diff --git a/btc-wire/src/bin/btc-wire-utils.rs b/btc-wire/src/bin/btc-wire-utils.rs @@ -21,7 +21,7 @@ use btc_wire::{ rpc::{Rpc, Category, Error, ErrorCode}, rpc_utils::default_data_dir, }; -use taler_common::{ +use common::{ config::{Config, CoreConfig}, postgres::{Client, NoTls}, rand_slice, diff --git a/btc-wire/src/config.rs b/btc-wire/src/config.rs @@ -21,7 +21,7 @@ use std::{ }; use bitcoin::Network; -use taler_common::log::log::error; +use common::log::log::error; pub const WIRE_WALLET_NAME: &str = "wire"; diff --git a/btc-wire/src/fail_point.rs b/btc-wire/src/fail_point.rs @@ -21,7 +21,7 @@ pub struct Injected(&'static str); #[allow(unused_variables)] pub fn fail_point(msg: &'static str, prob: f32) -> Result<(), Injected> { #[cfg(feature = "fail")] - return if taler_common::rand::random::<f32>() < prob { + return if common::rand::random::<f32>() < prob { Err(Injected(msg)) } else { Ok(()) diff --git a/btc-wire/src/loops.rs b/btc-wire/src/loops.rs @@ -15,7 +15,7 @@ */ use btc_wire::rpc; -use taler_common::postgres; +use common::postgres; use crate::fail_point::Injected; diff --git a/btc-wire/src/loops/analysis.rs b/btc-wire/src/loops/analysis.rs @@ -16,7 +16,7 @@ use std::sync::atomic::Ordering; use btc_wire::rpc::ChainTipsStatus; -use taler_common::{ +use common::{ config::BtcConfig, log::log::{error, warn}, postgres::fallible_iterator::FallibleIterator, diff --git a/btc-wire/src/loops/watcher.rs b/btc-wire/src/loops/watcher.rs @@ -13,7 +13,7 @@ You should have received a copy of the GNU Affero General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -use taler_common::log::log::error; +use common::log::log::error; use crate::reconnect::{AutoReconnectRPC, AutoReconnectSql}; diff --git a/btc-wire/src/loops/worker.rs b/btc-wire/src/loops/worker.rs @@ -27,7 +27,7 @@ use btc_wire::{ GetOpReturnErr, GetSegwitErr, }; use postgres::{fallible_iterator::FallibleIterator, Client}; -use taler_common::{ +use common::{ api_common::base32, config::BtcConfig, log::log::{error, info, warn}, diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs @@ -21,7 +21,7 @@ use btc_wire::{ }; use reconnect::{AutoReconnectRPC, AutoReconnectSql}; use std::{sync::atomic::AtomicU16, thread::JoinHandle}; -use taler_common::{ +use common::{ config::{load_btc_config, BtcConfig}, log::log::info, }; @@ -41,7 +41,7 @@ pub struct WireState { } fn main() { - taler_common::log::init(); + common::log::init(); let config = load_btc_config(std::env::args_os().nth(1).expect("Missing conf path arg")); let data_dir = config @@ -55,9 +55,9 @@ fn main() { #[cfg(feature = "fail")] if btc_config.network == Network::Regtest { - taler_common::log::log::warn!("Running with random failures"); + common::log::log::warn!("Running with random failures"); } else { - taler_common::log::log::error!("Running with random failures is unsuitable for production"); + common::log::log::error!("Running with random failures is unsuitable for production"); std::process::exit(1); } let chain_name = match btc_config.network { diff --git a/btc-wire/src/metadata.rs b/btc-wire/src/metadata.rs @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ use bitcoin::{hashes::Hash, Txid}; -use taler_common::url::Url; +use common::url::Url; #[derive(Debug, Clone, Copy, thiserror::Error)] pub enum DecodeErr { @@ -91,7 +91,7 @@ impl OutMetadata { #[cfg(test)] mod test { use bitcoin::{hashes::Hash, Txid}; - use taler_common::{rand_slice, url::Url}; + use common::{rand_slice, url::Url}; use crate::metadata::OutMetadata; diff --git a/btc-wire/src/reconnect.rs b/btc-wire/src/reconnect.rs @@ -18,8 +18,8 @@ use std::time::Duration; use btc_wire::{config::BitcoinConfig, rpc::Rpc}; -use taler_common::log::log::error; -use taler_common::postgres::{Client, NoTls}; +use common::log::log::error; +use common::postgres::{Client, NoTls}; const RECONNECT_DELAY: Duration = Duration::from_secs(5); diff --git a/btc-wire/src/segwit.rs b/btc-wire/src/segwit.rs @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ use bech32::{u5, FromBase32, ToBase32, Variant}; -use taler_common::rand::{rngs::OsRng, RngCore}; +use common::rand::{rngs::OsRng, RngCore}; /// Encode metadata into a segwit address fn encode_segwit_addr(hrp: &str, metada: &[u8; 20]) -> String { @@ -122,7 +122,7 @@ pub fn decode_segwit_msg(segwit_addrs: &[impl AsRef<str>]) -> Result<[u8; 32], D // TODO find a way to hide that function while using it in test and benchmark pub fn rand_addresses(hrp: &str, key: &[u8; 32]) -> Vec<String> { - use taler_common::{rand::prelude::SliceRandom, rand_slice}; + use common::{rand::prelude::SliceRandom, rand_slice}; let mut rng_address: Vec<String> = std::iter::repeat_with(|| encode_segwit_addr(hrp, &rand_slice())) @@ -137,7 +137,7 @@ pub fn rand_addresses(hrp: &str, key: &[u8; 32]) -> Vec<String> { #[cfg(test)] mod test { - use taler_common::{ + use common::{ rand::{prelude::SliceRandom, rngs::OsRng}, rand_slice, }; diff --git a/btc-wire/src/sql.rs b/btc-wire/src/sql.rs @@ -15,8 +15,8 @@ */ use bitcoin::{hashes::Hash, Address, Amount as BtcAmount, Txid}; -use taler_common::postgres::Row; -use taler_common::sql::{sql_amount, sql_url}; +use common::postgres::Row; +use common::sql::{sql_amount, sql_url}; use crate::taler_util::{btc_payto_addr, taler_to_btc}; diff --git a/btc-wire/src/taler_util.rs b/btc-wire/src/taler_util.rs @@ -17,8 +17,8 @@ use bitcoin::{Address, Amount as BtcAmount, SignedAmount}; use std::str::FromStr; -use taler_common::api_common::Amount; -use taler_common::url::Url; +use common::api_common::Amount; +use common::url::Url; /// Generate a payto uri from a btc address pub fn btc_payto_url(addr: &Address) -> Url { diff --git a/common/Cargo.toml b/common/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "common" +version = "0.1.0" +edition = "2021" +license = "AGPL-3.0-or-later" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# Serialization framework +serde = { version = "1.0.136", features = ["derive"] } +# Serialization helper +serde_with = "1.11.0" +# JSON serialization +serde_json = "1.0.78" +# Url format +url = { version = "2.2.2", features = ["serde"] } +# Crockford’s base32 +base32 = "0.4.0" +# Error macros +thiserror = "1.0.30" +# Ini files +rust-ini = "0.17.0" +# Logging +log = "0.4.14" +flexi_logger = { version = "0.22.3", default-features = false, features = [ + "use_chrono_for_offset", # Temporary hack for multithreaded code https://rustsec.org/advisories/RUSTSEC-2020-0159 +] } +# Local timz +time = { version = "0.3.7", features = ["formatting", "macros"] } +# Postgres client +postgres = "0.19.2" +# Secure random +rand = { version = "0.8.4", features = ["getrandom"] } diff --git a/taler-common/src/api_common.rs b/common/src/api_common.rs diff --git a/taler-common/src/api_wire.rs b/common/src/api_wire.rs diff --git a/taler-common/src/config.rs b/common/src/config.rs diff --git a/taler-common/src/error_codes.rs b/common/src/error_codes.rs diff --git a/taler-common/src/lib.rs b/common/src/lib.rs diff --git a/taler-common/src/log.rs b/common/src/log.rs diff --git a/taler-common/src/sql.rs b/common/src/sql.rs diff --git a/eth-wire/Cargo.toml b/eth-wire/Cargo.toml @@ -20,5 +20,5 @@ ethereum-types = { version = "0.12.1", default-features = false, features = [ thiserror = "1.0.30" # Optimized uri binary format uri-pack = { path = "../uri-pack" } -# Taler libs -taler-common = { path = "../taler-common" } +# Common lib +common = { path = "../common" } diff --git a/eth-wire/src/bin/eth-wire-cli.rs b/eth-wire/src/bin/eth-wire-cli.rs @@ -16,7 +16,7 @@ use eth_wire::{rpc::Rpc, BlockState}; use ethereum_types::H160; -use taler_common::{ +use common::{ config::{Config, CoreConfig}, postgres::{Client, NoTls}, }; diff --git a/eth-wire/src/bin/eth-wire-utils.rs b/eth-wire/src/bin/eth-wire-utils.rs @@ -5,7 +5,7 @@ use eth_wire::{ taler_util::taler_to_eth, }; use ethereum_types::H160; -use taler_common::{api_common::Amount, rand_slice}; +use common::{api_common::Amount, rand_slice}; /* This file is part of TALER diff --git a/eth-wire/src/lib.rs b/eth-wire/src/lib.rs @@ -17,7 +17,7 @@ use ethereum_types::{Address, H256, U256, U64}; use metadata::{InMetadata, OutMetadata}; use rpc::hex::Hex; -use taler_common::url::Url; +use common::url::Url; pub mod metadata; pub mod rpc; @@ -104,7 +104,7 @@ impl BlockState { #[cfg(test)] mod test { use ethereum_types::{H256, U64}; - use taler_common::{rand::random, rand_slice}; + use common::{rand::random, rand_slice}; use crate::BlockState; diff --git a/eth-wire/src/loops/watcher.rs b/eth-wire/src/loops/watcher.rs @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ use eth_wire::rpc::Rpc; -use taler_common::postgres::Client; +use common::postgres::Client; pub fn watcher(mut rpc: Rpc, mut db: Client) { let mut notifier = rpc.subscribe_new_head().unwrap(); diff --git a/eth-wire/src/loops/worker.rs b/eth-wire/src/loops/worker.rs @@ -21,7 +21,7 @@ use eth_wire::{ taler_util::{eth_payto_url, eth_to_taler}, BlockState, }; -use taler_common::{ +use common::{ api_common::base32, log::log::{error, info}, postgres::{fallible_iterator::FallibleIterator, Client}, diff --git a/eth-wire/src/main.rs b/eth-wire/src/main.rs @@ -22,7 +22,7 @@ use eth_wire::{ }; use ethereum_types::H160; use loops::{watcher::watcher, worker::worker}; -use taler_common::{ +use common::{ config::{load_eth_config, EthConfig}, postgres::{self, Client, NoTls}, }; @@ -52,7 +52,7 @@ pub enum LoopError { pub type LoopResult<T> = Result<T, LoopError>; fn main() { - taler_common::log::init(); + common::log::init(); let path = std::env::args().nth(1).unwrap(); let config = load_eth_config(path); diff --git a/eth-wire/src/metadata.rs b/eth-wire/src/metadata.rs @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -use taler_common::url::Url; +use common::url::Url; use ethereum_types::H256; #[derive(Debug, Clone, Copy, thiserror::Error)] @@ -127,7 +127,7 @@ impl InMetadata { #[cfg(test)] mod test { - use taler_common::{rand_slice, url::Url}; + use common::{rand_slice, url::Url}; use ethereum_types::H256; use crate::metadata::{InMetadata, OutMetadata}; diff --git a/eth-wire/src/sql.rs b/eth-wire/src/sql.rs @@ -15,7 +15,7 @@ */ use eth_wire::taler_util::{eth_payto_addr, taler_to_eth}; use ethereum_types::{H160, U256}; -use taler_common::{ +use common::{ postgres::Row, sql::{sql_amount, sql_url}, }; diff --git a/eth-wire/src/taler_util.rs b/eth-wire/src/taler_util.rs @@ -16,7 +16,7 @@ use std::str::FromStr; use ethereum_types::{Address, U256}; -use taler_common::{api_common::Amount, url::Url}; +use common::{api_common::Amount, url::Url}; const WEI: u64 = 1_000_000_000_000_000_000; const TRUNC: u64 = 10_000_000_000; diff --git a/taler-common/Cargo.toml b/taler-common/Cargo.toml @@ -1,34 +0,0 @@ -[package] -name = "taler-common" -version = "0.1.0" -edition = "2021" -license = "AGPL-3.0-or-later" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -# Serialization framework -serde = { version = "1.0.136", features = ["derive"] } -# Serialization helper -serde_with = "1.11.0" -# JSON serialization -serde_json = "1.0.78" -# Url format -url = { version = "2.2.2", features = ["serde"] } -# Crockford’s base32 -base32 = "0.4.0" -# Error macros -thiserror = "1.0.30" -# Ini files -rust-ini = "0.17.0" -# Logging -log = "0.4.14" -flexi_logger = { version = "0.22.3", default-features = false, features = [ - "use_chrono_for_offset", # Temporary hack for multithreaded code https://rustsec.org/advisories/RUSTSEC-2020-0159 -] } -# Local timz -time = { version = "0.3.7", features = ["formatting", "macros"] } -# Postgres client -postgres = "0.19.2" -# Secure random -rand = { version = "0.8.4", features = ["getrandom"] } diff --git a/wire-gateway/Cargo.toml b/wire-gateway/Cargo.toml @@ -29,8 +29,8 @@ tokio-postgres = { version = "0.7.5" } deadpool-postgres = "0.10.1" # Socket activation listenfd = "0.5.0" -# Taler libs -taler-common = { path = "../taler-common" } +# Common lib +common = { path = "../common" } # Bitcoin types bitcoin = { version = "0.27.1", optional = true } # Euthereum types diff --git a/wire-gateway/src/error.rs b/wire-gateway/src/error.rs @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ use hyper::{header, Body, Response, StatusCode}; -use taler_common::{api_common::ErrorDetail, error_codes::ErrorCode}; +use common::{api_common::ErrorDetail, error_codes::ErrorCode}; /// Generic http error #[derive(Debug)] diff --git a/wire-gateway/src/main.rs b/wire-gateway/src/main.rs @@ -28,7 +28,7 @@ use std::{ sync::atomic::{AtomicBool, AtomicU32, Ordering}, time::{Duration, Instant}, }; -use taler_common::{ +use common::{ api_common::{ShortHashCode, Timestamp}, api_wire::{ HistoryParams, IncomingBankTransaction, IncomingHistory, OutgoingBankTransaction, @@ -86,13 +86,13 @@ impl ServerState { #[tokio::main] async fn main() { - taler_common::log::init(); + common::log::init(); let conf = GatewayConfig::load_from_file(std::env::args_os().nth(1).expect("Missing conf path arg")); #[cfg(feature = "test")] - taler_common::log::log::warn!("Running with test admin endpoint unsuitable for production"); + common::log::log::warn!("Running with test admin endpoint unsuitable for production"); // Parse postgres url let config = tokio_postgres::Config::from_str(&conf.core.db_url).unwrap(); @@ -434,7 +434,7 @@ async fn router( "/admin/add-incoming" => { // We do not check input as this is a test admin endpoint assert_method(&parts, Method::POST).unwrap(); - let request: taler_common::api_wire::AddIncomingRequest = + let request: common::api_wire::AddIncomingRequest = parse_body(&parts, body).await.unwrap(); let timestamp = Timestamp::now(); let db = state.pool.get().await.catch_code(