Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Feb 11, 2024
2 parents 74218e0 + 1b51e3d commit 858358f
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 43 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- rust: nightly
env:
RUSTFMTCHK: false
- rust: 1.41.1
- rust: 1.48.0
env:
RUSTFMTCHK: false
steps:
Expand All @@ -27,7 +27,6 @@ jobs:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- run: cargo update -p serde --precise 1.0.152
- name: Running test script
env: ${{ matrix.env }}
run: ./contrib/test.sh
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.18.0

- MSRV changed from 1.41.1 to 1.48.0
- Use `bitcoin::Network` in `GetBlockchainInfoResult `.
- Make checksum optional in `GetDescriptorInfoResult`.
- Make `getmempoolinfo` compatible with supported RPC versions.

# 0.17.0

- add `list_wallet_dir` rpc
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ The following versions are officially supported and automatically tested:
* 2.21.0

# Minimum Supported Rust Version (MSRV)
This library should always compile with any combination of features on **Rust 1.41.1**.
This library should always compile with any combination of features on **Rust 1.48.0**.
8 changes: 5 additions & 3 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "groestlcoincore-rpc"
version = "0.17.0"
version = "0.18.0"
authors = ["Groestlcoin Developers <[email protected]>"]
license = "CC0-1.0"
homepage = "https://github.com/Groestlcoin/rust-groestlcoincore-rpc/"
Expand All @@ -15,12 +15,14 @@ name = "groestlcoincore_rpc"
path = "src/lib.rs"

[dependencies]
groestlcoincore-rpc-json = { version = "0.17.0", path = "../json" }
groestlcoincore-rpc-json = { version = "0.18.0", path = "../json" }

log = "0.4.5"
jsonrpc = "0.14.0"

# Used for deserialization of JSON.
serde = "1"
serde_json = "1"
groestlcoin-private = "0.1.0"

[dev-dependencies]
tempfile = "3.3.0"
48 changes: 38 additions & 10 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::iter::FromIterator;
use std::path::PathBuf;
use std::{fmt, result};

