Skip to content

Commit f77ad1f

Browse files
committed
fix!: Box large enum variants
1 parent 417f519 commit f77ad1f

File tree

8 files changed

+207
-189
lines changed

8 files changed

+207
-189
lines changed

src/keyring/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::boxed::Box;
12
use core::fmt;
23

34
use miniscript::{Descriptor, DescriptorPublicKey};
@@ -10,7 +11,7 @@ pub enum KeyRingError<K> {
1011
/// The keychain exists in the [`KeyRing`] but mapped to a different descriptor
1112
KeychainAlreadyExists(K),
1213
/// The descriptor exists in the [`KeyRing`] but mapped to a different keychain
13-
DescAlreadyExists(Descriptor<DescriptorPublicKey>),
14+
DescAlreadyExists(Box<Descriptor<DescriptorPublicKey>>),
1415
/// No descriptor was provided
1516
DescMissing,
1617
}

src/keyring/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::chain::{DescriptorExt, Merge};
2626
use crate::descriptor::check_wallet_descriptor;
2727
use crate::descriptor::IntoWalletDescriptor;
2828
use crate::wallet::{DescriptorToExtract, LoadError};
29+
use alloc::boxed::Box;
2930
use alloc::collections::BTreeMap;
3031
use bitcoin::secp256k1::{All, Secp256k1};
3132
use bitcoin::Network;
@@ -124,7 +125,7 @@ where
124125
// if the descriptor or keychain already exist
125126
for (keychain_old, desc) in self.descriptors.iter() {
126127
if (desc == &descriptor) && (keychain_old != &keychain) {
127-
return Err(KeyRingError::DescAlreadyExists(desc.clone()));
128+
return Err(KeyRingError::DescAlreadyExists(Box::new(desc.clone())));
128129
}
129130
if (keychain_old == &keychain) && (desc != &descriptor) {
130131
return Err(KeyRingError::KeychainAlreadyExists(keychain));
@@ -214,8 +215,8 @@ where
214215
if exp_desc.descriptor_id() != loaded_desc.descriptor_id() {
215216
Err(LoadError::DescriptorMismatch {
216217
keychain,
217-
loaded: loaded_desc.clone(),
218-
expected: exp_desc,
218+
loaded: Box::new(loaded_desc.clone()),
219+
expected: Box::new(exp_desc),
219220
})?
220221
}
221222
}

src/persist_test_utils.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use crate::{
99
keychain_txout::{self},
1010
local_chain, tx_graph, ConfirmationBlockTime, DescriptorExt, Merge, SpkIterator,
1111
},
12-
locked_outpoints,
13-
keyring,
12+
keyring, locked_outpoints,
1413
miniscript::descriptor::{Descriptor, DescriptorPublicKey},
1514
ChangeSet, KeychainKind, WalletPersister,
1615
};
@@ -119,34 +118,32 @@ pub fn persist_wallet_changeset<Store, CreateStore, K>(
119118
confirmation_time: 1755317160,
120119
};
121120

121+
let outpoint = OutPoint::new(hash!("Rust"), 0);
122122

123-
let outpoint = OutPoint::new(hash!("Rust"), 0);
124-
125-
let tx_graph_changeset = tx_graph::ChangeSet::<ConfirmationBlockTime> {
126-
txs: [tx1.clone()].into(),
127-
txouts: [
128-
(
129-
outpoint,
130-
TxOut {
131-
value: Amount::from_sat(1300),
132-
script_pubkey: spk_at_index(&descriptor, 4),
133-
},
134-
),
135-
(
136-
OutPoint::new(hash!("REDB"), 0),
137-
TxOut {
138-
value: Amount::from_sat(1400),
139-
script_pubkey: spk_at_index(&descriptor, 10),
140-
},
141-
),
142-
]
143-
.into(),
144-
anchors: [(conf_anchor, tx1.compute_txid())].into(),
145-
last_seen: [(tx1.compute_txid(), 1755317760)].into(),
146-
first_seen: [(tx1.compute_txid(), 1755317750)].into(),
147-
last_evicted: [(tx1.compute_txid(), 1755317760)].into(),
148-
};
149-
123+
let tx_graph_changeset = tx_graph::ChangeSet::<ConfirmationBlockTime> {
124+
txs: [tx1.clone()].into(),
125+
txouts: [
126+
(
127+
outpoint,
128+
TxOut {
129+
value: Amount::from_sat(1300),
130+
script_pubkey: spk_at_index(&descriptor, 4),
131+
},
132+
),
133+
(
134+
OutPoint::new(hash!("REDB"), 0),
135+
TxOut {
136+
value: Amount::from_sat(1400),
137+
script_pubkey: spk_at_index(&descriptor, 10),
138+
},
139+
),
140+
]
141+
.into(),
142+
anchors: [(conf_anchor, tx1.compute_txid())].into(),
143+
last_seen: [(tx1.compute_txid(), 1755317760)].into(),
144+
first_seen: [(tx1.compute_txid(), 1755317750)].into(),
145+
last_evicted: [(tx1.compute_txid(), 1755317760)].into(),
146+
};
150147

