|
| 1 | +// SPDX-License-Identifier: CC0-1.0 |
| 2 | + |
| 3 | +//! The JSON-RPC API for Bitcoin Core `v28` - wallet. |
| 4 | +//! |
| 5 | +//! Types for methods found under the `== Wallet ==` section of the API docs. |
| 6 | +
|
| 7 | +use bitcoin::{Address, Amount, ScriptBuf, Txid, BlockHash, SignedAmount}; |
| 8 | +use bitcoin::address::NetworkUnchecked; |
| 9 | +use serde::{Deserialize, Serialize}; |
| 10 | +extern crate bitcoin; |
| 11 | + |
| 12 | +/// Result of the JSON-RPC method `listunspent`. |
| 13 | +/// |
| 14 | +/// > listunspent ( minconf maxconf ["addresses",...] `[include_unsafe]` `[query_options]`) |
| 15 | +/// > |
| 16 | +/// > Returns array of unspent transaction outputs |
| 17 | +/// > with between minconf and maxconf (inclusive) confirmations. |
| 18 | +/// > Optionally filter to only include txouts paid to specified addresses. |
| 19 | +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] |
| 20 | +pub struct ListUnspent(pub Vec<ListUnspentItem>); |
| 21 | + |
| 22 | +/// Unspent transaction output, returned as part of `listunspent`. |
| 23 | +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] |
| 24 | +#[serde(rename_all = "camelCase")] // Match typical JSON field names |
| 25 | +pub struct ListUnspentItem { |
| 26 | + /// The transaction id. |
| 27 | + pub txid: Txid, |
| 28 | + /// The vout value. |
| 29 | + pub vout: u32, |
| 30 | + /// The bitcoin address of the transaction (optional for non-standard scripts). |
| 31 | + pub address: Option<Address<NetworkUnchecked>>, |
| 32 | + /// The associated label, present only if the address is in the address book. |
| 33 | + pub label: Option<String>, |
| 34 | + /// Optional account field. |
| 35 | + pub account: Option<String>, |
| 36 | + /// The script key. |
| 37 | + #[serde(rename = "scriptPubKey")] |
| 38 | + pub script_pubkey: ScriptBuf, |
| 39 | + /// The transaction amount. |
| 40 | + // Use Amount (unsigned) for UTXOs |
| 41 | + #[serde(with = "bitcoin::amount::serde::as_btc")] |
| 42 | + pub amount: Amount, |
| 43 | + /// The number of confirmations. |
| 44 | + pub confirmations: u32, |
| 45 | + /// The redeemScript if scriptPubKey is P2SH. |
| 46 | + #[serde(rename = "redeemScript")] |
| 47 | + pub redeem_script: Option<ScriptBuf>, |
| 48 | + /// The witnessScript if the scriptPubKey is P2WSH or P2SH-P2WSH. |
| 49 | + #[serde(rename = "witnessScript")] |
| 50 | + pub witness_script: Option<ScriptBuf>, |
| 51 | + /// Whether we have the private keys to spend this output. |
| 52 | + pub spendable: bool, |
| 53 | + /// Whether we know how to spend this output, ignoring the lack of keys. |
| 54 | + pub solvable: bool, |
| 55 | + /// Whether this output is considered safe to spend. |
| 56 | + pub safe: bool, |
| 57 | + // Add other optional fields if needed for your version (desc, coinbase etc.) |
| 58 | + /// Output descriptor if available. |
| 59 | + pub desc: Option<String>, |
| 60 | + /// Whether this is a coinbase output (added in v25+). |
| 61 | + pub coinbase: Option<bool>, |
| 62 | +} |
| 63 | + |
| 64 | +/// Transaction item returned as part of `listtransactions`. |
| 65 | +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] // Removed Eq due to SignedAmount potentially not deriving Eq |
| 66 | +#[serde(rename_all = "camelCase")] // Match common JSON names if needed |
| 67 | +pub struct ListTransactionsItem { |
| 68 | + /// The bitcoin address of the transaction (optional). |
| 69 | + // Using Option<Address> as address might not always be present/decodable |
| 70 | + pub address: Option<Address<NetworkUnchecked>>, |
| 71 | + /// The transaction category. |
| 72 | + pub category: TransactionCategory, |
| 73 | + /// The amount. |
| 74 | + #[serde(with = "bitcoin::amount::serde::as_btc")] |
| 75 | + pub amount: SignedAmount, |
| 76 | + /// A comment for the address/transaction, if any. |
| 77 | + pub label: Option<String>, |
| 78 | + /// The vout value. |
| 79 | + pub vout: u32, |
| 80 | + /// The amount of the fee in BTC. (Made optional) |
| 81 | + pub fee: Option<f64>, |
| 82 | + /// The number of confirmations for the transaction. |
| 83 | + pub confirmations: i64, |
| 84 | + /// Whether we consider the outputs of this unconfirmed transaction safe to spend. |
| 85 | + pub trusted: Option<bool>, |
| 86 | + /// The block hash containing the transaction. |
| 87 | + #[serde(rename = "blockhash")] |
| 88 | + pub block_hash: Option<BlockHash>, |
| 89 | + /// The index of the transaction in the block that includes it. |
| 90 | + #[serde(rename = "blockindex")] |
| 91 | + pub block_index: Option<u32>, |
| 92 | + /// The block time in seconds since epoch (1 Jan 1970 GMT). |
| 93 | + #[serde(rename = "blocktime")] |
| 94 | + pub block_time: Option<u32>, |
| 95 | + /// The transaction id. |
| 96 | + pub txid: Txid, |
| 97 | + /// The transaction time in seconds since epoch (Jan 1 1970 GMT). |
| 98 | + pub time: u32, |
| 99 | + /// The time received in seconds since epoch (Jan 1 1970 GMT). |
| 100 | + #[serde(rename = "timereceived")] |
| 101 | + pub time_received: u32, |
| 102 | + /// If a comment is associated with the transaction. |
| 103 | + pub comment: Option<String>, |
| 104 | + /// Whether this transaction could be replaced due to BIP125 (replace-by-fee); |
| 105 | + #[serde(rename = "bip125-replaceable")] |
| 106 | + pub bip125_replaceable: Bip125Replaceable, |
| 107 | + /// If the transaction has been abandoned (inputs are respendable). |
| 108 | + pub abandoned: Option<bool>, |
| 109 | +} |
| 110 | + |
| 111 | +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] |
| 112 | +#[serde(rename_all = "lowercase")] |
| 113 | +pub enum TransactionCategory { Send, Receive, Generate, Immature, Orphan, Move } |
| 114 | + |
| 115 | +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] |
| 116 | +#[serde(rename_all = "lowercase")] |
| 117 | +pub enum Bip125Replaceable { Yes, No, Unknown } |
| 118 | + |
| 119 | +// Ensure you have the top-level struct too |
| 120 | +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] |
| 121 | +pub struct ListTransactions(pub Vec<ListTransactionsItem>); |
0 commit comments