Wrap promises with try blocks

This commit is contained in:
Ross Savage
2024-02-06 20:25:50 +01:00
parent 0379597d5e
commit aec144693d
17 changed files with 275 additions and 145 deletions

View File

@@ -8,47 +8,66 @@ import {
const exampleReceiveOnchain = async () => {
// ANCHOR: generate-receive-onchain-address
const swapInfo = await receiveOnchain({})
try {
const swapInfo = await receiveOnchain({})
// Send your funds to the below bitcoin address
const address = swapInfo.bitcoinAddress
console.log(`Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}`)
console.log(`Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}`)
// Send your funds to the below bitcoin address
const address = swapInfo.bitcoinAddress
console.log(`Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}`)
console.log(`Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}`)
} catch (err) {
console.error(err)
}
// ANCHOR_END: generate-receive-onchain-address
}
const exampleInProgressSwap = async () => {
// ANCHOR: in-progress-swap
const swapInfo = await inProgressSwap()
try {
const swapInfo = await inProgressSwap()
} catch (err) {
console.error(err)
}
// ANCHOR_END: in-progress-swap
}
const exampleListRefundables = async () => {
// ANCHOR: list-refundables
const refundables = await listRefundables()
try {
const refundables = await listRefundables()
} catch (err) {
console.error(err)
}
// ANCHOR_END: list-refundables
}
const exampleRefund = async () => {
// ANCHOR: execute-refund
const refundables = await listRefundables()
const toAddress = '...'
const satPerVbyte = 5
try {
const refundables = await listRefundables()
const toAddress = '...'
const satPerVbyte = 5
const refundResponse = await refund({
swapAddress: refundables[0].bitcoinAddress,
toAddress,
satPerVbyte
})
const refundResponse = await refund({
swapAddress: refundables[0].bitcoinAddress,
toAddress,
satPerVbyte
})
} catch (err) {
console.error(err)
}
// ANCHOR_END: execute-refund
}
const exampleOpenChannelFee = async () => {
// ANCHOR: get-channel-opening-fees
const amountMsat = 10000
const openChannelFeeResponse = await openChannelFee({
amountMsat
})
try {
const amountMsat = 10000
const openChannelFeeResponse = await openChannelFee({
amountMsat
})
} catch (err) {
console.error(err)
}
// ANCHOR_END: get-channel-opening-fees
}