Skip to content

Commit ff63089

Browse files
committed
Add missing fields to listunspent
There are missing return fields in v24 `listunspent`. Redefine the type for v24 with the missing fields. Update the model and into functions.
1 parent 0307e86 commit ff63089

File tree

11 files changed

+118
-14
lines changed

11 files changed

+118
-14
lines changed

types/src/model/wallet.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ pub struct ListUnspentItem {
654654
/// and unconfirmed replacement transactions are considered unsafe and are not eligible for
655655
/// spending by fundrawtransaction and sendtoaddress.
656656
pub safe: bool,
657+
/// List of parent descriptors for the scriptPubKey of this coin. v24 and later only.
658+
#[serde(rename = "parent_descs")]
659+
pub parent_descriptors: Option<Vec<String>>,
657660
}
658661

659662
/// Models the result of JSON-RPC method `listwallets`.

types/src/v17/wallet/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ impl ListUnspentItem {
684684
solvable: self.solvable,
685685
descriptor: None,
686686
safe: self.safe,
687+
parent_descriptors: None, // v24 and later only.
687688
})
688689
}
689690
}

types/src/v18/wallet/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl ListUnspentItem {
8585
solvable: self.solvable,
8686
descriptor: self.descriptor,
8787
safe: self.safe,
88+
parent_descriptors: None, // v24 and later only.
8889
})
8990
}
9091
}

