Created
March 18, 2025 09:53
-
-
Save adilcpm/6ecc84a5fd3cdf8c2ed7b519938521c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://germany.solana.dex.blxrbdn.com | |
pub fn get_random_tipping_address_bloxRoute() -> Result<Pubkey> { | |
let addresses = [ | |
"HWEoBxYs7ssKuudEjzjmpfJVX7Dvi7wescFsVx2L5yoY", | |
"95cfoy472fcQHaw4tPGBTKpn6ZQnfEPfBgDQx6gcRmRg", | |
"3UQUKjhMKaY2S6bjcQD6yHB7utcZt5bfarRCmctpRtUd", | |
"FogxVNs6Mm2w9rnGL1vkARSwJxvLE8mujTv3LK8RnUhF", | |
]; | |
let mut rng = rand::thread_rng(); | |
// Get a random element | |
let random_string = addresses.choose(&mut rng).unwrap(); | |
Ok(Pubkey::from_str(random_string).unwrap()) | |
} | |
pub async fn send_transaction_through_bloxroute( | |
transaction: &impl SerializableTransaction, | |
http_client: &reqwest::Client, | |
) -> Result<String> { | |
const BLOXROUTE_API_PATH: &str = "/api/v2/submit"; | |
let rpc_url_bloxroute = format!("{}{}", get_config().bloxroute_url, BLOXROUTE_API_PATH); | |
let base64_transaction = BASE64_STANDARD.encode(serialize(transaction).unwrap()); | |
static REQUEST_TEMPLATE: &str = r#"{"transaction":{"content":"{}"},"skipPreFlight": true,"frontRunningProtection": false,"useStakedRPCs": true}"#; | |
let request_body = REQUEST_TEMPLATE.replace("{}", &base64_transaction); | |
let response = http_client | |
.post(rpc_url_bloxroute) | |
.timeout(std::time::Duration::from_secs(5)) | |
.header("Content-Type", "application/json") | |
.header("Authorization", "NzU0YWViMmEtNWQ1Ny00NjAwLWIzOGUtZWM3OTFhYWZiMzY5OjMwMDg2N2E1YWEzYzcyZmRmNmQxZGEyZmVlMDFmMzkx") | |
.body(request_body) | |
.send() | |
.await; | |
let response = match response { | |
Ok(response) => response, | |
Err(e) => { | |
println_log!("Failed to send BLOX request: {:?}", e); | |
return Ok(generate_failed_signature()); | |
} | |
}; | |
let json_response = response.json::<serde_json::Value>().await; | |
let result_signature = match json_response { | |
Ok(parsed_json) => { | |
let parsed_signature = parsed_json["signature"].as_str(); | |
let result_signature = match parsed_signature { | |
Some(signature) => signature.to_string(), | |
None => { | |
println_log!("Failed to parse BLOX result field in json: {:?}", parsed_json); | |
return Ok(generate_failed_signature()); | |
} | |
}; | |
return Ok(result_signature); | |
} | |
Err(e) => { | |
println_log!("Failed to parse BLOX response as json: {:?}", e); | |
// Return a default signature as JSON value | |
return Ok(generate_failed_signature()); | |
} | |
}; | |
Ok(result_signature) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment