@@ -2,6 +2,7 @@ use graph::{
22 anyhow:: Error ,
33 blockchain:: BlockchainKind ,
44 components:: network_provider:: ChainName ,
5+ endpoint:: Compression ,
56 env:: ENV_VARS ,
67 firehose:: { SubgraphLimit , SUBGRAPHS_PER_CONN } ,
78 itertools:: Itertools ,
@@ -502,6 +503,7 @@ impl ChainSection {
502503 features,
503504 headers : Default :: default ( ) ,
504505 rules : vec ! [ ] ,
506+ compression : Compression :: None ,
505507 } ) ,
506508 } ;
507509 let entry = chains. entry ( name. to_string ( ) ) . or_insert_with ( || Chain {
@@ -705,6 +707,10 @@ pub struct Web3Provider {
705707
706708 #[ serde( default , rename = "match" ) ]
707709 rules : Vec < Web3Rule > ,
710+
711+ /// Compression method for RPC requests and responses
712+ #[ serde( default ) ]
713+ pub compression : Compression ,
708714}
709715
710716impl Web3Provider {
@@ -901,6 +907,7 @@ impl<'de> Deserialize<'de> for Provider {
901907 . ok_or_else ( || serde:: de:: Error :: missing_field ( "features" ) ) ?,
902908 headers : headers. unwrap_or_else ( HeaderMap :: new) ,
903909 rules : nodes,
910+ compression : Compression :: None ,
904911 } ) ,
905912 } ;
906913
@@ -944,6 +951,7 @@ pub enum Transport {
944951 Ipc ,
945952}
946953
954+
947955impl Default for Transport {
948956 fn default ( ) -> Self {
949957 Self :: Rpc
@@ -1307,6 +1315,7 @@ mod tests {
13071315 features: BTreeSet :: new( ) ,
13081316 headers: HeaderMap :: new( ) ,
13091317 rules: Vec :: new( ) ,
1318+ compression: Compression :: None ,
13101319 } ) ,
13111320 } ,
13121321 actual
@@ -1333,6 +1342,7 @@ mod tests {
13331342 features: BTreeSet :: new( ) ,
13341343 headers: HeaderMap :: new( ) ,
13351344 rules: Vec :: new( ) ,
1345+ compression: Compression :: None ,
13361346 } ) ,
13371347 } ,
13381348 actual
@@ -1440,6 +1450,7 @@ mod tests {
14401450 features,
14411451 headers,
14421452 rules: Vec :: new( ) ,
1453+ compression: Compression :: None ,
14431454 } ) ,
14441455 } ,
14451456 actual
@@ -1465,6 +1476,7 @@ mod tests {
14651476 features: BTreeSet :: new( ) ,
14661477 headers: HeaderMap :: new( ) ,
14671478 rules: Vec :: new( ) ,
1479+ compression: Compression :: None ,
14681480 } ) ,
14691481 } ,
14701482 actual
@@ -1834,6 +1846,7 @@ mod tests {
18341846 features: BTreeSet :: new( ) ,
18351847 headers: HeaderMap :: new( ) ,
18361848 rules: Vec :: new( ) ,
1849+ compression: Compression :: None ,
18371850 } ) ,
18381851 } ,
18391852 actual
@@ -1846,6 +1859,66 @@ mod tests {
18461859 assert ! ( SubgraphLimit :: Limit ( 10 ) > SubgraphLimit :: Disabled ) ;
18471860 }
18481861
1862+ #[ test]
1863+ fn it_parses_web3_provider_with_compression ( ) {
1864+ let actual = toml:: from_str (
1865+ r#"
1866+ label = "compressed"
1867+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "gzip" }
1868+ "# ,
1869+ )
1870+ . unwrap ( ) ;
1871+
1872+ assert_eq ! (
1873+ Provider {
1874+ label: "compressed" . to_owned( ) ,
1875+ details: ProviderDetails :: Web3 ( Web3Provider {
1876+ transport: Transport :: Rpc ,
1877+ url: "http://localhost:8545" . to_owned( ) ,
1878+ features: {
1879+ let mut features = BTreeSet :: new( ) ;
1880+ features. insert( "archive" . to_string( ) ) ;
1881+ features
1882+ } ,
1883+ headers: HeaderMap :: new( ) ,
1884+ rules: Vec :: new( ) ,
1885+ compression: Compression :: Gzip ,
1886+ } ) ,
1887+ } ,
1888+ actual
1889+ ) ;
1890+ }
1891+
1892+ #[ test]
1893+ fn it_parses_web3_provider_with_no_compression ( ) {
1894+ let actual = toml:: from_str (
1895+ r#"
1896+ label = "uncompressed"
1897+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "none" }
1898+ "# ,
1899+ )
1900+ . unwrap ( ) ;
1901+
1902+ assert_eq ! (
1903+ Provider {
1904+ label: "uncompressed" . to_owned( ) ,
1905+ details: ProviderDetails :: Web3 ( Web3Provider {
1906+ transport: Transport :: Rpc ,
1907+ url: "http://localhost:8545" . to_owned( ) ,
1908+ features: {
1909+ let mut features = BTreeSet :: new( ) ;
1910+ features. insert( "archive" . to_string( ) ) ;
1911+ features
1912+ } ,
1913+ headers: HeaderMap :: new( ) ,
1914+ rules: Vec :: new( ) ,
1915+ compression: Compression :: None ,
1916+ } ) ,
1917+ } ,
1918+ actual
1919+ ) ;
1920+ }
1921+
18491922 #[ test]
18501923 fn duplicated_labels_are_not_allowed_within_chain ( ) {
18511924 let mut actual = toml:: from_str :: < ChainSection > (
0 commit comments