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

Commit 49b72c1

Browse files
committed
Import jsonrpc crate
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.
1 parent 45addbd commit 49b72c1

15 files changed

+2321
-6
lines changed

Cargo-minimal.lock

+46-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ dependencies = [
106106
"serde_json",
107107
]
108108

109+
[[package]]
110+
name = "byteorder"
111+
version = "1.5.0"
112+
source = "registry+https://github.com/rust-lang/crates.io-index"
113+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
114+
109115
[[package]]
110116
name = "cc"
111117
version = "1.0.28"
@@ -136,15 +142,20 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
136142
[[package]]
137143
name = "jsonrpc"
138144
version = "0.18.0"
139-
source = "registry+https://github.com/rust-lang/crates.io-index"
140-
checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf"
141145
dependencies = [
142146
"base64",
143147
"minreq",
144148
"serde",
145149
"serde_json",
150+
"socks",
146151
]
147152

153+
[[package]]
154+
name = "libc"
155+
version = "0.2.158"
156+
source = "registry+https://github.com/rust-lang/crates.io-index"
157+
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
158+
148159
[[package]]
149160
name = "log"
150161
version = "0.4.18"
@@ -237,6 +248,17 @@ dependencies = [
237248
"serde",
238249
]
239250

251+
[[package]]
252+
name = "socks"
253+
version = "0.3.4"
254+
source = "registry+https://github.com/rust-lang/crates.io-index"
255+
checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b"
256+
dependencies = [
257+
"byteorder",
258+
"libc",
259+
"winapi",
260+
]
261+
240262
[[package]]
241263
name = "syn"
242264
version = "2.0.56"
@@ -253,3 +275,25 @@ name = "unicode-ident"
253275
version = "1.0.8"
254276
source = "registry+https://github.com/rust-lang/crates.io-index"
255277
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
278+
279+
[[package]]
280+
name = "winapi"
281+
version = "0.3.9"
282+
source = "registry+https://github.com/rust-lang/crates.io-index"
283+
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
284+
dependencies = [
285+
"winapi-i686-pc-windows-gnu",
286+
"winapi-x86_64-pc-windows-gnu",
287+
]
288+
289+
[[package]]
290+
name = "winapi-i686-pc-windows-gnu"
291+
version = "0.4.0"
292+
source = "registry+https://github.com/rust-lang/crates.io-index"
293+
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
294+
295+
[[package]]
296+
name = "winapi-x86_64-pc-windows-gnu"
297+
version = "0.4.0"
298+
source = "registry+https://github.com/rust-lang/crates.io-index"
299+
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

Cargo-recent.lock

+46-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ dependencies = [
106106
"serde_json",
107107
]
108108

109+
[[package]]
110+
name = "byteorder"
111+
version = "1.5.0"
112+
source = "registry+https://github.com/rust-lang/crates.io-index"
113+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
114+
109115
[[package]]
110116
name = "cc"
111117
version = "1.0.28"
@@ -136,15 +142,20 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
136142
[[package]]
137143
name = "jsonrpc"
138144
version = "0.18.0"
139-
source = "registry+https://github.com/rust-lang/crates.io-index"
140-
checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf"
141145
dependencies = [
142146
"base64",
143147
"minreq",
144148
"serde",
145149
"serde_json",
150+
"socks",
146151
]
147152

153+
[[package]]
154+
name = "libc"
155+
version = "0.2.158"
156+
source = "registry+https://github.com/rust-lang/crates.io-index"
157+
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
158+
148159
[[package]]
149160
name = "log"
150161
version = "0.4.18"
@@ -237,6 +248,17 @@ dependencies = [
237248
"serde",
238249
]
239250

251+
[[package]]
252+
name = "socks"
253+
version = "0.3.4"
254+
source = "registry+https://github.com/rust-lang/crates.io-index"
255+
checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b"
256+
dependencies = [
257+
"byteorder",
258+
"libc",
259+
"winapi",
260+
]
261+
240262
[[package]]
241263
name = "syn"
242264
version = "2.0.56"
@@ -253,3 +275,25 @@ name = "unicode-ident"
253275
version = "1.0.8"
254276
source = "registry+https://github.com/rust-lang/crates.io-index"
255277
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
278+
279+
[[package]]
280+
name = "winapi"
281+
version = "0.3.9"
282+
source = "registry+https://github.com/rust-lang/crates.io-index"
283+
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
284+
dependencies = [
285+
"winapi-i686-pc-windows-gnu",
286+
"winapi-x86_64-pc-windows-gnu",
287+
]
288+
289+
[[package]]
290+
name = "winapi-i686-pc-windows-gnu"
291+
version = "0.4.0"
292+
source = "registry+https://github.com/rust-lang/crates.io-index"
293+
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
294+
295+
[[package]]
296+
name = "winapi-x86_64-pc-windows-gnu"
297+
version = "0.4.0"
298+
source = "registry+https://github.com/rust-lang/crates.io-index"
299+
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["client", "json"]
2+
members = ["client", "json", "jsonrpc"]
33
exclude = ["integration_test", "regtest"]
44
resolver = "2"
55

