Skip to content

Commit 7011195

Browse files
authored
Merge pull request #131 from shesek/202008-getnettotals
Implement RpcApi::get_net_totals()
2 parents 8db30c0 + ff9066e commit 7011195

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

client/src/client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,12 @@ pub trait RpcApi: Sized {
991991
Ok((res.start_height, res.stop_height))
992992
}
993993

994+
/// Returns information about network traffic, including bytes in, bytes out,
995+
/// and current time.
996+
fn get_net_totals(&self) -> Result<json::GetNetTotalsResult> {
997+
self.call("getnettotals", &[])
998+
}
999+
9941000
/// Returns the estimated network hashes per second based on the last n blocks.
9951001
fn get_network_hash_ps(&self, nblocks: Option<u64>, height: Option<u64>) -> Result<f64> {
9961002
let mut args = [opt_into_json(nblocks)?, opt_into_json(height)?];

integration_test/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ fn main() {
147147
test_get_peer_info(&cl);
148148
test_rescan_blockchain(&cl);
149149
test_create_wallet(&cl);
150+
test_get_net_totals(&cl);
150151
test_get_network_hash_ps(&cl);
151152
test_uptime(&cl);
152153
//TODO import_multi(
@@ -899,6 +900,10 @@ fn test_create_wallet(cl: &Client) {
899900
assert!(wallet_list.iter().zip(wallet_names).all(|(a, b)| a == b));
900901
}
901902

903+
fn test_get_net_totals(cl: &Client) {
904+
cl.get_net_totals().unwrap();
905+
}
906+
902907
fn test_get_network_hash_ps(cl: &Client) {
903908
cl.get_network_hash_ps(None, None).unwrap();
904909
}

json/src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,39 @@ pub struct SignRawTransactionInput {
11801180
pub amount: Option<Amount>,
11811181
}
11821182

1183+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1184+
pub struct GetNetTotalsResult {
1185+
/// Total bytes received
1186+
#[serde(rename = "totalbytesrecv")]
1187+
pub total_bytes_recv: u64,
1188+
/// Total bytes sent
1189+
#[serde(rename = "totalbytessent")]
1190+
pub total_bytes_sent: u64,
1191+
/// Current UNIX time in milliseconds
1192+
#[serde(rename = "timemillis")]
1193+
pub time_millis: u64,
1194+
/// Upload target statistics
1195+
#[serde(rename = "uploadtarget")]
1196+
pub upload_target: GetNetTotalsResultUploadTarget,
1197+
}
1198+
1199+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1200+
pub struct GetNetTotalsResultUploadTarget {
1201+
/// Length of the measuring timeframe in seconds
1202+
#[serde(rename = "timeframe")]
1203+
pub time_frame: u64,
1204+
/// Target in bytes
1205+
pub target: u64,
1206+
/// True if target is reached
1207+
pub target_reached: bool,
1208+
/// True if serving historical blocks
1209+
pub serve_historical_blocks: bool,
1210+
/// Bytes left in current time cycle
1211+
pub bytes_left_in_cycle: u64,
1212+
/// Seconds left in current time cycle
1213+
pub time_left_in_cycle: u64,
1214+
}
1215+
11831216
/// Used to represent an address type.
11841217
#[derive(Copy, Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
11851218
#[serde(rename_all = "kebab-case")]

0 commit comments

Comments
 (0)