Skip to content

Commit

Permalink
add substreams config provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed Aug 31, 2022
1 parent 6180c89 commit e93862d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion node/resources/tests/full_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ ingestor = "index_0"
[chains.mainnet]
shard = "primary"
provider = [
{ label = "mainnet-0", url = "http://rpc.mainnet.io", features = ["archive", "traces"] }
{ label = "mainnet-0", url = "http://rpc.mainnet.io", features = ["archive", "traces"] },
{ label = "firehose", details = { type = "firehose", url = "http://localhost:9000", features = [] }},
{ label = "substreams", details = { type = "substreams", url = "http://localhost:9000", features = [] }},
]

[chains.ropsten]
Expand Down
28 changes: 27 additions & 1 deletion node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ pub struct Provider {
pub enum ProviderDetails {
Firehose(FirehoseProvider),
Web3(Web3Provider),
Substreams(FirehoseProvider),
}

const FIREHOSE_FILTER_FEATURE: &str = "filters";
Expand Down Expand Up @@ -637,7 +638,8 @@ impl Provider {
validate_name(&self.label).context("illegal provider name")?;

match self.details {
ProviderDetails::Firehose(ref mut firehose) => {
ProviderDetails::Firehose(ref mut firehose)
| ProviderDetails::Substreams(ref mut firehose) => {
firehose.url = shellexpand::env(&firehose.url)?.into_owned();

// A Firehose url must be a valid Uri since gRPC library we use (Tonic)
Expand Down Expand Up @@ -1339,6 +1341,30 @@ mod tests {
);
}

#[test]
fn it_works_on_substreams_provider_from_toml() {
let actual = toml::from_str(
r#"
label = "firehose"
details = { type = "substreams", url = "http://localhost:9000", features = [] }
"#,
)
.unwrap();

assert_eq!(
Provider {
// The label can be anything so this being firehose doens't mean anything more than "bananas" would.
label: "firehose".to_owned(),
details: ProviderDetails::Substreams(FirehoseProvider {
url: "http://localhost:9000".to_owned(),
token: None,
features: BTreeSet::new(),
conn_pool_size: 10,
}),
},
actual
);
}
#[test]
fn it_works_on_new_firehose_provider_from_toml_no_features() {
let actual = toml::from_str(
Expand Down

0 comments on commit e93862d

Please sign in to comment.