deserialize block header with custom serde deserializer
This commit is contained in:
parent
7b37037e79
commit
e27d82d702
12
src/types.rs
12
src/types.rs
@ -107,6 +107,16 @@ where
|
||||
Ok(answer)
|
||||
}
|
||||
|
||||
fn from_hex_header<'de, D>(deserializer: D) -> Result<block::BlockHeader, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
use bitcoin::consensus::deserialize;
|
||||
|
||||
let vec: Vec<u8> = from_hex(deserializer)?;
|
||||
deserialize(&vec).map_err(de::Error::custom)
|
||||
}
|
||||
|
||||
/// Response to a [`script_get_history`](../client/struct.Client.html#method.script_get_history) request.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct GetHistoryRes {
|
||||
@ -189,8 +199,8 @@ pub struct GetMerkleRes {
|
||||
pub struct HeaderNotification {
|
||||
/// New block height.
|
||||
pub height: usize,
|
||||
#[serde(rename(serialize = "hex"))]
|
||||
/// Newly added header.
|
||||
#[serde(rename = "hex", deserialize_with = "from_hex_header")]
|
||||
pub header: block::BlockHeader,
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user