Skip to content

Commit

Permalink
fix(sdk): allow PSBTBuilder to fetch more UTXOs as needed (#77)
Browse files Browse the repository at this point in the history
* fix: let PSBTBuilder fetch more UTXOs as needed

* feat: change scope of isEligible method to private
  • Loading branch information
iamcrazycoder authored Sep 29, 2023
1 parent 7420afa commit 100c6b7
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/sdk/src/instant-trade/InstantTradeBuyerTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ export default class InstantTradeBuyerTxBuilder extends InstantTradeBuilder {
}

// bind minimum utxos. PSBTBuilder will add more if needed
return utxos.slice(0, 3)
return utxos.slice(0, 2)
}

async isEligible() {
private async isEligible() {
if (!this.inscriptionOutpoint) {
throw new Error("decode seller PSBT to check eligiblity")
}
Expand All @@ -142,24 +142,19 @@ export default class InstantTradeBuyerTxBuilder extends InstantTradeBuilder {
this.postage = inscriptionUTXO.sats

const sortedUTXOs = utxos.sort((a, b) => a.sats - b.sats)
const [refundableUTXOOne, refundableUTXOTwo, ...restUTXOs] = sortedUTXOs
const [refundableUTXOOne, refundableUTXOTwo] = sortedUTXOs
const refundables = [refundableUTXOOne, refundableUTXOTwo].reduce((acc, curr) => (acc += curr.sats), 0)
const spendables = restUTXOs.reduce((acc, curr) => (acc += curr.sats), 0)
const eligible = refundables >= MINIMUM_AMOUNT_IN_SATS * 2 && spendables >= MINIMUM_AMOUNT_IN_SATS
const eligible = refundables >= MINIMUM_AMOUNT_IN_SATS * 2

if (eligible) {
this.utxos = utxos
}

return {
eligible,
refundables,
spendables
}
return true
}

async build() {
const { eligible } = await this.isEligible()
const eligible = await this.isEligible()
if (!eligible) {
throw new Error("Not eligible")
}
Expand Down

0 comments on commit 100c6b7

Please sign in to comment.