Skip to content

Commit 5f18d72

Browse files
authored
rebase master, add docs for ts,clippy fixes (#431)
1 parent 8a29d1d commit 5f18d72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4841
-778
lines changed

.github/workflows/rust.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16+
- name: Free up disk space
17+
run: |
18+
echo "Before cleanup:"
19+
df -h
20+
docker system prune -a -f
21+
sudo rm -rf /usr/local/lib/android
22+
sudo rm -rf /opt/ghc
23+
sudo apt-get clean
24+
sudo apt-get autoremove -y
25+
echo "After cleanup:"
26+
df -h
27+
1628
- name: Switch rust version
1729
run: rustup default nightly
1830

@@ -32,6 +44,15 @@ jobs:
3244
- name: Build
3345
run: cargo build --verbose
3446

47+
- name: Install wasm-pack
48+
run: |
49+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
50+
51+
- name: Build WASM for PWA
52+
run: |
53+
cd crates/bcr-ebill-pwa
54+
wasm-pack build --target web
55+
3556
- name: Install required cargo
3657
run: cargo install clippy-sarif sarif-fmt
3758

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ jobs:
1616
- name: Check out repository
1717
uses: actions/checkout@v4
1818

19+
- name: Free up disk space
20+
run: |
21+
echo "Before cleanup:"
22+
df -h
23+
docker system prune -a -f
24+
sudo rm -rf /usr/local/lib/android
25+
sudo rm -rf /opt/ghc
26+
sudo apt-get clean
27+
sudo apt-get autoremove -y
28+
echo "After cleanup:"
29+
df -h
30+
1931
- name: Install Rust
2032
uses: dtolnay/rust-toolchain@master
2133
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/test/*
1212
/files/*
1313
/company/*
14+
/pkg/*
1415

1516
.idea/
1617
Cargo.lock

Cargo.toml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
[workspace]
22
resolver = "3"
3-
members = [ "crates/bcr-ebill-web", "crates/bcr-ebill-core", "crates/bcr-ebill-api", "crates/bcr-ebill-persistence" , "crates/bcr-ebill-transport"]
3+
members = [ "crates/bcr-ebill-web", "crates/bcr-ebill-core", "crates/bcr-ebill-api", "crates/bcr-ebill-persistence" , "crates/bcr-ebill-transport", "crates/bcr-ebill-pwa"]
44

55

66
[workspace.dependencies]
7-
bs58 = "0.5.1"
8-
sha2 = { version = "0.10.8", default-features = false }
9-
borsh = "1.5.5"
10-
borsh-derive = "1.5.5"
11-
env_logger = { version = "0.11.6", default-features = false }
12-
log = "0.4.25"
13-
chrono = { version = "0.4.39", default-features = false, features = ["serde", "clock"] }
14-
tokio = "1.43.0"
15-
async-trait = "0.1.86"
16-
serde_json = "1.0.138"
17-
serde = { version = "1.0.217", default-features = false }
18-
serde_repr = "0.1.19"
19-
futures = { version = "0.3.31", default-features = false }
20-
anyhow = { version = "1.0.95", default-features = false }
21-
thiserror = { version = "2.0.11", default-features = false }
22-
lazy_static = "1.5.0"
23-
uuid = { version = "1", default-features = false, features = ["v4"] }
24-
bitcoin = { version = "0.32.5", default-features = false }
25-
bip39 = { version = "2.1.0", features = ["rand"] }
26-
ecies = { version = "0.2.6", default-features = false, features = ["pure"] }
27-
nostr-sdk = { version = "0.39.0", features = ["nip59"] }
7+
bs58 = "0.5"
8+
sha2 = { version = "0.10", default-features = false }
9+
borsh = "1.5"
10+
borsh-derive = "1.5"
11+
env_logger = { version = "0.11", default-features = false }
12+
log = "0.4"
13+
chrono = { version = "0.4", default-features = false, features = ["serde", "clock"] }
14+
tokio = { version = "1.43", default-features = false, features = ["rt"] }
15+
async-trait = "0.1"
16+
serde_json = "1"
17+
serde = { version = "1", default-features = false, features = ["derive"] }
18+
serde_repr = "0.1"
19+
futures = { version = "0.3", default-features = false }
20+
anyhow = { version = "1", default-features = false }
21+
thiserror = { version = "2", default-features = false }
22+
lazy_static = "1.5"
23+
uuid = { version = "1", default-features = false, features = ["v4", "js"] }
24+
bitcoin = { version = "0.32", default-features = false }
25+
bip39 = { version = "2.1", features = ["rand"] }
26+
ecies = { version = "0.2", default-features = false, features = ["pure"] }
27+
nostr-sdk = { version = "0.39", features = ["nip59"] }
28+
getrandom = { version = "0.3.1", features = ["wasm_js"] }
29+
reqwest = { version = "0.12", default-features = false, features = ["json"] }
30+
async-broadcast = "0.7.2"

README.md

Lines changed: 12 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,25 @@
11
# E-Bills
22

3-
Core for Bitcredit project.
3+
Core for Bitcredit E-Bills project.
44

5-
### Backend
5+
### Crates
66

7-
Make sure to have at least Rust version 1.85 as well as a recent version of the toolchain installed.
7+
The project consists of the following crates:
88

9-
#### On Ubuntu
10-
```bash
11-
# Install libs
12-
sudo apt install -y libclang-dev pkg-config build-essential
13-
```
14-
15-
#### On Fedora
16-
```bash
17-
# Install libs
18-
sudo dnf install -y make automake gcc gcc-c++ kernel-devel clang-devel
19-
sudo dnf install -y pkgconf-pkg-config @development-tools
20-
```
21-
22-
#### On Windows
23-
```bash
24-
# Using MSYS2 terminal
25-
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-llvm
26-
pacman -S base-devel pkgconf
27-
```
28-
29-
Finally build the backend
30-
```bash
31-
cargo build
32-
33-
# or with embedded db
34-
cargo build --features embedded-db
35-
```
36-
37-
Start the backend server in development mode:
38-
39-
```bash
40-
# Run with defaults
41-
RUST_LOG=info cargo run
42-
43-
# configure listening ports and addresses
44-
RUST_LOG=info cargo run -- --http-port 8001 --http-address 0.0.0.0
45-
46-
# Run with embedded database feature, data stored in data/surreal
47-
cargo run --features embedded-db -- --surreal-db-connection rocksdb://data/surreal
48-
```
9+
* `bcr-ebill-core` - core data models and traits
10+
* `bcr-ebill-persistence` - persistence traits and SurrealDB implementation
11+
* `bcr-ebill-transport` - network transport traits and Nostr implementation
12+
* `bcr-ebill-api` - API of the E-Bills project, contains most of the business logic
13+
* `bcr-ebill-web` - Entrypoint for Web applications using the Rocket web server
14+
* `bcr-ebill-pwa` - Entrypoint for WASM-based Progress Web Apps
4915

16+
### Entrypoints
5017

51-
### Development
52-
53-
Start the app in development mode with hot reloading
54-
(requires two terminals):
55-
56-
```bash
57-
RUST_LOG=info cargo watch -x run # watch can be installed with cargo install cargo-watch
58-
```
18+
There are both `WASM` and `Web` entry points into the API. You can find the documentation to build and configure them [here](docs/index.md):
5919

6020
### Tests
6121

62-
You can run the existing tests using the following commands:
22+
You can run the existing tests using the following commands in the project root:
6323

6424
```bash
6525
// without logs
@@ -69,88 +29,6 @@ cargo test
6929
RUST_LOG=info cargo test -- --nocapture
7030
```
7131

72-
### API docs
73-
74-
OpenApi specs and a Swagger UI are available at [http://localhost:8000/swagger-ui/](http://localhost:8000/swagger-ui/) when running the service.
75-
76-
### Docker
77-
78-
The docker build requires no dependencies other than docker or podman. It can
79-
also be used to run multiple instances of the app on different ports for testing
80-
the P2P functionality.
81-
82-
#### Build a standalone docker image
83-
84-
Build the image:
85-
86-
```bash
87-
# The image name can be changed to whatever you want
88-
docker build -t <image-name> .
89-
```
90-
91-
Launch the image:
92-
93-
```bash
94-
docker run -p 8000:8000 -p 1908:1908 -e RUST_LOG=info <image-name>
95-
```
96-
97-
You should be able to open the app at [http://127.0.0.1:8000/]([http://127.0.0.1:8000/])
98-
99-
#### Run with docker-compose
100-
101-
Build and launch the app with docker-compose running on a different port than
102-
the default 8000:
103-
104-
```bash
105-
# run in foreground, can be stopped using CTRL+C
106-
docker-compose up
107-
108-
# run in background, can be stopped using docker-compose stop
109-
docker-compose up -d
110-
111-
# rebuild the image
112-
docker-compose build
113-
```
114-
115-
If you use the above commands, the application state (identity, bills, contacts)
116-
will persist between sessions. However, if you use `docker-compose down`, or
117-
`docker-compose rm`, the existing container gets removed, along with it's state.
118-
Of course, rebuilding the image also removes the application state.
119-
120-
### SurrealDB
121-
122-
For development it is advised to use a local SurrealDB instance running as a
123-
separate service as compile times are quite long. In production builds SurrealDB
124-
will be available as an embedded database in the application. SurrealDB listens
125-
on port 8000 by default which is the same as the default port for the application
126-
so make sure to change the SurrealDB port or application port before running the
127-
services.
128-
129-
#### Connect to SurrealDB
130-
131-
When the application has been built with the `embedded-db` feature, it allows to
132-
use the application with a `rocksdb://path/to/db` connection string otherwise you
133-
need to connect the the database via web-socket like: `ws://localhost:8800`.
134-
135-
#### Run SurrealDB for development
136-
137-
```bash
138-
# build the application with surrealdb embedded
139-
cargo build --features embedded-db
140-
141-
# start surrealdb container included in docker-compose.yml (listening 8800)
142-
docker-compose up -d surrealdb
143-
144-
# with surrealdb installed on your local machine (listening on port 8800)
145-
surrealdb start --unauthenticated --bind 127.0.0.1:8800
146-
```
147-
148-
#### Explore the database with Surrealist
149-
150-
To work with and explore the database, you can use
151-
[Surrealist](https://surrealdb.com/surrealist) which is an interactive interface
152-
for SurrealDB.
153-
15432
## Contribute
15533

15634
Check out the project [contributing guide](./CONTRIBUTING.md).

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
too-many-arguments-threshold=12
1+
too-many-arguments-threshold=13

crates/bcr-ebill-api/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bcr-ebill-api"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2024"
55

66
[lib]
@@ -10,7 +10,6 @@ doctest = false
1010
borsh.workspace = true
1111
borsh-derive.workspace = true
1212
chrono.workspace = true
13-
tokio.workspace = true
1413
async-trait.workspace = true
1514
serde_json.workspace = true
1615
serde.workspace = true
@@ -22,10 +21,7 @@ uuid.workspace = true
2221
bitcoin.workspace = true
2322
nostr-sdk.workspace = true
2423
futures.workspace = true
25-
reqwest = { version = "0.12.12", default-features = false, features = [
26-
"rustls-tls",
27-
"json",
28-
] }
24+
reqwest.workspace = true
2925
rust_decimal = { version = "1.36.0", default-features = false }
3026
infer = { version = "0.19.0", default-features = false }
3127
bcr-ebill-core = { path = "../bcr-ebill-core" }
@@ -35,6 +31,8 @@ bcr-ebill-transport = { path = "../bcr-ebill-transport" }
3531
[dev-dependencies]
3632
mockall = "0.13.1"
3733
nostr-relay-builder = "0.39.0"
34+
tokio.workspace = true
35+
async-broadcast.workspace = true
3836

3937
[features]
4038
embedded-db = ["bcr-ebill-persistence/embedded-db"]

crates/bcr-ebill-api/src/external/bitcoin.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{get_config, util};
22
use async_trait::async_trait;
3+
use bcr_ebill_core::ServiceTraitBounds;
34
use bitcoin::{Network, secp256k1::Scalar};
45
use serde::Deserialize;
56
use std::str::FromStr;
@@ -32,8 +33,9 @@ pub enum Error {
3233
use mockall::automock;
3334

3435
#[cfg_attr(test, automock)]
35-
#[async_trait]
36-
pub trait BitcoinClientApi: Send + Sync {
36+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
37+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
38+
pub trait BitcoinClientApi: ServiceTraitBounds {
3739
async fn get_address_info(&self, address: &str) -> Result<AddressInfo>;
3840

3941
#[allow(dead_code)]
@@ -63,6 +65,11 @@ pub trait BitcoinClientApi: Send + Sync {
6365
#[derive(Clone)]
6466
pub struct BitcoinClient;
6567

68+
impl ServiceTraitBounds for BitcoinClient {}
69+
70+
#[cfg(test)]
71+
impl ServiceTraitBounds for MockBitcoinClientApi {}
72+
6673
impl BitcoinClient {
6774
pub fn new() -> Self {
6875
Self {}
@@ -97,7 +104,8 @@ impl Default for BitcoinClient {
97104
}
98105
}
99106

100-
#[async_trait]
107+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
108+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
101109
impl BitcoinClientApi for BitcoinClient {
102110
async fn get_address_info(&self, address: &str) -> Result<AddressInfo> {
103111
let address: AddressInfo = reqwest::get(&self.request_url(&format!("/address/{address}")))

crates/bcr-ebill-api/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub mod util;
1515
pub use blockchain::Block;
1616
pub use blockchain::Blockchain;
1717
pub use persistence::DbContext;
18+
pub use persistence::Error as PersistenceError;
19+
pub use persistence::db::SurrealDbConfig;
1820
pub use persistence::get_db_context;
1921
pub use persistence::notification::NotificationFilter;
2022

0 commit comments

Comments
 (0)