depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit e07437ecd30f4e16aad37caa2efbd084ce79a6a7
parent d3ae4c7a52fc10d5e010ef61359a215f252a0130
Author: Antoine A <>
Date:   Wed, 12 Jan 2022 12:08:50 +0100

Documentatiion draft

Diffstat:
MREADME.md | 17+++++++----------
Abtc-wire/README.md | 37+++++++++++++++++++++++++++++++++++++
Rwire-gateway/db/btc.sql -> db/btc.sql | 0
Rwire-gateway/db/common.sql -> db/common.sql | 0
Mmakefile | 18+++++++++---------
Mscript/prepare.sh | 23+++++++++++++----------
Mtaler-common/src/config.rs | 19++++++++++++++++---
Mtest/common.sh | 8++++----
Mtest/conf/taler_lifetime.conf | 3+++
Mtest/conf/taler_test.conf | 3+++
Muri-pack/README.md | 6+++---
Mwire-gateway/README.md | 9+++++++++
12 files changed, 104 insertions(+), 39 deletions(-)

diff --git a/README.md b/README.md @@ -1,13 +1,9 @@ # Depolymerization -## Install +## Project structure -``` -make install -``` - -## Test - -``` -make test -``` +- **wire-gateway**: [Taler Wire Gateway HTTP API](https://docs.taler.net/core/api-wire.html) server +- **btc-wire**: Taler wire implementation for [bitcoincore](https://bitcoincore.org/en/about/) node +- **uri-pack**: Efficient probabilistic binary encoding for URI +- **docs**: Documentation files +- **test**: Test scripts +\ No newline at end of file diff --git a/btc-wire/README.md b/btc-wire/README.md @@ -0,0 +1,36 @@ +# btc-wire + +btc-wire is taler wire implementation for [bitcoincore](https://bitcoincore.org/en/about/) node + +## Bitcoincore compatibility + +Bitcoind version >= 22.0 is required + +## Install + +`cargo install --path btc-wire` + +## Configuration + +### taler.conf + +The configuration is based on [taler.conf](https://docs.taler.net/manpages/taler.conf.5.html) + +### bitcoin.conf + +btc-wire will automatically read the bitcoin configuration file to connect to the RPC server, +`txindex=1` is mandatory. + +## Getting Started + +1. Init bitcoincore node: + 1. Edit the default bitcoin.conf to add `txindex=1` + 2. Start a bitcoincore node on your machine +2. Init postgresql database + 1. Start a postgres database + 2. Load the database [schema](../db/btc.sql) +3. Init bitcoin wallet + 1. `bitcoin-cli createwallet wire` + 2. `bitcoin-cli -rpcwallet=wire getnewaddress` + 3. Edit taler.conf with wallet info +4. Run wire-gateway and btc-wire +\ No newline at end of file diff --git a/wire-gateway/db/btc.sql b/db/btc.sql diff --git a/wire-gateway/db/common.sql b/db/common.sql diff --git a/makefile b/makefile @@ -3,16 +3,16 @@ install: cargo install --path wire-gateway test_gateway: - script/test_gateway.sh + test/gateway/api.sh test_btc: - script/test_btc_wire.sh - script/test_btc_lifetime.sh - script/test_btc_reconnect.sh - script/test_btc_fail.sh - script/test_btc_stress.sh - script/test_btc_conflict.sh - script/test_btc_reorg.sh - script/test_btc_hell.sh + test/btc/wire.sh + test/btc/lifetime.sh + test/btc/reconnect.sh + test/btc/fail.sh + test/btc/stress.sh + test/btc/conflict.sh + test/btc/reorg.sh + test/btc/hell.sh test: test_gateway test_btc \ No newline at end of file diff --git a/script/prepare.sh b/script/prepare.sh @@ -1,3 +1,7 @@ +#!/bin/bash + +## Install required dependencies to run tests + set -eu DIR=$(mktemp -d) @@ -12,15 +16,7 @@ function cleanup() { trap cleanup EXIT -echo "I - Install bitcoind version 0.22" -cd $DIR -curl -L https://bitcoin.org/bin/bitcoin-core-22.0/bitcoin-22.0-x86_64-linux-gnu.tar.gz -o btc.tar.gz -rm -rfv ~/bitcoin -mkdir -pv ~/bitcoin -tar xvzf btc.tar.gz -mv -v bitcoin-22.0/* ~/bitcoin - -echo "II - Install latest postgres from source" +echo "Ⅰ - Install latest postgres from source" cd $DIR git clone --depth 1 https://git.postgresql.org/git/postgresql.git cd postgresql @@ -28,7 +24,14 @@ cd postgresql make make install -echo "III - Config" +echo "Ⅱ - Install bitcoind version 0.22" +cd $DIR +curl -L https://bitcoin.org/bin/bitcoin-core-22.0/bitcoin-22.0-x86_64-linux-gnu.tar.gz -o btc.tar.gz +rm -rfv ~/bitcoin +mkdir -pv ~/bitcoin +tar xvzf btc.tar.gz +mv -v bitcoin-22.0/* ~/bitcoin +echo "Ⅲ - Config" echo "Add ~/bitcoin/bin to your path" echo "Add ~/postgresql/bin to your path" \ No newline at end of file diff --git a/taler-common/src/config.rs b/taler-common/src/config.rs @@ -1,4 +1,4 @@ -use ini::Properties; +use ini::{Ini, Properties}; use std::{ path::{Path, PathBuf}, str::FromStr, @@ -25,8 +25,9 @@ impl Config { /// Load from a file pub fn load_from_file(config_file: impl AsRef<Path>) -> Self { let conf = ini::Ini::load_from_file(config_file).unwrap(); - let ex_conf = conf.section(Some("exchange")).unwrap(); - let self_conf = conf.section(Some("depolymerizer-bitcoin")).unwrap(); + assert(section(&conf, "taler"), "CURRENCY", "BTC"); + let ex_conf = section(&conf, "exchange"); + let self_conf = section(&conf, "depolymerizer-bitcoin"); Self { base_url: require(ex_conf, "BASE_URL", url), db_url: require(self_conf, "DB_URL", string), @@ -49,6 +50,18 @@ impl Config { /* ----- Helper functions ----- */ +fn section<'a>(ini: &'a Ini, name: &str) -> &'a Properties { + ini.section(Some(name)) + .unwrap_or_else(|| panic!("missing config section {}", name)) +} + +fn assert(properties: &Properties, name: &str, expected: &str) { + let value = require(properties, name, string); + if value != expected { + panic!("config {} expected '{}' got '{}'", name, expected, value); + } +} + fn require<T>( properties: &Properties, name: &str, diff --git a/test/common.sh b/test/common.sh @@ -66,16 +66,16 @@ function check_down() { # Create new postgresql cluster and init database schema function setup_db() { - pg_ctl init -D $DB_DIR &> /dev/null + pg_ctl init -D $DB_DIR &>> log/postgres.log echo "port=5454" >> $DB_DIR/postgresql.conf - pg_ctl start -D $DB_DIR > /dev/null + pg_ctl start -D $DB_DIR >> log/postgres.log echo "CREATE ROLE postgres LOGIN SUPERUSER PASSWORD 'password'" | psql -p 5454 postgres > /dev/null - psql $DB_URL < wire-gateway/db/${SCHEMA:-common.sql} &> /dev/null + psql $DB_URL < db/${SCHEMA:-common.sql} &> /dev/null } # Erase database function reset_db() { - psql $DB_URL < wire-gateway/db/${SCHEMA:-common.sql} > /dev/null + psql $DB_URL < db/${SCHEMA:-common.sql} > /dev/null } # ----- Bitcoin node ----- # diff --git a/test/conf/taler_lifetime.conf b/test/conf/taler_lifetime.conf @@ -1,3 +1,6 @@ +[taler] +CURRENCY = BTC + [exchange] BASE_URL = http://test.com diff --git a/test/conf/taler_test.conf b/test/conf/taler_test.conf @@ -1,3 +1,6 @@ +[taler] +CURRENCY = BTC + [exchange] BASE_URL = http://test.com diff --git a/uri-pack/README.md b/uri-pack/README.md @@ -1,11 +1,11 @@ # uri-pack -uri-pack is an efficient binary format for URI +uri-pack is an efficient probabilistic binary encoding for URI -## Format +## Encoding Most commonly used characters (a-z . / - %) are encoded using 5b, remaining -ascii characters are encoded using 11b.If more than half the characters in an +ascii characters are encoded using 11b. If more than half the characters in an uri are encoded with 5b, the encoded size is smaller than a simple ascii format. diff --git a/wire-gateway/README.md b/wire-gateway/README.md @@ -2,6 +2,15 @@ Rust server for [Taler Wire Gateway HTTP API](https://docs.taler.net/core/api-wire.html) +## Install + +`cargo install --path wire-gateway` + +## Configuration + +Depend on the used wire implementation : +- [BTC](../btc-wire/README.md) + ## Database schema The server is wire implementation agnostic, it only require an postgres database with following schema: