@@ -2,6 +2,7 @@ use graph::{
2
2
anyhow:: Error ,
3
3
blockchain:: BlockchainKind ,
4
4
components:: network_provider:: ChainName ,
5
+ endpoint:: Compression ,
5
6
env:: ENV_VARS ,
6
7
firehose:: { SubgraphLimit , SUBGRAPHS_PER_CONN } ,
7
8
itertools:: Itertools ,
@@ -502,6 +503,7 @@ impl ChainSection {
502
503
features,
503
504
headers : Default :: default ( ) ,
504
505
rules : vec ! [ ] ,
506
+ compression : Compression :: None ,
505
507
} ) ,
506
508
} ;
507
509
let entry = chains. entry ( name. to_string ( ) ) . or_insert_with ( || Chain {
@@ -705,6 +707,10 @@ pub struct Web3Provider {
705
707
706
708
#[ serde( default , rename = "match" ) ]
707
709
rules : Vec < Web3Rule > ,
710
+
711
+ /// Compression method for RPC requests and responses
712
+ #[ serde( default ) ]
713
+ pub compression : Compression ,
708
714
}
709
715
710
716
impl Web3Provider {
@@ -901,6 +907,7 @@ impl<'de> Deserialize<'de> for Provider {
901
907
. ok_or_else ( || serde:: de:: Error :: missing_field ( "features" ) ) ?,
902
908
headers : headers. unwrap_or_else ( HeaderMap :: new) ,
903
909
rules : nodes,
910
+ compression : Compression :: None ,
904
911
} ) ,
905
912
} ;
906
913
@@ -1307,6 +1314,7 @@ mod tests {
1307
1314
features: BTreeSet :: new( ) ,
1308
1315
headers: HeaderMap :: new( ) ,
1309
1316
rules: Vec :: new( ) ,
1317
+ compression: Compression :: None ,
1310
1318
} ) ,
1311
1319
} ,
1312
1320
actual
@@ -1333,6 +1341,7 @@ mod tests {
1333
1341
features: BTreeSet :: new( ) ,
1334
1342
headers: HeaderMap :: new( ) ,
1335
1343
rules: Vec :: new( ) ,
1344
+ compression: Compression :: None ,
1336
1345
} ) ,
1337
1346
} ,
1338
1347
actual
@@ -1440,6 +1449,7 @@ mod tests {
1440
1449
features,
1441
1450
headers,
1442
1451
rules: Vec :: new( ) ,
1452
+ compression: Compression :: None ,
1443
1453
} ) ,
1444
1454
} ,
1445
1455
actual
@@ -1465,6 +1475,7 @@ mod tests {
1465
1475
features: BTreeSet :: new( ) ,
1466
1476
headers: HeaderMap :: new( ) ,
1467
1477
rules: Vec :: new( ) ,
1478
+ compression: Compression :: None ,
1468
1479
} ) ,
1469
1480
} ,
1470
1481
actual
@@ -1834,6 +1845,7 @@ mod tests {
1834
1845
features: BTreeSet :: new( ) ,
1835
1846
headers: HeaderMap :: new( ) ,
1836
1847
rules: Vec :: new( ) ,
1848
+ compression: Compression :: None ,
1837
1849
} ) ,
1838
1850
} ,
1839
1851
actual
@@ -1846,6 +1858,66 @@ mod tests {
1846
1858
assert ! ( SubgraphLimit :: Limit ( 10 ) > SubgraphLimit :: Disabled ) ;
1847
1859
}
1848
1860
1861
+ #[ test]
1862
+ fn it_parses_web3_provider_with_compression ( ) {
1863
+ let actual = toml:: from_str (
1864
+ r#"
1865
+ label = "compressed"
1866
+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "gzip" }
1867
+ "# ,
1868
+ )
1869
+ . unwrap ( ) ;
1870
+
1871
+ assert_eq ! (
1872
+ Provider {
1873
+ label: "compressed" . to_owned( ) ,
1874
+ details: ProviderDetails :: Web3 ( Web3Provider {
1875
+ transport: Transport :: Rpc ,
1876
+ url: "http://localhost:8545" . to_owned( ) ,
1877
+ features: {
1878
+ let mut features = BTreeSet :: new( ) ;
1879
+ features. insert( "archive" . to_string( ) ) ;
1880
+ features
1881
+ } ,
1882
+ headers: HeaderMap :: new( ) ,
1883
+ rules: Vec :: new( ) ,
1884
+ compression: Compression :: Gzip ,
1885
+ } ) ,
1886
+ } ,
1887
+ actual
1888
+ ) ;
1889
+ }
1890
+
1891
+ #[ test]
1892
+ fn it_parses_web3_provider_with_no_compression ( ) {
1893
+ let actual = toml:: from_str (
1894
+ r#"
1895
+ label = "uncompressed"
1896
+ details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "none" }
1897
+ "# ,
1898
+ )
1899
+ . unwrap ( ) ;
1900
+
1901
+ assert_eq ! (
1902
+ Provider {
1903
+ label: "uncompressed" . to_owned( ) ,
1904
+ details: ProviderDetails :: Web3 ( Web3Provider {
1905
+ transport: Transport :: Rpc ,
1906
+ url: "http://localhost:8545" . to_owned( ) ,
1907
+ features: {
1908
+ let mut features = BTreeSet :: new( ) ;
1909
+ features. insert( "archive" . to_string( ) ) ;
1910
+ features
1911
+ } ,
1912
+ headers: HeaderMap :: new( ) ,
1913
+ rules: Vec :: new( ) ,
1914
+ compression: Compression :: None ,
1915
+ } ) ,
1916
+ } ,
1917
+ actual
1918
+ ) ;
1919
+ }
1920
+
1849
1921
#[ test]
1850
1922
fn duplicated_labels_are_not_allowed_within_chain ( ) {
1851
1923
let mut actual = toml:: from_str :: < ChainSection > (
0 commit comments