feat(jito): add API token authentication support

This commit is contained in:
ysq
2025-08-04 21:31:19 +08:00
parent 281218b15e
commit 1f7e60bf93
4 changed files with 29 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "sol-trade-sdk" name = "sol-trade-sdk"
version = "0.2.13" version = "0.2.14"
edition = "2021" edition = "2021"
authors = ["William <byteblock6@gmail.com>", "sgxiang <sgxiang@gmail.com>", "wei <1415121722@qq.com>"] authors = ["William <byteblock6@gmail.com>", "sgxiang <sgxiang@gmail.com>", "wei <1415121722@qq.com>"]
repository = "https://github.com/0xfnzero/sol-trade-sdk" repository = "https://github.com/0xfnzero/sol-trade-sdk"
+2 -2
View File
@@ -31,14 +31,14 @@ Add the dependency to your `Cargo.toml`:
```toml ```toml
# Add to your Cargo.toml # Add to your Cargo.toml
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.13" } sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.14" }
``` ```
### Use crates.io ### Use crates.io
```toml ```toml
# Add to your Cargo.toml # Add to your Cargo.toml
sol-trade-sdk = "0.2.13" sol-trade-sdk = "0.2.14"
``` ```
## Usage Examples ## Usage Examples
+2 -2
View File
@@ -31,14 +31,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk
```toml ```toml
# 添加到您的 Cargo.toml # 添加到您的 Cargo.toml
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.13" } sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.14" }
``` ```
### 使用 crates.io ### 使用 crates.io
```toml ```toml
# 添加到您的 Cargo.toml # 添加到您的 Cargo.toml
sol-trade-sdk = "0.2.13" sol-trade-sdk = "0.2.14"
``` ```
## 使用示例 ## 使用示例
+24 -6
View File
@@ -78,11 +78,20 @@ impl JitoClient {
] ]
}))?; }))?;
let endpoint = format!("{}/api/v1/transactions?uuid={}", self.endpoint, self.auth_token); let endpoint = if self.auth_token.is_empty() {
let response_text = self.http_client.post(&endpoint) format!("{}/api/v1/transactions", self.endpoint)
} else {
format!("{}/api/v1/transactions?uuid={}", self.endpoint, self.auth_token)
};
let response = if self.auth_token.is_empty() {
self.http_client.post(&endpoint)
} else {
self.http_client.post(&endpoint)
.header("x-jito-auth", &self.auth_token)
};
let response_text = response
.body(request_body) .body(request_body)
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.header("x-jito-auth", &self.auth_token)
.send() .send()
.await? .await?
.text() .text()
@@ -120,11 +129,20 @@ impl JitoClient {
"id": 1, "id": 1,
}); });
let endpoint = format!("{}/api/v1/bundles?uuid={}", self.endpoint, self.auth_token); let endpoint = if self.auth_token.is_empty() {
let response_text = self.http_client.post(&endpoint) format!("{}/api/v1/bundles", self.endpoint)
} else {
format!("{}/api/v1/bundles?uuid={}", self.endpoint, self.auth_token)
};
let response = if self.auth_token.is_empty() {
self.http_client.post(&endpoint)
} else {
self.http_client.post(&endpoint)
.header("x-jito-auth", &self.auth_token)
};
let response_text = response
.body(body.to_string()) .body(body.to_string())
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.header("x-jito-auth", &self.auth_token)
.send() .send()
.await? .await?
.text() .text()