Skip to content

Commit 4864bf3

Browse files
authored
Merge branch 'master' into 202008-utxo-info
2 parents ecae377 + 7011195 commit 4864bf3

File tree

3 files changed

+108
-36
lines changed

3 files changed

+108
-36
lines changed

client/src/client.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ pub trait RpcApi: Sized {
285285
opt_into_json(passphrase)?,
286286
opt_into_json(avoid_reuse)?,
287287
];
288-
self.call("createwallet", handle_defaults(
289-
&mut args, &[false.into(), false.into(), into_json("")?, false.into()]))
288+
self.call(
289+
"createwallet",
290+
handle_defaults(&mut args, &[false.into(), false.into(), into_json("")?, false.into()]),
291+
)
290292
}
291293

292294
fn list_wallets(&self) -> Result<Vec<String>> {
@@ -994,6 +996,23 @@ pub trait RpcApi: Sized {
994996
fn get_tx_out_set_info(&self) -> Result<json::GetTxOutSetInfoResult> {
995997
self.call("gettxoutsetinfo", &[])
996998
}
999+
1000+
/// Returns information about network traffic, including bytes in, bytes out,
1001+
/// and current time.
1002+
fn get_net_totals(&self) -> Result<json::GetNetTotalsResult> {
1003+
self.call("getnettotals", &[])
1004+
}
1005+
1006+
/// Returns the estimated network hashes per second based on the last n blocks.
1007+
fn get_network_hash_ps(&self, nblocks: Option<u64>, height: Option<u64>) -> Result<f64> {
1008+
let mut args = [opt_into_json(nblocks)?, opt_into_json(height)?];
1009+
self.call("getnetworkhashps", handle_defaults(&mut args, &[null(), null()]))
1010+
}
1011+
1012+
/// Returns the total uptime of the server in seconds
1013+
fn uptime(&self) -> Result<u64> {
1014+
self.call("uptime", &[])
1015+
}
9971016
}
9981017

9991018
/// Client implements a JSON-RPC client for the Bitcoin Core daemon or compatible APIs.

integration_test/src/main.rs

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ fn main() {
148148
test_rescan_blockchain(&cl);
149149
test_create_wallet(&cl);
150150
test_get_tx_out_set_info(&cl);
151+
test_get_net_totals(&cl);
152+
test_get_network_hash_ps(&cl);
153+
test_uptime(&cl);
151154
//TODO import_multi(
152155
//TODO verify_message(
153156
//TODO wait_for_new_block(&self, timeout: u64) -> Result<json::BlockRef> {
@@ -215,11 +218,13 @@ fn test_get_balance_generate_to_address(cl: &Client) {
215218
}
216219

217220
fn test_get_balances_generate_to_address(cl: &Client) {
218-
let initial = cl.get_balances().unwrap();
221+
if version() >= 190000 {
222+
let initial = cl.get_balances().unwrap();
219223

220-
let blocks = cl.generate_to_address(500, &cl.get_new_address(None, None).unwrap()).unwrap();
221-
assert_eq!(blocks.len(), 500);
222-
assert_ne!(cl.get_balances().unwrap(), initial);
224+
let blocks = cl.generate_to_address(500, &cl.get_new_address(None, None).unwrap()).unwrap();
225+
assert_eq!(blocks.len(), 500);
226+
assert_ne!(cl.get_balances().unwrap(), initial);
227+
}
223228
}
224229

225230
fn test_get_best_block_hash(cl: &Client) {
@@ -827,44 +832,42 @@ fn test_create_wallet(cl: &Client) {
827832
blank: Some(true),
828833
passphrase: None,
829834
avoid_reuse: None,
830-
}
835+
},
831836
];
832837

833838
if version() >= 190000 {
834-
wallet_params.push(
835-
WalletParams {
836-
name: wallet_names[3],
837-
disable_private_keys: None,
838-
blank: None,
839-
passphrase: Some("pass"),
840-
avoid_reuse: None,
841-
}
842-
);
843-
wallet_params.push(
844-
WalletParams {
845-
name: wallet_names[4],
846-
disable_private_keys: None,
847-
blank: None,
848-
passphrase: None,
849-
avoid_reuse: Some(true),
850-
}
851-
);
839+
wallet_params.push(WalletParams {
840+
name: wallet_names[3],
841+
disable_private_keys: None,
842+
blank: None,
843+
passphrase: Some("pass"),
844+
avoid_reuse: None,
845+
});
846+
wallet_params.push(WalletParams {
847+
name: wallet_names[4],
848+
disable_private_keys: None,
849+
blank: None,
850+
passphrase: None,
851+
avoid_reuse: Some(true),
852+
});
852853
}
853854

854855
for wallet_param in wallet_params {
855856
let result = cl
856-
.create_wallet(
857-
wallet_param.name,
858-
wallet_param.disable_private_keys,
859-
wallet_param.blank,
860-
wallet_param.passphrase,
861-
wallet_param.avoid_reuse,
862-
)
863-
.unwrap();
857+
.create_wallet(
858+
wallet_param.name,
859+
wallet_param.disable_private_keys,
860+
wallet_param.blank,
861+
wallet_param.passphrase,
862+
wallet_param.avoid_reuse,
863+
)
864+
.unwrap();
864865

865866
assert_eq!(result.name, wallet_param.name);
866867
let expected_warning = match (wallet_param.passphrase, wallet_param.avoid_reuse) {
867-
(None, Some(true)) => Some("Empty string given as passphrase, wallet will not be encrypted.".to_string()),
868+
(None, Some(true)) => {
869+
Some("Empty string given as passphrase, wallet will not be encrypted.".to_string())
870+
}
868871
_ => Some("".to_string()),
869872
};
870873
assert_eq!(result.warning, expected_warning);
@@ -883,7 +886,8 @@ fn test_create_wallet(cl: &Client) {
883886
assert_eq!(wallet_info.avoid_reuse.unwrap_or(false), has_avoid_reuse);
884887
assert_eq!(
885888
wallet_info.scanning.unwrap_or(json::ScanningDetails::NotScanning(false)),
886-
json::ScanningDetails::NotScanning(false));
889+
json::ScanningDetails::NotScanning(false)
890+
);
887891
}
888892

889893
let mut wallet_list = cl.list_wallets().unwrap();
@@ -901,6 +905,18 @@ fn test_get_tx_out_set_info(cl: &Client) {
901905
cl.get_tx_out_set_info().unwrap();
902906
}
903907

908+
fn test_get_net_totals(cl: &Client) {
909+
cl.get_net_totals().unwrap();
910+
}
911+
912+
fn test_get_network_hash_ps(cl: &Client) {
913+
cl.get_network_hash_ps(None, None).unwrap();
914+
}
915+
916+
fn test_uptime(cl: &Client) {
917+
cl.uptime().unwrap();
918+
}
919+
904920
fn test_stop(cl: Client) {
905921
println!("Stopping: '{}'", cl.stop().unwrap());
906922
}

json/src/lib.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ pub struct GetWalletInfoResult {
157157
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
158158
#[serde(untagged)]
159159
pub enum ScanningDetails {
160-
Scanning { duration: usize, progress: f32 },
160+
Scanning {
161+
duration: usize,
162+
progress: f32,
163+
},
161164
NotScanning(bool),
162165
}
163166

@@ -394,6 +397,7 @@ pub struct WalletTxInfo {
394397
pub blockhash: Option<bitcoin::BlockHash>,
395398
pub blockindex: Option<usize>,
396399
pub blocktime: Option<u64>,
400+
pub blockheight: Option<u32>,
397401
pub txid: bitcoin::Txid,
398402
pub time: u64,
399403
pub timereceived: u64,
@@ -1200,6 +1204,39 @@ pub struct GetTxOutSetInfoResult {
12001204
pub total_amount: Amount,
12011205
}
12021206

1207+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1208+
pub struct GetNetTotalsResult {
1209+
/// Total bytes received
1210+
#[serde(rename = "totalbytesrecv")]
1211+
pub total_bytes_recv: u64,
1212+
/// Total bytes sent
1213+
#[serde(rename = "totalbytessent")]
1214+
pub total_bytes_sent: u64,
1215+
/// Current UNIX time in milliseconds
1216+
#[serde(rename = "timemillis")]
1217+
pub time_millis: u64,
1218+
/// Upload target statistics
1219+
#[serde(rename = "uploadtarget")]
1220+
pub upload_target: GetNetTotalsResultUploadTarget,
1221+
}
1222+
1223+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1224+
pub struct GetNetTotalsResultUploadTarget {
1225+
/// Length of the measuring timeframe in seconds
1226+
#[serde(rename = "timeframe")]
1227+
pub time_frame: u64,
1228+
/// Target in bytes
1229+
pub target: u64,
1230+
/// True if target is reached
1231+
pub target_reached: bool,
1232+
/// True if serving historical blocks
1233+
pub serve_historical_blocks: bool,
1234+
/// Bytes left in current time cycle
1235+
pub bytes_left_in_cycle: u64,
1236+
/// Seconds left in current time cycle
1237+
pub time_left_in_cycle: u64,
1238+
}
1239+
12031240
/// Used to represent an address type.
12041241
#[derive(Copy, Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
12051242
#[serde(rename_all = "kebab-case")]

0 commit comments

Comments
 (0)