hypersync_client/config.rs
1use serde::{Deserialize, Serialize};
2use std::num::NonZeroU64;
3use url::Url;
4
5use crate::ColumnMapping;
6
7/// Configuration for the hypersync client.
8#[derive(Default, Debug, Clone, Deserialize, Serialize)]
9pub struct ClientConfig {
10 /// HyperSync server URL.
11 pub url: Option<Url>,
12 /// HyperSync server bearer token.
13 pub bearer_token: Option<String>,
14 /// Milliseconds to wait for a response before timing out.
15 pub http_req_timeout_millis: Option<NonZeroU64>,
16 /// Number of retries to attempt before returning error.
17 pub max_num_retries: Option<usize>,
18 /// Milliseconds that would be used for retry backoff increasing.
19 pub retry_backoff_ms: Option<u64>,
20 /// Initial wait time for request backoff.
21 pub retry_base_ms: Option<u64>,
22 /// Ceiling time for request backoff.
23 pub retry_ceiling_ms: Option<u64>,
24}
25
26/// Config for hypersync event streaming.
27#[derive(Default, Debug, Clone, Serialize, Deserialize)]
28pub struct StreamConfig {
29 /// Column mapping for stream function output.
30 /// It lets you map columns you want into the DataTypes you want.
31 pub column_mapping: Option<ColumnMapping>,
32 /// Event signature used to populate decode logs. Decode logs would be empty if set to None.
33 pub event_signature: Option<String>,
34 /// Determines formatting of binary columns numbers into utf8 hex.
35 #[serde(default)]
36 pub hex_output: HexOutput,
37 /// Initial batch size. Size would be adjusted based on response size during execution.
38 pub batch_size: Option<u64>,
39 /// Maximum batch size that could be used during dynamic adjustment.
40 pub max_batch_size: Option<u64>,
41 /// Minimum batch size that could be used during dynamic adjustment.
42 pub min_batch_size: Option<u64>,
43 /// Number of async threads that would be spawned to execute different block ranges of queries.
44 pub concurrency: Option<usize>,
45 /// Max number of blocks to fetch in a single request.
46 pub max_num_blocks: Option<usize>,
47 /// Max number of transactions to fetch in a single request.
48 pub max_num_transactions: Option<usize>,
49 /// Max number of logs to fetch in a single request.
50 pub max_num_logs: Option<usize>,
51 /// Max number of traces to fetch in a single request.
52 pub max_num_traces: Option<usize>,
53 /// Size of a response in bytes from which step size will be lowered
54 pub response_bytes_ceiling: Option<u64>,
55 /// Size of a response in bytes from which step size will be increased
56 pub response_bytes_floor: Option<u64>,
57 /// Stream data in reverse order
58 pub reverse: Option<bool>,
59}
60
61/// Determines format of Binary column
62#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
63pub enum HexOutput {
64 /// Binary column won't be formatted as hex
65 NoEncode,
66 /// Binary column would be formatted as prefixed hex i.e. 0xdeadbeef
67 Prefixed,
68 /// Binary column would be formatted as non prefixed hex i.e. deadbeef
69 NonPrefixed,
70}
71
72impl Default for HexOutput {
73 fn default() -> Self {
74 Self::NoEncode
75 }
76}