|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | +use std::time::Duration; |
| 3 | +use url::Url; |
| 4 | + |
| 5 | +#[derive(Clone, Debug, Deserialize, Serialize)] |
| 6 | +#[serde(deny_unknown_fields)] |
| 7 | +pub struct TransactionStreamConfig { |
| 8 | + pub indexer_grpc_data_service_address: Url, |
| 9 | + pub starting_version: Option<u64>, |
| 10 | + pub request_ending_version: Option<u64>, |
| 11 | + pub auth_token: String, |
| 12 | + pub request_name_header: String, |
| 13 | + #[serde(default = "TransactionStreamConfig::default_indexer_grpc_http2_ping_interval")] |
| 14 | + pub indexer_grpc_http2_ping_interval_secs: u64, |
| 15 | + #[serde(default = "TransactionStreamConfig::default_indexer_grpc_http2_ping_timeout")] |
| 16 | + pub indexer_grpc_http2_ping_timeout_secs: u64, |
| 17 | + #[serde(default = "TransactionStreamConfig::default_indexer_grpc_reconnection_timeout")] |
| 18 | + pub indexer_grpc_reconnection_timeout_secs: u64, |
| 19 | + #[serde(default = "TransactionStreamConfig::default_indexer_grpc_response_item_timeout")] |
| 20 | + pub indexer_grpc_response_item_timeout_secs: u64, |
| 21 | +} |
| 22 | + |
| 23 | +impl TransactionStreamConfig { |
| 24 | + pub const fn indexer_grpc_http2_ping_interval(&self) -> Duration { |
| 25 | + Duration::from_secs(self.indexer_grpc_http2_ping_interval_secs) |
| 26 | + } |
| 27 | + |
| 28 | + pub const fn indexer_grpc_http2_ping_timeout(&self) -> Duration { |
| 29 | + Duration::from_secs(self.indexer_grpc_http2_ping_timeout_secs) |
| 30 | + } |
| 31 | + |
| 32 | + pub const fn indexer_grpc_reconnection_timeout(&self) -> Duration { |
| 33 | + Duration::from_secs(self.indexer_grpc_reconnection_timeout_secs) |
| 34 | + } |
| 35 | + |
| 36 | + pub const fn indexer_grpc_response_item_timeout(&self) -> Duration { |
| 37 | + Duration::from_secs(self.indexer_grpc_response_item_timeout_secs) |
| 38 | + } |
| 39 | + |
| 40 | + /// Indexer GRPC http2 ping interval in seconds. Defaults to 30. |
| 41 | + /// Tonic ref: https://docs.rs/tonic/latest/tonic/transport/channel/struct.Endpoint.html#method.http2_keep_alive_interval |
| 42 | + pub const fn default_indexer_grpc_http2_ping_interval() -> u64 { |
| 43 | + 30 |
| 44 | + } |
| 45 | + |
| 46 | + /// Indexer GRPC http2 ping timeout in seconds. Defaults to 10. |
| 47 | + pub const fn default_indexer_grpc_http2_ping_timeout() -> u64 { |
| 48 | + 10 |
| 49 | + } |
| 50 | + |
| 51 | + /// Default timeout for establishing a grpc connection. Defaults to 5 seconds. |
| 52 | + pub const fn default_indexer_grpc_reconnection_timeout() -> u64 { |
| 53 | + 5 |
| 54 | + } |
| 55 | + |
| 56 | + /// Default timeout for receiving an item from grpc stream. Defaults to 60 seconds. |
| 57 | + pub const fn default_indexer_grpc_response_item_timeout() -> u64 { |
| 58 | + 60 |
| 59 | + } |
| 60 | +} |
0 commit comments