Skip to content

Commit 7d570c9

Browse files
author
Gabriel Comte
committed
Implement Display trait for BlockStatsFields
1 parent 7c294c6 commit 7d570c9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

client/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ pub trait RpcApi: Sized {
471471
height: u64,
472472
fields: &[json::BlockStatsFields],
473473
) -> Result<json::GetBlockStatsResultPartial> {
474-
let fields: Vec<&str> = fields.iter().map(|field| field.get_rpc_keyword()).collect();
474+
let fields: Vec<String> = fields.iter().map(|field| field.to_string()).collect();
475475

476476
self.call("getblockstats", &[height.into(), fields.into()])
477477
}

json/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use bitcoin::util::{bip158, bip32};
3131
use bitcoin::{Address, Amount, PrivateKey, PublicKey, Script, SignedAmount, Transaction};
3232
use serde::de::Error as SerdeError;
3333
use serde::{Deserialize, Serialize};
34+
use std::fmt;
3435

3536
//TODO(stevenroose) consider using a Time type
3637

@@ -435,7 +436,7 @@ pub enum BlockStatsFields {
435436
}
436437

437438
impl BlockStatsFields {
438-
pub fn get_rpc_keyword(&self) -> &str {
439+
fn get_rpc_keyword(&self) -> &str {
439440
match *self {
440441
BlockStatsFields::AverageFee => "avgfee",
441442
BlockStatsFields::AverageFeeRate => "avgfeerate",
@@ -470,6 +471,12 @@ impl BlockStatsFields {
470471
}
471472
}
472473

474+
impl fmt::Display for BlockStatsFields {
475+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
476+
write!(f, "{}", self.get_rpc_keyword())
477+
}
478+
}
479+
473480
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
474481
#[serde(rename_all = "camelCase")]
475482
pub struct GetMiningInfoResult {
@@ -1156,7 +1163,6 @@ impl<'de> serde::Deserialize<'de> for ImportMultiRescanSince {
11561163
D: serde::Deserializer<'de>,
11571164
{
11581165
use serde::de;
1159-
use std::fmt;
11601166
struct Visitor;
11611167
impl<'de> de::Visitor<'de> for Visitor {
11621168
type Value = ImportMultiRescanSince;

0 commit comments

Comments
 (0)