Skip to content

Commit

Permalink
feat(sdk): ensure that in recovery mode, there is only 1 output (#101)
Browse files Browse the repository at this point in the history
* feat(sdk): ensure that in recovery mode, there is only 1 output

* return recoverAddress, recoverAmount and recoverFee
  • Loading branch information
kevzzsk authored Dec 13, 2023
1 parent d760025 commit 747e37e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/sdk/src/transactions/Inscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Inscriber extends PSBTBuilder {
private payment: bitcoin.payments.Payment | null = null
private suitableUnspent: UTXOLimited | null = null
private recovery = false
private recoverAmount: number = 0
private safeMode: OnOffUnion
private encodeMetadata: boolean
private previewMode = false
Expand Down Expand Up @@ -130,10 +131,12 @@ export class Inscriber extends PSBTBuilder {
}

if (this.recovery) {
this.outputs.push({
this.recoverAmount = this.suitableUnspent.sats - this.fee
// when in recovery mode, there will only be 1 output
this.outputs = [{
address: this.changeAddress || this.address,
value: this.suitableUnspent.sats - this.fee
})
value: this.recoverAmount
}]
}

await this.prepare() // prepare PSBT using PSBTBuilder
Expand Down Expand Up @@ -246,6 +249,12 @@ export class Inscriber extends PSBTBuilder {
this.commitAddress = this.payment.address!

await this.calculateNetworkFeeUsingPreviewMode()

return {
recoverAddress: this.changeAddress || this.address,
recoverAmount: this.recoverAmount - this.fee, // need to minus this.fee again because the first time, fee is 0
recoverFee: this.fee
}
}

async isReady({ skipStrictSatsCheck, customAmount }: SkipStrictSatsCheckOptions = {}) {
Expand Down

0 comments on commit 747e37e

Please sign in to comment.