Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sdk): update response type of generate buyer and seller psbt #40

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/node/instant-buy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,15 +30,15 @@ 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
}

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,
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions packages/sdk/src/inscription/instant-buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down