Skip to content

Commit eae0257

Browse files
committed
f - Remove base64 dependency
1 parent b07e8fd commit eae0257

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lightning-block-sync/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ Utilities to fetch the chain data from a block source and feed them into Rust Li
1010

1111
[features]
1212
rest-client = [ "serde_json", "chunked_transfer" ]
13-
rpc-client = [ "serde_json", "base64", "chunked_transfer" ]
13+
rpc-client = [ "serde_json", "chunked_transfer" ]
1414

1515
[dependencies]
1616
bitcoin = "0.24"
1717
lightning = { version = "0.0.12", path = "../lightning" }
1818
tokio = { version = ">=0.2.12", features = [ "tcp", "io-util", "dns" ], optional = true }
1919
serde_json = { version = "1", optional = true }
20-
base64 = { version = "0.9", optional = true }
2120
chunked_transfer = { version = "1.3.0", optional = true }
2221
futures = { version = "0.3.8" }
2322

lightning-block-sync/src/rest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct RestClient {
1010
}
1111

1212
impl RestClient {
13+
/// Creates a new REST client connected to the given endpoint.
1314
pub fn new(endpoint: HttpEndpoint) -> std::io::Result<Self> {
1415
let client = HttpClient::connect(&endpoint)?;
1516
Ok(Self { endpoint, client })

lightning-block-sync/src/rpc.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::http::{HttpClient, HttpEndpoint, JsonResponse};
22

3-
use base64;
43
use serde_json;
54

65
use std::convert::TryFrom;
@@ -16,10 +15,13 @@ pub struct RpcClient {
1615
}
1716

1817
impl RpcClient {
19-
pub fn new(user_auth: &str, endpoint: HttpEndpoint) -> std::io::Result<Self> {
18+
/// Creates a new RPC client connected to the given endpoint with the provided credentials. The
19+
/// credentials should be a base64 encoding of a user name and password joined by a colon, as is
20+
/// required for HTTP basic access authentication.
21+
pub fn new(credentials: &str, endpoint: HttpEndpoint) -> std::io::Result<Self> {
2022
let client = HttpClient::connect(&endpoint)?;
2123
Ok(Self {
22-
basic_auth: "Basic ".to_string() + &base64::encode(user_auth),
24+
basic_auth: "Basic ".to_string() + credentials,
2325
endpoint,
2426
client,
2527
id: AtomicUsize::new(0),
@@ -64,6 +66,9 @@ mod tests {
6466
use super::*;
6567
use crate::http::client_tests::{HttpServer, MessageBody};
6668

69+
/// Credentials encoded in base64.
70+
const CREDENTIALS: &'static str = "dXNlcjpwYXNzd29yZA==";
71+
6772
/// Converts a JSON value into `u64`.
6873
impl TryInto<u64> for JsonResponse {
6974
type Error = std::io::Error;
@@ -79,7 +84,7 @@ mod tests {
7984
#[tokio::test]
8085
async fn call_method_returning_unknown_response() {
8186
let server = HttpServer::responding_with_not_found();
82-
let mut client = RpcClient::new("credentials", server.endpoint()).unwrap();
87+
let mut client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
8388

8489
match client.call_method::<u64>("getblockcount", &[]).await {
8590
Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::NotFound),
@@ -91,7 +96,7 @@ mod tests {
9196
async fn call_method_returning_malfomred_response() {
9297
let response = serde_json::json!("foo");
9398
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
94-
let mut client = RpcClient::new("credentials", server.endpoint()).unwrap();
99+
let mut client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
95100

96101
match client.call_method::<u64>("getblockcount", &[]).await {
97102
Err(e) => {
@@ -108,7 +113,7 @@ mod tests {
108113
"error": { "code": -8, "message": "invalid parameter" },
109114
});
110115
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
111-
let mut client = RpcClient::new("credentials", server.endpoint()).unwrap();
116+
let mut client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
112117

113118
let invalid_block_hash = serde_json::json!("foo");
114119
match client.call_method::<u64>("getblock", &[invalid_block_hash]).await {
@@ -124,7 +129,7 @@ mod tests {
124129
async fn call_method_returning_missing_result() {
125130
let response = serde_json::json!({ "result": null });
126131
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
127-
let mut client = RpcClient::new("credentials", server.endpoint()).unwrap();
132+
let mut client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
128133

129134
match client.call_method::<u64>("getblockcount", &[]).await {
130135
Err(e) => {
@@ -139,7 +144,7 @@ mod tests {
139144
async fn call_method_returning_valid_result() {
140145
let response = serde_json::json!({ "result": 654470 });
141146
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
142-
let mut client = RpcClient::new("credentials", server.endpoint()).unwrap();
147+
let mut client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
143148

144149
match client.call_method::<u64>("getblockcount", &[]).await {
145150
Err(e) => panic!("Unexpected error: {:?}", e),

0 commit comments

Comments
 (0)