Skip to content

Commit

Permalink
Merge pull request #50 from weaveVM/add-brotli-for-ar-writes
Browse files Browse the repository at this point in the history
feat: Brotli support for ar writes
  • Loading branch information
andreespirela authored Sep 4, 2024
2 parents cb24ee1 + 70149ad commit 9a736b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use reth::{
};
use reth_revm::{precompile::PrecompileErrors, primitives::B256};
use std::str::FromStr;
use rbrotli::to_brotli;

pub const PC_ADDRESS: u64 = 0x17;
pub const ARWEAVE_PC_BASE: u64 = 3_450;
Expand All @@ -19,6 +20,7 @@ pub const SOLANA_SILLY_PRIVATE_KEY: &str =
"kNykCXNxgePDjFbDWjPNvXQRa8U12Ywc19dFVaQ7tebUj3m7H4sF4KKdJwM7yxxb3rqxchdjezX9Szh8bLcQAjb";

fn arweave_upload(input: &Bytes, gas_limit: u64) -> PrecompileResult {
let input = to_brotli(input.to_vec());
let data_size = input.len();
let gas_used: u64 = (10_000 + data_size * 3) as u64;

Expand All @@ -45,8 +47,9 @@ fn arweave_upload(input: &Bytes, gas_limit: u64) -> PrecompileResult {
.set_private_key(SOLANA_SILLY_PRIVATE_KEY.to_string())
.set_tag("Content-Type", "application/octet-stream")
.set_tag("WeaveVM:Precompile", "true")
.set_tag("WeaveVM:Encoding", "Brotli")
.set_tag("WeaveVM:Precompile-Address", PC_ADDRESS.to_string().as_str())
.set_data(input.0.to_vec())
.set_data(input)
.send()
.await
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ fn kyve_read(input: &Bytes, gas_limit: u64) -> PrecompileResult {
let field = field.unwrap();

tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
println!("{}", format!(
"{}/ethereum/beacon/blob_sidecars?block_height={}",
KYVE_API_URL, blk_number
));
let req = reqwest::get(format!(
"{}/ethereum/beacon/blob_sidecars?block_height={}",
KYVE_API_URL, blk_number
))
).as_str())
.await;


match req {
Ok(resp) => match resp.json::<serde_json::Value>().await {
Ok(json_val) => {
Expand Down Expand Up @@ -95,9 +100,15 @@ fn kyve_read(input: &Bytes, gas_limit: u64) -> PrecompileResult {
"Invalid Response from server".to_string(),
))),
},
Err(_) => Err(PrecompileErrors::Error(PrecompileError::Other(
"Could not connect with KYVE".to_string(),
))),
Err(e) => {
println!("{:?}", e);
println!("{}", e.url().unwrap());
println!("{}", e.status().unwrap());
println!("{}", e.to_string());
Err(PrecompileErrors::Error(PrecompileError::Other(
"Could not connect with KYVE".to_string(),
)))
},
}
})
}
Expand Down

0 comments on commit 9a736b0

Please sign in to comment.