Skip to content

Commit

Permalink
Make getters
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Mar 1, 2025
1 parent d2431ff commit b9462b8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) enum Subcommand {
Cardinals,
#[command(about = "Create new wallet")]
Create(create::Create),
#[command(about = "Get wallet descriptors")]
#[command(about = "Print wallet descriptors")]
Descriptors,
#[command(about = "Create inscription")]
Inscribe(inscribe::Inscribe),
Expand Down
44 changes: 24 additions & 20 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ pub(crate) enum Maturity {

#[allow(dead_code)]
pub(crate) struct Wallet {
wallet: PersistedWallet<DatabasePersister>,
database: Arc<Database>,
has_rune_index: bool,
has_sat_index: bool,
rpc_url: Url,
utxos: BTreeMap<OutPoint, TxOut>,
ord_client: reqwest::blocking::Client,
inscription_info: BTreeMap<InscriptionId, api::Inscription>,
output_info: BTreeMap<OutPoint, api::Output>,
inscriptions: BTreeMap<SatPoint, Vec<InscriptionId>>,
locked_utxos: BTreeMap<OutPoint, TxOut>,
rpc_url: Url,
settings: Settings,
wallet: PersistedWallet<DatabasePersister>,
// inscription_info: BTreeMap<InscriptionId, api::Inscription>,
// inscriptions: BTreeMap<SatPoint, Vec<InscriptionId>>,
// locked_utxos: BTreeMap<OutPoint, TxOut>,
// output_info: BTreeMap<OutPoint, api::Output>,
// utxos: BTreeMap<OutPoint, TxOut>,
}

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

let mut wtx = database.begin_write()?;

Expand Down Expand Up @@ -146,7 +146,7 @@ impl Wallet {
);

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

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

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

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

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

pub(crate) fn lock_non_cardinal_outputs(&self) -> Result {
Expand Down Expand Up @@ -244,11 +244,15 @@ impl Wallet {
}

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

pub(crate) fn inscription_info(&self) -> BTreeMap<InscriptionId, api::Inscription> {
self.inscription_info.clone()
todo!();
}

pub(crate) fn output_info(&self) -> BTreeMap<OutPoint, api::Output> {
todo!();
}

pub(crate) fn get_inscription(
Expand Down Expand Up @@ -291,7 +295,7 @@ impl Wallet {
) -> Result<Option<Vec<InscriptionId>>> {
Ok(
self
.output_info
.output_info()
.get(output)
.ok_or(anyhow!("output not found in wallet"))?
.inscriptions
Expand All @@ -307,13 +311,13 @@ impl Wallet {
}

let satpoint = self
.inscription_info
.inscription_info()
.get(parent_id)
.ok_or_else(|| anyhow!("parent {parent_id} not in wallet"))?
.satpoint;

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

pub(crate) fn get_runic_outputs(&self) -> Result<Option<BTreeSet<OutPoint>>> {
let mut runic_outputs = BTreeSet::new();
for (output, info) in &self.output_info {
for (output, info) in &self.output_info() {
let Some(runes) = &info.runes else {
return Ok(None);
};
Expand All @@ -350,7 +354,7 @@ impl Wallet {
) -> Result<Option<BTreeMap<SpacedRune, Pile>>> {
Ok(
self
.output_info
.output_info()
.get(output)
.ok_or(anyhow!("output not found in wallet"))?
.runes
Expand Down
16 changes: 8 additions & 8 deletions src/wallet/wallet_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl WalletConstructor {
descriptor::standard(self.settings.chain().network(), master_private_key, 0, true)?;

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

Ok(Wallet {
wallet,
database,
has_rune_index: status.rune_index,
has_sat_index: status.sat_index,
inscription_info: BTreeMap::new(), // TODO
inscriptions: BTreeMap::new(), // TODO
locked_utxos: BTreeMap::new(), // TODO
ord_client: self.ord_client,
output_info: BTreeMap::new(), // TODO
rpc_url: self.rpc_url,
settings: self.settings,
utxos: BTreeMap::new(), // TODO
wallet,
// inscription_info: BTreeMap::new(), // TODO
// inscriptions: BTreeMap::new(), // TODO
// locked_utxos: BTreeMap::new(), // TODO
// output_info: BTreeMap::new(), // TODO
// utxos: BTreeMap::new(), // TODO
})
}

Expand Down

0 comments on commit b9462b8

Please sign in to comment.