Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only fetch inscriptions that are owned by the ord wallet #2310

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,24 +826,15 @@ impl Index {

pub(crate) fn get_inscriptions(
&self,
n: Option<usize>,
utxos: BTreeMap<OutPoint, Amount>,
) -> Result<BTreeMap<SatPoint, InscriptionId>> {
let rtx = self.database.begin_read()?;

let mut result = BTreeMap::new();

for range_result in rtx
.open_multimap_table(SATPOINT_TO_INSCRIPTION_ID)?
.range::<&[u8; 44]>(&[0; 44]..)?
{
let (satpoint, ids) = range_result?;
for id_result in ids {
let id = id_result?;
result.insert(Entry::load(*satpoint.value()), Entry::load(*id.value()));
}
if result.len() >= n.unwrap_or(usize::MAX) {
break;
}
let table = rtx.open_multimap_table(SATPOINT_TO_INSCRIPTION_ID)?;
for utxo in utxos.keys() {
result.extend(Self::inscriptions_on_output_unordered(&table, *utxo)?);
}

Ok(result)
Expand Down
4 changes: 3 additions & 1 deletion src/subcommand/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ pub(crate) fn run(options: Options) -> Result {
let index = Index::open(&options)?;
index.update()?;

let unspent_outputs = index.get_unspent_outputs(Wallet::load(&options)?)?;

let inscription_outputs = index
.get_inscriptions(None)?
.get_inscriptions(unspent_outputs)?
.keys()
.map(|satpoint| satpoint.outpoint)
.collect::<BTreeSet<OutPoint>>();
Expand Down
7 changes: 4 additions & 3 deletions src/subcommand/wallet/cardinals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ pub(crate) fn run(options: Options) -> Result {
let index = Index::open(&options)?;
index.update()?;

let unspent_outputs = index.get_unspent_outputs(Wallet::load(&options)?)?;

let inscribed_utxos = index
.get_inscriptions(None)?
.get_inscriptions(unspent_outputs.clone())?
.keys()
.map(|satpoint| satpoint.outpoint)
.collect::<BTreeSet<OutPoint>>();

let cardinal_utxos = index
.get_unspent_outputs(Wallet::load(&options)?)?
let cardinal_utxos = unspent_outputs
.iter()
.filter_map(|(output, amount)| {
if inscribed_utxos.contains(output) {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Inscribe {

let mut utxos = index.get_unspent_outputs(Wallet::load(&options)?)?;

let inscriptions = index.get_inscriptions(None)?;
let inscriptions = index.get_inscriptions(utxos.clone())?;

let commit_tx_change = [
get_change_address(&client, &options)?,
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub(crate) fn run(options: Options) -> Result {
let index = Index::open(&options)?;
index.update()?;

let inscriptions = index.get_inscriptions(None)?;
let unspent_outputs = index.get_unspent_outputs(Wallet::load(&options)?)?;
let inscriptions = index.get_inscriptions(unspent_outputs.clone())?;

let explorer = match options.chain() {
Chain::Mainnet => "https://ordinals.com/inscription/",
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Send {

let unspent_outputs = index.get_unspent_outputs(Wallet::load(&options)?)?;

let inscriptions = index.get_inscriptions(None)?;
let inscriptions = index.get_inscriptions(unspent_outputs.clone())?;

let satpoint = match self.outgoing {
Outgoing::SatPoint(satpoint) => {
Expand Down