@@ -8,3 +8,6 @@ path = "client"
88

99
[patch.crates-io.bitcoind-json-rpc-types]
1010
path = "json"
11+
12+
[patch.crates-io.jsonrpc]
13+
path = "jsonrpc"

contrib/crates.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# shellcheck disable=SC2148
33

44
# Crates in this workspace to test.
5-
CRATES=("json" "client")
5+
CRATES=("json" "client" "jsonrpc")

jsonrpc/Cargo.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
name = "jsonrpc"
3+
version = "0.18.0"
4+
authors = ["Andrew Poelstra <[email protected]>"]
5+
license = "CC0-1.0"
6+
homepage = "https://github.com/apoelstra/rust-jsonrpc/"
7+
repository = "https://github.com/apoelstra/rust-jsonrpc/"
8+
documentation = "https://docs.rs/jsonrpc/"
9+
description = "Rust support for the JSON-RPC 2.0 protocol"
10+
keywords = [ "protocol", "json", "http", "jsonrpc" ]
11+
readme = "README.md"
12+
edition = "2021"
13+
rust-version = "1.56.1"
14+
exclude = ["tests", "contrib"]
15+
16+
[package.metadata.docs.rs]
17+
all-features = true
18+
rustdoc-args = ["--cfg", "docsrs"]
19+
20+
[features]
21+
default = [ "simple_http", "simple_tcp" ]
22+
# A bare-minimum HTTP transport.
23+
simple_http = [ "base64" ]
24+
# A transport that uses `minreq` as the HTTP client.
25+
minreq_http = [ "base64", "minreq" ]
26+
# Basic transport over a raw TcpListener
27+
simple_tcp = []
28+
# Basic transport over a raw UnixStream
29+
simple_uds = []
30+
# Enable Socks5 Proxy in transport
31+
proxy = ["socks"]
32+
33+
[dependencies]
34+
serde = { version = "1", features = ["derive"] }
35+
serde_json = { version = "1", features = [ "raw_value" ] }
36+
37+
base64 = { version = "0.13.0", optional = true }
38+
minreq = { version = "2.7.0", features = ["json-using-serde"], optional = true }
39+
socks = { version = "0.3.4", optional = true}
40+
41+
[lints.rust]
42+
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(jsonrpc_fuzz)'] }

jsonrpc/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[![Status](https://travis-ci.org/apoelstra/rust-jsonrpc.png?branch=master)](https://travis-ci.org/apoelstra/rust-jsonrpc)
2+
3+
# Rust Version compatibility
4+
5+
This library is compatible with Rust **1.63.0** or higher.
6+
7+
# Rust JSONRPC Client
8+
9+
Rudimentary support for sending JSONRPC 2.0 requests and receiving responses.
10+
11+
As an example, hit a local bitcoind JSON-RPC endpoint and call the `uptime` command.
12+
13+
```rust
14+
use jsonrpc::Client;
15+
use jsonrpc::simple_http::{self, SimpleHttpTransport};
16+
17+
fn client(url: &str, user: &str, pass: &str) -> Result<Client, simple_http::Error> {
18+
let t = SimpleHttpTransport::builder()
19+
.url(url)?
20+
.auth(user, Some(pass))
21+
.build();
22+
23+
Ok(Client::with_transport(t))
24+
}
25+
26+
// Demonstrate an example JSON-RCP call against bitcoind.
27+
fn main() {
28+
let client = client("localhost:18443", "user", "pass").expect("failed to create client");
29+
let request = client.build_request("uptime", None);
30+
let response = client.send_request(request).expect("send_request failed");
31+
32+
// For other commands this would be a struct matching the returned json.
33+
let result: u64 = response.result().expect("response is an error, use check_error");
34+
println!("bitcoind uptime: {}", result);
35+
}
36+
```
37+
38+
## Githooks
39+
40+
To assist devs in catching errors _before_ running CI we provide some githooks. If you do not
41+
already have locally configured githooks you can use the ones in this repository by running, in the
42+
root directory of the repository:
43+
```
44+
git config --local core.hooksPath githooks/
45+
```
46+
47+
Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.

jsonrpc/contrib/test_vars.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# `rust-jsonrpc` does not have a std feature.
4+
FEATURES_WITH_STD=""
5+
6+
# So this is the var to use for all tests.
7+
FEATURES_WITHOUT_STD="simple_http minreq_http simple_tcp simple_uds proxy"
8+
9+
# Run these examples.
10+
EXAMPLES=""

0 commit comments

Comments
 (0)