Skip to content

Commit 9740fae

Browse files
committed
Merge #338: Test listreceivedbyaddress
f7f4f21 Run the formatter (Jamil Lambert, PhD) 3f03266 Test listreceivedbyaddress (Jamil Lambert, PhD) Pull request description: The RPC was untested and missing a change in the return type in v18. `involves_watch_only` is always optional, the v17-v23 help says "only returned...", from v24 it specifically says optional. - Update the struct in v18, make the field an Option and add a test. - Run the formatter. ACKs for top commit: tcharding: ACK f7f4f21 Tree-SHA512: b06cbddb45877cbd55f5a84347d4d80a115b0ad6611e6a1149dbad13288f0fa09cc964080fb21c6d66aa04c7dabfcc54b19c09416c616ddd21326c515efd2de2
2 parents 6fe8902 + f7f4f21 commit 9740fae

File tree

18 files changed

+261
-167
lines changed

18 files changed

+261
-167
lines changed

integration_test/tests/wallet.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,23 @@ fn wallet__list_received_by_label__modelled() {
548548
assert!(model.0.iter().any(|item| item.label == label));
549549
}
550550

551+
#[test]
552+
fn wallet__list_received_by_address__modelled() {
553+
let node = Node::with_wallet(Wallet::Default, &[]);
554+
node.fund_wallet();
555+
let address = node.client.new_address().expect("failed to create new address");
556+
let amount = Amount::from_sat(10_000);
557+
let _ = node.client.send_to_address(&address, amount).expect("sendtoaddress");
558+
node.mine_a_block();
559+
560+
let json: ListReceivedByAddress = node.client.list_received_by_address().expect("listreceivedbyaddress");
561+
let model: Result<mtype::ListReceivedByAddress, _> = json.into_model();
562+
let model = model.unwrap();
563+
564+
let unchecked_addr = address.as_unchecked();
565+
assert!(model.0.iter().any(|item| &item.address == unchecked_addr));
566+
}
567+
551568
#[test]
552569
fn wallet__import_multi() {
553570
let node = match () {

types/src/model/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ pub struct ListReceivedByAddress(pub Vec<ListReceivedByAddressItem>);
524524
#[serde(deny_unknown_fields)]
525525
pub struct ListReceivedByAddressItem {
526526
/// Only returned if imported addresses were involved in transaction.
527-
pub involves_watch_only: bool,
527+
pub involves_watch_only: Option<bool>,
528528
/// The receiving address.
529529
pub address: Address<NetworkUnchecked>,
530530
/// The total amount received by the address.

types/src/v17/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
//! | listlabels | version | |
185185
//! | listlockunspent | version + model | UNTESTED |
186186
//! | listreceivedbyaccount | returns nothing | |
187-
//! | listreceivedbyaddress | version + model | UNTESTED |
187+
//! | listreceivedbyaddress | version + model | |
188188
//! | listsinceblock | version + model | UNTESTED |
189189
//! | listtransactions | version + model | UNTESTED |
190190
//! | listunspent | version + model | |

types/src/v17/wallet/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ pub struct ListReceivedByAddress(pub Vec<ListReceivedByAddressItem>);
669669
pub struct ListReceivedByAddressItem {
670670
/// Only returned if imported addresses were involved in transaction.
671671
#[serde(rename = "involvesWatchonly")]
672-
pub involves_watch_only: bool,
672+
pub involves_watch_only: Option<bool>,
673673
/// The receiving address.
674674
pub address: String,
675675
/// DEPRECATED. Backwards compatible alias for label.

types/src/v18/mod.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
//! | listaddressgroupings | version + model | UNTESTED |
187187
//! | listlabels | version | |
188188
//! | listlockunspent | version + model | UNTESTED |
189-
//! | listreceivedbyaddress | version + model | UNTESTED |
189+
//! | listreceivedbyaddress | version + model | |
190190
//! | listreceivedbylabel | version + model | |
191191
//! | listsinceblock | version + model | UNTESTED |
192192
//! | listtransactions | version + model | UNTESTED |
@@ -245,8 +245,9 @@ pub use self::{
245245
util::{DeriveAddresses, GetDescriptorInfo},
246246
wallet::{
247247
GetAddressInfo, GetAddressInfoEmbedded, GetAddressInfoError, GetReceivedByLabel,
248-
ImportMulti, ImportMultiEntry, JsonRpcError, ListReceivedByLabel, ListReceivedByLabelError,
249-
ListUnspent, ListUnspentItem, ListWalletDir, ListWalletDirWallet,
248+
ImportMulti, ImportMultiEntry, JsonRpcError, ListReceivedByAddress,
249+
ListReceivedByAddressItem, ListReceivedByLabel, ListReceivedByLabelError, ListUnspent,
250+
ListUnspentItem, ListWalletDir, ListWalletDirWallet,
250251
},
251252
};
252253
#[doc(inline)]
@@ -272,16 +273,16 @@ pub use crate::v17::{
272273
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError,
273274
GetZmqNotifications, ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem,
274275
ListBanned, ListLabels, ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError,
275-
ListReceivedByAddress, ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock,
276-
ListSinceBlockError, ListSinceBlockTransaction, ListSinceBlockTransactionError,
277-
ListTransactions, ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError,
278-
ListWallets, LoadWallet, LockUnspent, Locked, Logging, MapMempoolEntryError, MempoolAcceptance,
279-
MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PruneBlockchain, PsbtInput,
280-
PsbtOutput, PsbtScript, RawTransaction, RawTransactionError, RawTransactionInput,
281-
RawTransactionOutput, RescanBlockchain, ScriptType, SendMany, SendRawTransaction,
282-
SendToAddress, SetNetworkActive, SetTxFee, SignFail, SignFailError, SignMessage,
283-
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, Softfork, SoftforkReject,
284-
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError,
285-
VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
286-
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
276+
ListReceivedByAddressError, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
277+
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
278+
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked,
279+
Logging, MapMempoolEntryError, MempoolAcceptance, MempoolEntryError, MempoolEntryFees,
280+
MempoolEntryFeesError, PruneBlockchain, PsbtInput, PsbtOutput, PsbtScript, RawTransaction,
281+
RawTransactionError, RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType,
282+
SendMany, SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignFail,
283+
SignFailError, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
284+
SignRawTransactionError, Softfork, SoftforkReject, TestMempoolAccept, TransactionCategory,
285+
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
286+
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
287+
WitnessUtxo,
287288
};

types/src/v18/wallet/into.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use bitcoin::{
1010

1111
use super::{
1212
GetAddressInfo, GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
13-
GetReceivedByLabel, ListReceivedByLabel, ListReceivedByLabelError, ListReceivedByLabelItem,
14-
ListUnspent, ListUnspentItem, ListUnspentItemError,
13+
GetReceivedByLabel, ListReceivedByAddress, ListReceivedByAddressError,
14+
ListReceivedByAddressItem, ListReceivedByLabel, ListReceivedByLabelError,
15+
ListReceivedByLabelItem, ListUnspent, ListUnspentItem, ListUnspentItemError,
1516
};
1617
use crate::model;
1718

@@ -165,6 +166,47 @@ impl GetReceivedByLabel {
165166
}
166167
}
167168

169+
impl ListReceivedByAddress {
170+
/// Converts version specific type to a version nonspecific, more strongly typed type.
171+
pub fn into_model(self) -> Result<model::ListReceivedByAddress, ListReceivedByAddressError> {
172+
let balances = self
173+
.0
174+
.into_iter()
175+
.map(|balance| balance.into_model())
176+
.collect::<Result<Vec<_>, _>>()?;
177+
Ok(model::ListReceivedByAddress(balances))
178+
}
179+
}
180+
181+
impl ListReceivedByAddressItem {
182+
/// Converts version specific type to a version nonspecific, more strongly typed type.
183+
pub fn into_model(
184+
self,
185+
) -> Result<model::ListReceivedByAddressItem, ListReceivedByAddressError> {
186+
use ListReceivedByAddressError as E;
187+
188+
let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
189+
let amount = Amount::from_btc(self.amount).map_err(E::Amount)?;
190+
let txids = self
191+
.txids
192+
.iter()
193+
.enumerate()
194+
.map(|(i, txid)| {
195+
txid.parse::<Txid>().map_err(|e| ListReceivedByAddressError::Txids(i, e))
196+
})
197+
.collect::<Result<Vec<_>, _>>()?;
198+
199+
Ok(model::ListReceivedByAddressItem {
200+
involves_watch_only: self.involves_watch_only,
201+
address,
202+
amount,
203+
confirmations: self.confirmations,
204+
label: self.label,
205+
txids,
206+
})
207+
}
208+
}
209+
168210
impl ListReceivedByLabel {
169211
/// Converts version specific type to a version nonspecific, more strongly typed type.
170212
pub fn into_model(self) -> Result<model::ListReceivedByLabel, ListReceivedByLabelError> {

types/src/v18/wallet/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use serde::{Deserialize, Serialize};
1111

1212
pub use self::error::{GetAddressInfoError, ListReceivedByLabelError};
1313
pub use super::{
14-
GetAddressInfoEmbeddedError, GetAddressInfoLabel, ListUnspentItemError, ScriptType,
14+
GetAddressInfoEmbeddedError, GetAddressInfoLabel, ListReceivedByAddressError,
15+
ListUnspentItemError, ScriptType,
1516
};
1617

1718
/// Result of the JSON-RPC method `getaddressinfo`.
@@ -190,6 +191,34 @@ pub struct JsonRpcError {
190191
pub data: Option<serde_json::Value>, // Can hold arbitrary extra information
191192
}
192193

194+
/// Result of the JSON-RPC method `listreceivedbyaddress`.
195+
///
196+
/// > listreceivedbyaddress ( minconf include_empty include_watchonly address_filter )
197+
/// >
198+
/// > List balances by receiving address.
199+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
200+
#[serde(deny_unknown_fields)]
201+
pub struct ListReceivedByAddress(pub Vec<ListReceivedByAddressItem>);
202+
203+
/// List item returned as part of of `listreceivedByaddress`.
204+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
205+
#[serde(deny_unknown_fields)]
206+
pub struct ListReceivedByAddressItem {
207+
/// Only returned if imported addresses were involved in transaction.
208+
#[serde(rename = "involvesWatchonly")]
209+
pub involves_watch_only: Option<bool>,
210+
/// The receiving address.
211+
pub address: String,
212+
/// The total amount in BTC received by the address.
213+
pub amount: f64,
214+
/// The number of confirmations of the most recent transaction included.
215+
pub confirmations: i64,
216+
/// The label of the receiving address. The default label is "".
217+
pub label: String,
218+
/// The ids of transactions received with the address.
219+
pub txids: Vec<String>,
220+
}
221+
193222
/// Result of the JSON-RPC method `listreceivedbylabel`.
194223
///
195224
/// > listreceivedbylabel ( minconf include_empty include_watchonly )

types/src/v19/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
//! | listaddressgroupings | version + model | UNTESTED |
188188
//! | listlabels | version | |
189189
//! | listlockunspent | version + model | UNTESTED |
190-
//! | listreceivedbyaddress | version + model | UNTESTED |
190+
//! | listreceivedbyaddress | version + model | |
191191
//! | listreceivedbylabel | version + model | |
192192
//! | listsinceblock | version + model | UNTESTED |
193193
//! | listtransactions | version + model | UNTESTED |
@@ -271,22 +271,22 @@ pub use crate::v17::{
271271
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError,
272272
GetZmqNotifications, ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem,
273273
ListBanned, ListLabels, ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError,
274-
ListReceivedByAddress, ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock,
275-
ListSinceBlockError, ListSinceBlockTransaction, ListSinceBlockTransactionError,
276-
ListTransactions, ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError,
277-
ListWallets, LoadWallet, LockUnspent, Locked, Logging, PruneBlockchain, RawTransactionError,
278-
RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType, SendMany,
279-
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage,
280-
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SoftforkReject,
281-
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError,
282-
VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
274+
ListReceivedByAddressError, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
275+
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
276+
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked,
277+
Logging, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
278+
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
279+
SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
280+
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
281+
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
283282
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
284283
};
285284
#[doc(inline)]
286285
pub use crate::v18::{
287286
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
288287
AnalyzePsbtInputMissingError, DeriveAddresses, GetAddressInfo, GetAddressInfoEmbedded,
289288
GetAddressInfoError, GetNodeAddresses, GetReceivedByLabel, ImportMulti, ImportMultiEntry,
290-
JoinPsbts, JsonRpcError, ListReceivedByLabel, ListReceivedByLabelError, ListUnspent,
291-
ListUnspentItem, ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
289+
JoinPsbts, JsonRpcError, ListReceivedByAddress, ListReceivedByAddressItem, ListReceivedByLabel,
290+
ListReceivedByLabelError, ListUnspent, ListUnspentItem, ListWalletDir, ListWalletDirWallet,
291+
NodeAddress, UtxoUpdatePsbt,
292292
};

types/src/v20/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
//! | listaddressgroupings | version + model | UNTESTED |
189189
//! | listlabels | version | |
190190
//! | listlockunspent | version + model | UNTESTED |
191-
//! | listreceivedbyaddress | version + model | UNTESTED |
191+
//! | listreceivedbyaddress | version + model | |
192192
//! | listreceivedbylabel | version + model | |
193193
//! | listsinceblock | version + model | UNTESTED |
194194
//! | listtransactions | version + model | UNTESTED |
@@ -265,24 +265,24 @@ pub use crate::{
265265
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError,
266266
GetZmqNotifications, ListAddressGroupings, ListAddressGroupingsError,
267267
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
268-
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
269-
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
270-
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
271-
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
272-
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
273-
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress,
274-
SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
275-
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
276-
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
277-
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
278-
WitnessUtxo,
268+
ListLockUnspentItemError, ListReceivedByAddressError, ListSinceBlock, ListSinceBlockError,
269+
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
270+
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
271+
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
272+
RawTransactionOutput, RescanBlockchain, ScriptType, SendMany, SendRawTransaction,
273+
SendToAddress, SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey,
274+
SignRawTransaction, SignRawTransactionError, SoftforkReject, TestMempoolAccept,
275+
TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain,
276+
VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,
277+
WalletProcessPsbt, WitnessUtxo,
279278
},
280279
v18::{
281280
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
282281
AnalyzePsbtInputMissingError, DeriveAddresses, GetAddressInfoError, GetNodeAddresses,
283282
GetReceivedByLabel, ImportMulti, ImportMultiEntry, JoinPsbts, JsonRpcError,
284-
ListReceivedByLabel, ListReceivedByLabelError, ListUnspent, ListUnspentItem, ListWalletDir,
285-
ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
283+
ListReceivedByAddress, ListReceivedByAddressItem, ListReceivedByLabel,
284+
ListReceivedByLabelError, ListUnspent, ListUnspentItem, ListWalletDir, ListWalletDirWallet,
285+
NodeAddress, UtxoUpdatePsbt,
286286
},
287287
v19::{
288288
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances,

0 commit comments

Comments
 (0)