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

Commit

Permalink
Merge pull request #6 from tcharding/06-13-amount-bug
Browse files Browse the repository at this point in the history
Fix amount parsing in GetTransactionDetail
  • Loading branch information
tcharding authored Jun 13, 2024
2 parents f343dda + ee6525b commit 6729c07
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
"0_20_2",
"0_19_1",
"0_18_1",
"0_17_2",
"0_17_1",
]
steps:
- name: "Checkout repo"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gitignore for rust-bitcoin-core-json-rpc

Cargo.lock
/target
**/target
8 changes: 2 additions & 6 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies = [

[[package]]
name = "bitcoind-json-rpc-client"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"bitcoin",
"bitcoind-json-rpc-types",
Expand All @@ -98,7 +98,7 @@ dependencies = [

[[package]]
name = "bitcoind-json-rpc-types"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"bitcoin",
"bitcoin-internals",
Expand Down Expand Up @@ -253,7 +253,3 @@ name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

[[patch.unused]]
name = "bitcoind-json-rpc-regtest"
version = "0.1.0"
8 changes: 2 additions & 6 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies = [

[[package]]
name = "bitcoind-json-rpc-client"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"bitcoin",
"bitcoind-json-rpc-types",
Expand All @@ -98,7 +98,7 @@ dependencies = [

[[package]]
name = "bitcoind-json-rpc-types"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"bitcoin",
"bitcoin-internals",
Expand Down Expand Up @@ -253,7 +253,3 @@ name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

[[patch.unused]]
name = "bitcoind-json-rpc-regtest"
version = "0.1.0"
8 changes: 8 additions & 0 deletions client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 0.2.0 - 2024-06-13

- Use Bitcoin Core 0.17.1 (0.17.2 seems to not exist and have been a mistake).

# 0.1.0 - 2024-06-13

Initial release.

4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitcoind-json-rpc-client"
version = "0.1.0"
version = "0.2.0"
authors = [
"Steven Roose <[email protected]>",
"Jean Pierre Dudey <[email protected]>",
Expand All @@ -23,7 +23,7 @@ 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 = [] }
json = { package = "bitcoind-json-rpc-types", version = "0.2.0", default-features = false, features = [] }
log = "0.4"
serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ] }
serde_json = { version = "1.0.117" }
Expand Down
4 changes: 2 additions & 2 deletions client/src/client_sync/v17/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0

//! A JSON-RPC client for testing against Bitcoin Core `v0.17.2`.
//! A JSON-RPC client for testing against Bitcoin Core `v0.17.1`.
//!
//! We ignore option arguments unless they effect the shape of the returned JSON data.
Expand Down Expand Up @@ -34,7 +34,7 @@ crate::impl_client_v17__generatetoaddress!();

// == Network ==
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [170200] });
crate::impl_client_check_expected_server_version!({ [170100] });

// == Rawtransactions ==
crate::impl_client_v17__sendrawtransaction!();
Expand Down
8 changes: 4 additions & 4 deletions contrib/run_bitcoind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ KNOWN_VERSION
- v20 Bitcoin Core v0.20.2
- v19 Bitcoin Core v0.19.1
- v18 Bitcoin Core v0.18.1
- v17 Bitcoin Core v0.17.2
- v17 Bitcoin Core v0.17.1
EOF
}

Expand All @@ -57,7 +57,7 @@ main() {
start "v20" # 0.20.2
start "v19" # 0.19.1
start "v18" # 0.18.1
start "v17" # 0.17.2
start "v17" # 0.17.1
;;

start)
Expand All @@ -66,7 +66,7 @@ main() {

stop)
pkill bitcoind
rm -rf "/tmp/rust-bitcoind-json-rpc-0.17.2/2/regtest/wallets" > /dev/null
rm -rf "/tmp/rust-bitcoind-json-rpc-0.17.1/2/regtest/wallets" > /dev/null
rm -rf "/tmp/rust-bitcoind-json-rpc-0.18.1/2/regtest/wallets" > /dev/null
rm -rf "/tmp/rust-bitcoind-json-rpc-22.1/2/regtest/wallets" > /dev/null
;;
Expand Down Expand Up @@ -128,7 +128,7 @@ start() {
;;

v17)
local version_number="0.17.2"
local version_number="0.17.1"
local version_id="172"
;;

Expand Down
6 changes: 3 additions & 3 deletions integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ edition = "2021"
"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_2" = ["v17", "bitcoind/0_17_2"]
"0_17_1" = ["v17", "bitcoind/0_17_1"]

# Each minor version is tested with the same client.
"v26" = []
Expand All @@ -46,8 +46,8 @@ edition = "2021"

