Skip to content

Commit

Permalink
Serialize with bip70 (rust-bitcoin#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Oct 17, 2024
1 parent 06a6c15 commit 392f3b9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ pub enum StringOrStringArray {
pub struct GetBlockchainInfoResult {
/// Current network name as defined in BIP70 (main, test, signet, regtest)
#[serde(deserialize_with = "deserialize_bip70_network")]
#[serde(serialize_with = "serialize_bip70_network")]
pub chain: Network,
/// The current number of blocks processed in the server
pub blocks: u64,
Expand Down Expand Up @@ -2190,6 +2191,13 @@ where
Ok(Some(res))
}

fn serialize_bip70_network<S>(network: &Network, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(network.to_core_arg())
}

/// deserialize_bip70_network deserializes a Bitcoin Core network according to BIP70
/// The accepted input variants are: {"main", "test", "signet", "regtest"}
fn deserialize_bip70_network<'de, D>(deserializer: D) -> Result<Network, D::Error>
Expand Down

0 comments on commit 392f3b9

Please sign in to comment.