-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathrpc.rs
More file actions
83 lines (76 loc) · 2.52 KB
/
rpc.rs
File metadata and controls
83 lines (76 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use clap::{
Args,
Subcommand,
};
use fuel_core_types::fuel_types::BlockHeight;
use std::net;
#[derive(Debug, Clone, Args)]
pub struct RpcArgs {
/// The IP address to bind the RPC service to
#[clap(long = "rpc_ip", default_value = "127.0.0.1", value_parser, env)]
pub rpc_ip: net::IpAddr,
/// The port to bind the RPC service to
#[clap(long = "rpc_port", default_value = "4001", env)]
pub rpc_port: u16,
#[command(subcommand)]
pub storage_method: Option<StorageMethod>,
#[clap(long = "api_buffer_size", default_value = "1000", env)]
pub api_buffer_size: usize,
}
#[derive(Debug, Clone, Subcommand)]
pub enum StorageMethod {
Local,
S3 {
#[clap(long = "bucket", env)]
bucket: String,
#[clap(long = "endpoint_url", env)]
endpoint_url: Option<String>,
#[clap(long = "requester_pays", env, default_value = "false")]
requester_pays: bool,
},
S3NoPublish {
#[clap(long = "bucket", env)]
bucket: String,
#[clap(long = "endpoint_url", env)]
endpoint_url: Option<String>,
#[clap(long = "requester_pays", env, default_value = "false")]
requester_pays: bool,
},
}
impl RpcArgs {
pub fn into_config(self) -> fuel_core_block_aggregator_api::service::Config {
fuel_core_block_aggregator_api::service::Config {
addr: net::SocketAddr::new(self.rpc_ip, self.rpc_port),
sync_from: Some(BlockHeight::from(0)),
storage_method: self.storage_method.map(Into::into).unwrap_or_default(),
api_buffer_size: self.api_buffer_size,
}
}
}
impl From<StorageMethod> for fuel_core_block_aggregator_api::service::StorageMethod {
fn from(storage_method: StorageMethod) -> Self {
match storage_method {
StorageMethod::Local => {
fuel_core_block_aggregator_api::service::StorageMethod::Local
}
StorageMethod::S3 {
bucket,
endpoint_url,
requester_pays,
} => fuel_core_block_aggregator_api::service::StorageMethod::S3 {
bucket,
endpoint_url,
requester_pays,
},
StorageMethod::S3NoPublish {
bucket,
endpoint_url,
requester_pays,
} => fuel_core_block_aggregator_api::service::StorageMethod::S3NoPublish {
bucket,
endpoint_url,
requester_pays,
},
}
}
}