Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Import jsonrpc crate
Browse files Browse the repository at this point in the history
Import the `rust-jsonrpc` crate from
https://github.com/apoelstra/rust-jsonrpc using current tip of master

`59646e6 Merge apoelstra/rust-jsonrpc#119: Use rust-bitcoin-maintainer-tools and re-write CI`

Full commit hash: 59646e6e6ac95f07998133b1709e4a1fa2dbc7bd

Do so using the following commands:

mkdir jsonrpc
mkdir jsonrpc/contrib
rsync -avz ../../rust-jsonrpc/master/README.md jsonrpc
rsync -avz ../../rust-jsonrpc/master/src jsonrpc
rsync -avz ../../rust-jsonrpc/master/contrib/test_vars.sh jsonrpc/contrib

Then:

- Update `contrib/crates.sh` to include `jsonrpc`.
- Remove workspaces from `jsonrpc/Cargo.toml`.
- Add `jsonrpc` to repository workspace (and add patch section).

Note, this PR does not bring over the `fuzz` directory, that will be
done separately. Also we do not copy the integration testing because
we get sufficient coverage from the current integration tests.
  • Loading branch information
tcharding committed Aug 23, 2024
1 parent 4b0bd28 commit 5877e80
Show file tree
Hide file tree
Showing 15 changed files with 2,321 additions and 6 deletions.
48 changes: 46 additions & 2 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ dependencies = [
"serde_json",
]

[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"

[[package]]
name = "cc"
version = "1.0.28"
Expand Down Expand Up @@ -136,15 +142,20 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "jsonrpc"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf"
dependencies = [
"base64",
"minreq",
"serde",
"serde_json",
"socks",
]

[[package]]
name = "libc"
version = "0.2.158"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"

[[package]]
name = "log"
version = "0.4.18"
Expand Down Expand Up @@ -237,6 +248,17 @@ dependencies = [
"serde",
]

[[package]]
name = "socks"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b"
dependencies = [
"byteorder",
"libc",
"winapi",
]

[[package]]
name = "syn"
version = "2.0.56"
Expand All @@ -253,3 +275,25 @@ name = "unicode-ident"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"

[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
48 changes: 46 additions & 2 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ dependencies = [
"serde_json",
]

[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"

[[package]]
name = "cc"
version = "1.0.28"
Expand Down Expand Up @@ -136,15 +142,20 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "jsonrpc"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf"
dependencies = [
"base64",
"minreq",
"serde",
"serde_json",
"socks",
]

[[package]]
name = "libc"
version = "0.2.158"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"

[[package]]
name = "log"
version = "0.4.18"
Expand Down Expand Up @@ -237,6 +248,17 @@ dependencies = [
"serde",
]

[[package]]
name = "socks"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b"
dependencies = [
"byteorder",
"libc",
"winapi",
]

[[package]]
name = "syn"
version = "2.0.56"
Expand All @@ -253,3 +275,25 @@ name = "unicode-ident"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"

[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["client", "json"]
members = ["client", "json", "jsonrpc"]
exclude = ["integration_test", "regtest"]
resolver = "2"

Expand All @@ -8,3 +8,6 @@ path = "client"

[patch.crates-io.bitcoind-json-rpc-types]
path = "json"

[patch.crates-io.jsonrpc]
path = "jsonrpc"
2 changes: 1 addition & 1 deletion contrib/crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# shellcheck disable=SC2148

# Crates in this workspace to test.
CRATES=("json" "client")
CRATES=("json" "client" "jsonrpc")
42 changes: 42 additions & 0 deletions jsonrpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "jsonrpc"
version = "0.18.0"
authors = ["Andrew Poelstra <[email protected]>"]
license = "CC0-1.0"
homepage = "https://github.com/apoelstra/rust-jsonrpc/"
repository = "https://github.com/apoelstra/rust-jsonrpc/"
documentation = "https://docs.rs/jsonrpc/"
description = "Rust support for the JSON-RPC 2.0 protocol"
keywords = [ "protocol", "json", "http", "jsonrpc" ]
readme = "README.md"
edition = "2021"
rust-version = "1.56.1"
exclude = ["tests", "contrib"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = [ "simple_http", "simple_tcp" ]
# A bare-minimum HTTP transport.
simple_http = [ "base64" ]
# A transport that uses `minreq` as the HTTP client.
minreq_http = [ "base64", "minreq" ]
# Basic transport over a raw TcpListener
simple_tcp = []
# Basic transport over a raw UnixStream
simple_uds = []
# Enable Socks5 Proxy in transport
proxy = ["socks"]

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = [ "raw_value" ] }

base64 = { version = "0.13.0", optional = true }
minreq = { version = "2.7.0", features = ["json-using-serde"], optional = true }
socks = { version = "0.3.4", optional = true}

[lints.rust]
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(jsonrpc_fuzz)'] }
47 changes: 47 additions & 0 deletions jsonrpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[![Status](https://travis-ci.org/apoelstra/rust-jsonrpc.png?branch=master)](https://travis-ci.org/apoelstra/rust-jsonrpc)

# Rust Version compatibility

This library is compatible with Rust **1.63.0** or higher.

# Rust JSONRPC Client

Rudimentary support for sending JSONRPC 2.0 requests and receiving responses.

As an example, hit a local bitcoind JSON-RPC endpoint and call the `uptime` command.

```rust
use jsonrpc::Client;
use jsonrpc::simple_http::{self, SimpleHttpTransport};

fn client(url: &str, user: &str, pass: &str) -> Result<Client, simple_http::Error> {
let t = SimpleHttpTransport::builder()
.url(url)?
.auth(user, Some(pass))
.build();

Ok(Client::with_transport(t))
}

// Demonstrate an example JSON-RCP call against bitcoind.
fn main() {
let client = client("localhost:18443", "user", "pass").expect("failed to create client");
let request = client.build_request("uptime", None);
let response = client.send_request(request).expect("send_request failed");

// For other commands this would be a struct matching the returned json.
let result: u64 = response.result().expect("response is an error, use check_error");
println!("bitcoind uptime: {}", result);
}
```

## Githooks

To assist devs in catching errors _before_ running CI we provide some githooks. If you do not
already have locally configured githooks you can use the ones in this repository by running, in the
root directory of the repository:
```
git config --local core.hooksPath githooks/
```

Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.
10 changes: 10 additions & 0 deletions jsonrpc/contrib/test_vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# `rust-jsonrpc` does not have a std feature.
FEATURES_WITH_STD=""

# So this is the var to use for all tests.
FEATURES_WITHOUT_STD="simple_http minreq_http simple_tcp simple_uds proxy"

# Run these examples.
EXAMPLES=""
Loading

0 comments on commit 5877e80

Please sign in to comment.