Skip to content

Commit

Permalink
Serialize regtest network type (#128)
Browse files Browse the repository at this point in the history
* Serialize regtest network type

* Update changelog

* Some changes
  • Loading branch information
aleksuss authored and alekseysidorov committed Jun 6, 2018
1 parent d497b5b commit 9c37a1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- Changed `btc::Network` (de)serializing into/from string

## 0.8 - 2018-06-01

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ travis-ci = { repository = "exonum/exonum-btc-anchoring" }
exonum = "0.8.0"
exonum_bitcoinrpc = "0.5.1"

bitcoin="0.13.0"
bitcoin = "=0.13.1"
byteorder = "1.0.0"
btc-transaction-utils = "0.2.0"
clap = "2.22.1"
Expand Down
15 changes: 4 additions & 11 deletions src/blockchain/consensus_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,17 @@ fn btc_network_to_str<S>(network: &btc::Network, ser: S) -> Result<S::Ok, S::Err
where
S: ::serde::Serializer,
{
match *network {
btc::Network::Bitcoin => ser.serialize_str("bitcoin"),
btc::Network::Testnet => ser.serialize_str("testnet"),
}
ser.serialize_str(&network.to_string())
}

fn btc_network_from_str<'de, D>(deserializer: D) -> Result<btc::Network, D::Error>
where
D: Deserializer<'de>,
{
const VARIANTS: &[&str] = &["bitcoin", "testnet", "regtest"];
let s: String = Deserialize::deserialize(deserializer)?;

const VARIANTS: &[&str] = &["bitcoin", "testnet"];
match s.as_str() {
"bitcoin" => Ok(btc::Network::Bitcoin),
"testnet" => Ok(btc::Network::Testnet),
other => Err(::serde::de::Error::unknown_variant(other, VARIANTS)),
}
s.parse::<btc::Network>()
.map_err(|_| ::serde::de::Error::unknown_variant(&s, VARIANTS))
}

impl StorageValue for AnchoringConfig {
Expand Down

0 comments on commit 9c37a1b

Please sign in to comment.