x402-bch-axios 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +9 -3
- package/package.json +1 -1
- package/test/unit/index-unit.js +1 -1
package/index.js
CHANGED
|
@@ -211,6 +211,10 @@ async function sendPaymentFullstack (signer, paymentRequirements, bchServerConfi
|
|
|
211
211
|
utxos = utxos.filter(utxo => utxo.value >= paymentAmountSats)
|
|
212
212
|
// console.log(`UTXOs available for payment: ${JSON.stringify(utxos, null, 2)}`)
|
|
213
213
|
|
|
214
|
+
if (utxos.length === 0) {
|
|
215
|
+
throw new Error('Not enough funds. Send more BCH to your wallet address.')
|
|
216
|
+
}
|
|
217
|
+
|
|
214
218
|
// Choose the first UTXO that is big enough to pay for the transaction.
|
|
215
219
|
const utxo = utxos[0]
|
|
216
220
|
|
|
@@ -263,8 +267,9 @@ async function sendPaymentFullstack (signer, paymentRequirements, bchServerConfi
|
|
|
263
267
|
console.log(' ')
|
|
264
268
|
|
|
265
269
|
// Broadcast transation to the network
|
|
266
|
-
const txid2 = await bchjs.RawTransactions.sendRawTransaction(
|
|
267
|
-
//
|
|
270
|
+
const txid2 = await bchjs.RawTransactions.sendRawTransaction(hex)
|
|
271
|
+
// txid2 = txid2[0]
|
|
272
|
+
// console.log(`1) Transaction ID: `, txid2)
|
|
268
273
|
|
|
269
274
|
return {
|
|
270
275
|
txid: txid2,
|
|
@@ -272,7 +277,7 @@ async function sendPaymentFullstack (signer, paymentRequirements, bchServerConfi
|
|
|
272
277
|
satsSent: paymentAmountSats
|
|
273
278
|
}
|
|
274
279
|
} catch (err) {
|
|
275
|
-
console.error('Error in x402-bch-axios/sendPaymentFullstack(): ', err)
|
|
280
|
+
console.error('Error in x402-bch-axios/sendPaymentFullstack(): ', err.message)
|
|
276
281
|
throw err
|
|
277
282
|
}
|
|
278
283
|
}
|
|
@@ -317,6 +322,7 @@ async function sendPaymentGeneric (signer, paymentRequirements, bchServerConfig
|
|
|
317
322
|
}
|
|
318
323
|
|
|
319
324
|
const txid = await retryQueue.addToQueue(sendWithRetry, receivers)
|
|
325
|
+
// console.log(`2) Transaction ID: ${txid}`)
|
|
320
326
|
|
|
321
327
|
if (txid === null) {
|
|
322
328
|
throw new Error('Insufficient balance')
|
package/package.json
CHANGED
package/test/unit/index-unit.js
CHANGED
|
@@ -658,7 +658,7 @@ describe('#index.js', () => {
|
|
|
658
658
|
assert.isTrue(mockTransactionBuilder.addOutput.calledTwice)
|
|
659
659
|
assert.isTrue(mockTransactionBuilder.sign.calledOnce)
|
|
660
660
|
assert.isTrue(mockBchjs.RawTransactions.sendRawTransaction.calledOnce)
|
|
661
|
-
assert.deepEqual(mockBchjs.RawTransactions.sendRawTransaction.firstCall.args[0],
|
|
661
|
+
assert.deepEqual(mockBchjs.RawTransactions.sendRawTransaction.firstCall.args[0], 'raw-hex')
|
|
662
662
|
|
|
663
663
|
__resetDependencies()
|
|
664
664
|
})
|