Skip to content

Commit

Permalink
Merge branch 'main' into documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen authored Sep 5, 2024
2 parents 5f54f01 + 1503836 commit 1d374aa
Show file tree
Hide file tree
Showing 20 changed files with 509 additions and 381 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- RPC server interface is disabled by default
- It can be enabled by a feature flag

## [0.0.10] - 2024-09-04

### Changed

- If there is a connection to ledger while calling `Client::new()`, database won't get cleaned
- Block lock checks fixed

## [0.0.9] - 2024-09-03

### Added

- Simple UTXO management

### Changed

- Improved logging
- Error on unimplemented RPC argument
- Improved main binary CLI interface

## [0.0.8] - 2024-08-28

### Added
Expand Down Expand Up @@ -122,6 +148,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `generate_to_address`
- `get_balance`

[Unreleased]: https://github.com/chainwayxyz/bitcoin-mock-rpc/compare/v0.0.10...HEAD
[0.0.10]: https://github.com/chainwayxyz/bitcoin-mock-rpc/compare/v0.0.9...v0.0.10
[0.0.9]: https://github.com/chainwayxyz/bitcoin-mock-rpc/compare/v0.0.8...v0.0.9
[0.0.8]: https://github.com/chainwayxyz/bitcoin-mock-rpc/compare/v0.0.7...v0.0.8
[0.0.7]: https://github.com/chainwayxyz/bitcoin-mock-rpc/compare/v0.0.6...v0.0.7
[0.0.6]: https://github.com/chainwayxyz/bitcoin-mock-rpc/compare/v0.0.5...v0.0.6
Expand Down
16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitcoin-mock-rpc"
version = "0.0.8"
version = "0.0.9"
edition = "2021"

[dependencies]
Expand All @@ -13,12 +13,16 @@ thiserror = "1.0.63"
bitcoin-scriptexec = { git = "https://github.com/Bitcoin-Wildlife-Sanctuary/rust-bitcoin-scriptexec" }
rusqlite = { version = "0.32.1", features = ["bundled"] }
rs_merkle = "1.4"
jsonrpsee = { version = "0.24.3", features = ["server", "client", "macros"], default-features = false }
tokio = { version = "1.39.3", features = ["full"]}
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tower = "0.4.13"
clap = { version = "4.5.16", features = ["derive"] }
jsonrpsee = { version = "0.24.3", features = ["server", "client", "macros"], default-features = false, optional = true }
tokio = { version = "1.39.3", features = ["full"], optional = true }
tower = { version = "0.4.13", optional = true }

[[bin]]
name = "bitcoin_mock_rpc"
[dev-dependencies]
tokio = { version = "1.39.3", features = ["full"] }

[features]
# Enables RPC server interface. Note: Not stable nor complete. Use it in your own caution.
rpc_server = ["dep:jsonrpsee", "dep:tokio", "dep:tower"]
75 changes: 18 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Bitcoin Mock Remote Procedure Call

Bitcoin-mock-rpc is a mock Bitcoin ledger with RPC interface but without a
wallet support. Meaning there are only checks for consensus details of an
operation. This library can be used to test Bitcoin applications, without
needing to set up Bitcoin and with a **sandboxed environment**, for each test.

Bitcoin-mock-rpc is built on
[bitcoincore-rpc's](https://github.com/rust-bitcoin/rust-bitcoincore-rpc)
`RpcApi` trait. Meaning no real servers are needed for Rust applications. There
is also an RPC server that can communicate with any application: No rust
dependencies!
`bitcoin-mock-rpc` is a mock Bitcoin ledger without a wallet support built on
`RpcApi` trait in
[bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc) library.
Meaning there are only checks for consensus details of an operation. This
library can be used to test Bitcoin applications, without needing to set up
Bitcoin and with a **sandboxed environment**, for each test.

This library is aimed to help the development of
[Clementine](https://github.com/chainwayxyz/clementine). Therefore, it's usage
Expand All @@ -19,55 +15,8 @@ of this library can be taken as a reference.
not gives any guarantee to act as the Bitcoin itself at any scale. Use it at
your own risk.

## Differences Between Real Bitcoin RPC and Feature Set

This library is currently **under heavy development**. And it is not expected to
provide a full Bitcoin experience. Code needs to be checked for what really is
available as futures. Also, [changelog](CHANGELOG.md) is a great summary for
what's available.

Some of the RPC functions behave similarly with real RPC while some of them are
not (mostly wallet operations). To check if an RPC function behaves different
than the real one, please check function comments in
[`src/client/rpc_api.rs`](src/client/rpc_api.rs).

## Usage

### RPC Server

RPC server can be spawned as long as there are available ports for them. Each
server will have an independent blockchain.

To run from CLI:

```bash
$ cargo run
Server started at 127.0.0.1:1024
# ^^^^^^^^^^^^^^
# Use this address in applications
$ cargo run -- --help # Prints usage information
```

To run in a Rust application:

```rust
#[test]
fn test() {
// Calling `spawn_rpc_server` in a different test while this test is running
// is OK and will spawn another blockchain. If parameters are the same
// however, they will operate on the same blockchain. Note: (None, None)
// will result to pick random values.
let address = bitcoin_mock_rpc::spawn_rpc_server(None, None).unwrap();

let rpc =
bitcoincore_rpc::Client::new(&address.0.to_string(), bitcoincore_rpc::Auth::None).unwrap();

// Use `bitcoincore_rpc` as is from now on. No code change is needed.
}
```

### `RpcApiWrapper` Trait For Rust Applications

`RpcApiWrapper` trait can be used to select between real and mock RPC:

```rust
Expand Down Expand Up @@ -98,6 +47,18 @@ fn test() {
}
```

## Differences Between Real Bitcoin RPC and Feature Set

This library is currently **under heavy development**. And it is not expected to
provide a full Bitcoin experience. Code needs to be checked for what really is
available as futures. Also, [changelog](CHANGELOG.md) is a great summary for
what's available.

Some of the RPC functions behave similarly with real RPC while some of them are
not (mostly wallet operations). To check if an RPC function behaves different
than the real one, please check function comments in
[`src/client/rpc_api.rs`](src/client/rpc_api.rs).

## Testing

Standard Rust tools are sufficient for testing:
Expand Down
61 changes: 0 additions & 61 deletions src/bin/bitcoin_mock_rpc.rs

This file was deleted.

Loading

0 comments on commit 1d374aa

Please sign in to comment.