{"version":3,"sources":["../../src/bitcoinUtils/createSendInscriptionTransaction.ts"],"sourcesContent":["import * as btc from \"@scure/btc-signer\"\nimport { isNotNull } from \"../utils/typeHelpers\"\nimport { BitcoinNetwork, isSameUTXO, UTXOBasic } from \"./bitcoinHelpers\"\nimport { createTransaction } from \"./createTransaction\"\nimport { prepareTransaction } from \"./prepareTransaction\"\nimport {\n  GetConfirmedSpendableUTXOFn,\n  reselectSpendableUTXOsFactory,\n} from \"./selectUTXOs\"\n\nexport interface InscriptionRecipient {\n  inscriptionUtxo: UTXOBasic\n  addressScriptPubKey: Uint8Array\n}\n\nexport async function createSendInscriptionTransaction(options: {\n  network: BitcoinNetwork\n  inscriptionRecipients: InscriptionRecipient[]\n  changeAddressScriptPubKey: Uint8Array\n  opReturnData?: Uint8Array[]\n  availableFeeUtxos: UTXOBasic[]\n  feeRate: bigint\n  getUTXOSpendable: GetConfirmedSpendableUTXOFn\n}): Promise<{\n  tx: btc.Transaction\n  inscriptionUtxoInputIndices: number[]\n  bitcoinUtxoInputIndices: number[]\n}> {\n  const opReturnData = options.opReturnData ?? []\n\n  const recipients = options.inscriptionRecipients.map(r => ({\n    addressScriptPubKey: r.addressScriptPubKey,\n    satsAmount: r.inscriptionUtxo.amount,\n  }))\n\n  const selectedUTXOs = await Promise.all(\n    options.inscriptionRecipients.map(r =>\n      options.getUTXOSpendable(r.inscriptionUtxo),\n    ),\n  ).then(utxos => utxos.filter(isNotNull))\n\n  const {\n    inputs,\n    recipients: newRecipients,\n    changeAmount,\n  } = await prepareTransaction({\n    recipients,\n    changeAddressScriptPubKey: options.changeAddressScriptPubKey,\n    opReturnData,\n    feeRate: options.feeRate,\n    selectedUTXOs,\n    reselectSpendableUTXOs: reselectSpendableUTXOsFactory(\n      options.availableFeeUtxos.filter(\n        u => !selectedUTXOs.find(_u => isSameUTXO(u, _u)),\n      ),\n      options.getUTXOSpendable,\n    ),\n  })\n\n  const tx = createTransaction(\n    inputs,\n    newRecipients.concat(\n      changeAmount === 0n\n        ? []\n        : {\n            addressScriptPubKey: options.changeAddressScriptPubKey,\n            satsAmount: changeAmount,\n          },\n    ),\n    opReturnData,\n  )\n\n  const inscriptionCount = options.inscriptionRecipients.length\n  return {\n    tx,\n    inscriptionUtxoInputIndices: inputs\n      .slice(0, inscriptionCount)\n      .map((_, i) => i),\n    bitcoinUtxoInputIndices: inputs\n      .slice(inscriptionCount)\n      .map((_, i) => i + inscriptionCount),\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAeA,eAAsB,iCAAiC,SAYpD;AACD,QAAM,eAAe,QAAQ,gBAAgB,CAAC;AAE9C,QAAM,aAAa,QAAQ,sBAAsB,IAAI,QAAM;AAAA,IACzD,qBAAqB,EAAE;AAAA,IACvB,YAAY,EAAE,gBAAgB;AAAA,EAChC,EAAE;AAEF,QAAM,gBAAgB,MAAM,QAAQ;AAAA,IAClC,QAAQ,sBAAsB;AAAA,MAAI,OAChC,QAAQ,iBAAiB,EAAE,eAAe;AAAA,IAC5C;AAAA,EACF,EAAE,KAAK,WAAS,MAAM,OAAO,SAAS,CAAC;AAEvC,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,EACF,IAAI,MAAM,mBAAmB;AAAA,IAC3B;AAAA,IACA,2BAA2B,QAAQ;AAAA,IACnC;AAAA,IACA,SAAS,QAAQ;AAAA,IACjB;AAAA,IACA,wBAAwB;AAAA,MACtB,QAAQ,kBAAkB;AAAA,QACxB,OAAK,CAAC,cAAc,KAAK,QAAM,WAAW,GAAG,EAAE,CAAC;AAAA,MAClD;AAAA,MACA,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,KAAK;AAAA,IACT;AAAA,IACA,cAAc;AAAA,MACZ,iBAAiB,KACb,CAAC,IACD;AAAA,QACE,qBAAqB,QAAQ;AAAA,QAC7B,YAAY;AAAA,MACd;AAAA,IACN;AAAA,IACA;AAAA,EACF;AAEA,QAAM,mBAAmB,QAAQ,sBAAsB;AACvD,SAAO;AAAA,IACL;AAAA,IACA,6BAA6B,OAC1B,MAAM,GAAG,gBAAgB,EACzB,IAAI,CAAC,GAAG,MAAM,CAAC;AAAA,IAClB,yBAAyB,OACtB,MAAM,gBAAgB,EACtB,IAAI,CAAC,GAAG,MAAM,IAAI,gBAAgB;AAAA,EACvC;AACF;","names":[]}