From 1877ea54d1f05d978441c7834250a4b7d1910753 Mon Sep 17 00:00:00 2001 From: Nishant Ghodke Date: Fri, 11 Aug 2023 15:01:08 +0530 Subject: [PATCH 1/2] refactor: update response type of generate buyer and seller psbt --- packages/sdk/src/inscription/instant-buy.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/sdk/src/inscription/instant-buy.ts b/packages/sdk/src/inscription/instant-buy.ts index 08b89459..bb493738 100644 --- a/packages/sdk/src/inscription/instant-buy.ts +++ b/packages/sdk/src/inscription/instant-buy.ts @@ -37,7 +37,10 @@ export async function generateSellerPsbt({ psbt.addInput(inputs[0]) psbt.addOutput(outputs[0]) - return psbt + return { + hex: psbt.toHex(), + base64: psbt.toBase64() + } } export async function generateBuyerPsbt({ @@ -164,14 +167,18 @@ export async function generateBuyerPsbt({ throw new Error("Insufficient funds to buy this inscription") } - if (changeValue > 580) { + if (changeValue > MINIMUM_AMOUNT_IN_SATS) { psbt.addOutput({ address: address.address!, value: changeValue }) } - return psbt + return { + hex: psbt.toHex(), + base64: psbt.toBase64(), + fee + } } export async function generateRefundableUTXOs({ From c7eb3b306d058bccc6250c44a9ef00c0df4a211c Mon Sep 17 00:00:00 2001 From: Nishant Ghodke Date: Fri, 11 Aug 2023 15:15:38 +0530 Subject: [PATCH 2/2] refactor: update instant-buy example per latest changes --- examples/node/instant-buy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/node/instant-buy.js b/examples/node/instant-buy.js index 64e644a8..418029e7 100644 --- a/examples/node/instant-buy.js +++ b/examples/node/instant-buy.js @@ -21,7 +21,7 @@ buyerWallet.setDefaultAddress('taproot') async function createSellOrder() { // replace w/ inscription outputpoint you'd like to sell, price, and address to receive sell proceeds - const sellerPSBT = await Ordit.instantBuy.generateSellerPsbt({ + const { hex: sellerPSBT } = await Ordit.instantBuy.generateSellerPsbt({ inscriptionOutPoint: '8d4a576aecb33b809c208d672a43fd6b175478d9454df4455ed0a2dc7eb7cbf6:0', price: 4000, // Total sale proceeds will be price + inscription output value (4000 + 2000 = 6000 sats) receiveAddress: sellerWallet.selectedAddress, @@ -30,7 +30,7 @@ async function createSellOrder() { network: 'testnet' }) - const signedSellerPSBT = sellerWallet.signPsbt(sellerPSBT.toHex(), { finalize: false, extractTx: false }) + const signedSellerPSBT = sellerWallet.signPsbt(sellerPSBT, { finalize: false, extractTx: false }) return signedSellerPSBT // hex } @@ -38,7 +38,7 @@ async function createSellOrder() { async function createBuyOrder({ sellerPSBT }) { await checkForExistingRefundableUTXOs(buyerWallet.selectedAddress) - const buyerPSBT = await Ordit.instantBuy.generateBuyerPsbt({ + const { hex: buyerPSBT } = await Ordit.instantBuy.generateBuyerPsbt({ sellerPsbt: sellerPSBT, publicKey: buyerWallet.publicKey, pubKeyType: buyerWallet.selectedAddressType, @@ -47,7 +47,7 @@ async function createBuyOrder({ sellerPSBT }) { inscriptionOutPoint: '0f3891f61b944c31fb48b0d9e770dc9e66a4b49097027be53b078be67aca72d4:0' }) - const signature = buyerWallet.signPsbt(buyerPSBT.toHex()) + const signature = buyerWallet.signPsbt(buyerPSBT) const tx = await buyerWallet.relayTx(signature, 'testnet') return tx