151148
let keychain_txout_changeset = keychain_txout::ChangeSet {
152149
last_revealed: [(descriptor.descriptor_id(), 12)].into(),
@@ -157,9 +154,9 @@ let tx_graph_changeset = tx_graph::ChangeSet::<ConfirmationBlockTime> {
157154
.into(),
158155
};
159156

160-
let locked_outpoints_changeset = locked_outpoints::ChangeSet {
161-
outpoints: [(outpoint, true)].into(),
162-
};
157+
let locked_outpoints_changeset = locked_outpoints::ChangeSet {
158+
outpoints: [(outpoint, true)].into(),
159+
};
163160
let keyring_changeset = crate::keyring::ChangeSet {
164161
network: Some(Network::Testnet),
165162
descriptors: [(keychain.clone(), descriptor.clone())].into(),
@@ -187,7 +184,6 @@ let locked_outpoints_changeset = locked_outpoints::ChangeSet {
187184
blocks: [(910236, Some(hash!("BDK")))].into(),
188185
};
189186

190-
191187
let conf_anchor: ConfirmationBlockTime = ConfirmationBlockTime {
192188
block_id: block_id!(910236, "BDK"),
193189
confirmation_time: 1755317760,
@@ -211,10 +207,9 @@ let locked_outpoints_changeset = locked_outpoints::ChangeSet {
211207
last_evicted: [(tx2.compute_txid(), 1755317760)].into(),
212208
};
213209

214-
215-
let locked_outpoints_changeset = locked_outpoints::ChangeSet {
216-
outpoints: [(outpoint, true)].into(),
217-
};
210+
let locked_outpoints_changeset = locked_outpoints::ChangeSet {
211+
outpoints: [(outpoint, true)].into(),
212+
};
218213
let keychain_txout_changeset = keychain_txout::ChangeSet {
219214
last_revealed: [(descriptor.descriptor_id(), 14)].into(),
220215
spk_cache: [(

src/test_utils.rs

Lines changed: 84 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -251,63 +251,76 @@ impl From<ConfirmationBlockTime> for ReceiveTo {
251251
}
252252
}
253253

254-
/// Receive a tx output with the given value in the latest block
255-
pub fn receive_output_in_latest_block<K>(wallet: &mut Wallet<K>, value: Amount, keychain: K) -> OutPoint
256-
where K: Ord + Clone + fmt::Debug {
257-
let latest_cp = wallet.latest_checkpoint();
258-
let height = latest_cp.height();
259-
assert!(height > 0, "cannot receive tx into genesis block");
260-
receive_output(
261-
wallet,
262-
value,
263-
ConfirmationBlockTime {
264-
block_id: latest_cp.block_id(),
265-
confirmation_time: 0,
266-
},
267-
keychain,
268-
)
269-
}
270-
271-
/// Receive a tx output with the given value and chain position
272-
pub fn receive_output<K>(
273-
wallet: &mut Wallet<K>,
274-
value: Amount,
275-
receive_to: impl Into<ReceiveTo>,
276-
keychain: K,
277-
) -> OutPoint
278-
where K: Ord + Clone + fmt::Debug {
279-
let addr = wallet.next_unused_address(keychain).expect("keychain should exist").address;
280-
receive_output_to_address(wallet, addr, value, receive_to)
281-
}
282-
283-
/// Receive a tx output to an address with the given value and chain position
284-
pub fn receive_output_to_address<K>(
285-
wallet: &mut Wallet<K>,
286-
addr: Address,
287-
value: Amount,
288-
receive_to: impl Into<ReceiveTo>,
289-
) -> OutPoint
290-
where K: Ord + Clone + fmt::Debug {
291-
let tx = Transaction {
292-
version: transaction::Version::ONE,
293-
lock_time: absolute::LockTime::ZERO,
294-
input: vec![],
295-
output: vec![TxOut {
296-
script_pubkey: addr.script_pubkey(),
297-
value,
298-
}],
299-
};
300-
301-
let txid = tx.compute_txid();
302-
insert_tx(wallet, tx);
303-
304-
match receive_to.into() {
305-
ReceiveTo::Block(anchor) => insert_anchor(wallet, txid, anchor),
306-
ReceiveTo::Mempool(last_seen) => insert_seen_at(wallet, txid, last_seen),
307-
}
308-
309-
OutPoint { txid, vout: 0 }
310-
}
254+
/// Receive a tx output with the given value in the latest block
255+
pub fn receive_output_in_latest_block<K>(
256+
wallet: &mut Wallet<K>,
257+
value: Amount,
258+
keychain: K,
259+
) -> OutPoint
260+
where
261+
K: Ord + Clone + fmt::Debug,
262+
{
263+
let latest_cp = wallet.latest_checkpoint();
264+
let height = latest_cp.height();
265+
assert!(height > 0, "cannot receive tx into genesis block");
266+
receive_output(
267+
wallet,
268+
value,
269+
ConfirmationBlockTime {
270+
block_id: latest_cp.block_id(),
271+
confirmation_time: 0,
272+
},
273+
keychain,
274+
)
275+
}
276+
277+
/// Receive a tx output with the given value and chain position
278+
pub fn receive_output<K>(
279+
wallet: &mut Wallet<K>,
280+
value: Amount,
281+
receive_to: impl Into<ReceiveTo>,
282+
keychain: K,
283+
) -> OutPoint
284+
where
285+
K: Ord + Clone + fmt::Debug,
286+
{
287+
let addr = wallet
288+
.next_unused_address(keychain)
289+
.expect("keychain should exist")
290+
.address;
291+
receive_output_to_address(wallet, addr, value, receive_to)
292+
}
293+
294+
/// Receive a tx output to an address with the given value and chain position
295+
pub fn receive_output_to_address<K>(
296+
wallet: &mut Wallet<K>,
297+
addr: Address,
298+
value: Amount,
299+
receive_to: impl Into<ReceiveTo>,
300+
) -> OutPoint
301+
where
302+
K: Ord + Clone + fmt::Debug,
303+
{
304+
let tx = Transaction {
305+
version: transaction::Version::ONE,
306+
lock_time: absolute::LockTime::ZERO,
307+
input: vec![],
308+
output: vec![TxOut {
309+
script_pubkey: addr.script_pubkey(),
310+
value,
311+
}],
312+
};
313+
314+
let txid = tx.compute_txid();
315+
insert_tx(wallet, tx);
316+
317+
match receive_to.into() {
318+
ReceiveTo::Block(anchor) => insert_anchor(wallet, txid, anchor),
319+
ReceiveTo::Mempool(last_seen) => insert_seen_at(wallet, txid, last_seen),
320+
}
321+
322+
OutPoint { txid, vout: 0 }
323+
}
311324

312325
/// Insert a checkpoint into the wallet. This can be used to extend the wallet's local chain
313326
/// or to insert a block that did not exist previously. Note that if replacing a block with
@@ -361,15 +374,17 @@ pub fn insert_anchor<K: Ord + fmt::Debug + Clone>(
361374
.expect("failed to apply update");
362375
}
363376

364-
/// Marks the given `txid` seen as unconfirmed at `seen_at`
365-
pub fn insert_seen_at<K>(wallet: &mut Wallet<K>, txid: Txid, seen_at: u64)
366-
where K: Ord + Clone + fmt::Debug {
367-
let mut tx_update = TxUpdate::default();
368-
tx_update.seen_ats = [(txid, seen_at)].into();
369-
wallet
370-
.apply_update(Update {
371-
tx_update,
372-
..Default::default()
373-
})
374-
.expect("failed to apply update");
375-
}
377+
/// Marks the given `txid` seen as unconfirmed at `seen_at`
378+
pub fn insert_seen_at<K>(wallet: &mut Wallet<K>, txid: Txid, seen_at: u64)
379+
where
380+
K: Ord + Clone + fmt::Debug,
381+
{
382+
let mut tx_update = TxUpdate::default();
383+
tx_update.seen_ats = [(txid, seen_at)].into();
384+
wallet
385+
.apply_update(Update {
386+
tx_update,
387+
..Default::default()
388+
})
389+
.expect("failed to apply update");
390+
}

0 commit comments

Comments
 (0)