types/src/v24/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub use self::{
253253
DecodePsbt, DecodePsbtError, GlobalXpub, Proprietary, PsbtInput, PsbtOutput,
254254
TaprootBip32Deriv, TaprootLeaf, TaprootScript, TaprootScriptPathSig,
255255
},
256-
wallet::{GetTransaction, GetTransactionError, GetTransactionDetail},
256+
wallet::{GetTransaction, GetTransactionError, GetTransactionDetail, ListUnspent, ListUnspentItem},
257257
};
258258
#[doc(inline)]
259259
pub use crate::{
@@ -292,7 +292,7 @@ pub use crate::{
292292
v18::{
293293
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
294294
AnalyzePsbtInputMissingError, DeriveAddresses, GetNodeAddresses, GetReceivedByLabel,
295-
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError, ListUnspent, ListUnspentItem,
295+
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError,
296296
ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
297297
},
298298
v19::{

types/src/v24/wallet/into.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// SPDX-License-Identifier: CC0-1.0
22

33
use bitcoin::consensus::encode;
4-
use bitcoin::{Address, BlockHash, SignedAmount, Transaction, Txid};
4+
use bitcoin::{Address, BlockHash, ScriptBuf, SignedAmount, Transaction, Txid};
55

6-
use super::{GetTransaction, GetTransactionDetail, GetTransactionDetailError, GetTransactionError};
6+
use super::{
7+
GetTransaction, GetTransactionDetail, GetTransactionDetailError, GetTransactionError,
8+
ListUnspent, ListUnspentItem, ListUnspentItemError,
9+
};
710
use crate::model;
811

912
impl GetTransaction {
@@ -92,3 +95,49 @@ impl GetTransactionDetail {
9295
})
9396
}
9497
}
98+
99+
impl ListUnspent {
100+
/// Converts version specific type to a version nonspecific, more strongly typed type.
101+
pub fn into_model(self) -> Result<model::ListUnspent, ListUnspentItemError> {
102+
self.0
103+
.into_iter()
104+
.map(|item| item.into_model())
105+
.collect::<Result<Vec<_>, _>>()
106+
.map(model::ListUnspent)
107+
}
108+
}
109+
110+
impl ListUnspentItem {
111+
/// Converts version specific type to a version nonspecific, more strongly typed type.
112+
pub fn into_model(self) -> Result<model::ListUnspentItem, ListUnspentItemError> {
113+
use ListUnspentItemError as E;
114+
115+
let txid = self.txid.parse::<Txid>().map_err(E::Txid)?;
116+
let vout = crate::to_u32(self.vout, "vout")?;
117+
let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
118+
let script_pubkey = ScriptBuf::from_hex(&self.script_pubkey).map_err(E::ScriptPubkey)?;
119+
120+
let amount = SignedAmount::from_btc(self.amount).map_err(E::Amount)?;
121+
let confirmations = crate::to_u32(self.confirmations, "confirmations")?;
122+
let redeem_script = self
123+
.redeem_script
124+
.map(|hex| ScriptBuf::from_hex(&hex).map_err(E::RedeemScript))
125+
.transpose()?;
126+
127+
Ok(model::ListUnspentItem {
128+
txid,
129+
vout,
130+
address,
131+
label: self.label,
132+
script_pubkey,
133+
amount,
134+
confirmations,
135+
redeem_script,
136+
spendable: self.spendable,
137+
solvable: self.solvable,
138+
descriptor: self.descriptor,
139+
safe: self.safe,
140+
parent_descriptors: self.parent_descriptors,
141+
})
142+
}
143+
}

types/src/v24/wallet/mod.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use bitcoin::Transaction;
1111
use serde::{Deserialize, Serialize};
1212

1313
pub use self::error::GetTransactionError;
14-
pub use super::{Bip125Replaceable, GetTransactionDetailError, TransactionCategory};
14+
pub use super::{
15+
Bip125Replaceable, GetTransactionDetailError, ListUnspentItemError, TransactionCategory,
16+
};
1517

1618
/// Result of the JSON-RPC method `gettransaction`.
1719
///
@@ -113,3 +115,50 @@ pub struct GetTransactionDetail {
113115
#[serde(rename = "parent_descs")]
114116
pub parent_descriptors: Option<Vec<String>>,
115117
}
118+
119+
/// Result of the JSON-RPC method `listunspent`.
120+
///
121+
/// > listunspent ( minconf maxconf ["addresses",...] `[include_unsafe]` `[query_options]`)
122+
/// >
123+
/// > Returns array of unspent transaction outputs
124+
/// > with between minconf and maxconf (inclusive) confirmations.
125+
/// > Optionally filter to only include txouts paid to specified addresses.
126+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
127+
pub struct ListUnspent(pub Vec<ListUnspentItem>);
128+
129+
/// Unspent transaction output, returned as part of `listunspent`.
130+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
131+
pub struct ListUnspentItem {
132+
/// The transaction id.
133+
pub txid: String,
134+
/// The vout value.
135+
pub vout: i64,
136+
/// The bitcoin address of the transaction.
137+
pub address: String,
138+
/// The associated label, or "" for the default label.
139+
pub label: String,
140+
/// The script key.
141+
#[serde(rename = "scriptPubKey")]
142+
pub script_pubkey: String,
143+
/// The transaction amount in BTC.
144+
pub amount: f64,
145+
/// The number of confirmations.
146+
pub confirmations: i64,
147+
/// The redeemScript if scriptPubKey is P2SH.
148+
#[serde(rename = "redeemScript")]
149+
pub redeem_script: Option<String>,
150+
/// Whether we have the private keys to spend this output.
151+
pub spendable: bool,
152+
/// Whether we know how to spend this output, ignoring the lack of keys.
153+
pub solvable: bool,
154+
/// A descriptor for spending this output (only when solvable)
155+
#[serde(rename = "desc")]
156+
pub descriptor: Option<String>,
157+
/// Whether this output is considered safe to spend. Unconfirmed transactions from outside keys
158+
/// and unconfirmed replacement transactions are considered unsafe and are not eligible for
159+
/// spending by fundrawtransaction and sendtoaddress.
160+
pub safe: bool,
161+
/// List of parent descriptors for the scriptPubKey of this coin. v24 and later only.
162+
#[serde(rename = "parent_descs")]
163+
pub parent_descriptors: Option<Vec<String>>,
164+
}

types/src/v25/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub use crate::{
287287
v18::{
288288
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
289289
AnalyzePsbtInputMissingError, DeriveAddresses, GetNodeAddresses, GetReceivedByLabel,
290-
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError, ListUnspent, ListUnspentItem,
290+
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError,
291291
ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
292292
},
293293
v19::{
@@ -305,5 +305,6 @@ pub use crate::{
305305
DecodePsbt, DecodePsbtError, GetMempoolEntry, GetMempoolInfo, GetPeerInfo, GlobalXpub,
306306
Proprietary, PsbtInput, PsbtOutput, TaprootBip32Deriv, TaprootLeaf, TaprootScript,
307307
TaprootScriptPathSig, GetTransaction, GetTransactionError, GetTransactionDetail,
308+
ListUnspent, ListUnspentItem,
308309
},
309310
};

types/src/v26/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub use crate::{
304304
v18::{
305305
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
306306
AnalyzePsbtInputMissingError, DeriveAddresses, GetNodeAddresses, GetReceivedByLabel,
307-
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError, ListUnspent, ListUnspentItem,
307+
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError,
308308
ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
309309
},
310310
v19::{
@@ -321,7 +321,7 @@ pub use crate::{
321321
v24::{
322322
DecodePsbt, DecodePsbtError, GetMempoolEntry, GetMempoolInfo, GlobalXpub, Proprietary,
323323
PsbtInput, PsbtOutput, TaprootBip32Deriv, TaprootLeaf, TaprootScript, TaprootScriptPathSig,
324-
GetTransactionDetail,
324+
GetTransactionDetail, ListUnspent, ListUnspentItem,
325325
},
326326
v25::GetBlockStats,
327327
};

types/src/v27/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ pub use crate::{
284284
v18::{
285285
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
286286
AnalyzePsbtInputMissingError, DeriveAddresses, GetNodeAddresses, GetReceivedByLabel,
287-
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError, ListUnspent, ListUnspentItem,
287+
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError,
288288
ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
289289
},
290290
v19::{
@@ -301,7 +301,7 @@ pub use crate::{
301301
v24::{
302302
DecodePsbt, DecodePsbtError, GetMempoolEntry, GetMempoolInfo, GlobalXpub, Proprietary,
303303
PsbtInput, PsbtOutput, TaprootBip32Deriv, TaprootLeaf, TaprootScript, TaprootScriptPathSig,
304-
GetTransactionDetail,
304+
GetTransactionDetail, ListUnspent, ListUnspentItem,
305305
},
306306
v25::GetBlockStats,
307307
v26::{

types/src/v28/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub use crate::{
305305
v18::{
306306
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
307307
AnalyzePsbtInputMissingError, DeriveAddresses, GetNodeAddresses, GetReceivedByLabel,
308-
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError, ListUnspent, ListUnspentItem,
308+
JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError,
309309
ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
310310
},
311311
v19::{
@@ -321,7 +321,7 @@ pub use crate::{
321321
v24::{
322322
DecodePsbt, DecodePsbtError, GetMempoolEntry, GetMempoolInfo, GlobalXpub, Proprietary,
323323
PsbtInput, PsbtOutput, TaprootBip32Deriv, TaprootLeaf, TaprootScript, TaprootScriptPathSig,
324-
GetTransactionDetail,
324+
GetTransactionDetail, ListUnspent, ListUnspentItem,
325325
},
326326
v25::GetBlockStats,
327327
v26::{

0 commit comments

Comments
 (0)