From 112963cfd0954e6f3d7883d57d486b3731d46c28 Mon Sep 17 00:00:00 2001 From: Nishant Ghodke <64554492+iamcrazycoder@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:55:17 +0530 Subject: [PATCH] fix(sdk): send inscription to destination address & recovered funds to change address (#73) fix(sdk): send inscription to destination address also, send recovered funds to change address --- packages/sdk/src/inscription/collection.ts | 6 +++--- packages/sdk/src/transactions/Inscriber.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/sdk/src/inscription/collection.ts b/packages/sdk/src/inscription/collection.ts index dd3e9ee1..3399a9ac 100644 --- a/packages/sdk/src/inscription/collection.ts +++ b/packages/sdk/src/inscription/collection.ts @@ -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.") } @@ -126,7 +126,7 @@ export type PublishCollectionOptions = Pick & { postage: number mediaType: string mediaContent: string - destination: string + destinationAddress: string changeAddress: string title: string description: string @@ -162,7 +162,7 @@ export type MintFromCollectionOptions = Pick & { postage: number mediaType: string mediaContent: string - destination: string + destinationAddress: string changeAddress: string collectionOutpoint: string inscriptionIid: string diff --git a/packages/sdk/src/transactions/Inscriber.ts b/packages/sdk/src/transactions/Inscriber.ts index 52b659e4..a8b5f696 100644 --- a/packages/sdk/src/transactions/Inscriber.ts +++ b/packages/sdk/src/transactions/Inscriber.ts @@ -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 @@ -43,6 +44,7 @@ export class Inscriber extends PSBTBuilder { network, address, changeAddress, + destinationAddress, publicKey, feeRate, postage, @@ -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 @@ -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 }) } @@ -285,12 +288,12 @@ export class OrdTransaction extends Inscriber { export type InscriberArgOptions = Pick & { network: Network address: string + destinationAddress: string publicKey: string feeRate: number postage: number mediaType: string mediaContent: string - destination: string changeAddress: string meta?: NestedObject outputs?: Outputs