Skip to content

Commit

Permalink
fix(sdk): send inscription to destination address & recovered funds t…
Browse files Browse the repository at this point in the history
…o change address (#73)

fix(sdk): send inscription to destination address

also, send recovered funds to change address
  • Loading branch information
iamcrazycoder authored Sep 28, 2023
1 parent 1afa18f commit 112963c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/sdk/src/inscription/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function publishCollection({
}

export async function mintFromCollection(options: MintFromCollectionOptions) {
if (!options.collectionOutpoint || !options.inscriptionIid || !options.destination) {
if (!options.collectionOutpoint || !options.inscriptionIid || !options.destinationAddress) {
throw new Error("Invalid options supplied.")
}

Expand Down Expand Up @@ -126,7 +126,7 @@ export type PublishCollectionOptions = Pick<GetWalletOptions, "safeMode"> & {
postage: number
mediaType: string
mediaContent: string
destination: string
destinationAddress: string
changeAddress: string
title: string
description: string
Expand Down Expand Up @@ -162,7 +162,7 @@ export type MintFromCollectionOptions = Pick<GetWalletOptions, "safeMode"> & {
postage: number
mediaType: string
mediaContent: string
destination: string
destinationAddress: string
changeAddress: string
collectionOutpoint: string
inscriptionIid: string
Expand Down
9 changes: 6 additions & 3 deletions packages/sdk/src/transactions/Inscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Inscriber extends PSBTBuilder {

private ready = false
private commitAddress: string | null = null
private destinationAddress: string
private payment: bitcoin.payments.Payment | null = null
private suitableUnspent: UTXOLimited | null = null
private recovery = false
Expand All @@ -43,6 +44,7 @@ export class Inscriber extends PSBTBuilder {
network,
address,
changeAddress,
destinationAddress,
publicKey,
feeRate,
postage,
Expand All @@ -66,6 +68,7 @@ export class Inscriber extends PSBTBuilder {
throw new Error("Invalid options provided")
}

this.destinationAddress = destinationAddress
this.mediaType = mediaType
this.mediaContent = mediaContent
this.meta = meta
Expand Down Expand Up @@ -117,14 +120,14 @@ export class Inscriber extends PSBTBuilder {

if (!this.recovery) {
this.outputs.push({
address: this.address,
address: this.destinationAddress || this.address,
value: this.postage
})
}

if (this.recovery) {
this.outputs.push({
address: this.address,
address: this.changeAddress || this.address,
value: this.suitableUnspent.sats - this.fee
})
}
Expand Down Expand Up @@ -285,12 +288,12 @@ export class OrdTransaction extends Inscriber {
export type InscriberArgOptions = Pick<GetWalletOptions, "safeMode"> & {
network: Network
address: string
destinationAddress: string
publicKey: string
feeRate: number
postage: number
mediaType: string
mediaContent: string
destination: string
changeAddress: string
meta?: NestedObject
outputs?: Outputs
Expand Down

0 comments on commit 112963c

Please sign in to comment.