Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"

members = [
"examples/simple-logs",
"hyperfuel-client",
"hyperfuel-format",
"hyperfuel-net-types",
Expand Down
11 changes: 11 additions & 0 deletions examples/simple-logs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "simple-logs"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
hex-literal = "0.4.1"
hyperfuel-client = { path = "../../hyperfuel-client" }
tokio = { version = "1", features = ["full"] }
url = "2.5.0"
30 changes: 30 additions & 0 deletions examples/simple-logs/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use hyperfuel_client::{Client, ClientConfig};
use url::Url;

#[tokio::main]
async fn main() {
let client_config = ClientConfig {
url: Some(Url::parse("https://fuel.hypersync.xyz").unwrap()),
..Default::default()
};
let client = Client::new(client_config).unwrap();

let contracts = vec![hex_literal::hex!(
"4a2ce054e3e94155f7092f7365b212f7f45105b74819c623744ebcc5d065c6ac"
)];
let from_block = 0;
let to_block = Some(50_000);

let logs = client
.preset_query_get_logs(contracts, from_block, to_block)
.await
.unwrap();

println!(
"archive_height={:?} next_block={} total_execution_time={}ms logs={}",
logs.archive_height,
logs.next_block,
logs.total_execution_time,
logs.data.len()
);
}
3 changes: 1 addition & 2 deletions hyperfuel-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperfuel-client"
version = "3.0.1"
version = "3.1.0"
edition = "2021"
description = "client library for hyperfuel"
license = "MPL-2.0"
Expand All @@ -27,7 +27,6 @@ arrayvec = { version = "0.7", features = ["serde"] }
tokio = { version = "1", default-features = false, features = [
"rt-multi-thread",
"fs",
"test-util",
"rt",
"macros",
] }
Expand Down
8 changes: 4 additions & 4 deletions hyperfuel-client/src/column_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ pub struct ColumnMapping {
/// Mapping for transaction data.
#[serde(default)]
pub transaction: BTreeMap<String, DataType>,
/// Mapping for log data.
/// Mapping for receipt data.
#[serde(default)]
pub receipt: BTreeMap<String, DataType>,
/// Mapping for trace data.
/// Mapping for input data.
#[serde(default)]
pub input: BTreeMap<String, DataType>,
/// Mapping for decoded log data.
/// Mapping for output data.
#[serde(default)]
pub output: BTreeMap<String, DataType>,
}
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn apply_to_batch(
.context(format!("apply cast to column '{}'", field.name))?
} else {
map_column(&**col, dt)
.context(format!("apply cast to colum '{}'", field.name))?
.context(format!("apply cast to column '{}'", field.name))?
}
}
None => col.clone(),
Expand Down
11 changes: 7 additions & 4 deletions hyperfuel-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl Client {

let height: ArchiveHeight = res.json().await.context("read response body json")?;

Ok(height.height.unwrap_or(0))
height.height.context("missing height in response")
}

/// Get the chain_id from the server with retries.
Expand Down Expand Up @@ -367,12 +367,15 @@ impl Client {
}

let bytes = res.bytes().await.context("read response body bytes")?;
let byte_len = bytes.len();

let res = tokio::task::block_in_place(|| {
let res = tokio::task::spawn_blocking(move || {
parse_query_response(&bytes).context("parse query response")
})?;
})
.await
.context("join parse task")??;

Ok((res, bytes.len().try_into().unwrap()))
Ok((res, byte_len.try_into().unwrap()))
}

/// Executes query with retries and returns the response in Arrow format.
Expand Down
7 changes: 6 additions & 1 deletion hyperfuel-client/src/parse_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ fn read_chunks(bytes: &[u8]) -> Result<Vec<ArrowBatch>> {

pub fn parse_query_response(bytes: &[u8]) -> Result<ArrowResponse> {
let mut opts = capnp::message::ReaderOptions::new();
opts.nesting_limit(i32::MAX).traversal_limit_in_words(None);
// Bounded limits for untrusted network input. Default capnp limits are 64
// nesting / 64 MiB traversal; we raise the traversal cap to 512 MiB (64M
// words * 8 bytes/word) to fit large paginated arrow payloads. Callers
// hitting this should reduce per-query block ranges via max_num_blocks.
opts.nesting_limit(64)
.traversal_limit_in_words(Some(64 * 1024 * 1024));
let message_reader =
capnp::serialize_packed::read_message(bytes, opts).context("create message reader")?;

Expand Down
Loading
Loading