Skip to content

Commit ece2c61

Browse files
committed
Test and update listtransactions
The RPC was implemented for v17 and untested. The struct now uses the fixed `TransactionItem` struct and associated error and into functions. Update all the version types to use the fixed `TransactionItem`. Add a test and update the types tables.
1 parent cf7b28b commit ece2c61

File tree

22 files changed

+145
-37
lines changed

22 files changed

+145
-37
lines changed

integration_test/tests/wallet.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,24 @@ fn wallet__list_since_block__modelled() {
610610
assert_eq!(first_tx.txid.unwrap().to_string().len(), 64);
611611
}
612612

613+
#[test]
614+
fn wallet__list_transactions__modelled() {
615+
let node = Node::with_wallet(Wallet::Default, &[]);
616+
617+
node.fund_wallet();
618+
let addr = node.client.new_address().expect("newaddress");
619+
let amount = Amount::from_sat(5_000);
620+
node.client.send_to_address(&addr, amount).expect("sendtoaddress");
621+
node.mine_a_block();
622+
623+
let json: ListTransactions = node.client.list_transactions().expect("listtransactions");
624+
let model: Result<mtype::ListTransactions, TransactionItemError> = json.into_model();
625+
let model = model.unwrap();
626+
627+
let first_tx: mtype::TransactionItem = model.0[0].clone();
628+
assert_eq!(first_tx.txid.unwrap().to_string().len(), 64);
629+
}
630+
613631
#[test]
614632
fn wallet__import_multi() {
615633
let node = match () {

types/src/v17/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
//! | listreceivedbyaccount | returns nothing | |
187187
//! | listreceivedbyaddress | version + model | |
188188
//! | listsinceblock | version + model | |
189-
//! | listtransactions | version + model | UNTESTED |
189+
//! | listtransactions | version + model | |
190190
//! | listunspent | version + model | |
191191
//! | listwallets | version + model | |
192192
//! | loadwallet | version + model | |

types/src/v18/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
//! | listreceivedbyaddress | version + model | |
190190
//! | listreceivedbylabel | version + model | |
191191
//! | listsinceblock | version + model | |
192-
//! | listtransactions | version + model | UNTESTED |
192+
//! | listtransactions | version + model | |
193193
//! | listunspent | version + model | |
194194
//! | listwalletdir | version | |
195195
//! | listwallets | version + model | |

types/src/v19/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
//! | listreceivedbyaddress | version + model | |
191191
//! | listreceivedbylabel | version + model | |
192192
//! | listsinceblock | version + model | |
193-
//! | listtransactions | version + model | UNTESTED |
193+
//! | listtransactions | version + model | |
194194
//! | listunspent | version + model | |
195195
//! | listwalletdir | version | |
196196
//! | listwallets | version + model | |

types/src/v20/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
//! | listreceivedbyaddress | version + model | |
192192
//! | listreceivedbylabel | version + model | |
193193
//! | listsinceblock | version + model | |
194-
//! | listtransactions | version + model | UNTESTED |
194+
//! | listtransactions | version + model | |
195195
//! | listunspent | version + model | |
196196
//! | listwalletdir | version | |
197197
//! | listwallets | version + model | |
@@ -241,7 +241,7 @@ pub use self::{
241241
wallet::{
242242
AddMultisigAddress, GetAddressInfo, GetAddressInfoEmbedded, GetTransaction,
243243
GetTransactionDetail, ListSinceBlock, ListSinceBlockError, TransactionItem,
244-
TransactionItemError,
244+
TransactionItemError, ListTransactions,
245245
},
246246
};
247247
#[doc(inline)]
@@ -266,7 +266,7 @@ pub use crate::{
266266
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings,
267267
ListAddressGroupingsError, ListAddressGroupingsItem, ListLabels, ListLockUnspent,
268268
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddressError,
269-
ListTransactions, ListUnspentItemError,
269+
ListUnspentItemError,
270270
ListWallets, LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError,
271271
RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType, SendMany,
272272
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage,

types/src/v20/wallet/into.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{
1212
AddMultisigAddress, AddMultisigAddressError, GetAddressInfo, GetAddressInfoEmbedded,
1313
GetAddressInfoEmbeddedError, GetAddressInfoError, GetTransaction, GetTransactionDetail,
1414
GetTransactionDetailError, GetTransactionError, ListSinceBlock, ListSinceBlockError,
15-
TransactionItem, TransactionItemError,
15+
ListTransactions, TransactionItem, TransactionItemError,
1616
};
1717
use crate::model;
1818

@@ -332,3 +332,12 @@ impl TransactionItem {
332332
})
333333
}
334334
}
335+
336+
impl ListTransactions {
337+
/// Converts version specific type to a version nonspecific, more strongly typed type.
338+
pub fn into_model(self) -> Result<model::ListTransactions, TransactionItemError> {
339+
let transactions =
340+
self.0.into_iter().map(|tx| tx.into_model()).collect::<Result<Vec<_>, _>>()?;
341+
Ok(model::ListTransactions(transactions))
342+
}
343+
}

