citadel-tech / coinswap

Functioning, minimal-viable binaries and libraries to perform a trustless, p2p Maxwell-Belcher Coinswap Protocol
https://gist.github.com/chris-belcher/9144bd57a91c194e332fb5ca371d0964
Other
63 stars 35 forks source link
bitcoin coinswap fungibility

Coinswap

Functioning, minimal-viable binaries and libraries to perform a trustless, p2p Maxwell-Belcher Coinswap Protocol.

CC0 1.0 Universal Licensed CI Status CI Status CI Status Coverage Rustc Version 1.75.0+

[!WARNING] This library is currently under beta development and at an experimental stage. There are known and unknown bugs. Mainnet use is strictly NOT recommended.

Table of Contents

About

CoinSwap is a rust implementation of a variant of atomic-swap protocol, using HTLCs on Bitcoin. Read more at:

Build and Test

Macos (M series) needs some feature for compilation

$ cargo build --target=aarch64-apple-darwin  --features=build-macos-aarch

The repo contains a fully automated integration testing framework on Bitcoin Regtest. The bitcoin binary used for testing is included here.

[!TIP] Delete the bitcoind binary to reduce repo size, if you don't intend to run the integration tests.

The integration tests are the best way to look at a working demonstration of the coinswap protocol, involving multiple makers, a taker and the directory server. All working over Tor by default. No pre-requisite setup is needed, other than rust and cargo.

Run all the integration tests by running:

$ cargo test --features=integration-test -- --nocapture

Each test in the tests folder covers a different edge-case situation and demonstrates how the taker and makers recover from various types of swap failures.

keep an eye on the logs, that's where all the actions are happening.

Play through a single test case, for example, standard_swap, by running:

$ cargo test --features=integration-test --tests test_standard_coinswap -- --nocapture

The individual test names can be found in the test files.

For in-depth developer documentation on the coinswap protocol and implementation, consult the dev book.

Architecture

The project is divided into distinct modules, each focused on specific functionalities.

docs/
src/
├─ bin/
├─ maker/
├─ market/
├─ protocol/
├─ taker/
tests/
Directory Description
doc Contains all the project-related docs. The dev-book includes major developer salient points.
src/taker Taker module houses its core logic in src/taker/api.rs and handles both Taker-related behaviors and most of the protocol-related logic.
src/maker Encompasses Maker-specific logic and plays a relatively passive role compared to Taker.
src/wallet Manages wallet-related operations, including storage and blockchain interaction.
src/market Handles market-related logic, where Makers post their offers.
src/protocol Contains utility functions, error handling, and messages for protocol communication.
tests Contains integration tests. Describes behavior of various abort/malice cases.

[!IMPORTANT] The project currently only compiles in Linux. Mac/Windows is not supported. To compile in Mac/Windows use virtual machines

Roadmap

V 0.1.0

V 0.1.*

Contributing

The project is under active development by a few motivated Rusty Bitcoin devs. Any contribution for features, tests, docs and other fixes/upgrades is encouraged and welcomed. The maintainers will use the PR thread to provide quick reviews and suggestions and are generally proactive at merging good contributions.

Few directions for new contributors:

Setting Up Git Hooks

The repo contains pre-commit githooks to do auto-linting before commits. Set up the pre-commit hook by running:

ln -s ../../git_hooks/pre-commit .git/hooks/pre-commit

Community

The dev community lurks in a Discord here.

Dev discussions predominantly happen via FOSS best practices, and by using Github as the Community Forum.

The Issues, PRs and Discussions are where all the hard lifting happening.