[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 = { package = "bitcoind-json-rpc-regtest", version = "0.1.0", default-features = false, features = [] }
client = { package = "bitcoind-json-rpc-client", version = "0.2.0", default-features = false, features = ["client-sync"] }
bitcoind = { package = "bitcoind-json-rpc-regtest", version = "0.2.0", default-features = false, features = [] }
rand = "0.8.5"
env_logger = "0.9.0"

Expand Down
9 changes: 7 additions & 2 deletions integration_test/src/v17/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ macro_rules! impl_test_v17__getbalance {
() => {
#[test]
fn get_balance() {
use client::json::model;

let bitcoind = $crate::bitcoind_with_default_wallet();
let _ = bitcoind.client.get_balance().expect("getbalance");
let json = bitcoind.client.get_balance().expect("getbalance");
let _: model::GetBalance = json.try_into().unwrap();
}
};
}
Expand Down Expand Up @@ -92,6 +95,7 @@ macro_rules! impl_test_v17__gettransaction {
#[test]
fn get_transaction() {
use bitcoin::Amount;
use client::json::model;

let bitcoind = $crate::bitcoind_with_default_wallet();
let address = bitcoind.client.new_address().expect("failed to create new address");
Expand All @@ -102,7 +106,8 @@ macro_rules! impl_test_v17__gettransaction {
.send_to_address(&address, Amount::from_sat(10_000))
.expect("sendtoaddress");

let _ = bitcoind.client.get_transaction(txid).expect("gettransaction");
let json = bitcoind.client.get_transaction(txid).expect("gettransaction");
let _: model::GetTransaction = json.try_into().unwrap();
}
};
}
8 changes: 8 additions & 0 deletions json/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 0.2.0 - 2024-06-13

- Use Bitcoin Core 0.17.1 (0.17.2 seems to not exist and have been a mistake).
- Fix `GetTransactionDetail` conversion to use a signed bitcoin amount.

# 0.1.0 - 2024-06-13

Initial release.
2 changes: 1 addition & 1 deletion json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitcoind-json-rpc-types"
version = "0.1.0"
version = "0.2.0"
authors = [
"Steven Roose <[email protected]>",
"Jean Pierre Dudey <[email protected]>",
Expand Down
3 changes: 2 additions & 1 deletion json/src/model/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ pub struct GetTransaction {
pub struct GetTransactionDetail {
pub address: Address<NetworkUnchecked>,
pub category: GetTransactionDetailCategory,
pub amount: Amount,
#[serde(default, with = "bitcoin::amount::serde::as_btc")]
pub amount: SignedAmount,
pub label: Option<String>,
pub vout: u32,
#[serde(default, with = "bitcoin::amount::serde::as_btc::opt")]
Expand Down
2 changes: 1 addition & 1 deletion json/src/v17/wallet/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl TryFrom<v17::GetTransactionDetail> for model::GetTransactionDetail {
use GetTransactionDetailError as E;

let address = Address::from_str(&json.address).map_err(E::Address)?;
let amount = Amount::from_btc(json.amount).map_err(E::Amount)?;
let amount = SignedAmount::from_btc(json.amount).map_err(E::Amount)?;
// FIMXE: Use combinators.
let fee = match json.fee {
None => None,
Expand Down
62 changes: 4 additions & 58 deletions regtest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,8 @@
# Changelog
# 0.2.0 - 2024-06-13

## 0.36.0
- Use Bitcoin Core 0.17.1 (0.17.2 seems to not exist and have been a mistake).

- Remove range dependencies for `bitcoincore-rpc` and depend on the
latest version `v0.19.0` [#163](https://github.com/rust-bitcoin/bitcoind/pull/163).
# 0.1.0 - 2024-06-13

## 0.35.2
Initial release, this is an import of `bitcoind v.036.0`.

- Use range dependencies for `bitcoincore-rpc` and `bitcoin_hashes`

## Release 0.35.1

- Bump MSRV to 1.56.1
- Add `BITCOIND_SKIP_DOWNLOAD` build feature

## Release 0.34.2

- Support Bitcoin Core 26.0

## Release 0.34.1

- Optionally enable ZMQ

## Release 0.34.0

- upgrade bitcoincore dep to 0.18.0 and with it bitcoin to 0.31.0

## Release 0.28.0

### Changed

- bump `ureq`'s version to `2.5.0`
- bump `flate2`'s version to `1.0.24`
- bump `filetime`'s version to `0.2.18`

## Release 0.27.1

### Changed

- use bitcoin_hashes 0.11 also for build dep

## Release 0.27.0

### Added

- Introduced CHANGELOG
- Supports windows OS
- Provide errors if `rpcuser` and `rpcpassword` are provided

### Changed

- use bitcoin dep to 0.29.1

### Fixed

- fix bitcoin 0.23 on MacOS X
- fix test flakiness

### Removed

- removed `datadir` from `ConnectionParams`, use equivalent `workdir()`
8 changes: 4 additions & 4 deletions regtest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitcoind-json-rpc-regtest"
version = "0.1.0"
version = "0.2.0"
authors = ["Riccardo Casatta <[email protected]>", "Tobin C. Harding <[email protected]>"]
license = "MIT"
repository = "https://github.com/tcharding/rust-bitcoind-json-rpc"
Expand All @@ -13,7 +13,7 @@ rust-version = "1.56.1"
exclude = ["tests", "contrib"]

[dependencies]
bitcoind-json-rpc-client = { version = "0.1", features = ["client-sync"] }
bitcoind-json-rpc-client = { version = "0.2", features = ["client-sync"] }
log = "0.4"
which = "4.2.5"
anyhow = "1.0.66"
Expand Down Expand Up @@ -58,8 +58,8 @@ anyhow = "1.0.66"
"0_21_2" = ["download", "0_20_2"]
"0_20_2" = ["download", "0_19_1"]
"0_19_1" = ["download", "0_18_1"]
"0_18_1" = ["download", "0_17_2"]
"0_17_2" = ["download"]
"0_18_1" = ["download", "0_17_1"]
"0_17_1" = ["download"]

"doc" = [] # used only for documentation building

Expand Down
31 changes: 31 additions & 0 deletions regtest/sha256/bitcoin-core-0.17.1-SHA256SUMS.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

5659c436ca92eed8ef42d5b2d162ff6283feba220748f9a373a5a53968975e34 bitcoin-0.17.1-aarch64-linux-gnu.tar.gz
aab3c1fb92e47734fadded1d3f9ccf0ac5a59e3cdc28c43a52fcab9f0cb395bc bitcoin-0.17.1-arm-linux-gnueabihf.tar.gz
b1e1dcf8265521fef9021a9d49d8661833e3f844ca9a410a9dd12a617553dda1 bitcoin-0.17.1-i686-pc-linux-gnu.tar.gz
6aa567381b95a20ac96b0b949701b04729a0c5796c320481bfa1db22da25efdb bitcoin-0.17.1-osx64.tar.gz
e3d785d800b71d277959d15b2c2b33d44dd72c1288e559928a40488dd935c949 bitcoin-0.17.1-osx.dmg
3e564fb5cf832f39e930e19c83ea53e09cfe6f93a663294ed83a32e194bda42a bitcoin-0.17.1.tar.gz
e9245e682126ef9fa4998eabbbdd1c3959df811dc10df60be626a5e5ffba9b78 bitcoin-0.17.1-win32-setup.exe
6464aa2d338f3697950613bb88124e58d6ce78ead5e9ecacb5ba79d1e86a4e30 bitcoin-0.17.1-win32.zip
fa1e80c5e4ecc705549a8061e5e7e0aa6b2d26967f99681b5989d9bd938d8467 bitcoin-0.17.1-win64-setup.exe
1abbe6aa170ce7d8263d262f8cb0ae2a5bb3993aacd2f0c7e5316ae595fe81d7 bitcoin-0.17.1-win64.zip
53ffca45809127c9ba33ce0080558634101ec49de5224b2998c489b6d0fc2b17 bitcoin-0.17.1-x86_64-linux-gnu.tar.gz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBCAAGBQJcIeQ5AAoJEJDIAZ42wulk0NoQAIunIBT06bd2IhhxV/48NUvf
sgTto4qYrKuX5Vkn+kfGuMBvNpmILi5CiVtnucWo7fKM6k5IPMyBQuE9iDVDzT9i
YemA9Au8Xy2aIGmVriuQoXxk8b17wAMS9uw362A3nXCz3kA+BWMDuMfBp3P3NPM/
PeOg6n04Q7seO/zNdT5i/ysaFB/XA8szrQxCRukSrXeGMUpv79UbcWOu3+nfGit9
yYo/F2yO57Yacv597rKILlg29QxEVTqa5+slMdwuU7NP5AdAcQV4EtFqoCOqM7C7
JL/zZWYnTywK3l0hOuCBJiY86izutWME5xgm7Eh3ORj+K6ZYT4iXw2JIkTdumeuS
X0WDE3ShH4rb35IaQX75FJLp5R7hLTXiNgng7b8Xhy/62bJ75Ob4HVVSLG1Lkhps
vtml10br+78qXiofzk8zaAW6KaG7G9nbBa0hfDjUEsYzA6P5iWA+53ykupc82HNa
ZT2gk+wWhNhZOd/ANheriM0eqm/ZlK7oydYRRtf9Tamk+XJgREU1x8cWlMZcCPEE
uIUzb7/REvYSjwcwArYLCq/eFPfjQe7jcG2WexnpxxkKJBvu2v4zVw9LLUPll094
BAmfk34iJKhN2cGVhvjO0Q9GKk0B2HzvhD5xn1Hnlp+NbXVNbKonYvkB71D3GY4W
t/eRyv7Erfi4dhHf+8oQ
=UEoM
-----END PGP SIGNATURE-----
29 changes: 0 additions & 29 deletions regtest/sha256/bitcoin-core-0.17.2-SHA256SUMS.asc

This file was deleted.

Loading

0 comments on commit 6729c07

Please sign in to comment.