types/src/v20/wallet/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,16 @@ pub struct TransactionItem {
342342
/// If a comment to is associated with the transaction.
343343
pub to: Option<String>,
344344
}
345+
346+
/// Result of the JSON-RPC method `listtransactions`.
347+
///
348+
/// > listtransactions (label count skip include_watchonly)
349+
/// >
350+
/// > If a label name is provided, this will return only incoming transactions paying to addresses with the specified label.
351+
/// >
352+
/// > Returns up to 'count' most recent transactions skipping the first 'from' transactions.
353+
/// > Note that the "account" argument and "otheraccount" return value have been removed in V0.17. To use this RPC with an "account" argument, restart
354+
/// > bitcoind with -deprecatedrpc=accounts
355+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
356+
#[serde(deny_unknown_fields)]
357+
pub struct ListTransactions(pub Vec<TransactionItem>);

types/src/v21/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
//! | listreceivedbyaddress | version + model | |
196196
//! | listreceivedbylabel | version + model | |
197197
//! | listsinceblock | version + model | |
198-
//! | listtransactions | version + model | UNTESTED |
198+
//! | listtransactions | version + model | |
199199
//! | listunspent | version + model | |
200200
//! | listwalletdir | version | |
201201
//! | listwallets | version + model | |
@@ -282,7 +282,7 @@ pub use crate::{
282282
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings,
283283
ListAddressGroupingsError, ListAddressGroupingsItem, ListLabels, ListLockUnspent,
284284
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddressError,
285-
ListTransactions, ListUnspentItemError,
285+
ListUnspentItemError,
286286
ListWallets, LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError,
287287
RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType,
288288
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage,
@@ -308,6 +308,6 @@ pub use crate::{
308308
v20::{
309309
AddMultisigAddress, Banned, CreateMultisig, GenerateToDescriptor, GetAddressInfo,
310310
GetAddressInfoEmbedded, GetTransaction, GetTransactionDetail, ListBanned, ListSinceBlock,
311-
ListSinceBlockError, TransactionItem, TransactionItemError, Logging,
311+
ListSinceBlockError, TransactionItem, TransactionItemError, Logging, ListTransactions,
312312
},
313313
};

types/src/v22/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
//! | listreceivedbyaddress | version + model | |
206206
//! | listreceivedbylabel | version + model | |
207207
//! | listsinceblock | version + model | |
208-
//! | listtransactions | version + model | UNTESTED |
208+
//! | listtransactions | version + model | |
209209
//! | listunspent | version + model | |
210210
//! | listwalletdir | version | |
211211
//! | listwallets | version + model | |
@@ -283,7 +283,7 @@ pub use crate::{
283283
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
284284
GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
285285
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
286-
ListLockUnspentItemError, ListReceivedByAddressError, ListTransactions,
286+
ListLockUnspentItemError, ListReceivedByAddressError,
287287
ListUnspentItemError, ListWallets,
288288
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
289289
RawTransactionOutput, RescanBlockchain, ScriptType, SendRawTransaction, SendToAddress,
@@ -309,7 +309,7 @@ pub use crate::{
309309
v20::{
310310
AddMultisigAddress, CreateMultisig, GenerateToDescriptor, GetTransaction,
311311
GetTransactionDetail, ListSinceBlock, ListSinceBlockError, TransactionItem,
312-
TransactionItemError,
312+
TransactionItemError, ListTransactions,
313313
},
314314
v21::{
315315
AddPeerAddress, Bip9SoftforkInfo, GenerateBlock, GetBlockchainInfo, GetIndexInfo,

types/src/v23/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
//! | listreceivedbyaddress | version + model | |
198198
//! | listreceivedbylabel | version + model | |
199199
//! | listsinceblock | version + model | |
200-
//! | listtransactions | version + model | UNTESTED |
200+
//! | listtransactions | version + model | |
201201
//! | listunspent | version + model | |
202202
//! | listwalletdir | version | |
203203
//! | listwallets | version + model | |
@@ -261,7 +261,7 @@ pub use self::{
261261
wallet::{
262262
AddMultisigAddress, GetTransaction, GetTransactionError, GetWalletInfo,
263263
GetWalletInfoScanning, ListSinceBlock, ListSinceBlockError, TransactionItem,
264-
TransactionItemError, RestoreWallet,
264+
TransactionItemError, RestoreWallet, ListTransactions,
265265
},
266266
};
267267
#[doc(inline)]
@@ -285,7 +285,7 @@ pub use crate::{
285285
GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance,
286286
GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
287287
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
288-
ListLockUnspentItemError, ListReceivedByAddressError, ListTransactions,
288+
ListLockUnspentItemError, ListReceivedByAddressError,
289289
ListUnspentItemError, ListWallets,
290290
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
291291
RawTransactionOutput, RescanBlockchain, ScriptType, SendRawTransaction, SendToAddress,

0 commit comments

Comments
 (0)