use crate::{groestlcoin, deserialize_hex};
use groestlcoin_private::hex::exts::DisplayHex;
use groestlcoin::hex::DisplayHex;
use jsonrpc;
use serde;
use serde_json;
Expand Down Expand Up @@ -201,19 +202,16 @@ pub enum Auth {
impl Auth {
/// Convert into the arguments that jsonrpc::Client needs.
pub fn get_user_pass(self) -> Result<(Option<String>, Option<String>)> {
use std::io::Read;
match self {
Auth::None => Ok((None, None)),
Auth::UserPass(u, p) => Ok((Some(u), Some(p))),
Auth::CookieFile(path) => {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let mut split = contents.splitn(2, ":");
Ok((
Some(split.next().ok_or(Error::InvalidCookieFile)?.into()),
Some(split.next().ok_or(Error::InvalidCookieFile)?.into()),
))
let line = BufReader::new(File::open(path)?)
.lines()
.next()
.ok_or(Error::InvalidCookieFile)??;
let colon = line.find(':').ok_or(Error::InvalidCookieFile)?;
Ok((Some(line[..colon].into()), Some(line[colon + 1..].into())))
}
}
}
Expand Down Expand Up @@ -1429,4 +1427,34 @@ mod tests {
fn test_handle_defaults() {
test_handle_defaults_inner().unwrap();
}

#[test]
fn auth_cookie_file_ignores_newline() {
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("cookie");
std::fs::write(&path, "foo:bar\n").unwrap();
assert_eq!(
Auth::CookieFile(path).get_user_pass().unwrap(),
(Some("foo".into()), Some("bar".into())),
);
}

#[test]
fn auth_cookie_file_ignores_additional_lines() {
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("cookie");
std::fs::write(&path, "foo:bar\nbaz").unwrap();
assert_eq!(
Auth::CookieFile(path).get_user_pass().unwrap(),
(Some("foo".into()), Some("bar".into())),
);
}

#[test]
fn auth_cookie_file_fails_if_colon_isnt_present() {
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("cookie");
std::fs::write(&path, "foobar").unwrap();
assert!(matches!(Auth::CookieFile(path).get_user_pass(), Err(Error::InvalidCookieFile)));
}
}
6 changes: 3 additions & 3 deletions client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use serde_json;
#[derive(Debug)]
pub enum Error {
JsonRpc(jsonrpc::error::Error),
Hex(hex::Error),
Hex(hex::HexToBytesError),
Json(serde_json::error::Error),
BitcoinSerialization(groestlcoin::consensus::encode::Error),
Secp256k1(secp256k1::Error),
Expand All @@ -39,8 +39,8 @@ impl From<jsonrpc::error::Error> for Error {
}
}

impl From<hex::Error> for Error {
fn from(e: hex::Error) -> Error {
impl From<hex::HexToBytesError> for Error {
fn from(e: hex::HexToBytesError) -> Error {
Error::Hex(e)
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub extern crate groestlcoincore_rpc_json;
pub use crate::json::groestlcoin;
pub use groestlcoincore_rpc_json as json;
use json::groestlcoin::consensus::{Decodable, ReadExt};
use json::groestlcoin::hashes::hex::HexIterator;
use json::groestlcoin::hex::HexToBytesIter;

mod client;
mod error;
Expand All @@ -39,7 +39,7 @@ pub use crate::error::Error;
pub use crate::queryable::*;

fn deserialize_hex<T: Decodable>(hex: &str) -> Result<T> {
let mut reader = HexIterator::new(&hex)?;
let mut reader = HexToBytesIter::new(&hex)?;
let object = Decodable::consensus_decode(&mut reader)?;
if reader.read_u8().is_ok() {
Err(Error::BitcoinSerialization(groestlcoin::consensus::encode::Error::ParseFailed(
Expand Down
14 changes: 13 additions & 1 deletion contrib/test.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

set -xe

# Just echo all the relevant env vars to help debug Github Actions.
MSRV="1\.48"

# Just echo all the relevant env vars to help debug Travis.
echo "RUSTFMTCHECK: \"$RUSTFMTCHECK\""
echo "GROESTLCOINVERSION: \"$GROESTLCOINVERSION\""
echo "PATH: \"$PATH\""
Expand All @@ -11,6 +13,16 @@ if [ -n "$RUSTFMTCHECK" ]; then
cargo fmt --all -- --check
fi

# Test pinned versions (these are from rust-bitcoin pinning for 1.48).
if cargo --version | grep ${MSRV}; then
cargo update -p tempfile --precise 3.3.0
cargo update -p log --precise 0.4.18
cargo update -p serde_json --precise 1.0.99
cargo update -p serde --precise 1.0.156
cargo update -p quote --precise 1.0.30
cargo update -p proc-macro2 --precise 1.0.63
fi

# Integration test.
if [ -n "$GROESTLCOINVERSION" ]; then
wget https://github.com/Groestlcoin/groestlcoin/releases/download/v$GROESTLCOINVERSION/groestlcoin-$GROESTLCOINVERSION-x86_64-linux-gnu.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2018"

[dependencies]
groestlcoincore-rpc = { path = "../client" }
groestlcoin = { version = "0.30.0", features = ["serde", "rand"]}
groestlcoin = { version = "0.31.0", features = ["serde", "rand"]}
lazy_static = "1.4.0"
log = "0.4"
24 changes: 14 additions & 10 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::HashMap;
use std::str::FromStr;

use groestlcoin::absolute::LockTime;
use groestlcoin::address::NetworkChecked;
use groestlcoin::address::{NetworkChecked, NetworkUnchecked};
use groestlcoincore_rpc::json;
use groestlcoincore_rpc::jsonrpc::error::Error as JsonRpcError;
use groestlcoincore_rpc::{Auth, Client, Error, RpcApi};
Expand All @@ -28,8 +28,8 @@ use groestlcoin::hashes::hex::FromHex;
use groestlcoin::hashes::Hash;
use groestlcoin::{secp256k1, ScriptBuf, sighash};
use groestlcoin::{
Address, Amount, Network, OutPoint, PrivateKey,
Sequence, SignedAmount, Transaction, TxIn, TxOut, Txid, Witness,
transaction, Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount,
Transaction, TxIn, TxOut, Txid, Witness,
};
use groestlcoincore_rpc::groestlcoincore_rpc_json::{
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest,
Expand Down Expand Up @@ -584,7 +584,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
let unspent = unspent.into_iter().nth(0).unwrap();

let tx = Transaction {
version: 1,
version: transaction::Version::ONE,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint {
Expand All @@ -596,7 +596,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
witness: Witness::new(),
}],
output: vec![TxOut {
value: (unspent.amount - *FEE).to_sat(),
value: (unspent.amount - *FEE),
script_pubkey: addr.script_pubkey(),
}],
};
Expand All @@ -613,7 +613,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
let txid = cl.send_raw_transaction(&res.transaction().unwrap()).unwrap();

let tx = Transaction {
version: 1,
version: transaction::Version::ONE,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint {
Expand All @@ -625,7 +625,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
witness: Witness::new(),
}],
output: vec![TxOut {
value: (unspent.amount - *FEE - *FEE).to_sat(),
value: (unspent.amount - *FEE - *FEE),
script_pubkey: RANDOM_ADDRESS.script_pubkey(),
}],
};
Expand Down Expand Up @@ -1367,18 +1367,22 @@ fn test_add_multisig_address(cl: &Client) {
assert!(cl.add_multisig_address(addresses.len(), &addresses, None, Some(json::AddressType::Bech32)).is_ok());
}

#[rustfmt::skip]
fn test_derive_addresses(cl: &Client) {
let descriptor = r"pkh(02e96fe52ef0e22d2f131dd425ce1893073a3c6ad20e8cac36726393dfb4856a4c)#62k9sn4x";
assert_eq!(cl.derive_addresses(descriptor, None).unwrap(), vec!["mrkwtj5xpYQjHeJe5wsweNjVeTKkvR5fCr".parse().unwrap()]);
assert_eq!(
cl.derive_addresses(descriptor, None).unwrap(),
vec!["mrkwtj5xpYQjHeJe5wsweNjVeTKkvR5fCr".parse::<Address<NetworkUnchecked>>().unwrap()]
);
assert!(cl.derive_addresses(descriptor, Some([0, 1])).is_err()); // Range should not be specified for an unranged descriptor

let descriptor = std::concat!(
r"wpkh([1004658e/84'/1'/0']tpubDCBEcmVKbfC9KfdydyLbJ2gfNL88grZu1XcWSW9ytTM6fi",
r"tvaRmVyr8Ddf7SjZ2ZfMx9RicjYAXhuh3fmLiVLPodPEqnQQURUfrBKiiVZc8/0/*)#g8l47ngv",
);
assert_eq!(cl.derive_addresses(descriptor, Some([0, 1])).unwrap(), vec![
"bcrt1q5n5tjkpva8v5s0uadu2y5f0g7pn4h5eqaq2ux2".parse().unwrap(),
"bcrt1qcgl303ht03ja2e0hudpwk7ypcxk5t478wspzlt".parse().unwrap(),
"bcrt1q5n5tjkpva8v5s0uadu2y5f0g7pn4h5eqaq2ux2".parse::<Address<NetworkUnchecked>>().unwrap(),
"bcrt1qcgl303ht03ja2e0hudpwk7ypcxk5t478wspzlt".parse::<Address<NetworkUnchecked>>().unwrap(),
]);
assert!(cl.derive_addresses(descriptor, None).is_err()); // Range must be specified for a ranged descriptor
}
Expand Down
5 changes: 2 additions & 3 deletions json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "groestlcoincore-rpc-json"
version = "0.17.0"
version = "0.18.0"
authors = ["Groestlcoin Developers <[email protected]>"]
license = "CC0-1.0"
homepage = "https://github.com/Groestlcoin/rust-groestlcoincore-rpc/"
Expand All @@ -18,5 +18,4 @@ path = "src/lib.rs"
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"

groestlcoin = { version = "0.30.0", features = ["serde", "rand-std"]}
groestlcoin-private = "0.1.0"
groestlcoin = { version = "0.31.0", features = ["serde", "rand-std"]}
12 changes: 5 additions & 7 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ use std::fmt;
///
/// The module is compatible with the serde attribute.
pub mod serde_hex {
use groestlcoin::hashes::hex::FromHex;
use groestlcoin_private::hex::exts::DisplayHex;
use groestlcoin::hex::{DisplayHex, FromHex};
use serde::de::Error;
use serde::{Deserializer, Serializer};

Expand All @@ -56,8 +55,7 @@ pub mod serde_hex {
}

pub mod opt {
use groestlcoin::hashes::hex::FromHex;
use groestlcoin_private::hex::exts::DisplayHex;
use groestlcoin::hex::{DisplayHex, FromHex};
use serde::de::Error;
use serde::{Deserializer, Serializer};

Expand Down Expand Up @@ -174,7 +172,7 @@ pub struct GetWalletInfoResult {
#[serde(rename = "paytxfee", with = "groestlcoin::amount::serde::as_btc")]
pub pay_tx_fee: Amount,
#[serde(rename = "hdseedid")]
pub hd_seed_id: Option<groestlcoin::hash_types::XpubIdentifier>,
pub hd_seed_id: Option<groestlcoin::bip32::XKeyIdentifier>,
pub private_keys_enabled: bool,
pub avoid_reuse: Option<bool>,
pub scanning: Option<ScanningDetails>,
Expand Down Expand Up @@ -944,7 +942,7 @@ pub struct GetAddressInfoResultEmbedded {
#[serde(rename = "hdkeypath")]
pub hd_key_path: Option<bip32::DerivationPath>,
#[serde(rename = "hdseedid")]
pub hd_seed_id: Option<groestlcoin::hash_types::XpubIdentifier>,
pub hd_seed_id: Option<groestlcoin::bip32::XKeyIdentifier>,
#[serde(default)]
pub labels: Vec<GetAddressInfoResultLabel>,
}
Expand Down Expand Up @@ -998,7 +996,7 @@ pub struct GetAddressInfoResult {
#[serde(rename = "hdkeypath")]
pub hd_key_path: Option<bip32::DerivationPath>,
#[serde(rename = "hdseedid")]
pub hd_seed_id: Option<groestlcoin::hash_types::XpubIdentifier>,
pub hd_seed_id: Option<groestlcoin::bip32::XKeyIdentifier>,
pub labels: Vec<GetAddressInfoResultLabel>,
/// Deprecated in v2.20.1. See `labels` field instead.
#[deprecated(note = "since Core v2.20.1")]
Expand Down

0 comments on commit 858358f

Please sign in to comment.