Skip to content

Commit b9462b8

Browse files
committed
Make getters
1 parent d2431ff commit b9462b8

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

src/subcommand/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(crate) enum Subcommand {
6060
Cardinals,
6161
#[command(about = "Create new wallet")]
6262
Create(create::Create),
63-
#[command(about = "Get wallet descriptors")]
63+
#[command(about = "Print wallet descriptors")]
6464
Descriptors,
6565
#[command(about = "Create inscription")]
6666
Inscribe(inscribe::Inscribe),

src/wallet.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ pub(crate) enum Maturity {
6565

6666
#[allow(dead_code)]
6767
pub(crate) struct Wallet {
68-
wallet: PersistedWallet<DatabasePersister>,
6968
database: Arc<Database>,
7069
has_rune_index: bool,
7170
has_sat_index: bool,
72-
rpc_url: Url,
73-
utxos: BTreeMap<OutPoint, TxOut>,
7471
ord_client: reqwest::blocking::Client,
75-
inscription_info: BTreeMap<InscriptionId, api::Inscription>,
76-
output_info: BTreeMap<OutPoint, api::Output>,
77-
inscriptions: BTreeMap<SatPoint, Vec<InscriptionId>>,
78-
locked_utxos: BTreeMap<OutPoint, TxOut>,
72+
rpc_url: Url,
7973
settings: Settings,
74+
wallet: PersistedWallet<DatabasePersister>,
75+
// inscription_info: BTreeMap<InscriptionId, api::Inscription>,
76+
// inscriptions: BTreeMap<SatPoint, Vec<InscriptionId>>,
77+
// locked_utxos: BTreeMap<OutPoint, TxOut>,
78+
// output_info: BTreeMap<OutPoint, api::Output>,
79+
// utxos: BTreeMap<OutPoint, TxOut>,
8080
}
8181

8282
#[allow(dead_code)]
@@ -88,7 +88,7 @@ impl Wallet {
8888
seed: [u8; 64],
8989
timestamp: bitcoincore_rpc::json::Timestamp,
9090
) -> Result {
91-
let database = Arc::new(create_database(&name, settings)?);
91+
let database = create_database(&name, settings)?;
9292

9393
let mut wtx = database.begin_write()?;
9494

@@ -146,7 +146,7 @@ impl Wallet {
146146
);
147147

148148
let mut output_sat_ranges = Vec::new();
149-
for (output, info) in self.output_info.iter() {
149+
for (output, info) in self.output_info().iter() {
150150
if let Some(sat_ranges) = &info.sat_ranges {
151151
output_sat_ranges.push((*output, sat_ranges.clone()));
152152
} else {
@@ -163,7 +163,7 @@ impl Wallet {
163163
"ord index must be built with `--index-sats` to see sat ranges"
164164
);
165165

166-
if let Some(info) = self.output_info.get(output) {
166+
if let Some(info) = self.output_info().get(output) {
167167
if let Some(sat_ranges) = &info.sat_ranges {
168168
Ok(sat_ranges.clone())
169169
} else {
@@ -180,7 +180,7 @@ impl Wallet {
180180
"ord index must be built with `--index-sats` to use `--sat`"
181181
);
182182

183-
for (outpoint, info) in self.output_info.iter() {
183+
for (outpoint, info) in self.output_info().iter() {
184184
if let Some(sat_ranges) = &info.sat_ranges {
185185
let mut offset = 0;
186186
for (start, end) in sat_ranges {
@@ -207,11 +207,11 @@ impl Wallet {
207207
}
208208

209209
pub(crate) fn utxos(&self) -> &BTreeMap<OutPoint, TxOut> {
210-
&self.utxos
210+
todo!()
211211
}
212212

213213
pub(crate) fn locked_utxos(&self) -> &BTreeMap<OutPoint, TxOut> {
214-
&self.locked_utxos
214+
todo!()
215215
}
216216

217217
pub(crate) fn lock_non_cardinal_outputs(&self) -> Result {
@@ -244,11 +244,15 @@ impl Wallet {
244244
}
245245

246246
pub(crate) fn inscriptions(&self) -> &BTreeMap<SatPoint, Vec<InscriptionId>> {
247-
&self.inscriptions
247+
todo!();
248248
}
249249

250250
pub(crate) fn inscription_info(&self) -> BTreeMap<InscriptionId, api::Inscription> {
251-
self.inscription_info.clone()
251+
todo!();
252+
}
253+
254+
pub(crate) fn output_info(&self) -> BTreeMap<OutPoint, api::Output> {
255+
todo!();
252256
}
253257

254258
pub(crate) fn get_inscription(
@@ -291,7 +295,7 @@ impl Wallet {
291295
) -> Result<Option<Vec<InscriptionId>>> {
292296
Ok(
293297
self
294-
.output_info
298+
.output_info()
295299
.get(output)
296300
.ok_or(anyhow!("output not found in wallet"))?
297301
.inscriptions
@@ -307,13 +311,13 @@ impl Wallet {
307311
}
308312

309313
let satpoint = self
310-
.inscription_info
314+
.inscription_info()
311315
.get(parent_id)
312316
.ok_or_else(|| anyhow!("parent {parent_id} not in wallet"))?
313317
.satpoint;
314318

315319
let tx_out = self
316-
.utxos
320+
.utxos()
317321
.get(&satpoint.outpoint)
318322
.ok_or_else(|| anyhow!("parent {parent_id} not in wallet"))?
319323
.clone();
@@ -331,7 +335,7 @@ impl Wallet {
331335

332336
pub(crate) fn get_runic_outputs(&self) -> Result<Option<BTreeSet<OutPoint>>> {
333337
let mut runic_outputs = BTreeSet::new();
334-
for (output, info) in &self.output_info {
338+
for (output, info) in &self.output_info() {
335339
let Some(runes) = &info.runes else {
336340
return Ok(None);
337341
};
@@ -350,7 +354,7 @@ impl Wallet {
350354
) -> Result<Option<BTreeMap<SpacedRune, Pile>>> {
351355
Ok(
352356
self
353-
.output_info
357+
.output_info()
354358
.get(output)
355359
.ok_or(anyhow!("output not found in wallet"))?
356360
.runes

src/wallet/wallet_constructor.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ impl WalletConstructor {
7070
descriptor::standard(self.settings.chain().network(), master_private_key, 0, true)?;
7171

7272
let wallet = match bdk::Wallet::load()
73-
.check_network(self.settings.chain().network())
74-
// .descriptor()// https://docs.rs/bdk_wallet/1.1.0/bdk_wallet/struct.LoadParams.html#method.descriptor
73+
.check_network(self.settings.chain().network()) // TODO: add a test for this
74+
// .descriptor()// https://docs.rs/bdk_wallet/1.1.0/bdk_wallet/struct.LoadParams.html#method.descriptor // TODO: try this
7575
//.extract_keys()
7676
.keymap(KeychainKind::External, external_keymap)
7777
.keymap(KeychainKind::Internal, internal_keymap)
@@ -85,18 +85,18 @@ impl WalletConstructor {
8585
let status = self.get_server_status()?;
8686

8787
Ok(Wallet {
88-
wallet,
8988
database,
9089
has_rune_index: status.rune_index,
9190
has_sat_index: status.sat_index,
92-
inscription_info: BTreeMap::new(), // TODO
93-
inscriptions: BTreeMap::new(), // TODO
94-
locked_utxos: BTreeMap::new(), // TODO
9591
ord_client: self.ord_client,
96-
output_info: BTreeMap::new(), // TODO
9792
rpc_url: self.rpc_url,
9893
settings: self.settings,
99-
utxos: BTreeMap::new(), // TODO
94+
wallet,
95+
// inscription_info: BTreeMap::new(), // TODO
96+
// inscriptions: BTreeMap::new(), // TODO
97+
// locked_utxos: BTreeMap::new(), // TODO
98+
// output_info: BTreeMap::new(), // TODO
99+
// utxos: BTreeMap::new(), // TODO
100100
})
101101
}
102102

0 commit comments

Comments
 (0)