From ccab3446c1b424bcf95984c08b256fa219ce1b1b Mon Sep 17 00:00:00 2001 From: Slava Date: Mon, 18 Nov 2024 13:42:40 +0300 Subject: [PATCH] chore: fix review remarks --- sdk/src/wallet/utxo.ts | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/sdk/src/wallet/utxo.ts b/sdk/src/wallet/utxo.ts index ef86263d..64f3eb95 100644 --- a/sdk/src/wallet/utxo.ts +++ b/sdk/src/wallet/utxo.ts @@ -91,22 +91,15 @@ export async function createBitcoinPsbt( const ordinalsClient = new OrdinalsClient(addressInfo.network); let confirmedUtxos: UTXO[] = []; + // contains UTXOs which do not contain inscriptions let outputsFromAddress: OutputJson[] = []; - if (feeRate) { - [confirmedUtxos, outputsFromAddress] = await Promise.all([ - esploraClient.getAddressUtxos(fromAddress), - // cardinal = return UTXOs not containing inscriptions or runes - addressInfo.type === AddressType.p2tr ? ordinalsClient.getOutputsFromAddress(fromAddress, 'cardinal') : [], - ]); - } else { - [confirmedUtxos, feeRate, outputsFromAddress] = await Promise.all([ - esploraClient.getAddressUtxos(fromAddress), - esploraClient.getFeeEstimate(confirmationTarget), - // cardinal = return UTXOs not containing inscriptions or runes - addressInfo.type === AddressType.p2tr ? ordinalsClient.getOutputsFromAddress(fromAddress, 'cardinal') : [], - ]); - } + [confirmedUtxos, feeRate, outputsFromAddress] = await Promise.all([ + esploraClient.getAddressUtxos(fromAddress), + feeRate === undefined ? esploraClient.getFeeEstimate(confirmationTarget) : feeRate, + // cardinal = return UTXOs not containing inscriptions or runes + addressInfo.type === AddressType.p2tr ? ordinalsClient.getOutputsFromAddress(fromAddress, 'cardinal') : [], + ]); if (confirmedUtxos.length === 0) { throw new Error('No confirmed UTXOs'); @@ -313,22 +306,15 @@ export async function estimateTxFee( const ordinalsClient = new OrdinalsClient(addressInfo.network); let confirmedUtxos: UTXO[] = []; + // contains UTXOs which do not contain inscriptions let outputsFromAddress: OutputJson[] = []; - if (feeRate) { - [confirmedUtxos, outputsFromAddress] = await Promise.all([ - esploraClient.getAddressUtxos(fromAddress), - // cardinal = return UTXOs not containing inscriptions or runes - addressInfo.type === AddressType.p2tr ? ordinalsClient.getOutputsFromAddress(fromAddress, 'cardinal') : [], - ]); - } else { - [confirmedUtxos, feeRate, outputsFromAddress] = await Promise.all([ - esploraClient.getAddressUtxos(fromAddress), - esploraClient.getFeeEstimate(confirmationTarget), - // cardinal = return UTXOs not containing inscriptions or runes - addressInfo.type === AddressType.p2tr ? ordinalsClient.getOutputsFromAddress(fromAddress, 'cardinal') : [], - ]); - } + [confirmedUtxos, feeRate, outputsFromAddress] = await Promise.all([ + esploraClient.getAddressUtxos(fromAddress), + feeRate === undefined ? esploraClient.getFeeEstimate(confirmationTarget) : feeRate, + // cardinal = return UTXOs not containing inscriptions or runes + addressInfo.type === AddressType.p2tr ? ordinalsClient.getOutputsFromAddress(fromAddress, 'cardinal') : [], + ]); if (confirmedUtxos.length === 0) { throw new Error('No confirmed UTXOs');