commit 7d9efbb0705fff3ab3d58e374c9d088567e9aec6 parent 535ce15a129cd35a528ef215ec2c739f68dae144 Author: Antoine A <> Date: Tue, 29 Jul 2025 16:12:40 +0200 common: clean project structure Diffstat:
69 files changed, 115 insertions(+), 164 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock @@ -425,18 +425,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] -name = "common" -version = "0.1.0" -dependencies = [ - "rand 0.9.2", - "sqlx", - "taler-common", - "thiserror", - "uri-pack", - "url", -] - -[[package]] name = "concurrent-queue" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -780,9 +768,9 @@ dependencies = [ "bech32", "bitcoin", "clap", - "common", "const-hex", "criterion", + "depolymerizer-common", "rand 0.9.2", "serde", "serde_json", @@ -794,6 +782,19 @@ dependencies = [ "thiserror", "tokio", "tracing", + "url", +] + +[[package]] +name = "depolymerizer-common" +version = "0.1.0" +dependencies = [ + "rand 0.9.2", + "sqlx", + "taler-common", + "thiserror", + "uri-pack", + "url", ] [[package]] @@ -2914,8 +2915,8 @@ dependencies = [ "anyhow", "bitcoin", "clap", - "common", "depolymerizer-bitcoin", + "depolymerizer-common", "indicatif", "owo-colors", "reedline", @@ -2926,6 +2927,7 @@ dependencies = [ "tracing", "tracing-subscriber", "ureq", + "url", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml @@ -1,6 +1,11 @@ [workspace] resolver = "3" -members = ["depolymerizer-bitcoin", "uri-pack", "common", "testbench"] +members = [ + "depolymerizer-bitcoin", + "depolymerizer-common", + "uri-pack", + "testbench", +] [workspace.package] edition = "2024" @@ -28,6 +33,7 @@ url = { version = "2.2", features = ["serde"] } taler-common = { git = "https://git.taler.net/taler-rust.git/" } taler-api = { git = "https://git.taler.net/taler-rust.git/" } taler-test-utils = { git = "https://git.taler.net/taler-rust.git/" } +depolymerizer-common = { path = "depolymerizer-common" } bitcoin = { version = "0.32.5", features = [ "std", "serde", diff --git a/README.md b/README.md @@ -0,0 +1,18 @@ +# Taler Depolymerization + +Depolymerization is a GNU Taler project to create blockchain adapters +(depolymerizer) for the Taler ecosystem. + +## Depolymerizer + +### depolymerizer-bitcoin + +Depolymerizer for the bitcoin blockchain using bitcoind v29. Supports the +[Taler Wire Gateway API](https://docs.taler.net/core/api-bank-wire.html). + +## Project structure + +- **depolymerizer-bitcoin**: Bitcoin Depolymerizer +- **depolymerizer-common**: Depolymerizer common logic +- **uri-pack**: Efficient probabilistic binary encoding for URI +- **testbench**: Offline instrumentation test and online testbench diff --git a/common/Cargo.toml b/common/Cargo.toml @@ -1,19 +0,0 @@ -[package] -name = "common" -version = "0.1.0" -edition.workspace = true -authors.workspace = true -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -sqlx = { workspace = true, features = ["macros"] } -# Url format -url.workspace = true -# Error macros -thiserror.workspace = true -# Optimized uri binary format -uri-pack = { path = "../uri-pack" } -taler-common.workspace = true -rand.workspace = true -\ No newline at end of file diff --git a/common/src/lib.rs b/common/src/lib.rs @@ -1,28 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022-2025 Taler Systems SA - - TALER 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, or (at your option) any later version. - - TALER 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 - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -use rand::{RngCore as _, rngs::ThreadRng}; -pub use taler_common; -pub use url; - -pub mod metadata; -pub mod status; - -/// Secure random slice generator using getrandom -pub fn rand_slice<const N: usize>() -> [u8; N] { - let mut slice = [0; N]; - ThreadRng::default().fill_bytes(&mut slice); - slice -} diff --git a/contrib/ci/jobs/0-codespell/job.sh b/contrib/ci/jobs/0-codespell/job.sh @@ -4,16 +4,15 @@ set -exuo pipefail job_dir=$(dirname "${BASH_SOURCE[0]}") skip=$(cat <<EOF -*/doc/prebuilt/* */.git/* */.ci/* */target/* */contrib/ci/* *.conf *.log +./doc ./uri-pack/src/majestic_million.csv ./uri-pack/src/urltestdata.json -./article-brains22/* ./testbench/env ./testbench/instrumentation EOF diff --git a/depolymerizer-bitcoin/Cargo.toml b/depolymerizer-bitcoin/Cargo.toml @@ -15,7 +15,7 @@ fail = [] [dependencies] bech32 = "0.11.0" serde_repr = "0.1.16" -common = { path = "../common" } +depolymerizer-common.workspace = true bitcoin.workspace = true clap.workspace = true serde.workspace = true @@ -31,6 +31,7 @@ tracing.workspace = true axum.workspace = true base64.workspace = true rand.workspace = true +url.workspace = true [dev-dependencies] criterion.workspace = true @@ -68,12 +69,12 @@ assets = [ ], # Sql [ - "../database-versioning/versioning.sql", + "../depolymerizer-common/db/versioning.sql", "/usr/share/depolymerizer-bitcoin/sql/", "644", ], [ - "../database-versioning/depolymerizer-bitcoin*.sql", + "db/depolymerizer-bitcoin*.sql", "/usr/share/depolymerizer-bitcoin/sql/", "644", ], @@ -89,7 +90,7 @@ assets = [ "/etc", "644", ], - # Man pages + # Man pages [ "../doc/prebuilt/man/depolymerizer-bitcoin.1", "/usr/share/man/man1/", diff --git a/depolymerizer-bitcoin/benches/metadata.rs b/depolymerizer-bitcoin/benches/metadata.rs @@ -14,7 +14,6 @@ use bech32::Hrp; 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 common::rand_slice; use criterion::{Criterion, criterion_group, criterion_main}; use depolymerizer_bitcoin::segwit::{decode_segwit_msg, encode_segwit_key, rand_addresses}; diff --git a/database-versioning/depolymerizer-bitcoin-0001.sql b/depolymerizer-bitcoin/db/depolymerizer-bitcoin-0001.sql diff --git a/database-versioning/depolymerizer-bitcoin-drop.sql b/depolymerizer-bitcoin/db/depolymerizer-bitcoin-drop.sql diff --git a/database-versioning/depolymerizer-bitcoin-procedures.sql b/depolymerizer-bitcoin/db/depolymerizer-bitcoin-procedures.sql diff --git a/depolymerizer-bitcoin/src/bin/segwit-demo.rs b/depolymerizer-bitcoin/src/bin/segwit-demo.rs @@ -2,11 +2,12 @@ use std::str::FromStr; use bech32::Hrp; use bitcoin::{Address, Amount, Network}; -use common::{rand_slice, taler_common::types::base32}; use depolymerizer_bitcoin::{ guess_network, rpc_utils, segwit::{decode_segwit_msg, encode_segwit_addr}, }; +use depolymerizer_common::rand_slice; +use taler_common::types::base32; pub fn main() { let address = Address::from_str("tb1qhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v") diff --git a/depolymerizer-bitcoin/src/db.rs b/depolymerizer-bitcoin/src/db.rs @@ -16,10 +16,7 @@ use bitcoin::{Address, BlockHash}; use bitcoin::{Txid, hashes::Hash}; -use common::{ - status::{BounceStatus, DebitStatus}, - url::Url, -}; +use depolymerizer_common::status::{BounceStatus, DebitStatus}; use sqlx::{ PgExecutor, PgPool, QueryBuilder, Row, postgres::{PgListener, PgRow}, @@ -38,6 +35,7 @@ use taler_common::{ }, }; use tokio::sync::watch::Receiver; +use url::Url; use crate::{ payto::FullBtcPayto, diff --git a/depolymerizer-bitcoin/src/loops/worker.rs b/depolymerizer-bitcoin/src/loops/worker.rs @@ -16,16 +16,12 @@ use std::{fmt::Write, time::SystemTime}; use bitcoin::{Amount as BtcAmount, Txid, hashes::Hash}; -use common::{ - metadata::OutMetadata, - status::BounceStatus, - taler_common::{api_common::ShortHashCode, types::timestamp::Timestamp}, - url::Url, -}; +use depolymerizer_common::{metadata::OutMetadata, status::BounceStatus}; use sqlx::{PgPool, postgres::PgListener}; -use taler_common::ExpoBackoffDecorr; +use taler_common::{api_common::ShortHashCode, types::timestamp::Timestamp, ExpoBackoffDecorr}; use tokio::time::sleep; use tracing::{debug, error, info, trace, warn}; +use url::Url; use crate::{ GetOpReturnErr, GetSegwitErr, diff --git a/depolymerizer-bitcoin/src/segwit.rs b/depolymerizer-bitcoin/src/segwit.rs @@ -14,8 +14,9 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ use bech32::Hrp; -use common::{rand_slice, taler_common::api_common::EddsaPublicKey}; +use depolymerizer_common::rand_slice; use rand::rngs::ThreadRng; +use taler_common::api_common::EddsaPublicKey; use std::cmp::Ordering; // TODO use segwit v1 to only use a single address @@ -140,8 +141,8 @@ pub fn rand_addresses(hrp: Hrp, key: &[u8; 32]) -> Vec<String> { #[cfg(test)] mod test { - use common::taler_common::types::base32::Base32; use rand::{prelude::SliceRandom, rngs::ThreadRng}; + use taler_common::types::base32::Base32; use crate::segwit::{decode_segwit_msg, encode_segwit_key, rand_addresses}; diff --git a/depolymerizer-bitcoin/src/taler_utils.rs b/depolymerizer-bitcoin/src/taler_utils.rs @@ -16,8 +16,7 @@ //! Utils function to convert taler API types to bitcoin API types use bitcoin::{Amount as BtcAmount, SignedAmount}; -use common::taler_common::types::amount::{Amount, FRAC_BASE}; -use taler_common::types::amount::Currency; +use taler_common::types::amount::{Amount, Currency, FRAC_BASE}; /// Transform a btc amount into a taler amount pub fn btc_to_taler(amount: &SignedAmount, currency: &Currency) -> Amount { diff --git a/depolymerizer-common/Cargo.toml b/depolymerizer-common/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "depolymerizer-common" +version = "0.1.0" +edition.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true +license-file.workspace = true + +[dependencies] +sqlx = { workspace = true, features = ["macros"] } +# Url format +url.workspace = true +# Error macros +thiserror.workspace = true +# Optimized uri binary format +uri-pack = { path = "../uri-pack" } +taler-common.workspace = true +rand.workspace = true +\ No newline at end of file diff --git a/database-versioning/versioning.sql b/depolymerizer-common/db/versioning.sql diff --git a/depolymerizer-common/src/lib.rs b/depolymerizer-common/src/lib.rs @@ -0,0 +1,26 @@ +/* + This file is part of TALER + Copyright (C) 2022-2025 Taler Systems SA + + TALER 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, or (at your option) any later version. + + TALER 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 + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +use rand::{RngCore as _, rngs::ThreadRng}; + +pub mod metadata; +pub mod status; + +/// Secure random slice generator using getrandom +pub fn rand_slice<const N: usize>() -> [u8; N] { + let mut slice = [0; N]; + ThreadRng::default().fill_bytes(&mut slice); + slice +} diff --git a/common/src/metadata.rs b/depolymerizer-common/src/metadata.rs diff --git a/common/src/status.rs b/depolymerizer-common/src/status.rs diff --git a/article-brains22/biblio.bib b/doc/article-brains22/biblio.bib diff --git a/article-brains22/depolymerizer.tex b/doc/article-brains22/depolymerizer.tex diff --git a/article-brains22/figures/analysis.tex b/doc/article-brains22/figures/analysis.tex diff --git a/article-brains22/figures/conf_delay.tex b/doc/article-brains22/figures/conf_delay.tex diff --git a/article-brains22/figures/conflict.tex b/doc/article-brains22/figures/conflict.tex diff --git a/article-brains22/figures/depolymerizer_arch.tex b/doc/article-brains22/figures/depolymerizer_arch.tex diff --git a/article-brains22/figures/fork.tex b/doc/article-brains22/figures/fork.tex diff --git a/article-brains22/figures/harmless_reorg.tex b/doc/article-brains22/figures/harmless_reorg.tex diff --git a/article-brains22/figures/settlement_layer.tex b/doc/article-brains22/figures/settlement_layer.tex diff --git a/article-brains22/figures/taler_arch.tex b/doc/article-brains22/figures/taler_arch.tex diff --git a/article-brains22/media/fee.png b/doc/article-brains22/media/fee.png Binary files differ. diff --git a/article-brains22/media/fee_var.png b/doc/article-brains22/media/fee_var.png Binary files differ. diff --git a/article-brains22/media/news0.png b/doc/article-brains22/media/news0.png Binary files differ. diff --git a/article-brains22/media/news1.png b/doc/article-brains22/media/news1.png Binary files differ. diff --git a/article-brains22/media/news2.png b/doc/article-brains22/media/news2.png Binary files differ. diff --git a/article-brains22/media/taler.png b/doc/article-brains22/media/taler.png Binary files differ. diff --git a/article-brains22/rfc.bib b/doc/article-brains22/rfc.bib diff --git a/docs/figures/analysis.tex b/doc/depolymerization/figures/analysis.tex diff --git a/docs/figures/conf_delay.tex b/doc/depolymerization/figures/conf_delay.tex diff --git a/docs/figures/conflict.tex b/doc/depolymerization/figures/conflict.tex diff --git a/docs/figures/depolymerizer_arch.tex b/doc/depolymerization/figures/depolymerizer_arch.tex diff --git a/docs/figures/fork.tex b/doc/depolymerization/figures/fork.tex diff --git a/docs/figures/harmless_reorg.tex b/doc/depolymerization/figures/harmless_reorg.tex diff --git a/docs/figures/reorg.tex b/doc/depolymerization/figures/reorg.tex diff --git a/docs/figures/settlement_layer.tex b/doc/depolymerization/figures/settlement_layer.tex diff --git a/docs/figures/taler_arch.tex b/doc/depolymerization/figures/taler_arch.tex diff --git a/docs/literature.bib b/doc/depolymerization/literature.bib diff --git a/docs/media/fee.png b/doc/depolymerization/media/fee.png Binary files differ. diff --git a/docs/media/fee_var.png b/doc/depolymerization/media/fee_var.png Binary files differ. diff --git a/docs/media/news0.png b/doc/depolymerization/media/news0.png Binary files differ. diff --git a/docs/media/news1.png b/doc/depolymerization/media/news1.png Binary files differ. diff --git a/docs/media/news2.png b/doc/depolymerization/media/news2.png Binary files differ. diff --git a/docs/media/taler.png b/doc/depolymerization/media/taler.png Binary files differ. diff --git a/docs/presentation.tex b/doc/depolymerization/presentation.tex diff --git a/docs/report.tex b/doc/depolymerization/report.tex diff --git a/docs/tables/5-11.tex b/doc/depolymerization/tables/5-11.tex diff --git a/docs/legal.docx b/doc/legal.docx Binary files differ. diff --git a/pres-brains22/electrum.jpg b/doc/pres-brains22/electrum.jpg Binary files differ. diff --git a/pres-brains22/presentation.tex b/doc/pres-brains22/presentation.tex diff --git a/docs/taler-btc-full.conf b/docs/taler-btc-full.conf @@ -1,20 +0,0 @@ -# Full btc-wire configuration -[taler] -CURRENCY = BITCOINBTC - -[exchange] -BASE_URL = http://test.com - -[depolymerizer-bitcoin] -DB_URL = postgres://%2Fvar%2Frun%2Fpostgresql/btc-wire?user=depolymerization -PAYTO = payto://bitcoin/bc1qcr40fzphnh4mcwlv65kvdam4dxq977t2rn54qx -AUTH_METHOD = basic -AUTH_TOKEN = YWRtaW46cGFzc3dvcmQ= -PORT = 8080 -UNIX_PATH = -CONF_PATH = ~/.bitcoin -CONFIRMATION = 6 -BOUNCE_FEE = 0.00001 -HTTP_LIFETIME = 0 -WIRE_LIFETIME = 0 -BUMP_DELAY = 0 diff --git a/docs/taler-btc-min.conf b/docs/taler-btc-min.conf @@ -1,11 +0,0 @@ -# Minimal btc-wire configuration -[taler] -CURRENCY = BITCOINBTC - -[exchange] -BASE_URL = http://test.com - -[depolymerizer-bitcoin] -DB_URL = postgres://%2Fvar%2Frun%2Fpostgresql/btc-wire?user=depolymerization -PAYTO = payto://bitcoin/bc1qcr40fzphnh4mcwlv65kvdam4dxq977t2rn54qx -AUTH_METHOD = none diff --git a/docs/taler-eth-full.conf b/docs/taler-eth-full.conf @@ -1,20 +0,0 @@ -# Full eth-wire configuration -[taler] -CURRENCY = ETHEREUMETH - -[exchange] -BASE_URL = http://test.com - -[depolymerizer-ethereum] -DB_URL = postgres://%2Fvar%2Frun%2Fpostgresql/eth-wire?user=depolymerization -PAYTO = payto://ethereum/425870d7b77ad5665ca982ff85c398222a70fe7c -AUTH_METHOD = basic -AUTH_TOKEN = YWRtaW46cGFzc3dvcmQ= -PORT = 8080 -UNIX_PATH = -IPC_PATH = ~/.ethereum/geth/geth.ipc -CONFIRMATION = 37 -BOUNCE_FEE = 0.00001 -HTTP_LIFETIME = 0 -WIRE_LIFETIME = 0 -BUMP_DELAY = 0 diff --git a/docs/taler-eth-min.conf b/docs/taler-eth-min.conf @@ -1,11 +0,0 @@ -# Minimal eth-wire configuration -[taler] -CURRENCY = ETHEREUMETH - -[exchange] -BASE_URL = http://test.com - -[depolymerizer-ethereum] -DB_URL = postgres://%2Fvar%2Frun%2Fpostgresql/eth-wire?user=depolymerization -PAYTO = payto://ethereum/425870d7b77ad5665ca982ff85c398222a70fe7c -AUTH_METHOD = none diff --git a/makefile b/makefile @@ -20,8 +20,8 @@ build: .PHONY: install-nobuild-files install-nobuild-files: install -m 644 -D -t $(share_dir)/depolymerizer-bitcoin/config.d depolymerizer-bitcoin/depolymerizer-bitcoin.conf - install -m 644 -D -t $(share_dir)/depolymerizer-bitcoin/sql database-versioning/versioning.sql - install -m 644 -D -t $(share_dir)/depolymerizer-bitcoin/sql database-versioning/depolymerizer-bitcoin*.sql + install -m 644 -D -t $(share_dir)/depolymerizer-bitcoin/sql depolymerizer-common/db/versioning.sql + install -m 644 -D -t $(share_dir)/depolymerizer-bitcoin/sql depolymerizer-bitcoin/db/depolymerizer-bitcoin*.sql install -m 644 -D -t $(man_dir)/man1 doc/prebuilt/man/depolymerizer-bitcoin.1 install -m 644 -D -t $(man_dir)/man5 doc/prebuilt/man/depolymerizer-bitcoin.conf.5 diff --git a/testbench/Cargo.toml b/testbench/Cargo.toml @@ -10,7 +10,7 @@ license-file.workspace = true [dependencies] # Cli args parser clap.workspace = true -common = { path = "../common" } +depolymerizer-common.workspace = true # Bitcoin depolymerizer-bitcoin = { path = "../depolymerizer-bitcoin" } bitcoin.workspace = true @@ -29,3 +29,4 @@ anyhow.workspace = true tracing-subscriber.workspace = true tracing.workspace = true sqlx.workspace = true +url.workspace = true diff --git a/testbench/src/btc.rs b/testbench/src/btc.rs @@ -22,10 +22,6 @@ use std::{ }; use bitcoin::{Address, Amount}; -use common::taler_common::{ - api_common::{EddsaPublicKey, ShortHashCode}, - types::base32::Base32, -}; use depolymerizer_bitcoin::{ CONFIG_SOURCE, config::{RpcAuth, RpcCfg, ServeCfg, WorkerCfg}, @@ -34,6 +30,10 @@ use depolymerizer_bitcoin::{ rpc_utils::segwit_min_amount, taler_utils::btc_to_taler, }; +use taler_common::{ + api_common::{EddsaPublicKey, ShortHashCode}, + types::base32::Base32, +}; use ini::Ini; use taler_common::{config::Config, types::payto::Payto}; diff --git a/testbench/src/main.rs b/testbench/src/main.rs @@ -26,7 +26,6 @@ use std::{ use bitcoin::{Address, Txid, address::NetworkUnchecked}; use clap::{Parser, ValueEnum}; -use common::url::Url; use depolymerizer_bitcoin::{ CONFIG_SOURCE, DB_SCHEMA, cli::{Command, run}, @@ -36,6 +35,7 @@ use depolymerizer_bitcoin::{ rpc::{Error, ErrorCode, Rpc, rpc_common, rpc_wallet}, taler_utils::taler_to_btc, }; +use url::Url; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use owo_colors::OwoColorize; use reedline::{Prompt, Reedline, Signal}; diff --git a/testbench/src/utils.rs b/testbench/src/utils.rs @@ -26,16 +26,10 @@ use std::{ time::Duration, }; -use common::{ - taler_common::{ - api_common::{EddsaPublicKey, ShortHashCode}, - api_wire::{IncomingBankTransaction, IncomingHistory, OutgoingHistory, TransferRequest}, - types::{amount::Amount, base32::Base32, payto::PaytoURI}, - }, - url::Url, -}; use indicatif::ProgressBar; use ini::Ini; +use taler_common::{api_common::{EddsaPublicKey, ShortHashCode}, api_wire::{IncomingBankTransaction, IncomingHistory, OutgoingHistory, TransferRequest}, types::{amount::Amount, base32::Base32, payto::PaytoURI}}; +use url::Url; const LOG: &str = "INFO";