Skip to content

Commit ff9066e

Browse files
authored
Merge branch 'master' into 202008-getnettotals
2 parents 7ab34ea + 8db30c0 commit ff9066e

File tree

3 files changed

+64
-36
lines changed

3 files changed

+64
-36
lines changed

client/src/client.rs

Lines changed: 15 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,17 @@ pub trait RpcApi: Sized {
994996
fn get_net_totals(&self) -> Result<json::GetNetTotalsResult> {
995997
self.call("getnettotals", &[])
996998
}
999+
1000+
/// Returns the estimated network hashes per second based on the last n blocks.
1001+
fn get_network_hash_ps(&self, nblocks: Option<u64>, height: Option<u64>) -> Result<f64> {
1002+
let mut args = [opt_into_json(nblocks)?, opt_into_json(height)?];
1003+
self.call("getnetworkhashps", handle_defaults(&mut args, &[null(), null()]))
1004+
}
1005+
1006+
/// Returns the total uptime of the server in seconds
1007+
fn uptime(&self) -> Result<u64> {
1008+
self.call("uptime", &[])
1009+
}
9971010
}
9981011

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

integration_test/src/main.rs

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ fn main() {
148148
test_rescan_blockchain(&cl);
149149
test_create_wallet(&cl);
150150
test_get_net_totals(&cl);
151+
test_get_network_hash_ps(&cl);
152+
test_uptime(&cl);
151153
//TODO import_multi(
152154
//TODO verify_message(
153155
//TODO wait_for_new_block(&self, timeout: u64) -> Result<json::BlockRef> {
@@ -215,11 +217,13 @@ fn test_get_balance_generate_to_address(cl: &Client) {
215217
}
216218

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

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);
223+
let blocks = cl.generate_to_address(500, &cl.get_new_address(None, None).unwrap()).unwrap();
224+
assert_eq!(blocks.len(), 500);
225+
assert_ne!(cl.get_balances().unwrap(), initial);
226+
}
223227
}
224228

225229
fn test_get_best_block_hash(cl: &Client) {
@@ -827,44 +831,42 @@ fn test_create_wallet(cl: &Client) {
827831
blank: Some(true),
828832
passphrase: None,
829833
avoid_reuse: None,
830-
}
834+
},
831835
];
832836

833837
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-
);
838+
wallet_params.push(WalletParams {
839+
name: wallet_names[3],
840+
disable_private_keys: None,
841+
blank: None,
842+
passphrase: Some("pass"),
843+
avoid_reuse: None,
844+
});
845+
wallet_params.push(WalletParams {
846+
name: wallet_names[4],
847+
disable_private_keys: None,
848+
blank: None,
849+
passphrase: None,
850+
avoid_reuse: Some(true),
851+
});
852852
}
853853

854854
for wallet_param in wallet_params {
855855
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();
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();
864864

865865
assert_eq!(result.name, wallet_param.name);
866866
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()),
867+
(None, Some(true)) => {
868+
Some("Empty string given as passphrase, wallet will not be encrypted.".to_string())
869+
}
868870
_ => Some("".to_string()),
869871
};
870872
assert_eq!(result.warning, expected_warning);
@@ -883,7 +885,8 @@ fn test_create_wallet(cl: &Client) {
883885
assert_eq!(wallet_info.avoid_reuse.unwrap_or(false), has_avoid_reuse);
884886
assert_eq!(
885887
wallet_info.scanning.unwrap_or(json::ScanningDetails::NotScanning(false)),
886-
json::ScanningDetails::NotScanning(false));
888+
json::ScanningDetails::NotScanning(false)
889+
);
887890
}
888891

889892
let mut wallet_list = cl.list_wallets().unwrap();
@@ -901,6 +904,14 @@ fn test_get_net_totals(cl: &Client) {
901904
cl.get_net_totals().unwrap();
902905
}
903906

907+
fn test_get_network_hash_ps(cl: &Client) {
908+
cl.get_network_hash_ps(None, None).unwrap();
909+
}
910+
911+
fn test_uptime(cl: &Client) {
912+
cl.uptime().unwrap();
913+
}
914+
904915
fn test_stop(cl: Client) {
905916
println!("Stopping: '{}'", cl.stop().unwrap());
906917
}

json/src/lib.rs

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

@@ -393,6 +396,7 @@ pub struct WalletTxInfo {
393396
pub blockhash: Option<bitcoin::BlockHash>,
394397
pub blockindex: Option<usize>,
395398
pub blocktime: Option<u64>,
399+
pub blockheight: Option<u32>,
396400
pub txid: bitcoin::Txid,
397401
pub time: u64,
398402
pub timereceived: u64,

0 commit comments

Comments
 (0)