Skip to content

Commit 9c763a3

Browse files
authored
Merge branch 'ord' into deserialize-import-descriptors
2 parents df2ab99 + c33b948 commit 9c763a3

File tree

5 files changed

+55
-25
lines changed

5 files changed

+55
-25
lines changed

client/Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
2-
name = "bitcoincore-rpc"
3-
version = "0.16.0"
2+
name = "ord-bitcoincore-rpc"
3+
version = "0.16.4"
44
authors = [
55
"Steven Roose <[email protected]>",
66
"Jean Pierre Dudey <[email protected]>",
@@ -19,11 +19,14 @@ name = "bitcoincore_rpc"
1919
path = "src/lib.rs"
2020

2121
[dependencies]
22-
bitcoincore-rpc-json = { version = "0.16.0", path = "../json" }
22+
ord-bitcoincore-rpc-json = { version = "0.16.0", path = "../json" }
2323

2424
log = "0.4.5"
25-
jsonrpc = "0.13.0"
25+
jsonrpc = "0.14.0"
2626

2727
# Used for deserialization of JSON.
2828
serde = "1"
2929
serde_json = "1"
30+
31+
[dev-dependencies]
32+
tempfile = "3.3.0"

client/src/client.rs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use std::collections::HashMap;
1212
use std::fs::File;
13+
use std::io::{BufRead, BufReader};
1314
use std::iter::FromIterator;
1415
use std::path::PathBuf;
1516
use std::{fmt, result};
@@ -199,20 +200,16 @@ pub enum Auth {
199200
impl Auth {
200201
/// Convert into the arguments that jsonrpc::Client needs.
201202
pub fn get_user_pass(self) -> Result<(Option<String>, Option<String>)> {
202-
use std::io::Read;
203203
match self {
204204
Auth::None => Ok((None, None)),
205205
Auth::UserPass(u, p) => Ok((Some(u), Some(p))),
206-
Auth::CookieFile(path) => {
207-
let mut file = File::open(path)?;
208-
let mut contents = String::new();
209-
file.read_to_string(&mut contents)?;
210-
let mut split = contents.splitn(2, ":");
211-
Ok((
212-
Some(split.next().ok_or(Error::InvalidCookieFile)?.into()),
213-
Some(split.next().ok_or(Error::InvalidCookieFile)?.into()),
214-
))
215-
}
206+
Auth::CookieFile(path) => BufReader::new(File::open(path)?)
207+
.lines()
208+
.next()
209+
.ok_or(Error::InvalidCookieFile)??
210+
.split_once(':')
211+
.map(|(user, pass)| (Some(user.into()), Some(pass.into())))
212+
.ok_or(Error::InvalidCookieFile),
216213
}
217214
}
218215
}
@@ -1413,4 +1410,34 @@ mod tests {
14131410
fn test_handle_defaults() {
14141411
test_handle_defaults_inner().unwrap();
14151412
}
1413+
1414+
#[test]
1415+
fn auth_cookie_file_ignores_newline() {
1416+
let tempdir = tempfile::tempdir().unwrap();
1417+
let path = tempdir.path().join("cookie");
1418+
std::fs::write(&path, "foo:bar\n").unwrap();
1419+
assert_eq!(
1420+
Auth::CookieFile(path).get_user_pass().unwrap(),
1421+
(Some("foo".into()), Some("bar".into())),
1422+
);
1423+
}
1424+
1425+
#[test]
1426+
fn auth_cookie_file_ignores_additional_lines() {
1427+
let tempdir = tempfile::tempdir().unwrap();
1428+
let path = tempdir.path().join("cookie");
1429+
std::fs::write(&path, "foo:bar\nbaz").unwrap();
1430+
assert_eq!(
1431+
Auth::CookieFile(path).get_user_pass().unwrap(),
1432+
(Some("foo".into()), Some("bar".into())),
1433+
);
1434+
}
1435+
1436+
#[test]
1437+
fn auth_cookie_file_fails_if_colon_isnt_present() {
1438+
let tempdir = tempfile::tempdir().unwrap();
1439+
let path = tempdir.path().join("cookie");
1440+
std::fs::write(&path, "foobar").unwrap();
1441+
assert!(matches!(Auth::CookieFile(path).get_user_pass(), Err(Error::InvalidCookieFile)));
1442+
}
14161443
}

integration_test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Steven Roose <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
bitcoincore-rpc = { path = "../client" }
8+
ord-bitcoincore-rpc = { path = "../client" }
99
bitcoin = { version = "0.29.0", features = ["serde", "rand"]}
1010
lazy_static = "1.4.0"
1111
log = "0.4"

json/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
2-
name = "bitcoincore-rpc-json"
3-
version = "0.16.0"
2+
name = "ord-bitcoincore-rpc-json"
3+
version = "0.16.4"
44
authors = [
55
"Steven Roose <[email protected]>",
66
"Jean Pierre Dudey <[email protected]>",

json/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ pub enum GetTransactionResultDetailCategory {
659659
Orphan,
660660
}
661661

662-
#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
662+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
663663
pub struct GetTransactionResultDetail {
664664
pub address: Option<Address>,
665665
pub category: GetTransactionResultDetailCategory,
@@ -672,7 +672,7 @@ pub struct GetTransactionResultDetail {
672672
pub abandoned: Option<bool>,
673673
}
674674

675-
#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
675+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
676676
pub struct WalletTxInfo {
677677
pub confirmations: i32,
678678
pub blockhash: Option<bitcoin::BlockHash>,
@@ -689,7 +689,7 @@ pub struct WalletTxInfo {
689689
pub wallet_conflicts: Vec<bitcoin::Txid>,
690690
}
691691

692-
#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
692+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
693693
pub struct GetTransactionResult {
694694
#[serde(flatten)]
695695
pub info: WalletTxInfo,
@@ -708,7 +708,7 @@ impl GetTransactionResult {
708708
}
709709
}
710710

711-
#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
711+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
712712
pub struct ListTransactionResult {
713713
#[serde(flatten)]
714714
pub info: WalletTxInfo,
@@ -1809,7 +1809,7 @@ impl serde::Serialize for SigHashType {
18091809
}
18101810

18111811
// Used for createrawtransaction argument.
1812-
#[derive(Serialize, Clone, PartialEq, Eq, Debug)]
1812+
#[derive(Serialize, Clone, PartialEq, Eq, Debug, Deserialize)]
18131813
#[serde(rename_all = "camelCase")]
18141814
pub struct CreateRawTransactionInput {
18151815
pub txid: bitcoin::Txid,
@@ -1861,7 +1861,7 @@ pub struct FundRawTransactionResult {
18611861
pub change_position: i32,
18621862
}
18631863

1864-
#[derive(Deserialize, Clone, PartialEq, Eq, Debug)]
1864+
#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, Debug)]
18651865
pub struct GetBalancesResultEntry {
18661866
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
18671867
pub trusted: Amount,
@@ -1871,7 +1871,7 @@ pub struct GetBalancesResultEntry {
18711871
pub immature: Amount,
18721872
}
18731873

1874-
#[derive(Deserialize, Clone, PartialEq, Eq, Debug)]
1874+
#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, Debug)]
18751875
#[serde(rename_all = "camelCase")]
18761876
pub struct GetBalancesResult {
18771877
pub mine: GetBalancesResultEntry,

0 commit comments

Comments
 (0)