From e975c993eb5361f697395b0980fdc57a00551354 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sun, 2 Jun 2024 07:38:06 +1000 Subject: [PATCH] Convert the crate to a workspace Mirror the crate structure in `rust-bitcoincore-rpc` by adding crates: - `client` - `json` - `integration_test` Exclude `integration_test` from the workspace because it should currently be used with specific versions (all features won't work until "26_0" is implemented). --- Cargo.toml | 57 ++------ .../mining/convert.rs => client/CHANGELOG.md | 0 client/Cargo.toml | 40 ++++++ client/LICENSE | 122 ++++++++++++++++ {src => client/src}/client_sync/error.rs | 0 {src => client/src}/client_sync/mod.rs | 4 +- .../src}/client_sync/v17/blockchain.rs | 4 +- .../src}/client_sync/v17/control.rs | 0 .../src}/client_sync/v17/generating.rs | 0 {src => client/src}/client_sync/v17/mod.rs | 0 .../src}/client_sync/v17/network.rs | 0 {src => client/src}/client_sync/v17/wallet.rs | 0 {src => client/src}/client_sync/v18/mod.rs | 1 - {src => client/src}/client_sync/v22/mod.rs | 0 {src => client/src}/client_sync/v22/wallet.rs | 0 client/src/lib.rs | 13 ++ integration_test/Cargo.toml | 49 +++++++ integration_test/src/lib.rs | 40 ++++++ .../src}/v17/blockchain.rs | 8 +- .../src}/v17/control.rs | 2 +- .../src}/v17/generating.rs | 2 +- .../src}/v17/mod.rs | 0 .../src}/v17/network.rs | 2 +- .../src}/v17/wallet.rs | 12 +- .../src}/v22/blockchain.rs | 4 +- .../src}/v22/mod.rs | 0 .../src}/v22/wallet.rs | 4 +- integration_test/tests/v17_api.rs | 49 +++++++ integration_test/tests/v18_api.rs | 47 ++++++ integration_test/tests/v22_api.rs | 51 +++++++ .../v17/util/convert.rs => json/CHANGELOG.md | 0 json/Cargo.toml | 24 ++++ json/LICENSE | 122 ++++++++++++++++ json/src/lib.rs | 16 +++ json/src/mod.rs | 0 {src => json/src}/model/blockchain.rs | 0 {src => json/src}/model/control.rs | 0 {src => json/src}/model/generating.rs | 0 {src => json/src}/model/mining.rs | 0 {src => json/src}/model/mod.rs | 0 {src => json/src}/model/network.rs | 0 {src => json/src}/model/raw_transactions.rs | 0 {src => json/src}/model/util.rs | 0 {src => json/src}/model/wallet.rs | 0 {src => json/src}/model/zmq.rs | 0 .../src}/v17/blockchain/convert.rs | 2 +- {src/json => json/src}/v17/blockchain/mod.rs | 0 {src/json => json/src}/v17/control/mod.rs | 0 .../src}/v17/generating/convert.rs | 2 +- {src/json => json/src}/v17/generating/mod.rs | 0 json/src/v17/mining/convert.rs | 0 {src/json => json/src}/v17/mining/mod.rs | 0 {src/json => json/src}/v17/mod.rs | 0 {src/json => json/src}/v17/network/convert.rs | 2 +- {src/json => json/src}/v17/network/mod.rs | 0 .../src}/v17/raw_transactions/mod.rs | 0 {src/json => json/src}/v17/rpc-api.txt | 0 json/src/v17/util/convert.rs | 0 {src/json => json/src}/v17/util/mod.rs | 0 {src/json => json/src}/v17/wallet/convert.rs | 2 +- {src/json => json/src}/v17/wallet/mod.rs | 0 {src/json => json/src}/v17/zmq/mod.rs | 0 {src/json => json/src}/v18/mod.rs | 22 +-- {src/json => json/src}/v18/rpc-api.txt | 0 .../src}/v22/blockchain/convert.rs | 2 +- {src/json => json/src}/v22/blockchain/mod.rs | 0 {src/json => json/src}/v22/generating/mod.rs | 0 {src/json => json/src}/v22/mod.rs | 10 +- {src/json => json/src}/v22/network/convert.rs | 2 +- {src/json => json/src}/v22/network/mod.rs | 0 {src/json => json/src}/v22/rpc-api.txt | 0 {src/json => json/src}/v22/wallet/convert.rs | 2 +- {src/json => json/src}/v22/wallet/mod.rs | 0 src/json/mod.rs | 10 -- tests/client/mod.rs | 136 ------------------ tests/v17_api.rs | 51 ------- tests/v18_api.rs | 49 ------- tests/v22_api.rs | 53 ------- 78 files changed, 627 insertions(+), 391 deletions(-) rename src/json/v17/mining/convert.rs => client/CHANGELOG.md (100%) create mode 100644 client/Cargo.toml create mode 100644 client/LICENSE rename {src => client/src}/client_sync/error.rs (100%) rename {src => client/src}/client_sync/mod.rs (98%) rename {src => client/src}/client_sync/v17/blockchain.rs (93%) rename {src => client/src}/client_sync/v17/control.rs (100%) rename {src => client/src}/client_sync/v17/generating.rs (100%) rename {src => client/src}/client_sync/v17/mod.rs (100%) rename {src => client/src}/client_sync/v17/network.rs (100%) rename {src => client/src}/client_sync/v17/wallet.rs (100%) rename {src => client/src}/client_sync/v18/mod.rs (97%) rename {src => client/src}/client_sync/v22/mod.rs (100%) rename {src => client/src}/client_sync/v22/wallet.rs (100%) create mode 100644 client/src/lib.rs create mode 100644 integration_test/Cargo.toml create mode 100644 integration_test/src/lib.rs rename {tests/client => integration_test/src}/v17/blockchain.rs (88%) rename {tests/client => integration_test/src}/v17/control.rs (88%) rename {tests/client => integration_test/src}/v17/generating.rs (90%) rename {tests/client => integration_test/src}/v17/mod.rs (100%) rename {tests/client => integration_test/src}/v17/network.rs (90%) rename {tests/client => integration_test/src}/v17/wallet.rs (85%) rename {tests/client => integration_test/src}/v22/blockchain.rs (90%) rename {tests/client => integration_test/src}/v22/mod.rs (100%) rename {tests/client => integration_test/src}/v22/wallet.rs (88%) create mode 100644 integration_test/tests/v17_api.rs create mode 100644 integration_test/tests/v18_api.rs create mode 100644 integration_test/tests/v22_api.rs rename src/json/v17/util/convert.rs => json/CHANGELOG.md (100%) create mode 100644 json/Cargo.toml create mode 100644 json/LICENSE create mode 100644 json/src/lib.rs create mode 100644 json/src/mod.rs rename {src => json/src}/model/blockchain.rs (100%) rename {src => json/src}/model/control.rs (100%) rename {src => json/src}/model/generating.rs (100%) rename {src => json/src}/model/mining.rs (100%) rename {src => json/src}/model/mod.rs (100%) rename {src => json/src}/model/network.rs (100%) rename {src => json/src}/model/raw_transactions.rs (100%) rename {src => json/src}/model/util.rs (100%) rename {src => json/src}/model/wallet.rs (100%) rename {src => json/src}/model/zmq.rs (100%) rename {src/json => json/src}/v17/blockchain/convert.rs (99%) rename {src/json => json/src}/v17/blockchain/mod.rs (100%) rename {src/json => json/src}/v17/control/mod.rs (100%) rename {src/json => json/src}/v17/generating/convert.rs (96%) rename {src/json => json/src}/v17/generating/mod.rs (100%) create mode 100644 json/src/v17/mining/convert.rs rename {src/json => json/src}/v17/mining/mod.rs (100%) rename {src/json => json/src}/v17/mod.rs (100%) rename {src/json => json/src}/v17/network/convert.rs (99%) rename {src/json => json/src}/v17/network/mod.rs (100%) rename {src/json => json/src}/v17/raw_transactions/mod.rs (100%) rename {src/json => json/src}/v17/rpc-api.txt (100%) create mode 100644 json/src/v17/util/convert.rs rename {src/json => json/src}/v17/util/mod.rs (100%) rename {src/json => json/src}/v17/wallet/convert.rs (98%) rename {src/json => json/src}/v17/wallet/mod.rs (100%) rename {src/json => json/src}/v17/zmq/mod.rs (100%) rename {src/json => json/src}/v18/mod.rs (96%) rename {src/json => json/src}/v18/rpc-api.txt (100%) rename {src/json => json/src}/v22/blockchain/convert.rs (99%) rename {src/json => json/src}/v22/blockchain/mod.rs (100%) rename {src/json => json/src}/v22/generating/mod.rs (100%) rename {src/json => json/src}/v22/mod.rs (98%) rename {src/json => json/src}/v22/network/convert.rs (99%) rename {src/json => json/src}/v22/network/mod.rs (100%) rename {src/json => json/src}/v22/rpc-api.txt (100%) rename {src/json => json/src}/v22/wallet/convert.rs (99%) rename {src/json => json/src}/v22/wallet/mod.rs (100%) delete mode 100644 src/json/mod.rs delete mode 100644 tests/client/mod.rs delete mode 100644 tests/v17_api.rs delete mode 100644 tests/v18_api.rs delete mode 100644 tests/v22_api.rs diff --git a/Cargo.toml b/Cargo.toml index b3f6aa4..af67edf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,51 +1,14 @@ -[package] -name = "bitcoind-json-rpc" -version = "0.1.0" -authors = [ - "Steven Roose ", - "Jean Pierre Dudey ", - "Dawid Ciężarkiewicz ", - "Tobin C. Harding " -] -license = "CC0-1.0" -description = "Support for the Bitcoin Core JSON-RPC API" -keywords = ["bitcoin", "json-rpc"] -edition = "2021" +[workspace] +members = ["client", "json"] +exclude = ["integration_test"] +resolver = "2" -[features] -default = [] -# Enable this feature to get JSON-RPC client code. -client-sync = ["jsonrpc"] +[patch.crates-io.bitcoind-json-rpc-client] +path = "client" -# These are only for controlling tests. -"v26" = ["bitcoind/26_0"] # FIXME: The `json/16` module was written for 26.1 -"v25" = ["bitcoind/25_1"] -"v24" = ["bitcoind/24_0_1"] -"v23" = ["bitcoind/23_1"] -"v22" = ["bitcoind/22_1"] -"v21" = ["bitcoind/0_21_2"] -"v20" = ["bitcoind/0_20_2"] -"v19" = ["bitcoind/0_19_1"] -"v18" = ["bitcoind/0_18_1"] -"v17" = ["bitcoind/0_17_1"] - -[dependencies] -bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] } -internals = { package = "bitcoin-internals", version = "0.3.0", default-features = false, features = ["std"] } -log = "0.4" -serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ] } -serde_json = { version = "1.0.117" } - -jsonrpc = { version = "0.18.0", features = ["minreq_http"], optional = true } - -[dev-dependencies] -rand = "0.8.5" -env_logger = "0.9.0" -# FIXME: How are we going to handle features (using features in this crate, ugh!)? -bitcoind = { version = "0.36.0", features = ["22_1"] } +[patch.crates-io.bitcoind-json-rpc-types] +path = "json" [patch.crates-io.bitcoind] -path = "/home/tobin/build/github.com/tcharding/bitcoind/bitcoind-json-rpc" - -[patch.crates-io.bitcoind-json-rpc] -path = "." +git = "https://github.com/tcharding/bitcoind" +branch = "bitcoind-json-rpc" diff --git a/src/json/v17/mining/convert.rs b/client/CHANGELOG.md similarity index 100% rename from src/json/v17/mining/convert.rs rename to client/CHANGELOG.md diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000..0abeccd --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "bitcoind-json-rpc-client" +version = "0.1.0" +authors = [ + "Steven Roose ", + "Jean Pierre Dudey ", + "Dawid Ciężarkiewicz ", + "Tobin C. Harding " +] +license = "CC0-1.0" +description = "Bitcoin Core JSON-RPC client" +keywords = ["bitcoin", "bitcoind", "json-rpc"] +edition = "2021" + +[features] +default = [] +# Enable this feature to get a blocking JSON-RPC client. +client-sync = ["jsonrpc"] + +[dependencies] +bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] } +json = { package = "bitcoind-json-rpc-types", version = "0.1.0", default-features = false, features = [] } +internals = { package = "bitcoin-internals", version = "0.3.0", default-features = false, features = ["std"] } +log = "0.4" +serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ] } +serde_json = { version = "1.0.117" } + +jsonrpc = { version = "0.18.0", features = ["minreq_http"], optional = true } + +[dev-dependencies] +rand = "0.8.5" +env_logger = "0.9.0" +# FIXME: How are we going to handle features (using features in this crate, ugh!)? +bitcoind = { version = "0.36.0", features = ["22_1"] } + +[patch.crates-io.bitcoind] +path = "/home/tobin/build/github.com/tcharding/bitcoind/bitcoind-json-rpc" + +[patch.crates-io.bitcoind-json-rpc] +path = "." diff --git a/client/LICENSE b/client/LICENSE new file mode 100644 index 0000000..6ca207e --- /dev/null +++ b/client/LICENSE @@ -0,0 +1,122 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. + diff --git a/src/client_sync/error.rs b/client/src/client_sync/error.rs similarity index 100% rename from src/client_sync/error.rs rename to client/src/client_sync/error.rs diff --git a/src/client_sync/mod.rs b/client/src/client_sync/mod.rs similarity index 98% rename from src/client_sync/mod.rs rename to client/src/client_sync/mod.rs index 43138a1..0e03250 100644 --- a/src/client_sync/mod.rs +++ b/client/src/client_sync/mod.rs @@ -134,14 +134,14 @@ macro_rules! impl_client_helpers { /// Gets the blockhash of the current chain tip. pub fn best_block_hash(&self) -> Result { let json = self.get_blockchain_info()?; - let concrete: $crate::model::GetBlockchainInfo = json.try_into().unwrap(); + let concrete: $crate::json::model::GetBlockchainInfo = json.try_into().unwrap(); Ok(concrete.best_block_hash) } /// Gets a block by blockhash. pub fn get_block(&self, hash: &bitcoin::BlockHash) -> Result { let json = self.get_block_verbosity_zero(hash)?; - let concrete: $crate::model::GetBlockVerbosityZero = json.try_into()?; + let concrete: $crate::json::model::GetBlockVerbosityZero = json.try_into()?; Ok(concrete.0) } } diff --git a/src/client_sync/v17/blockchain.rs b/client/src/client_sync/v17/blockchain.rs similarity index 93% rename from src/client_sync/v17/blockchain.rs rename to client/src/client_sync/v17/blockchain.rs index 21ecb73..9ae7858 100644 --- a/src/client_sync/v17/blockchain.rs +++ b/client/src/client_sync/v17/blockchain.rs @@ -29,7 +29,7 @@ macro_rules! impl_client_v17__getbestblockhash { /// Gets the blockhash of the current chain tip. pub fn best_block_hash(&self) -> Result { let json = self.get_best_block_hash()?; - let concrete: $crate::model::GetBestBlockHash = json.try_into().unwrap(); + let concrete: $crate::json::model::GetBestBlockHash = json.try_into().unwrap(); Ok(concrete.0) } @@ -48,7 +48,7 @@ macro_rules! impl_client_v17__getblock { /// Gets a block by blockhash. pub fn get_block(&self, hash: &BlockHash) -> Result { let json = self.get_block_verbosity_zero(hash)?; - let concrete: $crate::model::GetBlockVerbosityZero = json.try_into()?; + let concrete: $crate::json::model::GetBlockVerbosityZero = json.try_into()?; Ok(concrete.0) } diff --git a/src/client_sync/v17/control.rs b/client/src/client_sync/v17/control.rs similarity index 100% rename from src/client_sync/v17/control.rs rename to client/src/client_sync/v17/control.rs diff --git a/src/client_sync/v17/generating.rs b/client/src/client_sync/v17/generating.rs similarity index 100% rename from src/client_sync/v17/generating.rs rename to client/src/client_sync/v17/generating.rs diff --git a/src/client_sync/v17/mod.rs b/client/src/client_sync/v17/mod.rs similarity index 100% rename from src/client_sync/v17/mod.rs rename to client/src/client_sync/v17/mod.rs diff --git a/src/client_sync/v17/network.rs b/client/src/client_sync/v17/network.rs similarity index 100% rename from src/client_sync/v17/network.rs rename to client/src/client_sync/v17/network.rs diff --git a/src/client_sync/v17/wallet.rs b/client/src/client_sync/v17/wallet.rs similarity index 100% rename from src/client_sync/v17/wallet.rs rename to client/src/client_sync/v17/wallet.rs diff --git a/src/client_sync/v18/mod.rs b/client/src/client_sync/v18/mod.rs similarity index 97% rename from src/client_sync/v18/mod.rs rename to client/src/client_sync/v18/mod.rs index c3fbff7..40c6b08 100644 --- a/src/client_sync/v18/mod.rs +++ b/client/src/client_sync/v18/mod.rs @@ -14,7 +14,6 @@ use crate::json::v18::*; const EXPECTED_SERVER_VERSION: usize = 180100; crate::define_jsonrpc_minreq_client!(); -//crate::impl_client_helpers!(); // == Network == crate::impl_client_v17__getnetworkinfo!(); diff --git a/src/client_sync/v22/mod.rs b/client/src/client_sync/v22/mod.rs similarity index 100% rename from src/client_sync/v22/mod.rs rename to client/src/client_sync/v22/mod.rs diff --git a/src/client_sync/v22/wallet.rs b/client/src/client_sync/v22/wallet.rs similarity index 100% rename from src/client_sync/v22/wallet.rs rename to client/src/client_sync/v22/wallet.rs diff --git a/client/src/lib.rs b/client/src/lib.rs new file mode 100644 index 0000000..c7f425e --- /dev/null +++ b/client/src/lib.rs @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: CC0-1.0 + +//! Support for connecting to Bitcoin Core via JSON-RPC. + +/// Re-export the `rust-bitcoin` crate. +pub extern crate bitcoin; + +/// Re-export the `rust-bitcoin-json-rpc-tyes` crate. +pub extern crate json; + +#[cfg(feature = "client-sync")] +#[macro_use] +pub mod client_sync; diff --git a/integration_test/Cargo.toml b/integration_test/Cargo.toml new file mode 100644 index 0000000..11d8735 --- /dev/null +++ b/integration_test/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "integration-test" +version = "0.1.0" +authors = ["Tobin C. Harding "] +license = "CC0-1.0" +description = "Integration tests for bitcoind-json-rpc-client/types" +edition = "2021" + +[features] +"26_0" =["v26", "bitcoind/26_0"] +"25_1" = ["v25", "bitcoind/25_1"] +"25_0" = ["v25", "bitcoind/25_0"] +"24_0_1" = ["v24", "bitcoind/24_0_1"] +"23_1" = ["v23", "bitcoind/23_1"] +"22_1" = ["v22", "bitcoind/22_1"] +"0_21_2" = ["v21", "bitcoind/0_21_2"] +"0_20_2" = ["v20", "bitcoind/0_20_2"] +"0_19_1" = ["v19", "bitcoind/0_19_1"] +"0_18_1" = ["v18", "bitcoind/0_18_1"] +"0_17_1" = ["v17", "bitcoind/0_17_1"] + +"v26" = [] +"v25" = [] +"v24" = [] +"v23" = [] +"v22" = [] +"v21" = [] +"v20" = [] +"v19" = [] +"v18" = [] +"v17" = [] + +[dependencies] +bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] } +client = { package = "bitcoind-json-rpc-client", version = "0.1.0", default-features = false, features = ["client-sync"] } +bitcoind = { version = "0.36.0", default-features = false, features = [] } +rand = "0.8.5" +env_logger = "0.9.0" + +[dev-dependencies] + +[patch.crates-io.bitcoind-json-rpc-client] +path = "../client" + +[patch.crates-io.bitcoind-json-rpc-types] +path = "../json" + +[patch.crates-io.bitcoind] +path = "/home/tobin/build/github.com/tcharding/bitcoind/bitcoind-json-rpc" diff --git a/integration_test/src/lib.rs b/integration_test/src/lib.rs new file mode 100644 index 0000000..4a9114c --- /dev/null +++ b/integration_test/src/lib.rs @@ -0,0 +1,40 @@ +//! Provides a macro that implements the tests. + +pub mod v17; +pub mod v22; + +/// Requires `RPC_PORT` to be in scope. +use bitcoind::BitcoinD; + +/// Initialize a logger (configure with `RUST_LOG=trace cargo test`). +#[allow(dead_code)] // Not all tests use this function. +pub fn init_logger() { let _ = env_logger::try_init(); } + +/// Returns a handle to a `bitcoind` instance with "default" wallet loaded. +#[allow(dead_code)] // Not all tests use this function. +pub fn bitcoind_with_default_wallet() -> BitcoinD { + let exe = bitcoind::exe_path().expect("failed to get bitcoind executable"); + + let conf = bitcoind::Conf::default(); + BitcoinD::with_conf(exe, &conf).expect("failed to create BitcoinD") +} + +/// Returns a handle to a `bitcoind` instance without any wallets. +#[allow(dead_code)] // Not all tests use this function. +pub fn bitcoind_with_wallet(wallet: String) -> BitcoinD { + let exe = bitcoind::exe_path().expect("failed to get bitcoind executable"); + + let mut conf = bitcoind::Conf::default(); + conf.wallet = Some(wallet); + BitcoinD::with_conf(exe, &conf).expect("failed to create BitcoinD") +} + +/// Returns a handle to a `bitcoind` instance without any wallet loaded. +#[allow(dead_code)] // Not all tests use this function. +pub fn bitcoind_no_wallet() -> BitcoinD { + let exe = bitcoind::exe_path().expect("failed to get bitcoind executable"); + + let mut conf = bitcoind::Conf::default(); + conf.wallet = None; + BitcoinD::with_conf(exe, &conf).expect("failed to create BitcoinD") +} diff --git a/tests/client/v17/blockchain.rs b/integration_test/src/v17/blockchain.rs similarity index 88% rename from tests/client/v17/blockchain.rs rename to integration_test/src/v17/blockchain.rs index 11a795c..e7b0be0 100644 --- a/tests/client/v17/blockchain.rs +++ b/integration_test/src/v17/blockchain.rs @@ -11,7 +11,7 @@ macro_rules! impl_test_v17__getblockchaininfo { () => { #[test] fn get_blockchain_info() { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let _ = bitcoind.client.get_blockchain_info().expect("getblockchaininfo"); } }; @@ -22,13 +22,13 @@ macro_rules! impl_test_v17__getblockchaininfo { macro_rules! impl_test_v17__getbestblockhash { () => { fn best_block_hash() -> bitcoin::BlockHash { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); bitcoind.client.best_block_hash().expect("best_block_hash failed") } #[test] fn get_best_block_hash() { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let _ = bitcoind.client.get_best_block_hash().expect("getbestblockhash"); } }; @@ -40,7 +40,7 @@ macro_rules! impl_test_v17__getblock { () => { #[test] fn get_block() { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let block_hash = best_block_hash(); let _ = bitcoind.client.get_block_verbosity_zero(&block_hash).expect("getblock 0"); diff --git a/tests/client/v17/control.rs b/integration_test/src/v17/control.rs similarity index 88% rename from tests/client/v17/control.rs rename to integration_test/src/v17/control.rs index 792300b..0dffa3c 100644 --- a/tests/client/v17/control.rs +++ b/integration_test/src/v17/control.rs @@ -11,7 +11,7 @@ macro_rules! impl_test_v17__stop { () => { #[test] fn stop() { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let _ = bitcoind.client.stop().expect("stop"); } }; diff --git a/tests/client/v17/generating.rs b/integration_test/src/v17/generating.rs similarity index 90% rename from tests/client/v17/generating.rs rename to integration_test/src/v17/generating.rs index 2c5dfa7..19000c5 100644 --- a/tests/client/v17/generating.rs +++ b/integration_test/src/v17/generating.rs @@ -11,7 +11,7 @@ macro_rules! impl_test_v17__generatetoaddress { () => { #[test] fn generate_to_address() { - let bitcoind = bitcoind_with_default_wallet(); + let bitcoind = $crate::bitcoind_with_default_wallet(); let address = bitcoind.client.new_address().expect("failed to get new address"); let _ = bitcoind.client.generate_to_address(1, &address).expect("generatetoaddress"); } diff --git a/tests/client/v17/mod.rs b/integration_test/src/v17/mod.rs similarity index 100% rename from tests/client/v17/mod.rs rename to integration_test/src/v17/mod.rs diff --git a/tests/client/v17/network.rs b/integration_test/src/v17/network.rs similarity index 90% rename from tests/client/v17/network.rs rename to integration_test/src/v17/network.rs index 08dbb94..f7f6faa 100644 --- a/tests/client/v17/network.rs +++ b/integration_test/src/v17/network.rs @@ -11,7 +11,7 @@ macro_rules! impl_test_v17__getnetworkinfo { () => { #[test] fn get_network_info() { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let _ = bitcoind.client.get_network_info().expect("getnetworkinfo"); } }; diff --git a/tests/client/v17/wallet.rs b/integration_test/src/v17/wallet.rs similarity index 85% rename from tests/client/v17/wallet.rs rename to integration_test/src/v17/wallet.rs index 0d88f43..92ded92 100644 --- a/tests/client/v17/wallet.rs +++ b/integration_test/src/v17/wallet.rs @@ -5,7 +5,7 @@ macro_rules! impl_test_v17__createwallet { #[test] pub fn create_wallet() { // Implicitly tests createwalled because we create the default wallet. - let _ = bitcoind_with_default_wallet(); + let _ = $crate::bitcoind_with_default_wallet(); } }; } @@ -17,7 +17,7 @@ macro_rules! impl_test_v17__loadwallet { #[test] fn load_wallet() { // Implicitly test loadwalled because we load the default wallet. - let _ = bitcoind_with_default_wallet(); + let _ = $crate::bitcoind_with_default_wallet(); } }; } @@ -28,7 +28,7 @@ macro_rules! impl_test_v17__unloadwallet { () => { #[test] fn unload_wallet() { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let wallet = format!("wallet-{}", rand::random::()).to_string(); bitcoind.client.create_wallet(&wallet).expect("failed to create wallet"); let _ = bitcoind.client.unload_wallet(&wallet).expect("unloadwallet"); @@ -42,7 +42,7 @@ macro_rules! impl_test_v17__getnewaddress { () => { #[test] fn get_new_address() { - let bitcoind = bitcoind_with_default_wallet(); + let bitcoind = $crate::bitcoind_with_default_wallet(); let _ = bitcoind.client.get_new_address().expect("getnewaddress"); } }; @@ -54,7 +54,7 @@ macro_rules! impl_test_v17__getbalance { () => { #[test] fn get_balance() { - let bitcoind = bitcoind_with_default_wallet(); + let bitcoind = $crate::bitcoind_with_default_wallet(); let _ = bitcoind.client.get_balance().expect("getbalance"); } }; @@ -68,7 +68,7 @@ macro_rules! impl_test_v17__sendtoaddress { fn send_to_address() { use bitcoin::Amount; - let bitcoind = bitcoind_with_default_wallet(); + let bitcoind = $crate::bitcoind_with_default_wallet(); let address = bitcoind.client.new_address().expect("failed to create new address"); let _ = bitcoind.client.generate_to_address(101, &address).expect("generatetoaddress"); diff --git a/tests/client/v22/blockchain.rs b/integration_test/src/v22/blockchain.rs similarity index 90% rename from tests/client/v22/blockchain.rs rename to integration_test/src/v22/blockchain.rs index abdc561..b17e97a 100644 --- a/tests/client/v22/blockchain.rs +++ b/integration_test/src/v22/blockchain.rs @@ -4,9 +4,9 @@ macro_rules! impl_test_v22__getblock { () => { #[test] fn get_block() { - use bitcoind_json_rpc::model; + use client::json::model; - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let block_hash = best_block_hash(); // Users who only want to use `json` module can do: diff --git a/tests/client/v22/mod.rs b/integration_test/src/v22/mod.rs similarity index 100% rename from tests/client/v22/mod.rs rename to integration_test/src/v22/mod.rs diff --git a/tests/client/v22/wallet.rs b/integration_test/src/v22/wallet.rs similarity index 88% rename from tests/client/v22/wallet.rs rename to integration_test/src/v22/wallet.rs index e9c7868..ef3955c 100644 --- a/tests/client/v22/wallet.rs +++ b/integration_test/src/v22/wallet.rs @@ -4,7 +4,7 @@ macro_rules! impl_test_v22__unloadwallet { () => { #[test] fn unload_wallet() { - let bitcoind = bitcoind_no_wallet(); + let bitcoind = $crate::bitcoind_no_wallet(); let wallet = format!("wallet-{}", rand::random::()).to_string(); bitcoind.client.create_wallet(&wallet).expect("failed to create wallet"); let _ = bitcoind.client.unload_wallet(&wallet).expect("unloadwallet "); @@ -18,7 +18,7 @@ macro_rules! impl_test_v22__getbalances { () => { #[test] fn get_balances() { - let bitcoind = bitcoind_with_default_wallet(); + let bitcoind = $crate::bitcoind_with_default_wallet(); let address = bitcoind.client.new_address().expect("failed to get new address"); let _ = bitcoind.client.generate_to_address(101, &address).expect("generatetoaddress"); let _ = bitcoind.client.get_balances().expect("getbalances"); diff --git a/integration_test/tests/v17_api.rs b/integration_test/tests/v17_api.rs new file mode 100644 index 0000000..15d4e65 --- /dev/null +++ b/integration_test/tests/v17_api.rs @@ -0,0 +1,49 @@ +//! Test the JSON-RPC API against `bitcoind v0.17.1`. + +#![cfg(feature = "v17")] + +use integration_test::*; + +// == Blockchain == +mod blockchain { + use super::*; + + impl_test_v17__getblockchaininfo!(); + impl_test_v17__getbestblockhash!(); + impl_test_v17__getblock!(); + // impl_test_v22__gettxout!(); +} + +// == Control == +mod control { + use super::*; + + impl_test_v17__stop!(); +} + +// == Generating == +mod generating { + use super::*; + + impl_test_v17__generatetoaddress!(); +} + +// == Network == +mod network { + use super::*; + + impl_test_v17__getnetworkinfo!(); +} + +// == Wallet == +mod wallet { + use super::*; + + impl_test_v17__createwallet!(); + impl_test_v17__loadwallet!(); + // impl_test_v17__unloadwallet!(); + + impl_test_v17__getnewaddress!(); + impl_test_v17__getbalance!(); + impl_test_v17__sendtoaddress!(); +} diff --git a/integration_test/tests/v18_api.rs b/integration_test/tests/v18_api.rs new file mode 100644 index 0000000..90b05d0 --- /dev/null +++ b/integration_test/tests/v18_api.rs @@ -0,0 +1,47 @@ +//! Test the JSON-RPC API against `bitcoind v0.18.1`. + +#![cfg(feature = "v18")] + +use integration_test::*; + +// == Blockchain == +mod blockchain { + use super::*; + + impl_test_v17__getblockchaininfo!(); + impl_test_v17__getbestblockhash!(); + impl_test_v17__getblock!(); +} + +// == Control == +mod control { + use super::*; + + impl_test_v17__stop!(); +} + +// == Generating == +mod generating { + use super::*; + + impl_test_v17__generatetoaddress!(); +} + +// == Network == +mod network { + use super::*; + + impl_test_v17__getnetworkinfo!(); +} + +// == Wallet == +mod wallet { + use super::*; + + impl_test_v17__createwallet!(); + impl_test_v17__loadwallet!(); + + impl_test_v17__getnewaddress!(); + impl_test_v17__getbalance!(); + impl_test_v17__sendtoaddress!(); +} diff --git a/integration_test/tests/v22_api.rs b/integration_test/tests/v22_api.rs new file mode 100644 index 0000000..2820fa3 --- /dev/null +++ b/integration_test/tests/v22_api.rs @@ -0,0 +1,51 @@ +//! Test the JSON-RPC API against `bitcoind v22.1`. + +#![cfg(feature = "v22")] + +use integration_test::*; + +// == Blockchain == +mod blockchain { + use super::*; + + impl_test_v17__getblockchaininfo!(); + impl_test_v17__getbestblockhash!(); + impl_test_v22__getblock!(); + // impl_test_v22__gettxout!(); +} + +// == Control == +mod control { + use super::*; + + impl_test_v17__stop!(); +} + +// == Generating == +mod generating { + use super::*; + + impl_test_v17__generatetoaddress!(); +} + +// == Network == +mod network { + use super::*; + + impl_test_v17__getnetworkinfo!(); +} + +// == Wallet == +mod wallet { + use super::*; + + impl_test_v17__createwallet!(); + // FIXME: Broken + // impl_test_v22__unloadwallet!(); + impl_test_v17__loadwallet!(); + + impl_test_v17__getnewaddress!(); + impl_test_v17__getbalance!(); + impl_test_v22__getbalances!(); + impl_test_v17__sendtoaddress!(); +} diff --git a/src/json/v17/util/convert.rs b/json/CHANGELOG.md similarity index 100% rename from src/json/v17/util/convert.rs rename to json/CHANGELOG.md diff --git a/json/Cargo.toml b/json/Cargo.toml new file mode 100644 index 0000000..6e21610 --- /dev/null +++ b/json/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "bitcoind-json-rpc-types" +version = "0.1.0" +authors = [ + "Steven Roose ", + "Jean Pierre Dudey ", + "Dawid Ciężarkiewicz ", + "Tobin C. Harding " +] +license = "CC0-1.0" +description = "Bitcoin Core JSON-RPC API types" +keywords = ["bitcoin", "bitcoind", "json-rpc"] +edition = "2021" + +[features] +default = [] + +[dependencies] +bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] } +internals = { package = "bitcoin-internals", version = "0.3.0", default-features = false, features = ["std"] } +serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ] } +serde_json = { version = "1.0.117" } + +[dev-dependencies] diff --git a/json/LICENSE b/json/LICENSE new file mode 100644 index 0000000..6ca207e --- /dev/null +++ b/json/LICENSE @@ -0,0 +1,122 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. + diff --git a/json/src/lib.rs b/json/src/lib.rs new file mode 100644 index 0000000..634fd47 --- /dev/null +++ b/json/src/lib.rs @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: CC0-1.0 + +//! Types returned by the JSON-RPC API of Bitcoin Core. + +/// Re-export the `rust-bitcoin` crate. +pub extern crate bitcoin; + +// TODO: Consider updating https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29 when this is complete. + +// JSON types, for each specific version of `bitcoind`. +pub mod v17; +pub mod v18; +pub mod v22; + +// JSON types that model _all_ `bitcoind` versions. +pub mod model; diff --git a/json/src/mod.rs b/json/src/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/model/blockchain.rs b/json/src/model/blockchain.rs similarity index 100% rename from src/model/blockchain.rs rename to json/src/model/blockchain.rs diff --git a/src/model/control.rs b/json/src/model/control.rs similarity index 100% rename from src/model/control.rs rename to json/src/model/control.rs diff --git a/src/model/generating.rs b/json/src/model/generating.rs similarity index 100% rename from src/model/generating.rs rename to json/src/model/generating.rs diff --git a/src/model/mining.rs b/json/src/model/mining.rs similarity index 100% rename from src/model/mining.rs rename to json/src/model/mining.rs diff --git a/src/model/mod.rs b/json/src/model/mod.rs similarity index 100% rename from src/model/mod.rs rename to json/src/model/mod.rs diff --git a/src/model/network.rs b/json/src/model/network.rs similarity index 100% rename from src/model/network.rs rename to json/src/model/network.rs diff --git a/src/model/raw_transactions.rs b/json/src/model/raw_transactions.rs similarity index 100% rename from src/model/raw_transactions.rs rename to json/src/model/raw_transactions.rs diff --git a/src/model/util.rs b/json/src/model/util.rs similarity index 100% rename from src/model/util.rs rename to json/src/model/util.rs diff --git a/src/model/wallet.rs b/json/src/model/wallet.rs similarity index 100% rename from src/model/wallet.rs rename to json/src/model/wallet.rs diff --git a/src/model/zmq.rs b/json/src/model/zmq.rs similarity index 100% rename from src/model/zmq.rs rename to json/src/model/zmq.rs diff --git a/src/json/v17/blockchain/convert.rs b/json/src/v17/blockchain/convert.rs similarity index 99% rename from src/json/v17/blockchain/convert.rs rename to json/src/v17/blockchain/convert.rs index 9b78a12..c6a14f1 100644 --- a/src/json/v17/blockchain/convert.rs +++ b/json/src/v17/blockchain/convert.rs @@ -14,7 +14,7 @@ use bitcoin::{ }; use internals::write_err; -use crate::json::v17; +use crate::v17; use crate::model; impl TryFrom for model::GetBlockchainInfo { diff --git a/src/json/v17/blockchain/mod.rs b/json/src/v17/blockchain/mod.rs similarity index 100% rename from src/json/v17/blockchain/mod.rs rename to json/src/v17/blockchain/mod.rs diff --git a/src/json/v17/control/mod.rs b/json/src/v17/control/mod.rs similarity index 100% rename from src/json/v17/control/mod.rs rename to json/src/v17/control/mod.rs diff --git a/src/json/v17/generating/convert.rs b/json/src/v17/generating/convert.rs similarity index 96% rename from src/json/v17/generating/convert.rs rename to json/src/v17/generating/convert.rs index c318c0c..69802f1 100644 --- a/src/json/v17/generating/convert.rs +++ b/json/src/v17/generating/convert.rs @@ -6,7 +6,7 @@ use bitcoin::{hex, BlockHash}; -use crate::json::v17; +use crate::v17; use crate::model; impl TryFrom for model::GenerateToAddress { diff --git a/src/json/v17/generating/mod.rs b/json/src/v17/generating/mod.rs similarity index 100% rename from src/json/v17/generating/mod.rs rename to json/src/v17/generating/mod.rs diff --git a/json/src/v17/mining/convert.rs b/json/src/v17/mining/convert.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/json/v17/mining/mod.rs b/json/src/v17/mining/mod.rs similarity index 100% rename from src/json/v17/mining/mod.rs rename to json/src/v17/mining/mod.rs diff --git a/src/json/v17/mod.rs b/json/src/v17/mod.rs similarity index 100% rename from src/json/v17/mod.rs rename to json/src/v17/mod.rs diff --git a/src/json/v17/network/convert.rs b/json/src/v17/network/convert.rs similarity index 99% rename from src/json/v17/network/convert.rs rename to json/src/v17/network/convert.rs index 15b6f2f..ef50d19 100644 --- a/src/json/v17/network/convert.rs +++ b/json/src/v17/network/convert.rs @@ -10,7 +10,7 @@ use bitcoin::amount::ParseAmountError; use bitcoin::{Amount, FeeRate}; use internals::write_err; -use crate::json::v17; +use crate::v17; use crate::model; // TODO: Upstream to `rust-bitcoin`. diff --git a/src/json/v17/network/mod.rs b/json/src/v17/network/mod.rs similarity index 100% rename from src/json/v17/network/mod.rs rename to json/src/v17/network/mod.rs diff --git a/src/json/v17/raw_transactions/mod.rs b/json/src/v17/raw_transactions/mod.rs similarity index 100% rename from src/json/v17/raw_transactions/mod.rs rename to json/src/v17/raw_transactions/mod.rs diff --git a/src/json/v17/rpc-api.txt b/json/src/v17/rpc-api.txt similarity index 100% rename from src/json/v17/rpc-api.txt rename to json/src/v17/rpc-api.txt diff --git a/json/src/v17/util/convert.rs b/json/src/v17/util/convert.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/json/v17/util/mod.rs b/json/src/v17/util/mod.rs similarity index 100% rename from src/json/v17/util/mod.rs rename to json/src/v17/util/mod.rs diff --git a/src/json/v17/wallet/convert.rs b/json/src/v17/wallet/convert.rs similarity index 98% rename from src/json/v17/wallet/convert.rs rename to json/src/v17/wallet/convert.rs index 4df7892..e44ff3a 100644 --- a/src/json/v17/wallet/convert.rs +++ b/json/src/v17/wallet/convert.rs @@ -9,7 +9,7 @@ use std::str::FromStr; use bitcoin::amount::ParseAmountError; use bitcoin::{address, hex, Address, Amount, Txid}; -use crate::json::v17; +use crate::v17; use crate::model; impl From for model::CreateWallet { diff --git a/src/json/v17/wallet/mod.rs b/json/src/v17/wallet/mod.rs similarity index 100% rename from src/json/v17/wallet/mod.rs rename to json/src/v17/wallet/mod.rs diff --git a/src/json/v17/zmq/mod.rs b/json/src/v17/zmq/mod.rs similarity index 100% rename from src/json/v17/zmq/mod.rs rename to json/src/v17/zmq/mod.rs diff --git a/src/json/v18/mod.rs b/json/src/v18/mod.rs similarity index 96% rename from src/json/v18/mod.rs rename to json/src/v18/mod.rs index 7a07337..ff39de2 100644 --- a/src/json/v18/mod.rs +++ b/json/src/v18/mod.rs @@ -155,13 +155,13 @@ // == Blockchain == // getbestblockhash #[doc(inline)] -pub use crate::json::v17::GetBestBlockHash; +pub use crate::v17::GetBestBlockHash; // getblock "blockhash" ( verbosity ) #[doc(inline)] -pub use crate::json::v17::{GetBlockVerbosityOne, GetBlockVerbosityZero}; +pub use crate::v17::{GetBlockVerbosityOne, GetBlockVerbosityZero}; // getblockchaininfo #[doc(inline)] -pub use crate::json::v17::GetBlockchainInfo; +pub use crate::v17::GetBlockchainInfo; // getblockcount // getblockhash height // getblockheader "blockhash" ( verbose ) @@ -176,7 +176,7 @@ pub use crate::json::v17::GetBlockchainInfo; // getrawmempool ( verbose ) // gettxout "txid" n ( include_mempool ) #[doc(inline)] -pub use crate::json::v17::GetTxOut; +pub use crate::v17::GetTxOut; // gettxoutproof ["txid",...] ( "blockhash" ) // gettxoutsetinfo // preciousblock "blockhash" @@ -197,7 +197,7 @@ pub use crate::json::v17::GetTxOut; // generate nblocks ( maxtries ) // generatetoaddress nblocks "address" ( maxtries ) #[doc(inline)] -pub use crate::json::v17::GenerateToAddress; +pub use crate::v17::GenerateToAddress; // == Mining == // getblocktemplate "template_request" @@ -216,7 +216,7 @@ pub use crate::json::v17::GenerateToAddress; // getnettotals // getnetworkinfo #[doc(inline)] -pub use crate::json::v17::GetNetworkInfo; +pub use crate::v17::GetNetworkInfo; // getnodeaddresses ( count ) // getpeerinfo // listbanned @@ -260,7 +260,7 @@ pub use crate::json::v17::GetNetworkInfo; // bumpfee "txid" ( options ) // createwallet "wallet_name" ( disable_private_keys blank ) #[doc(inline)] -pub use crate::json::v17::CreateWallet; +pub use crate::v17::CreateWallet; // dumpprivkey "address" // dumpwallet "filename" // encryptwallet "passphrase" @@ -268,10 +268,10 @@ pub use crate::json::v17::CreateWallet; // getaddressinfo "address" // getbalance ( "dummy" minconf include_watchonly ) #[doc(inline)] -pub use crate::json::v17::GetBalance; +pub use crate::v17::GetBalance; // getnewaddress ( "label" "address_type" ) #[doc(inline)] -pub use crate::json::v17::GetNewAddress; +pub use crate::v17::GetNewAddress; // getrawchangeaddress ( "address_type" ) // getreceivedbyaddress "address" ( minconf ) // getreceivedbylabel "label" ( minconf ) @@ -297,14 +297,14 @@ pub use crate::json::v17::GetNewAddress; // listwallets // loadwallet "filename" #[doc(inline)] -pub use crate::json::v17::LoadWallet; +pub use crate::v17::LoadWallet; // lockunspent unlock ( [{"txid":"hex","vout":n},...] ) // removeprunedfunds "txid" // rescanblockchain ( start_height stop_height ) // sendmany "" {"address":amount} ( minconf "comment" ["address",...] replaceable conf_target "estimate_mode" ) // sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode" ) #[doc(inline)] -pub use crate::json::v17::SendToAddress; +pub use crate::v17::SendToAddress; // sethdseed ( newkeypool "seed" ) // setlabel "address" "label" // settxfee amount diff --git a/src/json/v18/rpc-api.txt b/json/src/v18/rpc-api.txt similarity index 100% rename from src/json/v18/rpc-api.txt rename to json/src/v18/rpc-api.txt diff --git a/src/json/v22/blockchain/convert.rs b/json/src/v22/blockchain/convert.rs similarity index 99% rename from src/json/v22/blockchain/convert.rs rename to json/src/v22/blockchain/convert.rs index eefae8e..27919a6 100644 --- a/src/json/v22/blockchain/convert.rs +++ b/json/src/v22/blockchain/convert.rs @@ -10,7 +10,7 @@ use std::collections::BTreeMap; use bitcoin::{hex, network, Network, Work}; use internals::write_err; -use crate::json::v22; +use crate::v22; use crate::model; impl TryFrom for model::GetBlockchainInfo { diff --git a/src/json/v22/blockchain/mod.rs b/json/src/v22/blockchain/mod.rs similarity index 100% rename from src/json/v22/blockchain/mod.rs rename to json/src/v22/blockchain/mod.rs diff --git a/src/json/v22/generating/mod.rs b/json/src/v22/generating/mod.rs similarity index 100% rename from src/json/v22/generating/mod.rs rename to json/src/v22/generating/mod.rs diff --git a/src/json/v22/mod.rs b/json/src/v22/mod.rs similarity index 98% rename from src/json/v22/mod.rs rename to json/src/v22/mod.rs index d400174..a04cff5 100644 --- a/src/json/v22/mod.rs +++ b/json/src/v22/mod.rs @@ -178,10 +178,10 @@ mod wallet; pub use self::blockchain::*; // getbestblockhash #[doc(inline)] -pub use crate::json::v17::GetBestBlockHash; +pub use crate::v17::GetBestBlockHash; // getblock "blockhash" ( verbosity ) #[doc(inline)] -pub use crate::json::v17::{GetBlockVerbosityZero, GetBlockVerbosityOne}; +pub use crate::v17::{GetBlockVerbosityZero, GetBlockVerbosityOne}; // getblockchaininfo // getblockcount // getblockfilter "blockhash" ( "filtertype" ) @@ -198,7 +198,7 @@ pub use crate::json::v17::{GetBlockVerbosityZero, GetBlockVerbosityOne}; // getrawmempool ( verbose mempool_sequence ) // gettxout "txid" n ( include_mempool ) #[doc(inline)] -pub use crate::json::v17::GetTxOut; +pub use crate::v17::GetTxOut; // gettxoutproof ["txid",...] ( "blockhash" ) // gettxoutsetinfo ( "hash_type" hash_or_height use_index ) // preciousblock "blockhash" @@ -221,7 +221,7 @@ pub use crate::json::v17::GetTxOut; // generatetoaddress nblocks "address" ( maxtries ) // generatetodescriptor num_blocks "descriptor" ( maxtries ) #[doc(inline)] -pub use crate::json::v17::GenerateToAddress; +pub use crate::v17::GenerateToAddress; // == Mining == // getblocktemplate ( "template_request" ) @@ -298,7 +298,7 @@ pub use self::wallet::*; // getbalances // getnewaddress ( "label" "address_type" ) #[doc(inline)] -pub use crate::json::v17::GetNewAddress; +pub use crate::v17::GetNewAddress; // getrawchangeaddress ( "address_type" ) // getreceivedbyaddress "address" ( minconf ) // getreceivedbylabel "label" ( minconf ) diff --git a/src/json/v22/network/convert.rs b/json/src/v22/network/convert.rs similarity index 99% rename from src/json/v22/network/convert.rs rename to json/src/v22/network/convert.rs index a3a4183..4c7db5e 100644 --- a/src/json/v22/network/convert.rs +++ b/json/src/v22/network/convert.rs @@ -10,7 +10,7 @@ use bitcoin::amount::ParseAmountError; use bitcoin::{Amount, FeeRate}; use internals::write_err; -use crate::json::v22; +use crate::v22; use crate::model; // TODO: Upstream to `rust-bitcoin`. diff --git a/src/json/v22/network/mod.rs b/json/src/v22/network/mod.rs similarity index 100% rename from src/json/v22/network/mod.rs rename to json/src/v22/network/mod.rs diff --git a/src/json/v22/rpc-api.txt b/json/src/v22/rpc-api.txt similarity index 100% rename from src/json/v22/rpc-api.txt rename to json/src/v22/rpc-api.txt diff --git a/src/json/v22/wallet/convert.rs b/json/src/v22/wallet/convert.rs similarity index 99% rename from src/json/v22/wallet/convert.rs rename to json/src/v22/wallet/convert.rs index 8d66281..de89a1f 100644 --- a/src/json/v22/wallet/convert.rs +++ b/json/src/v22/wallet/convert.rs @@ -7,7 +7,7 @@ use bitcoin::amount::ParseAmountError; use bitcoin::{hex, Amount, Txid}; -use crate::json::v22; +use crate::v22; use crate::model; impl From for model::CreateWallet { diff --git a/src/json/v22/wallet/mod.rs b/json/src/v22/wallet/mod.rs similarity index 100% rename from src/json/v22/wallet/mod.rs rename to json/src/v22/wallet/mod.rs diff --git a/src/json/mod.rs b/src/json/mod.rs deleted file mode 100644 index 42b2ca1..0000000 --- a/src/json/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: CC0-1.0 - -//! Types returned by the JSON-RPC API of Bitcoin Core. -//! -//! Note, the types here are specific the the `bitcoind` version and we currently only support the -//! latest minor version number for each major release i.e., `v22` means `bitcoind v22.1`. - -pub mod v17; -pub mod v18; -pub mod v22; diff --git a/tests/client/mod.rs b/tests/client/mod.rs deleted file mode 100644 index 18a7d3e..0000000 --- a/tests/client/mod.rs +++ /dev/null @@ -1,136 +0,0 @@ -//! Provides a macro that implements the tests. - -pub mod v17; -pub mod v22; - -/// Requires `RPC_PORT` to be in scope. -macro_rules! impl_constructors { - () => { - use bitcoind::BitcoinD; - - /// Initialize a logger (configure with `RUST_LOG=trace cargo test`). - #[allow(dead_code)] // Not all tests use this function. - fn init_logger() { let _ = env_logger::try_init(); } - - /// Returns a handle to a `bitcoind` instance with "default" wallet loaded. - #[allow(dead_code)] // Not all tests use this function. - fn bitcoind_with_default_wallet() -> BitcoinD { - let exe = bitcoind::exe_path().expect("failed to get bitcoind executable"); - - let conf = bitcoind::Conf::default(); - BitcoinD::with_conf(exe, &conf).expect("failed to create BitcoinD") - } - - /// Returns a handle to a `bitcoind` instance without any wallets. - #[allow(dead_code)] // Not all tests use this function. - fn bitcoind_with_wallet(wallet: String) -> BitcoinD { - let exe = bitcoind::exe_path().expect("failed to get bitcoind executable"); - - let mut conf = bitcoind::Conf::default(); - conf.wallet = Some(wallet); - BitcoinD::with_conf(exe, &conf).expect("failed to create BitcoinD") - } - - /// Returns a handle to a `bitcoind` instance without any wallet loaded. - #[allow(dead_code)] // Not all tests use this function. - fn bitcoind_no_wallet() -> BitcoinD { - let exe = bitcoind::exe_path().expect("failed to get bitcoind executable"); - - let mut conf = bitcoind::Conf::default(); - conf.wallet = None; - BitcoinD::with_conf(exe, &conf).expect("failed to create BitcoinD") - } - }; -} -pub(crate) use impl_constructors; - -/// Requires the correct `Client` to be in scope. -/// -/// Requires the generatetoaddress API method. -#[macro_export] -macro_rules! impl_extended_tests_wallet { - ($mod_name:ident) => { - pub use $mod_name::{setup, wait}; - - mod $mod_name { - use std::{thread, time}; - - use super::*; - - pub fn setup() -> (Client, Client, bitcoin::Address) { - // Use one client to create the new wallet. - let client = client(); - let wallet = random_wallet_name(); - let _ = client.create_wallet(&wallet).expect("createwallet "); - - // And another for the wallet path calls. - let wallet_client = client_for_wallet(&wallet); - let address = wallet_client.new_address().expect("getnewaddress"); - - (client, wallet_client, address) - } - - // For flaky tests, just wait a bit. - pub fn wait() { - let wait = time::Duration::from_millis(100); - thread::sleep(wait); - } - - #[test] - fn new_address() { let _ = setup(); } - - #[test] - fn generate_to_address() { - let (client, _, address) = setup(); - let _ = client.generate_to_address(101, &address).expect("generatetoaddress"); - } - - #[test] - fn get_balance() { - let (client, wallet_client, address) = setup(); - let _ = client.generate_to_address(101, &address).expect("generatetoaddress"); - wait(); - - let _ = wallet_client.get_balance().expect("getbalance"); - } - - #[test] - fn send_to_address() { - use bitcoin::Amount; - - let (client, wallet_client, address) = setup(); - let _ = client.generate_to_address(1000, &address).expect("generatetoaddress"); - wait(); - - let balance = wallet_client.get_balance().expect("getbalance"); - dbg!(balance); - - let new = wallet_client.new_address().expect("failed to get a new address"); - let _ = wallet_client - .send_to_address(&new, Amount::from_sat(10_000)) - .expect("sendtoaddress"); - } - } - }; -} - -/// Requires the correct `Client` to be in scope. -/// -/// Requires the `impl_extended_tests_wallet` macro to have been called. -#[macro_export] -macro_rules! impl_test_wallet_balances { - ($mod_name:ident) => { - mod $mod_name { - use super::*; - - #[test] - fn get_balances() { - let (client, wallet_client, address) = setup(); - let _ = client.generate_to_address(101, &address).expect("generatetoaddress"); - wait(); - - let _ = wallet_client.get_balances().expect("getbalances"); - } - } - }; -} diff --git a/tests/v17_api.rs b/tests/v17_api.rs deleted file mode 100644 index 94bfbeb..0000000 --- a/tests/v17_api.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! Test the JSON-RPC API against `bitcoind v0.17.1`. - -#![cfg(all(feature = "client-sync", feature = "v17"))] - -mod client; - -client::impl_constructors!(); - -// == Blockchain == -mod blockchain { - use super::*; - - crate::impl_test_v17__getblockchaininfo!(); - crate::impl_test_v17__getbestblockhash!(); - crate::impl_test_v17__getblock!(); - // crate::impl_test_v22__gettxout!(); -} - -// == Control == -mod control { - use super::*; - - crate::impl_test_v17__stop!(); -} - -// == Generating == -mod generating { - use super::*; - - crate::impl_test_v17__generatetoaddress!(); -} - -// == Network == -mod network { - use super::*; - - crate::impl_test_v17__getnetworkinfo!(); -} - -// == Wallet == -mod wallet { - use super::*; - - crate::impl_test_v17__createwallet!(); - crate::impl_test_v17__loadwallet!(); - // crate::impl_test_v17__unloadwallet!(); - - crate::impl_test_v17__getnewaddress!(); - crate::impl_test_v17__getbalance!(); - crate::impl_test_v17__sendtoaddress!(); -} diff --git a/tests/v18_api.rs b/tests/v18_api.rs deleted file mode 100644 index 6dae204..0000000 --- a/tests/v18_api.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Test the JSON-RPC API against `bitcoind v0.18.1`. - -#![cfg(all(feature = "client-sync", feature = "v18"))] - -mod client; - -client::impl_constructors!(); - -// == Blockchain == -mod blockchain { - use super::*; - - crate::impl_test_v17__getblockchaininfo!(); - crate::impl_test_v17__getbestblockhash!(); - crate::impl_test_v17__getblock!(); -} - -// == Control == -mod control { - use super::*; - - crate::impl_test_v17__stop!(); -} - -// == Generating == -mod generating { - use super::*; - - crate::impl_test_v17__generatetoaddress!(); -} - -// == Network == -mod network { - use super::*; - - crate::impl_test_v17__getnetworkinfo!(); -} - -// == Wallet == -mod wallet { - use super::*; - - crate::impl_test_v17__createwallet!(); - crate::impl_test_v17__loadwallet!(); - - crate::impl_test_v17__getnewaddress!(); - crate::impl_test_v17__getbalance!(); - crate::impl_test_v17__sendtoaddress!(); -} diff --git a/tests/v22_api.rs b/tests/v22_api.rs deleted file mode 100644 index dcedc13..0000000 --- a/tests/v22_api.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Test the JSON-RPC API against `bitcoind v22.1`. - -#![cfg(all(feature = "client-sync", feature = "v22"))] - -mod client; - -client::impl_constructors!(); - -// == Blockchain == -mod blockchain { - use super::*; - - crate::impl_test_v17__getblockchaininfo!(); - crate::impl_test_v17__getbestblockhash!(); - crate::impl_test_v22__getblock!(); - // crate::impl_test_v22__gettxout!(); -} - -// == Control == -mod control { - use super::*; - - crate::impl_test_v17__stop!(); -} - -// == Generating == -mod generating { - use super::*; - - crate::impl_test_v17__generatetoaddress!(); -} - -// == Network == -mod network { - use super::*; - - crate::impl_test_v17__getnetworkinfo!(); -} - -// == Wallet == -mod wallet { - use super::*; - - crate::impl_test_v17__createwallet!(); - // FIXME: Broken - // crate::impl_test_v22__unloadwallet!(); - crate::impl_test_v17__loadwallet!(); - - crate::impl_test_v17__getnewaddress!(); - crate::impl_test_v17__getbalance!(); - crate::impl_test_v22__getbalances!(); - crate::impl_test_v17__sendtoaddress!(); -}