[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-depolymerization] branch master updated (fb88a48 -> 9eabce5)
From: |
gnunet |
Subject: |
[taler-depolymerization] branch master updated (fb88a48 -> 9eabce5) |
Date: |
Thu, 03 Feb 2022 18:26:37 +0100 |
This is an automated email from the git hooks/post-receive script.
antoine pushed a change to branch master
in repository depolymerization.
from fb88a48 presentation: progress
new cfb5da3 wire-gateway: support eth and btc
new 0abc24d presentation: progress
new 6d2599c Rename taler_common to common as it is less taler specific
new 9eabce5 Remove Delayed transaction status
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.gitignore | 2 +-
Cargo.lock | 43 ++--
Cargo.toml | 2 +-
README.md | 29 +--
btc-wire/Cargo.toml | 4 +-
btc-wire/README.md | 60 +----
btc-wire/benches/metadata.rs | 2 +-
btc-wire/src/bin/btc-wire-cli.rs | 2 +-
btc-wire/src/bin/btc-wire-utils.rs | 2 +-
btc-wire/src/config.rs | 2 +-
btc-wire/src/fail_point.rs | 2 +-
btc-wire/src/loops.rs | 2 +-
btc-wire/src/loops/analysis.rs | 2 +-
btc-wire/src/loops/watcher.rs | 2 +-
btc-wire/src/loops/worker.rs | 101 +++-----
btc-wire/src/main.rs | 15 +-
btc-wire/src/metadata.rs | 12 +-
btc-wire/src/reconnect.rs | 4 +-
btc-wire/src/segwit.rs | 6 +-
btc-wire/src/sql.rs | 4 +-
btc-wire/src/status.rs | 69 -----
btc-wire/src/taler_util.rs | 4 +-
{taler-common => common}/Cargo.toml | 2 +-
{taler-common => common}/src/api_common.rs | 0
{taler-common => common}/src/api_wire.rs | 0
{taler-common => common}/src/config.rs | 0
{taler-common => common}/src/error_codes.rs | 0
{taler-common => common}/src/lib.rs | 1 +
{taler-common => common}/src/log.rs | 0
{taler-common => common}/src/sql.rs | 0
{eth-wire => common}/src/status.rs | 37 +--
docs/{ => media}/fee.png | Bin
docs/media/news0.png | Bin 0 -> 45301 bytes
docs/media/news1.png | Bin 0 -> 367250 bytes
docs/media/news2.png | Bin 0 -> 36734 bytes
docs/{ => media}/taler.png | Bin
docs/presentation.tex | 376 ++++++++++++++++------------
eth-wire/Cargo.toml | 4 +-
eth-wire/src/bin/eth-wire-cli.rs | 2 +-
eth-wire/src/bin/eth-wire-utils.rs | 2 +-
eth-wire/src/lib.rs | 4 +-
eth-wire/src/loops/watcher.rs | 2 +-
eth-wire/src/loops/worker.rs | 46 ++--
eth-wire/src/main.rs | 17 +-
eth-wire/src/metadata.rs | 4 +-
eth-wire/src/sql.rs | 2 +-
eth-wire/src/taler_util.rs | 2 +-
makefile | 2 +-
test/common.sh | 2 +-
wire-gateway/Cargo.toml | 23 +-
wire-gateway/src/error.rs | 2 +-
wire-gateway/src/main.rs | 42 ++--
52 files changed, 436 insertions(+), 507 deletions(-)
delete mode 100644 btc-wire/src/status.rs
rename {taler-common => common}/Cargo.toml (97%)
rename {taler-common => common}/src/api_common.rs (100%)
rename {taler-common => common}/src/api_wire.rs (100%)
rename {taler-common => common}/src/config.rs (100%)
rename {taler-common => common}/src/error_codes.rs (100%)
rename {taler-common => common}/src/lib.rs (98%)
rename {taler-common => common}/src/log.rs (100%)
rename {taler-common => common}/src/sql.rs (100%)
rename {eth-wire => common}/src/status.rs (65%)
rename docs/{ => media}/fee.png (100%)
create mode 100644 docs/media/news0.png
create mode 100644 docs/media/news1.png
create mode 100644 docs/media/news2.png
rename docs/{ => media}/taler.png (100%)
diff --git a/.gitignore b/.gitignore
index 1d69ca7..0512646 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,4 @@ log
/docs/*
!/docs/*.docx
!/docs/*.tex
-!/docs/*.png
\ No newline at end of file
+!/docs/media
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index b4e5c13..e845d2b 100644
--- 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",
]
@@ -226,6 +226,24 @@ dependencies = [
"unicode-width",
]
+[[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"
@@ -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",
]
@@ -1566,24 +1584,6 @@ dependencies = [
"unicode-xid",
]
-[[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"
@@ -1978,7 +1978,9 @@ name = "wire-gateway"
version = "0.1.0"
dependencies = [
"bitcoin",
+ "common",
"deadpool-postgres",
+ "ethereum-types",
"hyper",
"hyperlocal",
"listenfd",
@@ -1987,7 +1989,6 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"serde_with",
- "taler-common",
"thiserror",
"tokio",
"tokio-postgres",
diff --git a/Cargo.toml b/Cargo.toml
index 4cf8132..d8063ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,5 +4,5 @@ members = [
"btc-wire",
"eth-wire",
"uri-pack",
- "taler-common",
+ "common",
]
diff --git a/README.md b/README.md
index 48ab3da..7fab976 100644
--- a/README.md
+++ b/README.md
@@ -40,25 +40,20 @@ HTTP_LIFETIME = 0
WIRE_LIFETIME = 0
```
-Modules have specific configuration:
-
-- [wire-gateway](wire-gateway/README.md#Configuration)
-- [btc-wire](btc-wire/README.md#Configuration)
+### Stuck transaction
-## Architecture
+When a transaction is sent with a fee too small compared to other transaction,
+it can take an unlimited amount of time for this transaction to be mined. It is
+possible to replace this transaction with another transaction with more fees.
+Depolymerizer can be configured to do this automatically:
-### Linking Taler to blockchains
-
-```
- ┌─────┐ ┌────────────────┐ ┌──────────┐
- │Taler│◄─►│Depolymerization│◄─►│Blockchain│
- └─────┘ └────────────────┘ └──────────┘
+``` ini
+[depolymerizer-___]
+# Delay in seconds before bumping an unconfirmed transaction fee (0 mean never)
+BUMP_DELAY = 0
```
-### Depolymerization architecture
+Modules have specific configuration:
-```
- ┌────────────┐ ┌──────────┐ ┌────────┐
- │wire_gateway│◄─►│PostgreSQL│◄─►│###_wire│
- └────────────┘ └──────────┘ └────────┘
-```
\ No newline at end of file
+- [wire-gateway](wire-gateway/README.md#Configuration)
+- [btc-wire](btc-wire/README.md#Configuration)
\ No newline at end of file
diff --git a/btc-wire/Cargo.toml b/btc-wire/Cargo.toml
index 3714840..a7606ae 100644
--- 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/README.md b/btc-wire/README.md
index ee6e472..fa567c0 100644
--- a/btc-wire/README.md
+++ b/btc-wire/README.md
@@ -22,7 +22,6 @@ The configuration is based on
[taler.conf](https://docs.taler.net/manpages/taler
DATA_DIR =
CONFIRMATION = 6
BOUNCE_FEE = 1000
-BUMP_DELAY =
```
### bitcoin.conf
@@ -41,62 +40,9 @@ the RPC server, `txindex=1` and `maxtxfee` are mandatory.
7. Run wire-gateway `wire-gateway`
8. Run btc-wire `btc-wire`
-## How it work ?
-
-
-### Outgoing transaction lifecycle
-
-#### Transaction lifecycle
-
-```
- │
- ▼
- ┌─────────┐
- ┌─┤Requested├─┐
- │ └─────────┘ │
- ▼ ▼
- ┌────┐ ┌───────┐
- │Sent│◄────►│Delayed│
- └────┘ └───────┘
-
- -> Requested API request
-Requested -> Sent Sent in the blockchain
-Requested -> Delayed Error while sending
-Delayed -> Sent Sent in the blockchain
-Send -> Delayed Conflicting transaction (reorg)
-```
-
-#### Bounce lifecycle
-
-```
- │
- ▼
- ┌─────────┐
- ┌─────┤Requested├────┐
- │ └────┬────┘ │
- ▼ ▼ ▼
- ┌────┐ ┌───────┐ ┌───────┐
- │Sent│◄─►│Delayed│ │Ignored│
- └────┘ └───────┘ └───────┘
-
- -> Requested Transaction in wrong format
-Requested -> Sent Sent in the blockchain
-Requested -> Ignored Insufficient amount
-Requested -> Delayed Error while sending
-Delayed -> Sent Sent in the blockchain
-Send -> Delayed Conflicting transaction (reorg)
-```
+## Implementation details
### Stuck transaction
-When a transaction is sent with a fee too small compared to other transaction,
-it can take an unlimited amount of time for this transaction to be mined. It is
-possible to replace this transaction with another transaction with more fees
-using [BIP
125](https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki).
-btc-wire can be configured to do this automatically:
-
-``` ini
-[depolymerizer-bitcoin]
-# Delay in seconds before bumping an unconfirmed transaction fee
-BUMP_DELAY = 10
-```
+We resolve stuck transaction by always sending replaceable transaction
+using [BIP
125](https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki).
\ No newline at end of file
diff --git a/btc-wire/benches/metadata.rs b/btc-wire/benches/metadata.rs
index da6f557..6a2af8a 100644
--- 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
index 47f3096..c070006 100644
--- 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
index b058656..bbda3f4 100644
--- 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
index bdb23fa..5f1cf7d 100644
--- 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
index ad88b3a..2a482de 100644
--- 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
index 3ad4ae8..468fb39 100644
--- 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
index dd0a562..dbe3fe7 100644
--- 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
index 6d74fa1..dee688f 100644
--- 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
index e752b50..518ac00 100644
--- a/btc-wire/src/loops/worker.rs
+++ b/btc-wire/src/loops/worker.rs
@@ -22,25 +22,25 @@ use std::{
use bitcoin::{hashes::Hash, Amount as BtcAmount, BlockHash, Txid};
use btc_wire::{
- rpc::{self, Rpc, Category, ErrorCode, TransactionFull},
+ rpc::{self, Category, ErrorCode, Rpc, TransactionFull},
rpc_utils::sender_address,
GetOpReturnErr, GetSegwitErr,
};
-use postgres::{fallible_iterator::FallibleIterator, Client};
-use taler_common::{
+use common::{
api_common::base32,
config::BtcConfig,
log::log::{error, info, warn},
postgres,
sql::{sql_array, sql_url},
+ status::{BounceStatus, WithdrawStatus},
};
+use postgres::{fallible_iterator::FallibleIterator, Client};
use crate::{
fail_point::fail_point,
metadata::OutMetadata,
reconnect::{AutoReconnectRPC, AutoReconnectSql},
sql::{sql_addr, sql_btc_amount, sql_txid},
- status::{BounceStatus, TxStatus},
taler_util::{btc_payto_url, btc_to_taler},
WireState,
};
@@ -108,16 +108,12 @@ pub fn worker(
// As we are now in sync with the blockchain if a transaction is
in requested or delayed state it have not been sent
- // Send delayed transactions
- while send(db, rpc, TxStatus::Delayed)? {}
- // Send requested transactions
- while send(db, rpc, TxStatus::Requested)? {}
+ // Send requested withdraws
+ while withdraw(db, rpc)? {}
let bounce_fee = BtcAmount::from_sat(config.bounce_fee);
- // Send delayed bounce
- while bounce(db, rpc, BounceStatus::Delayed, &bounce_fee)? {}
// Send requested bounce
- while bounce(db, rpc, BounceStatus::Requested, &bounce_fee)? {}
+ while bounce(db, rpc, &bounce_fee)? {}
Ok(())
})();
@@ -138,13 +134,12 @@ pub fn worker(
}
}
-/// Send atransaction on the blockchain, return true if more transactions with
the same status remains
-fn send(db: &mut Client, rpc: &mut Rpc, status: TxStatus) -> LoopResult<bool> {
- assert!(status == TxStatus::Delayed || status == TxStatus::Requested);
+/// Send a withdraw transaction on the blockchain, return false if no more
requested transaction are found
+fn withdraw(db: &mut Client, rpc: &mut Rpc) -> LoopResult<bool> {
// We rely on the advisory lock to ensure we are the only one sending
transactions
let row = db.query_opt(
"SELECT id, amount, wtid, credit_acc, exchange_url FROM tx_out WHERE
status=$1 ORDER BY _date LIMIT 1",
- &[&(status as i16)],
+ &[&(WithdrawStatus::Requested as i16)],
)?;
if let Some(row) = &row {
let id: i32 = row.get(0);
@@ -152,50 +147,33 @@ fn send(db: &mut Client, rpc: &mut Rpc, status: TxStatus)
-> LoopResult<bool> {
let wtid: [u8; 32] = sql_array(row, 2);
let addr = sql_addr(row, 3);
let url = sql_url(row, 4);
- let info = OutMetadata::Transaction { wtid, url };
- let metadata = info.encode();
+ let metadata = OutMetadata::Withdraw { wtid, url };
- match rpc.send_op_return(&addr, &amount, &metadata, false, true) {
- Ok(tx_id) => {
- fail_point("(injected) fail send", 0.3)?;
- db.execute(
- "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3",
- &[&(TxStatus::Sent as i16), &tx_id.as_ref(), &id],
- )?;
- let amount = btc_to_taler(&amount.to_signed().unwrap());
- info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id,
addr);
- }
- Err(e) => {
- db.execute(
- "UPDATE tx_out SET status=$1 WHERE id=$2",
- &[&(TxStatus::Delayed as i16), &id],
- )?;
- Err(e)?;
- }
- }
+ let tx_id = rpc.send_op_return(&addr, &amount, &metadata.encode(),
false, true)?;
+ fail_point("(injected) fail send", 0.3)?;
+ db.execute(
+ "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3",
+ &[&(WithdrawStatus::Sent as i16), &tx_id.as_ref(), &id],
+ )?;
+ let amount = btc_to_taler(&amount.to_signed().unwrap());
+ info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id, addr);
}
Ok(row.is_some())
}
-/// Bounce a transaction on the blockchain, return true if more bounce with
the same status remains
-fn bounce(
- db: &mut Client,
- rpc: &mut Rpc,
- status: BounceStatus,
- fee: &BtcAmount,
-) -> LoopResult<bool> {
- assert!(status == BounceStatus::Delayed || status ==
BounceStatus::Requested);
+/// Bounce a transaction on the blockchain, return false if nor more requested
transaction are found
+fn bounce(db: &mut Client, rpc: &mut Rpc, fee: &BtcAmount) -> LoopResult<bool>
{
// We rely on the advisory lock to ensure we are the only one sending
transactions
let row = db.query_opt(
"SELECT id, bounced FROM bounce WHERE status=$1 ORDER BY _date LIMIT
1",
- &[&(status as i16)],
+ &[&(BounceStatus::Requested as i16)],
)?;
if let Some(row) = &row {
let id: i32 = row.get(0);
let bounced: Txid = sql_txid(row, 1);
- let info = OutMetadata::Bounce { bounced };
+ let metadata = OutMetadata::Bounce { bounced };
- match rpc.bounce(&bounced, fee, &info.encode()) {
+ match rpc.bounce(&bounced, fee, &metadata.encode()) {
Ok(it) => {
fail_point("(injected) fail bounce", 0.3)?;
db.execute(
@@ -215,13 +193,7 @@ fn bounce(
)?;
info!("|| (ignore) {} because {}", &bounced, msg);
}
- e => {
- db.execute(
- "UPDATE bounce SET status=$1 WHERE id=$2",
- &[&(BounceStatus::Delayed as i16), &id],
- )?;
- Err(e)?;
- }
+ e => Err(e)?,
},
}
}
@@ -404,7 +376,7 @@ fn sync_chain_outgoing(
.map(|(full, bytes)| (full, OutMetadata::decode(&bytes)))
{
Ok((full, Ok(info))) => match info {
- OutMetadata::Transaction { wtid, .. } => {
+ OutMetadata::Withdraw { wtid, .. } => {
sync_chain_outgoing_send(id, &full, &wtid, rpc, db,
confirmations, config)?
}
OutMetadata::Bounce { bounced } => {
@@ -438,7 +410,7 @@ fn sync_chain_outgoing_send(
// Handle conflicting tx
let nb_row = db.execute(
"UPDATE tx_out SET status=$1, txid=NULL where txid=$2",
- &[&(TxStatus::Delayed as i16), &id.as_ref()],
+ &[&(WithdrawStatus::Requested as i16), &id.as_ref()],
)?;
if nb_row > 0 {
warn!(
@@ -459,11 +431,16 @@ fn sync_chain_outgoing_send(
// If already in database, sync status
let row_id: i32 = row.get(0);
let status: i16 = row.get(1);
- match TxStatus::try_from(status as u8).unwrap() {
- TxStatus::Requested | TxStatus::Delayed => {
+ match WithdrawStatus::try_from(status as u8).unwrap() {
+ WithdrawStatus::Requested => {
let nb_row = db.execute(
"UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3 AND
status=$4",
- &[&(TxStatus::Sent as i16), &id.as_ref(), &row_id,
&status],
+ &[
+ &(WithdrawStatus::Sent as i16),
+ &id.as_ref(),
+ &row_id,
+ &status,
+ ],
)?;
if nb_row > 0 {
warn!(
@@ -475,7 +452,7 @@ fn sync_chain_outgoing_send(
);
}
}
- TxStatus::Sent => {
+ WithdrawStatus::Sent => {
if let Some(txid) = full.replaces_txid {
let stored_id = sql_txid(&row, 2);
if txid == stored_id {
@@ -501,7 +478,7 @@ fn sync_chain_outgoing_send(
let date = SystemTime::UNIX_EPOCH + Duration::from_secs(full.time);
let nb = db.execute(
"INSERT INTO tx_out (_date, amount, wtid, debit_acc,
credit_acc, exchange_url, status, txid, request_uid) VALUES ($1, $2, $3, $4,
$5, $6, $7, $8, $9) ON CONFLICT (wtid) DO NOTHING",
- &[&date, &amount.to_string(), &wtid.as_ref(),
&btc_payto_url(&debit_addr).as_ref(), &btc_payto_url(credit_addr).as_ref(),
&config.base_url.as_ref(), &(TxStatus::Sent as i16), &id.as_ref(),
&None::<&[u8]>],
+ &[&date, &amount.to_string(), &wtid.as_ref(),
&btc_payto_url(&debit_addr).as_ref(), &btc_payto_url(credit_addr).as_ref(),
&config.base_url.as_ref(), &(WithdrawStatus::Sent as i16), &id.as_ref(),
&None::<&[u8]>],
)?;
if nb > 0 {
warn!(
@@ -551,7 +528,7 @@ fn sync_chain_outgoing_bounce(
// Handle conflicting tx
let nb_row = db.execute(
"UPDATE bounce SET status=$1, txid=NULL where txid=$2",
- &[&(BounceStatus::Delayed as i16), &id.as_ref()],
+ &[&(BounceStatus::Requested as i16), &id.as_ref()],
)?;
if nb_row > 0 {
warn!("|| (conflict) {} in {}", &bounced, &id);
@@ -567,7 +544,7 @@ fn sync_chain_outgoing_bounce(
let row_id: i32 = row.get(0);
let status: i16 = row.get(1);
match BounceStatus::try_from(status as u8).unwrap() {
- BounceStatus::Requested | BounceStatus::Delayed => {
+ BounceStatus::Requested => {
let nb_row = db.execute(
"UPDATE bounce SET status=$1, txid=$2 WHERE id=$3 AND
status=$4",
&[&(BounceStatus::Sent as i16), &id.as_ref(), &row_id,
&status],
diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs
index 0325253..e2495f7 100644
--- a/btc-wire/src/main.rs
+++ b/btc-wire/src/main.rs
@@ -19,21 +19,20 @@ use btc_wire::{
rpc::Rpc,
rpc_utils::default_data_dir,
};
-use reconnect::{AutoReconnectRPC, AutoReconnectSql};
-use std::{sync::atomic::AtomicU16, thread::JoinHandle};
-use taler_common::{
+use common::{
config::{load_btc_config, BtcConfig},
log::log::info,
};
+use reconnect::{AutoReconnectRPC, AutoReconnectSql};
+use std::{sync::atomic::AtomicU16, thread::JoinHandle};
use crate::loops::{analysis::analysis, watcher::watcher, worker::worker};
mod fail_point;
-mod metadata;
mod loops;
+mod metadata;
mod reconnect;
mod sql;
-mod status;
mod taler_util;
pub struct WireState {
@@ -41,7 +40,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 +54,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
index 43fd1c4..7618cfb 100644
--- 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 {
@@ -33,7 +33,7 @@ pub enum DecodeErr {
/// Encoded metadata for outgoing transaction
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OutMetadata {
- Transaction { wtid: [u8; 32], url: Url },
+ Withdraw { wtid: [u8; 32], url: Url },
Bounce { bounced: Txid },
}
@@ -44,7 +44,7 @@ impl OutMetadata {
pub fn encode(&self) -> Vec<u8> {
let mut buffer = Vec::new();
match self {
- OutMetadata::Transaction { wtid, url } => {
+ OutMetadata::Withdraw { wtid, url } => {
buffer.push(if url.scheme() == "http" { 1 } else { 0 });
buffer.extend_from_slice(wtid);
let parts = format!("{}{}", url.domain().unwrap_or(""),
url.path());
@@ -75,7 +75,7 @@ impl OutMetadata {
uri_pack::unpack_uri(&bytes[33..])?,
);
let url = Url::parse(&packed).unwrap();
- Ok(OutMetadata::Transaction {
+ Ok(OutMetadata::Withdraw {
wtid: bytes[1..33].try_into().unwrap(),
url,
})
@@ -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;
@@ -106,7 +106,7 @@ mod test {
for url in urls {
let wtid = rand_slice();
let url = Url::parse(url).unwrap();
- let info = OutMetadata::Transaction { wtid, url };
+ let info = OutMetadata::Withdraw { wtid, url };
let encoded = info.encode();
let decoded = OutMetadata::decode(&encoded).unwrap();
assert_eq!(decoded, info);
diff --git a/btc-wire/src/reconnect.rs b/btc-wire/src/reconnect.rs
index a3f15fd..1869f7e 100644
--- 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
index 76e00d0..414ef75 100644
--- 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
index edcfcf3..a98b1f4 100644
--- 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/status.rs b/btc-wire/src/status.rs
deleted file mode 100644
index 3ad45f9..0000000
--- a/btc-wire/src/status.rs
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 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/>
-*/
-//! Transactions status in database
-
-/// Outgoing transaction status
-#[repr(u8)]
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum TxStatus {
- /// Client have ask for a transaction (default)
- Requested = 0,
- /// The wire failed to send this transaction and will try later
- Delayed = 1,
- /// Transaction have been announced to the bitcoin network
- Sent = 2,
-}
-
-impl TryFrom<u8> for TxStatus {
- type Error = ();
-
- fn try_from(v: u8) -> Result<Self, Self::Error> {
- match v {
- x if x == TxStatus::Requested as u8 => Ok(TxStatus::Requested),
- x if x == TxStatus::Sent as u8 => Ok(TxStatus::Sent),
- x if x == TxStatus::Delayed as u8 => Ok(TxStatus::Delayed),
- _ => Err(()),
- }
- }
-}
-
-/// Bounce transaction status
-#[repr(u8)]
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum BounceStatus {
- /// Bounce have been requested (default)
- Requested = 0,
- /// The wire failed to send this bounce and will try later
- Delayed = 1,
- /// Bounce will not be sent (e.g: bounce amount smaller than bounce fee)
- Ignored = 2,
- /// Bounce have been announced to the bitcoin network
- Sent = 3,
-}
-
-impl TryFrom<u8> for BounceStatus {
- type Error = ();
-
- fn try_from(v: u8) -> Result<Self, Self::Error> {
- match v {
- x if x == BounceStatus::Requested as u8 =>
Ok(BounceStatus::Requested),
- x if x == BounceStatus::Sent as u8 => Ok(BounceStatus::Sent),
- x if x == BounceStatus::Delayed as u8 => Ok(BounceStatus::Delayed),
- x if x == BounceStatus::Ignored as u8 => Ok(BounceStatus::Ignored),
- _ => Err(()),
- }
- }
-}
diff --git a/btc-wire/src/taler_util.rs b/btc-wire/src/taler_util.rs
index 133e4a3..e9a48a4 100644
--- 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/taler-common/Cargo.toml b/common/Cargo.toml
similarity index 97%
rename from taler-common/Cargo.toml
rename to common/Cargo.toml
index a18afea..da28284 100644
--- a/taler-common/Cargo.toml
+++ b/common/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "taler-common"
+name = "common"
version = "0.1.0"
edition = "2021"
license = "AGPL-3.0-or-later"
diff --git a/taler-common/src/api_common.rs b/common/src/api_common.rs
similarity index 100%
rename from taler-common/src/api_common.rs
rename to common/src/api_common.rs
diff --git a/taler-common/src/api_wire.rs b/common/src/api_wire.rs
similarity index 100%
rename from taler-common/src/api_wire.rs
rename to common/src/api_wire.rs
diff --git a/taler-common/src/config.rs b/common/src/config.rs
similarity index 100%
rename from taler-common/src/config.rs
rename to common/src/config.rs
diff --git a/taler-common/src/error_codes.rs b/common/src/error_codes.rs
similarity index 100%
rename from taler-common/src/error_codes.rs
rename to common/src/error_codes.rs
diff --git a/taler-common/src/lib.rs b/common/src/lib.rs
similarity index 98%
rename from taler-common/src/lib.rs
rename to common/src/lib.rs
index 8bdf0ec..0ed82e1 100644
--- a/taler-common/src/lib.rs
+++ b/common/src/lib.rs
@@ -24,6 +24,7 @@ pub mod config;
pub mod error_codes;
pub mod log;
pub mod sql;
+pub mod status;
/// Secure random slice generator using getrandom
pub fn rand_slice<const N: usize>() -> [u8; N] {
diff --git a/taler-common/src/log.rs b/common/src/log.rs
similarity index 100%
rename from taler-common/src/log.rs
rename to common/src/log.rs
diff --git a/taler-common/src/sql.rs b/common/src/sql.rs
similarity index 100%
rename from taler-common/src/sql.rs
rename to common/src/sql.rs
diff --git a/eth-wire/src/status.rs b/common/src/status.rs
similarity index 65%
rename from eth-wire/src/status.rs
rename to common/src/status.rs
index 3ad45f9..b9e2493 100644
--- a/eth-wire/src/status.rs
+++ b/common/src/status.rs
@@ -15,43 +15,47 @@
*/
//! Transactions status in database
-/// Outgoing transaction status
+/// Withdraw transaction status
+///
+/// -> Requested API request
+/// Requested -> Sent Announced to the bitcoin network
+/// Sent -> Requested Conflicting transaction (reorg)
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum TxStatus {
- /// Client have ask for a transaction (default)
+pub enum WithdrawStatus {
+ /// Withdraw have been requested (default)
Requested = 0,
- /// The wire failed to send this transaction and will try later
- Delayed = 1,
- /// Transaction have been announced to the bitcoin network
- Sent = 2,
+ /// Withdraw have been announced to the bitcoin network
+ Sent = 1,
}
-impl TryFrom<u8> for TxStatus {
+impl TryFrom<u8> for WithdrawStatus {
type Error = ();
fn try_from(v: u8) -> Result<Self, Self::Error> {
match v {
- x if x == TxStatus::Requested as u8 => Ok(TxStatus::Requested),
- x if x == TxStatus::Sent as u8 => Ok(TxStatus::Sent),
- x if x == TxStatus::Delayed as u8 => Ok(TxStatus::Delayed),
+ x if x == WithdrawStatus::Requested as u8 =>
Ok(WithdrawStatus::Requested),
+ x if x == WithdrawStatus::Sent as u8 => Ok(WithdrawStatus::Sent),
_ => Err(()),
}
}
}
/// Bounce transaction status
+///
+/// -> Requested Deposit in wrong format
+/// Requested -> Ignored Insufficient found
+/// Requested -> Sent Announced to the bitcoin network
+/// Sent -> Requested Conflicting transaction (reorg)
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BounceStatus {
/// Bounce have been requested (default)
Requested = 0,
- /// The wire failed to send this bounce and will try later
- Delayed = 1,
- /// Bounce will not be sent (e.g: bounce amount smaller than bounce fee)
- Ignored = 2,
+ /// Bounce will never be sent (e.g: bounce amount smaller than bounce fee)
+ Ignored = 1,
/// Bounce have been announced to the bitcoin network
- Sent = 3,
+ Sent = 2,
}
impl TryFrom<u8> for BounceStatus {
@@ -61,7 +65,6 @@ impl TryFrom<u8> for BounceStatus {
match v {
x if x == BounceStatus::Requested as u8 =>
Ok(BounceStatus::Requested),
x if x == BounceStatus::Sent as u8 => Ok(BounceStatus::Sent),
- x if x == BounceStatus::Delayed as u8 => Ok(BounceStatus::Delayed),
x if x == BounceStatus::Ignored as u8 => Ok(BounceStatus::Ignored),
_ => Err(()),
}
diff --git a/docs/fee.png b/docs/media/fee.png
similarity index 100%
rename from docs/fee.png
rename to docs/media/fee.png
diff --git a/docs/media/news0.png b/docs/media/news0.png
new file mode 100644
index 0000000..d1f5ab7
Binary files /dev/null and b/docs/media/news0.png differ
diff --git a/docs/media/news1.png b/docs/media/news1.png
new file mode 100644
index 0000000..c567581
Binary files /dev/null and b/docs/media/news1.png differ
diff --git a/docs/media/news2.png b/docs/media/news2.png
new file mode 100644
index 0000000..f33c1ba
Binary files /dev/null and b/docs/media/news2.png differ
diff --git a/docs/taler.png b/docs/media/taler.png
similarity index 100%
rename from docs/taler.png
rename to docs/media/taler.png
diff --git a/docs/presentation.tex b/docs/presentation.tex
index 0d6cb8b..2e9cd3b 100644
--- a/docs/presentation.tex
+++ b/docs/presentation.tex
@@ -12,7 +12,7 @@
\author{Antoine d'Aligny}
\institute{Bern University of Applied Sciences}
\date{\today}
-\titlegraphic{\includegraphics[width=2.5cm]{taler.png}}
+\titlegraphic{\includegraphics[width=2.5cm]{media/taler.png}}
\begin{document}
@@ -20,137 +20,209 @@
\titlepage
\end{frame}
-\begin{frame}{Outline}
- \tableofcontents
-\end{frame}
-
-\section{Introduction}
-
-\begin{frame}{Introduction}
+\begin{frame}{Blockchain based cryptocurrencies}
+ \begin{tikzpicture}[remember picture,overlay]
+ \node (N1)[above right=5mm and 25mm of current page.center]
{\includegraphics[width=34mm]{media/news1.png}};
+ \node (N0)[below=-3mm of N1]
{\includegraphics[width=34mm]{media/news0.png}};
+ \node (N2)[below left=-26mm and -2.5mm of N1]
{\includegraphics[width=34mm]{media/news2.png}};
+ \end{tikzpicture}
\begin{block}{Biggest cryptocurrencies}
\begin{itemize}
\item \textbf{BTC} Bitcoin
\item \textbf{ETH} Ethereum
\end{itemize}
\end{block}
-
- \begin{block}{Common blockchain limitation}
+ \begin{block}{Common blockchain limitations}
\begin{itemize}
\item \textbf{Delay} block and confirmation delay
\item \textbf{Cost} transaction fees
\item \textbf{Scalability} limited amount of transaction per second
\item \textbf{Ecological impact} computation redundancy
\item \textbf{Privacy}
+ \item \textbf{Regulatory risk}
\end{itemize}
\end{block}
\end{frame}
-\section{Taler}
-
\begin{frame}{Taler}{Architecture}
- \begin{center}
+ \begin{columns}
+ \column{0.5\paperwidth}
\begin{tikzpicture}[
rect/.style={circle, draw=black},
- sym/.style={->, shorten >= 2pt, shorten <= 2pt}
+ sym/.style={-stealth, shorten >= 2pt, shorten <= 2pt}
]
+ % Taler payment system
\node[rect](1) {Exchange};
- \node[rect, below left=1.5cm and 0.7cm of 1](2) {Customer};
- \node[rect, below right=1.5cm and 0.7cm of 1](3) {Merchant};
+ \node[rect,below left=1.5cm and 0.7cm of 1](2) {Customer};
+ \node[rect,below right=1.5cm and 0.7cm of 1](3) {Merchant};
\draw[sym] (1) -- node [midway, above, sloped] {\tiny Withdraw
coins} (2);
\draw[sym] (2) -- node [midway, above, sloped] {\tiny Spend coins}
(3);
\draw[sym] (3) -- node [midway, above, sloped] {\tiny Deposit
coins} (1);
+ % Settlement layer
\node[left=2cm of 1](E1){};
\node[right=2cm of 1](E2){};
\draw[sym] (E1) -- node [midway, above] {\tiny Deposit money} (1);
\draw[sym] (1) -- node [midway, above] {\tiny Withdraw money} (E2);
-
+ % Auditor
\node[above= of 1](A){Auditor};
\draw[sym] (A) -- node [midway, right] {\tiny Verify} (1);
- \end{tikzpicture}
- \end{center}
-\end{frame}
-\begin{frame}{Taler}{Coins - WIP}
- \begin{itemize}
- \item Blind signatures
- \item Currency agnostic
- \item Change signature every year, Forget previous transactions
(Pruning)
- \item Compatibility ?
- \end{itemize}
+ % Separator
+ \node[below=1mm of E1] (S1S) {};
+ \node[below=1mm of E2] (S1E) {};
+ \node[above=6mm of E1] (S2S) {};
+ \node[above=6mm of E2] (S2E) {};
+
+ \draw[dotted] (S1S) -- (S1E);
+ \draw[dotted] (S2S) -- (S2E);
+
+ \node[below right=-2mm and -1.5mm of S2S] {\tiny{\emph{Settlement
Layer}}};
+ \node[below right=-2mm and -1.5mm of S1S] {\tiny{\emph{Taler
payment system}}};
+ \end{tikzpicture}
+ \column{0.47\paperwidth}
+ \begin{block}{Settlement layer}
+ \begin{itemize}
+ \item Blockchain?
+ \end{itemize}
+ \end{block}
+ \begin{block}{Taler payment system}
+ \begin{itemize}
+ \item Blind signatures (privacy)
+ \item Rotate keys every year. Forget previous transactions
(Pruning)
+ \end{itemize}
+ \end{block}
+
+ \end{columns}
\end{frame}
-\begin{frame}{Taler}{Off-chain transactions}
+\begin{frame}{Taler}{Blockchain settlement layer}
\begin{center}
\begin{tikzpicture}[
rect/.style={rectangle, draw=black, minimum width=28mm},
- sym/.style={<->, shorten >= 2pt, shorten <= 2pt},
+ sym/.style={stealth-stealth, shorten >= 2pt, shorten <= 2pt},
block/.style={rectangle,draw=black,fill=black!10,minimum
size=7mm},
]
%% Architecture
-
\node(Tt){Taler};
- \node[rect, below=0cm of Tt](Tc){Exchange};
- \node[rect, fit={(Tt) (Tc)}](T){};
+ \node[rect,below=0cm of Tt](Tc){Exchange};
+ \node[rect,fit={(Tt) (Tc)}](T){};
- \node[rect, below=7mm of Tc](D) {Depolymerization};
+ \node[rect,below=7mm of Tc](D) {Depolymerization};
- \node[rect, below=7mm of D](Bc){Node};
+ \node[rect,below=7mm of D](Bc){Node};
\node[below=0cm of Bc](Bt){Blockchain};
- \node[rect, fit={(Bt) (Bc)}](B){};
+ \node[rect,fit={(Bt) (Bc)}](B){};
\draw[sym] (T) -- (D);
\draw[sym] (D) -- (B);
%% Blockchain
- \node[block,right=7mm of B] (1){};
+ \node[block,right=8mm of B] (1){};
\node[block,right=4mm of 1] (2){};
\node[block,right=4mm of 2] (3){};
\node[block,right=4mm of 3] (4){};
\node[block,right=4mm of 4] (5){};
\node[block,right=4mm of 5] (6){};
- \draw[->] (1) -- (2);
- \draw[->] (2) -- (3);
- \draw[->] (3) -- (4);
- \draw[->] (4) -- (5);
- \draw[->] (5) -- (6);
+ \draw[-stealth] (1) -- (2);
+ \draw[-stealth] (2) -- (3);
+ \draw[-stealth] (3) -- (4);
+ \draw[-stealth] (4) -- (5);
+ \draw[-stealth] (5) -- (6);
- %% Taler
- \node[block, right=18mm of T] (off){Off-chain transactions};
+ \node[left=4mm of 1] (S){};
+ \node[right=4mm of 6] (E){};
+ \draw[-stealth] (S) -- (1);
+ \draw[-stealth] (6) -- (E);
- % Depolymerization
- \node[right=11mm of D] {\small{Deposit}};
- \node[right=49mm of D] {\small{Withdraw}};
- \draw[dashed,->] (1.north) |- (off.west);
- \draw[dashed,->] (off.east) -| (6.north);
+ %% Taler
+ \node[block, below right=-7.5mm and 20.5mm of T] (off){Off-chain
transactions};
+ \node[above=-0.5mm of off]
{\includegraphics[height=7mm]{media/taler.png}};
+
+ %% Depolymerization
+ \node[right=12mm of D] {\small{Deposit}};
+ \node[right=50mm of D] {\small{Withdraw}};
+ \draw[dashed,-stealth] (1.north) |- (off.west);
+ \draw[dashed,-stealth] (off.east) -| (6.north);
\end{tikzpicture}
\end{center}
\end{frame}
-\section{Depolymerization}
+\begin{frame}{Challenges}
+ \begin{block}{Taler Metadata}
+ \begin{itemize}
+ \item Metadata are required to link a wallet to its deposits and
withdraws
+ \item Putting metadata in blockchain transactions can be tricky
+ \item The whole on-chain transaction history can be retrieved from
+ the blockchain. \textbf{Easily auditable}
+ \end{itemize}
+ \end{block}
+ \begin{block}{Blockchain based cryptocurrencies}
+ \begin{itemize}
+ \item Reorganisation resilient
+ \item Adaptive confirmation
+ \item Resolve stuck transactions
+ \end{itemize}
+ \end{block}
+\end{frame}
-\begin{frame}{Depolymerization}{Metadata}
- \begin{itemize}
- \item Metadata are stored in depolymerizer on-chain transactions
- \item The whole on-chain transaction history can be retrieved from the
blockchain
- \item \textbf{Easily auditable}
- \end{itemize}
+\begin{frame}{Challenges}{Chain reorganisation}
+ \begin{center}
+ \begin{tikzpicture}[
+ block/.style={rectangle,draw=black,fill=black!10,minimum
size=7mm},
+ ar/.style={-stealth}
+ ]
+ % Common
+ \node[block](1){};
+ \node[block,right=5mm of 1](2){$D_0$};
+ \node[block,right=5mm of 2](3){};
+ \draw[ar] (1) -- (2);
+ \draw[ar] (2) -- (3);
+
+ % Current
+ \node [block,right=5mm of 3](4){};
+ \node[block,right=5mm of 4](5){};
+ \node[block,right=5mm of 5](6){$D_1$};
+ \draw[ar] (3) -- (4);
+ \draw[ar] (4) -- (5);
+ \draw[ar] (5) -- (6);
+
+ % Fork
+ \node [block,above=7mm of 4](4p){};
+ \node[block,right=5mm of 4p](5p){$D_2$};
+ \node[block,right=5mm of 5p](6p){};
+ \node[block,right=5mm of 6p](7p){};
+ \draw[ar] (3.east) -- (4p.west);
+ \draw[ar] (4p) -- (5p);
+ \draw[ar] (5p) -- (6p);
+ \draw[ar] (6p) -- (7p);
+
+ % Indication
+ \node [right=5mm of 7p]{\emph{fork}};
+ \node [right=17mm of 6]{\emph{active}};
+ \end{tikzpicture}
+ \end{center}
+ A fork is when concurrent blockchain states coexist. Nodes will follow
+ the longest chain, replacing recent blocks if necessary. That is a
+ blockchain reorganisation. Taler expects deposit transactions to be
+ consistent. If a deposit transaction disappears from the blockchain,
+ depolymerizer is comprised.
\end{frame}
\begin{frame}{Depolymerization}{Architecture}
\begin{center}
\begin{tikzpicture}[
rect/.style={rectangle, draw=black, minimum height=6mm,
minimum width=28mm},
- sym/.style={<->, shorten >= 2pt, shorten <= 2pt}
+ sym/.style={stealth-stealth, shorten >= 2pt, shorten <= 2pt}
]
\node[rect](1) {Taler Exchange};
- \node[rect,below=of 1](2) {wire\_gateway};
+ \node[rect,below=of 1](2) {Wire Gateway};
\node[rect,right=of 2](3) {PostgreSQL};
- \node[rect,right=of 3](4) {\#\#\#\_wire};
- \node[rect,above=of 4](5) {Full Node};
+ \node[rect,right=of 3](4) {DLT Wire};
+ \node[rect,above=of 4](5) {DLT Full Node};
\draw[sym] (1) -- node [midway,right] {\tiny HTTP} (2);
\draw[sym] (2) -- node [midway,above] {\tiny SQL} (3);
@@ -158,16 +230,45 @@
\draw[sym] (4) -- node [midway,left ] {\tiny RPC} (5);
+ \node[above= 2mm of 1]{\small{\emph{Wire Gateway API}}};
+ \node[above= 2mm of 5]{\small{\emph{DLT specific}}};
+ \node[above=22mm of 3](T) {};
+ \draw[dotted] (3) -- (T);
\end{tikzpicture}
\end{center}
- Two processes sharing a common database for state and communication.
- wire\_gateway is currency agnostic and there is a specific wire binary for
- every supported currency.
+ \begin{itemize}
+ \item Common database to store transactions state and communicate
+ with notifications
+ \item Wire Gateway for Taler API compatibility
+ \item Specific wire for DLT compatibility
+ \end{itemize}
\end{frame}
-\section{btc-wire}
+\begin{frame}{Depolymerization}{Metadata}
+ \begin{block}{Bitcoin - Withdraw}
+ \begin{itemize}
+ \item Transaction from code
+ \item Only 32B + URI
+ \item \textbf{OP\_RETURN}
+ \end{itemize}
+ \end{block}
+ \begin{block}{Bitcoin - Deposit}
+ \begin{itemize}
+ \item Transaction from common wallet software
+ \item Only 32B
+ \item \textbf{Fake Segwit Addresses}
+ \end{itemize}
+ \end{block}
+ \begin{block}{Ethereum - Withdraw and Deposit}
+ \begin{itemize}
+ \item Smart contract is the recommend way
+ \item Expensive and error prone (bigger attack surface)
+ \item \textbf{Custom contract input format}
+ \end{itemize}
+ \end{block}
+\end{frame}
-\begin{frame}{btc-wire}{Architecture}
+\begin{frame}{Depolymerization}{Architecture}
\begin{center}
\begin{tikzpicture}[
rect/.style={rectangle, draw=black, minimum height=6mm,
minimum width=38mm},
@@ -177,15 +278,15 @@
\node(wat) {Watcher};
\node[rect, below=1mm of wat](wa1) {Wait for new block};
\node[rect, below=4mm of wa1](wa2) {Notify new block};
- \draw[->] (wa1) -- (wa2);
- \draw[->] (wa2) .. controls ([xshift=-0.3cm] wa2.west) and
([xshift=-0.3cm] wa1.west) .. (wa1);
+ \draw[-stealth] (wa1) -- (wa2);
+ \draw[-stealth] (wa2) .. controls ([xshift=-0.3cm] wa2.west) and
([xshift=-0.3cm] wa1.west) .. (wa1);
% Analysis loop
\node[below=5mm of wa2] (at) {Analysis};
\node[rect, below=1mm of at](a1) {Wait for notification};
\node[rect, below=4mm of a1](a2) {Analyse};
- \draw[->] (a1) -- (a2);
- \draw[->] (a2) .. controls ([xshift=-0.3cm] a2.west) and
([xshift=-0.3cm] a1.west) .. (a1);
+ \draw[-stealth] (a1) -- (a2);
+ \draw[-stealth] (a2) .. controls ([xshift=-0.3cm] a2.west) and
([xshift=-0.3cm] a1.west) .. (a1);
% Worker loop
\node[rect, below right= -2mm and 1cm of wa1](wo1) {Wait for
notification};
@@ -193,134 +294,98 @@
\node[rect, below=4mm of wo2](wo3) {Send};
\node[rect, below=4mm of wo3](wo4) {Bounce};
\node[above=1mm of wo1]{Worker};
- \draw[->] (wo1) -- (wo2);
- \draw[->] (wo2) -- (wo3);
- \draw[->] (wo3) -- (wo4);
- \draw[->] (wo4) .. controls ([xshift=-0.4cm] wo4.west) and
([xshift=-0.4cm] wo1.west) .. (wo1);
+ \draw[-stealth] (wo1) -- (wo2);
+ \draw[-stealth] (wo2) -- (wo3);
+ \draw[-stealth] (wo3) -- (wo4);
+ \draw[-stealth] (wo4) .. controls ([xshift=-0.4cm] wo4.west) and
([xshift=-0.4cm] wo1.west) .. (wo1);
\end{tikzpicture}
\end{center}
\centering
Three concurrent loops
\end{frame}
-\begin{frame}{btc-wire}{Metadata}
- \begin{block}{Withdraw}
- \begin{itemize}
- \item Transaction from code
- \item Only 32B + URI
- \item \textbf{OP\_RETURN}
- \end{itemize}
- \end{block}
- \begin{block}{Deposit}
- \begin{itemize}
- \item Transaction from common wallet software
- \item Only 32B
- \item \textbf{Fake Segwit Addresses}
- \end{itemize}
- \end{block}
-\end{frame}
-
-
-\begin{frame}{btc-wire}{Security features}
- \begin{itemize}
- \item Reorg resilient
- \item Adaptive confirmation
- \item Resolve stuck transaction
- \end{itemize}
-\end{frame}
-
-\begin{frame}{btc-wire}{Reorg resilient}
+\begin{frame}{Reorganisation resilient}
\begin{center}
\begin{tikzpicture}[
block/.style={rectangle,draw=black,fill=black!10,minimum
size=7mm},
conf/.style={draw=black!60!green,fill=black!60!green!10},
err/.style={draw=black!60!red,fill=black!60!red!10},
+ ar/.style={-stealth}
]
% Common
- \only<1>{
- \node [block](1){};
- \node [block,right=5mm of 1](2){$D_0$};
- \node [block,right=5mm of 2](3){};
- }
- \only<2->{
- \node [block,conf](1){};
- \node [block,conf,right=5mm of 1](2){$D_0$};
- \node [block,conf,right=5mm of 2](3){};
- }
- \draw[->] (1) -- (2);
- \draw[->] (2) -- (3);
+ \node[block,conf](1){};
+ \node[block,conf,right=5mm of 1](2){$D_0$};
+ \node[block,conf,right=5mm of 2](3){};
+ \draw[ar] (1) -- (2);
+ \draw[ar] (2) -- (3);
% Current
- \only<1-2>{
+ \only<1>{
\node [block,right=5mm of 3](4){};
}
- \only<3->{
- \node [block,conf,right=5mm of 3](4){\only<4>{$D_3$}};
+ \only<2->{
+ \node [block,conf,right=5mm of 3](4){\only<3>{$D_3$}};
}
- \node [block,right=5mm of 4](5){};
- \node [block,right=5mm of 5](6){$D_1$};
- \draw[->] (3) -- (4);
- \draw[->] (4) -- (5);
- \draw[->] (5) -- (6);
+ \node[block,right=5mm of 4](5){};
+ \node[block,right=5mm of 5](6){$D_1$};
+ \draw[ar] (3) -- (4);
+ \draw[ar] (4) -- (5);
+ \draw[ar] (5) -- (6);
% Fork
- \only<-3>{
+ \only<-2>{
\node [block,above=7mm of 4](4p){};
}
- \only<4>{
+ \only<3>{
\node [block,err,above=7mm of 4](4p){$D_3'$};
}
- \node [block,right=5mm of 4p](5p){$D_2$};
- \node [block,right=5mm of 5p](6p){};
- \node [block,right=5mm of 6p](7p){};
- \draw[->] (3.east) -- (4p.west);
- \draw[->] (4p) -- (5p);
- \draw[->] (5p) -- (6p);
- \draw[->] (6p) -- (7p);
+ \node[block,right=5mm of 4p](5p){$D_2$};
+ \node[block,right=5mm of 5p](6p){};
+ \node[block,right=5mm of 6p](7p){};
+ \draw[ar] (3.east) -- (4p.west);
+ \draw[ar] (4p) -- (5p);
+ \draw[ar] (5p) -- (6p);
+ \draw[ar] (6p) -- (7p);
% Indication
\node [right=5mm of 7p]{\emph{fork}};
\node [right=17mm of 6]{\emph{active}};
\end{tikzpicture}
\end{center}
- \only<1>{A fork is when concurrent blockchain states coexist. Nodes will
- follow the longest chain, replacing recent blocks if necessary. That
is a
- blockchain reorganization. Taler expects deposit transactions to be
- consistent. If a deposit transaction disappears from the blockchain
btc-wire
- is comprised.}
- \only<2>{As small forks are common, we apply a confirmation delay to
- handle the most common disturbances and attacks.}
- \only<3>{If a reorganization longer than the confirmation delay happens,
+ \only<1>{As small reorganisations are common, we apply a confirmation delay
+ to handle the most common disturbances and attacks.}
+ \only<2>{If a reorganisation longer than the confirmation delay happens,
but it does not remove deposits, btc-wire is safe.}
- \only<4>{If it removed a confirmed deposit a powerful attacker may have
+ \only<3>{If it removed a confirmed deposit a powerful attacker may have
created a conflicting transaction. btc-wire suspends operation until
lost deposits reappear.}
\end{frame}
-\begin{frame}{btc-wire}{Adaptive confirmation}
+\begin{frame}{Adaptive confirmation}
\begin{center}
\begin{tikzpicture}[
block/.style={rectangle,draw=black,fill=black!10,minimum
size=7mm},
conf/.style={draw=black!60!green,fill=black!60!green!10},
conft/.style={text=black!60!green},
confl/.style={draw=black!60!green},
+ ar/.style={-stealth}
]
% Common
\node(0){};
\node[block,conf,right=5mm of 0](1){};
\node[block,conf,right=5mm of 1](2){};
- \draw[->] (0) -- (1);
- \draw[->] (1) -- (2);
+ \draw[ar] (0) -- (1);
+ \draw[ar] (1) -- (2);
% Current
\node[block,conf,right=5mm of 2](3){};
\node[block,right=5mm of 3](4){};
\node[block,right=5mm of 4](5){};
\node[block,right=5mm of 5](6){};
- \draw[->] (2) -- (3);
- \draw[->] (3) -- (4);
- \draw[->] (4) -- (5);
- \draw[->] (5) -- (6);
+ \draw[ar] (2) -- (3);
+ \draw[ar] (3) -- (4);
+ \draw[ar] (4) -- (5);
+ \draw[ar] (5) -- (6);
% Fork
\node[block,above=7mm of 3](3p){};
@@ -328,11 +393,11 @@
\node[block,right=5mm of 4p](5p){};
\node[block,right=5mm of 5p](6p){};
\node[block,right=5mm of 6p](7p){};
- \draw[->] (2.east) -- (3p.west);
- \draw[->] (3p) -- (4p);
- \draw[->] (4p) -- (5p);
- \draw[->] (5p) -- (6p);
- \draw[->] (6p) -- (7p);
+ \draw[ar] (2.east) -- (3p.west);
+ \draw[ar] (3p) -- (4p);
+ \draw[ar] (4p) -- (5p);
+ \draw[ar] (5p) -- (6p);
+ \draw[ar] (6p) -- (7p);
% Indication
\node[right=5mm of 7p]{\emph{fork}};
@@ -351,12 +416,11 @@
\end{tikzpicture}
\end{center}
If we experience a reorganisation once, its plausible for another one of
the
- same size to happen again. btc-wire learns from reorganizations by updating
+ same size to happen again. btc-wire learns from reorganisations by updating
its confirmation time.
\end{frame}
-
-\begin{frame}{btc-wire}{Handle stuck transactions}
+\begin{frame}{Handle stuck transactions}
\begin{center}
\begin{tikzpicture}[
dot/.style={circle,fill,inner sep=1pt,}
@@ -364,7 +428,7 @@
% TODO caption with source (Ychart)
- \node (I) {\includegraphics[width=\textwidth]{fee.png}};
+ \node (I) {\includegraphics[width=\textwidth]{media/fee.png}};
\only<2->{
\node [below left=-2.5mm and -1.5cm of I] (Tx) {\small Tx};
\node [dot,above=8.4mm of Tx](D) {};
@@ -415,12 +479,12 @@
\begin{frame}{Conclusion}
\begin{itemize}
\item [$-$] Trust exchange operator or auditors
- \item [$+$] Fast and cheap, no blockchain
+ \item [$+$] Fast and cheap
\item [$+$] Realtime, ms latency
- \item [$+$] Scalability, close to 100k txs per second
+ \item [$+$] Linear scalability
\item [$+$] Ecological
\item [$+$] Privacy when it can, transparency when it must (avoid tax
evasion and money laundering)
- \item [$+$] Currency agnostic (payment system)
+ \item [$+$] Compatibility with blockchains
\end{itemize}
\end{frame}
\end{document}
\ No newline at end of file
diff --git a/eth-wire/Cargo.toml b/eth-wire/Cargo.toml
index 8688146..c0ca0c6 100644
--- 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
index 02d7b0f..7c3f01a 100644
--- 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
index f47a681..d003b73 100644
--- 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
index e8a76b4..9561576 100644
--- 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
index 79f03ab..42b3ecb 100644
--- 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
index 8c2d74b..a98571e 100644
--- a/eth-wire/src/loops/worker.rs
+++ b/eth-wire/src/loops/worker.rs
@@ -15,22 +15,22 @@
*/
use std::time::SystemTime;
+use common::{
+ api_common::base32,
+ log::log::{error, info},
+ postgres::{fallible_iterator::FallibleIterator, Client},
+ sql::{sql_array, sql_url},
+ status::WithdrawStatus,
+};
use eth_wire::{
metadata::InMetadata,
rpc::Rpc,
taler_util::{eth_payto_url, eth_to_taler},
BlockState,
};
-use taler_common::{
- api_common::base32,
- log::log::{error, info},
- postgres::{fallible_iterator::FallibleIterator, Client},
- sql::{sql_array, sql_url},
-};
use crate::{
sql::{sql_addr, sql_eth_amount},
- status::TxStatus,
LoopResult, WireState,
};
@@ -54,7 +54,7 @@ pub fn worker(mut rpc: Rpc, mut db: Client, state:
&WireState) {
sync_chain(&mut rpc, &mut db, state)?;
- while send(&mut db, &mut rpc, state)? {}
+ while withdraw(&mut db, &mut rpc, state)? {}
Ok(())
})();
@@ -115,12 +115,12 @@ fn sync_chain(rpc: &mut Rpc, db: &mut Client, state:
&WireState) -> LoopResult<b
Ok(true)
}
-/// Send a transaction on the blockchain, return true if more transactions
with the same status remains
-fn send(db: &mut Client, rpc: &mut Rpc, state: &WireState) -> LoopResult<bool>
{
+/// Send a withdraw transaction on the blockchain, return false if no more
requested transaction are found
+fn withdraw(db: &mut Client, rpc: &mut Rpc, state: &WireState) ->
LoopResult<bool> {
// We rely on the advisory lock to ensure we are the only one sending
transactions
let row = db.query_opt(
"SELECT id, amount, wtid, credit_acc, exchange_url FROM tx_out WHERE status=$1
ORDER BY _date LIMIT 1",
-&[&(TxStatus::Requested as i16)],
+&[&(WithdrawStatus::Requested as i16)],
)?;
if let Some(row) = &row {
let id: i32 = row.get(0);
@@ -128,23 +128,13 @@ fn send(db: &mut Client, rpc: &mut Rpc, state:
&WireState) -> LoopResult<bool> {
let wtid: [u8; 32] = sql_array(row, 2);
let addr = sql_addr(row, 3);
let url = sql_url(row, 4);
- match rpc.withdraw(state.address, addr, amount, wtid, url) {
- Ok(tx_id) => {
- db.execute(
- "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3",
- &[&(TxStatus::Sent as i16), &tx_id.as_ref(), &id],
- )?;
- let amount = eth_to_taler(&amount);
- info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id,
addr);
- }
- Err(e) => {
- db.execute(
- "UPDATE tx_out SET status=$1 WHERE id=$2",
- &[&(TxStatus::Delayed as i16), &id],
- )?;
- Err(e)?;
- }
- }
+ let tx_id = rpc.withdraw(state.address, addr, amount, wtid, url)?;
+ db.execute(
+ "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3",
+ &[&(WithdrawStatus::Sent as i16), &tx_id.as_ref(), &id],
+ )?;
+ let amount = eth_to_taler(&amount);
+ info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id, addr);
}
Ok(row.is_some())
}
diff --git a/eth-wire/src/main.rs b/eth-wire/src/main.rs
index 324041d..de76e33 100644
--- a/eth-wire/src/main.rs
+++ b/eth-wire/src/main.rs
@@ -16,20 +16,19 @@
use std::sync::atomic::AtomicU16;
+use common::{
+ config::{load_eth_config, EthConfig},
+ postgres::{self, Client, NoTls},
+};
use eth_wire::{
rpc::{self, Rpc},
taler_util::eth_payto_addr,
};
use ethereum_types::H160;
use loops::{watcher::watcher, worker::worker};
-use taler_common::{
- config::{load_eth_config, EthConfig},
- postgres::{self, Client, NoTls},
-};
-mod status;
-mod sql;
mod loops;
+mod sql;
pub struct WireState {
confirmation: AtomicU16,
@@ -52,7 +51,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);
@@ -74,7 +73,9 @@ fn main() {
)
.unwrap();
- rpc_worker.unlock_account(&state.address, "password").unwrap();
+ rpc_worker
+ .unlock_account(&state.address, "password")
+ .unwrap();
let rpc_watcher = Rpc::new(
state
diff --git a/eth-wire/src/metadata.rs b/eth-wire/src/metadata.rs
index 50f9b05..a04e32d 100644
--- 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
index fe7af54..9e884ac 100644
--- 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
index f755ce3..7f9fef1 100644
--- 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/makefile b/makefile
index e11a023..6e374f0 100644
--- a/makefile
+++ b/makefile
@@ -22,4 +22,4 @@ test_btc:
test_eth:
test/eth/wire.sh
-test: install test_gateway test_btc test_eth
\ No newline at end of file
+test: install test_gateway test_eth test_btc
\ No newline at end of file
diff --git a/test/common.sh b/test/common.sh
index 5a0331a..e7481ac 100644
--- a/test/common.sh
+++ b/test/common.sh
@@ -10,7 +10,7 @@ function cleanup() {
for n in `jobs -p`; do
kill $n &> /dev/null || true
done
- rm -rf $DIR &> /dev/null
+ rm -rf $DIR &> /dev/null || true
wait
}
diff --git a/wire-gateway/Cargo.toml b/wire-gateway/Cargo.toml
index ca4140a..40e8878 100644
--- a/wire-gateway/Cargo.toml
+++ b/wire-gateway/Cargo.toml
@@ -4,9 +4,6 @@ version = "0.1.0"
edition = "2021"
license = "AGPL-3.0-or-later"
-[features]
-# Enable test admin endpoint
-test = []
[dependencies]
# Http library
@@ -32,9 +29,19 @@ 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
+ethereum-types = { version = "0.12.1", default-features = false, optional =
true }
+
-# TODO Put this behind a feature
-# Bitcoin data structure
-bitcoin = "0.27.1"
+[features]
+default = ["btc", "eth"]
+# Enable test admin endpoint
+test = []
+# Support btc-wire
+btc = ["bitcoin"]
+# Support eth-wire
+eth = ["ethereum-types"]
diff --git a/wire-gateway/src/error.rs b/wire-gateway/src/error.rs
index 34d10d3..a92210d 100644
--- 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
index db25fa5..62e0aa2 100644
--- 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,
@@ -50,7 +50,7 @@ mod json;
struct ServerState {
pool: Pool,
config: GatewayConfig,
- domain: &'static str,
+ payto_check: fn(&Url) -> bool,
notify: Notify,
lifetime: Option<AtomicU32>,
status: AtomicBool,
@@ -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();
@@ -122,9 +122,11 @@ async fn main() {
let pool = cfg.create_pool(Some(Runtime::Tokio1), NoTls).unwrap();
let state = ServerState {
pool,
- domain: match conf.core.currency.as_str() {
- "BTC" => "bitcoin",
- "ETH" => "ethereum",
+ payto_check: match conf.core.currency.as_str() {
+ #[cfg(feature = "btc")]
+ "BTC" => check_pay_to_btc,
+ #[cfg(feature = "eth")]
+ "ETH" => check_pay_to_eth,
currency => unimplemented!("Unsupported currency {}", currency),
},
config: conf.clone(),
@@ -206,15 +208,27 @@ async fn main() {
}
/// Check if an url is a valid bitcoin payto url
-fn check_pay_to(url: &Url, domain: &str) -> bool {
- // TODO currency agnostic
- return url.domain() == Some(domain)
+#[cfg(feature = "btc")]
+fn check_pay_to_btc(url: &Url) -> bool {
+ return url.domain() == Some("bitcoin")
&& url.scheme() == "payto"
&& url.username() == ""
&& url.password().is_none()
&& url.query().is_none()
- && url.fragment().is_none();
- //&&
bitcoin::Address::from_str(url.path().trim_start_matches('/')).is_ok();
+ && url.fragment().is_none()
+ &&
bitcoin::Address::from_str(url.path().trim_start_matches('/')).is_ok();
+}
+
+/// Check if an url is a valid ethereum payto url
+#[cfg(feature = "eth")]
+fn check_pay_to_eth(url: &Url) -> bool {
+ return url.domain() == Some("ethereum")
+ && url.scheme() == "payto"
+ && url.username() == ""
+ && url.password().is_none()
+ && url.query().is_none()
+ && url.fragment().is_none()
+ &&
ethereum_types::H160::from_str(url.path().trim_start_matches('/')).is_ok();
}
/// Assert request method match expected
@@ -278,7 +292,7 @@ async fn router(
StatusCode::BAD_REQUEST,
ErrorCode::GENERIC_PARAMETER_MALFORMED,
)?;
- if !check_pay_to(&request.credit_account, state.domain) {
+ if !(state.payto_check)(&request.credit_account) {
return Err(ServerError::code(
StatusCode::BAD_REQUEST,
ErrorCode::GENERIC_PAYTO_URI_MALFORMED,
@@ -420,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(
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-depolymerization] branch master updated (fb88a48 -> 9eabce5),
gnunet <=