Skip to content

Commit

Permalink
Merge #250: Derive serde::Serialize for GetTransactionResultDetail et al
Browse files Browse the repository at this point in the history
d85da1d Derive Serialize and Deserialize for as many API types as possible (Casey Rodarmor)

Pull request description:

  We're implementing `get_transaction` for our [dummy Bitcoin RPC server](https://crates.io/crates/test-bitcoincore-rpc), and we need to construct and return a `GetTransactionResultDetail`, but `GetTransactionResultDetail` doesn't implement `Serialize`. This PR derives `Serialize` for `GetTransactionResultDetail`, as well as the types it contains.

ACKs for top commit:
  tcharding:
    ACK d85da1d

Tree-SHA512: 40e1074deab674d309d9288742ce6f59eef448217ab9cf83ae229df4d91feed6e9a678e0b7814dcb0da760a38210809f4797795bf2565d8bac5f2ff3e2a04c55
  • Loading branch information
tcharding committed Apr 30, 2024
2 parents 05f5b82 + d85da1d commit 33293a5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ pub enum GetTransactionResultDetailCategory {
Orphan,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct GetTransactionResultDetail {
pub address: Option<Address<NetworkUnchecked>>,
pub category: GetTransactionResultDetailCategory,
Expand All @@ -680,7 +680,7 @@ pub struct GetTransactionResultDetail {
pub abandoned: Option<bool>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct WalletTxInfo {
pub confirmations: i32,
pub blockhash: Option<bitcoin::BlockHash>,
Expand All @@ -697,7 +697,7 @@ pub struct WalletTxInfo {
pub wallet_conflicts: Vec<bitcoin::Txid>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct GetTransactionResult {
#[serde(flatten)]
pub info: WalletTxInfo,
Expand All @@ -716,7 +716,7 @@ impl GetTransactionResult {
}
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct ListTransactionResult {
#[serde(flatten)]
pub info: WalletTxInfo,
Expand All @@ -727,7 +727,7 @@ pub struct ListTransactionResult {
pub comment: Option<String>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct ListSinceBlockResult {
pub transactions: Vec<ListTransactionResult>,
#[serde(default)]
Expand Down Expand Up @@ -1851,7 +1851,7 @@ impl serde::Serialize for SigHashType {
}

// Used for createrawtransaction argument.
#[derive(Serialize, Clone, PartialEq, Eq, Debug)]
#[derive(Serialize, Clone, PartialEq, Eq, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateRawTransactionInput {
pub txid: bitcoin::Txid,
Expand Down Expand Up @@ -1895,7 +1895,7 @@ pub struct FundRawTransactionOptions {
pub estimate_mode: Option<EstimateMode>,
}

#[derive(Deserialize, Clone, PartialEq, Eq, Debug)]
#[derive(Deserialize, Clone, PartialEq, Eq, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FundRawTransactionResult {
#[serde(with = "crate::serde_hex")]
Expand All @@ -1906,7 +1906,7 @@ pub struct FundRawTransactionResult {
pub change_position: i32,
}

#[derive(Deserialize, Clone, PartialEq, Eq, Debug)]
#[derive(Deserialize, Clone, PartialEq, Eq, Debug, Serialize)]
pub struct GetBalancesResultEntry {
#[serde(with = "bitcoin::amount::serde::as_btc")]
pub trusted: Amount,
Expand All @@ -1916,7 +1916,7 @@ pub struct GetBalancesResultEntry {
pub immature: Amount,
}

#[derive(Deserialize, Clone, PartialEq, Eq, Debug)]
#[derive(Deserialize, Clone, PartialEq, Eq, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetBalancesResult {
pub mine: GetBalancesResultEntry,
Expand All @@ -1930,7 +1930,7 @@ impl FundRawTransactionResult {
}

// Used for signrawtransaction argument.
#[derive(Serialize, Clone, PartialEq, Debug)]
#[derive(Serialize, Clone, PartialEq, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SignRawTransactionInput {
pub txid: bitcoin::Txid,
Expand All @@ -1947,7 +1947,7 @@ pub struct SignRawTransactionInput {
}

/// Used to represent UTXO set hash type
#[derive(Clone, Serialize, PartialEq, Eq, Debug)]
#[derive(Clone, Serialize, PartialEq, Eq, Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TxOutSetHashType {
HashSerialized2,
Expand All @@ -1956,7 +1956,7 @@ pub enum TxOutSetHashType {
}

/// Used to specify a block hash or a height
#[derive(Clone, Serialize, PartialEq, Eq, Debug)]
#[derive(Clone, Serialize, PartialEq, Eq, Debug, Deserialize)]
#[serde(untagged)]
pub enum HashOrHeight {
BlockHash(bitcoin::BlockHash),
Expand Down

0 comments on commit 33293a5

Please sign in to comment.