Skip to content

Commit 4f95040

Browse files
authored
Merge pull request #9 from Inon123/feat/account_info
feat(client): add bearer token to client
2 parents 123c533 + caaca7b commit 4f95040

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

xrpl_sdk_jsonrpc/src/client.rs

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
1616

1717
const DEFAULT_BASE_URL: &str = GENERAL_PURPOSE_MAINNET_URL;
1818

19+
const DEFAULT_BASE_TOKEN: &str = "";
20+
1921
const DEFAULT_USER_AGENT: &str = "rust-xrpl-sdk-rippled-client/0.1.0";
2022

2123
pub type Result<T> = std::result::Result<T, Error>;
@@ -36,6 +38,7 @@ pub struct RpcResponse<T> {
3638
#[derive(Default)]
3739
pub struct ClientBuilder {
3840
base_url: Option<String>,
41+
token: Option<String>,
3942
user_agent: Option<String>,
4043
http_client: Option<reqwest::Client>,
4144
timeout: Option<Duration>,
@@ -47,6 +50,11 @@ impl ClientBuilder {
4750
self
4851
}
4952

53+
pub fn token(mut self, token: &str) -> Self {
54+
self.token = Some(token.to_string());
55+
self
56+
}
57+
5058
pub fn user_agent(mut self, user_agent: &str) -> Self {
5159
self.user_agent = Some(user_agent.to_string());
5260
self
@@ -68,6 +76,7 @@ impl ClientBuilder {
6876
base_url: self
6977
.base_url
7078
.unwrap_or_else(|| DEFAULT_BASE_URL.to_string()),
79+
token: self.token.unwrap_or_else(|| DEFAULT_BASE_TOKEN.to_string()),
7180
user_agent: self
7281
.user_agent
7382
.unwrap_or_else(|| DEFAULT_USER_AGENT.to_string()),
@@ -85,6 +94,7 @@ impl ClientBuilder {
8594
pub struct Client {
8695
base_url: String,
8796
user_agent: String,
97+
token: String,
8898
// TODO: hm, not really used currently.
8999
http_client: reqwest::Client,
90100
}
@@ -125,6 +135,7 @@ impl Client {
125135
.post(&self.base_url)
126136
.body(body)
127137
.header(reqwest::header::USER_AGENT, &self.user_agent)
138+
.bearer_auth(&self.token)
128139
.send()
129140
.await?;
130141

0 commit comments

Comments
 (0)