Module bitcoin::util::amount::serde[][src]

This module adds serde serialization and deserialization support for Amounts. Since there is not a default way to serialize and deserialize Amounts, multiple ways are supported and it’s up to the user to decide which serialiation to use. The provided modules can be used as follows:

use serde::{Serialize, Deserialize};
use bitcoin::Amount;

#[derive(Serialize, Deserialize)]
pub struct HasAmount {
    #[serde(with = "bitcoin::util::amount::serde::as_btc")]
    pub amount: Amount,
}

Modules

as_btc

Serialize and deserialize [Amount] as JSON numbers denominated in BTC. Use with #[serde(with = "amount::serde::as_btc")].

as_sat

Serialize and deserialize [Amount] as real numbers denominated in satoshi. Use with #[serde(with = "amount::serde::as_sat")].

Traits

SerdeAmount

This trait is used only to avoid code duplication and naming collisions of the different serde serialization crates.

SerdeAmountForOpt

This trait is only for internal Amount type serialization/deserialization