@@ -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
@@ -944,6 +951,7 @@ pub enum Transport {
944
951
Ipc ,
945
952
}
946
953
954
+
947
955
impl Default for Transport {
948
956
fn default ( ) -> Self {
949
957
Self :: Rpc
@@ -1307,6 +1315,7 @@ mod tests {
1307
1315
features: BTreeSet :: new( ) ,
1308
1316
headers: HeaderMap :: new( ) ,
1309
1317
rules: Vec :: new( ) ,
1318
+ compression: Compression :: None ,
1310
1319
} ) ,
1311
1320
} ,
1312
1321
actual
@@ -1333,6 +1342,7 @@ mod tests {
1333
1342
features: BTreeSet :: new( ) ,
1334
1343
headers: HeaderMap :: new( ) ,
1335
1344
rules: Vec :: new( ) ,
1345
+ compression: Compression :: None ,
1336
1346
} ) ,
1337
1347
} ,
1338
1348
actual
@@ -1440,6 +1450,7 @@ mod tests {
1440
1450
features,
1441
1451
headers,
1442
1452
rules: Vec :: new( ) ,
1453
+ compression: Compression :: None ,
1443
1454
} ) ,
1444
1455
} ,
1445
1456
actual
@@ -1465,6 +1476,7 @@ mod tests {
1465
1476
features: BTreeSet :: new( ) ,
1466
1477
headers: HeaderMap :: new( ) ,
1467
1478
rules: Vec :: new( ) ,
1479
+ compression: Compression :: None ,
1468
1480
} ) ,
1469
1481
} ,
1470
1482
actual
@@ -1834,6 +1846,7 @@ mod tests {
1834
1846
features: BTreeSet :: new( ) ,
1835
1847
headers: HeaderMap :: new( ) ,
1836
1848
rules: Vec :: new( ) ,
1849
+ compression: Compression :: None ,
1837
1850
} ) ,
1838
1851
} ,
1839
1852
actual
@@ -1846,6 +1859,66 @@ mod tests {
1846
1859
assert ! ( SubgraphLimit :: Limit ( 10 ) > SubgraphLimit :: Disabled ) ;
1847
1860
}
1848
1861
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
+
1849
1922
#[ test]
1850
1923
fn duplicated_labels_are_not_allowed_within_chain ( ) {
1851
1924
let mut actual = toml:: from_str :: < ChainSection > (
0 commit comments