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

Better get balance #433

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open

Better get balance #433

wants to merge 43 commits into from

Conversation

slavastartsev
Copy link
Contributor

@slavastartsev slavastartsev commented Dec 12, 2024

  • for each unconfirmed tx, check there are no inscriptions:
    return parseInscriptions(tx);
  • for each input to that tx do step (1) if its also unconfirmed else check via the Ord API as we do now

Explanation: build a tree structure

  • for each output returned by esplora becomes root TreeNode
  • inputs to that tx are it's children
  • leaf nodes either confirmed outputs or outputs containing ordinals (flagged with cardinal: false).

If output has all leaf nodes with cardinal: true -- confirmed (not containing ordinals) then output amount could be spent.

Copy link

changeset-bot bot commented Dec 12, 2024

⚠️ No Changeset found

Latest commit: dd15a9b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bob ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 14, 2025 4:09pm

sdk/src/wallet/utxo.ts Outdated Show resolved Hide resolved
sdk/src/wallet/utxo.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@gregdhill gregdhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see similar logic changes in at least 2-3 parts of utxo.ts is there anyway to share logic?

sdk/src/wallet/utxo.ts Outdated Show resolved Hide resolved
sdk/test/utxo.test.ts Show resolved Hide resolved
sdk/src/wallet/utxo.ts Outdated Show resolved Hide resolved
* refactor: simplify wallet ord logic

Signed-off-by: Gregory Hill <gregorydhill@outlook.com>

* chore: run prettier format

* chore: skip process utxo test

* chore: uncomment test for find safe utxo

---------

Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
Co-authored-by: Slava <slava@interlay.io>
sdk/src/wallet/utxo.ts Outdated Show resolved Hide resolved
sdk/src/wallet/utxo.ts Show resolved Hide resolved
limit: number = 3
): Promise<boolean> => {
if (limit === 0) return false;
const transaction = await esploraClient.getTransaction(txid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting I think we can re-write this to use only the ordinalsClient but I was too lazy to do that. Something to consider or leave a note

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it's possible. from the current schema there're no endpoints which might returns us inputs for txid

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think it returns the hex encoded tx which can be decoded to a transaction object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately it's of another interface Transaction. coincident that name is the same

if (cardinalOutputsSet.has(OutPoint.toString(vin))) return true;

const output = await ordinalsClient.getInscriptionsFromOutPoint(vin);
if (output.indexed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we do this we should do parseInscriptions to short-circuit if it is a mempool tx that is committing or revealing inscription data

cardinalOutputsSet: Set<string>,
esploraClient: EsploraClient,
ordinalsClient: OrdinalsClient,
limit: number = 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this may happen if indexed = false from Ord API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants