1
+ use dkn_utils:: DriaNetwork ;
1
2
use eyre:: Context ;
2
3
3
- const POINTS_API_BASE_URL : & str = "https://mainnet.dkn.dria.co/points/v0/total/node/" ;
4
-
5
4
pub struct DriaPointsClient {
6
5
pub url : String ,
7
6
client : reqwest:: Client ,
@@ -18,13 +17,21 @@ pub struct DriaPoints {
18
17
}
19
18
20
19
impl DriaPointsClient {
20
+ /// The base URL for the points API, w.r.t network.
21
+ pub fn base_url ( network : & DriaNetwork ) -> & ' static str {
22
+ match network {
23
+ DriaNetwork :: Mainnet => "https://mainnet.dkn.dria.co/points/v0/total/node/" ,
24
+ DriaNetwork :: Testnet => "https://testnet.dkn.dria.co/points/v0/total/node/" ,
25
+ }
26
+ }
27
+
21
28
/// Creates a new `DriaPointsClient` for the given address.
22
- pub fn new ( address : & str ) -> eyre:: Result < Self > {
29
+ pub fn new ( address : & str , network : & DriaNetwork ) -> eyre:: Result < Self > {
23
30
const USER_AGENT : & str = concat ! ( env!( "CARGO_PKG_NAME" ) , "/" , env!( "CARGO_PKG_VERSION" ) ) ;
24
31
25
32
let url = format ! (
26
33
"{}/0x{}" ,
27
- POINTS_API_BASE_URL ,
34
+ Self :: base_url ( network ) ,
28
35
address. trim_start_matches( "0x" )
29
36
) ;
30
37
@@ -66,7 +73,11 @@ mod tests {
66
73
67
74
#[ tokio:: test]
68
75
async fn test_get_points ( ) {
69
- let client = DriaPointsClient :: new ( "0xa43536a6032a3907ccf60e8109429ee1047b207c" ) . unwrap ( ) ;
76
+ let client = DriaPointsClient :: new (
77
+ "0xa43536a6032a3907ccf60e8109429ee1047b207c" ,
78
+ & DriaNetwork :: Mainnet ,
79
+ )
80
+ . unwrap ( ) ;
70
81
let steps = client. get_points ( ) . await . unwrap ( ) ;
71
82
assert ! ( steps. score >= 0.0 ) ;
72
83
assert ! ( steps. percentile <= 100 ) ;
0 commit comments