Skip to content

Commit

Permalink
Updated Swift docs for LDK 0.0.121 (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy0Anonymous authored Mar 5, 2024
1 parent 739e979 commit a95f30c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion docs/building-a-node-with-ldk/closing-a-channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func handleEvent(event: Event) {
let outputs = event.getOutputs()
do {
let address = ldkManager!.bdkManager.getAddress(addressIndex: .new)!
let script = try Address(address: address).scriptPubkey().toBytes()
let network = ldkManager!.network == .Testnet ? BitcoinDevKit.Network.testnet : BitcoinDevKit.Network.regtest
let script = try Address(address: address, network: network).scriptPubkey().toBytes()
let res = ldkManager!.myKeysManager.spendSpendableOutputs(
descriptors: outputs,
outputs: [],
Expand Down
18 changes: 13 additions & 5 deletions docs/building-a-node-with-ldk/sending-payments.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ let invoiceStr = // get an invoice from the payee
let parsedInvoice = Bolt11Invoice.fromStr(s: invoiceStr)

if let invoiceVal = parsedInvoice.getValue() {
let invoicePaymentResult = Bindings.payInvoice(
invoice: invoiceVal,
retryStrategy: Bindings.Retry.initWithTimeout(a: 15),
channelmanager: channelManager
let invoicePaymentResult = Bindings.paymentParametersFromInvoice(invoice: invoiceVal)
guard invoicePaymentResult.isOk() else {
return false
}
let (paymentHash, recipientOnion, routeParams) = Bindings.paymentParametersFromInvoice(invoice: invoiceVal).getValue()!
let paymentId = invoice.paymentHash()!
let res = channelManager.sendPayment(
paymentHash: paymentHash,
recipientOnion: recipientOnion,
paymentId: paymentId,
routeParams: routeParams,
retryStrategy: .initWithTimeout(a: 15)
)

if invoicePaymentResult.isOk() {
if res.isOk() {
// Payment Sent
}
}
Expand Down
20 changes: 11 additions & 9 deletions docs/building-a-node-with-ldk/setting-up-a-channel-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ val feeEstimator: FeeEstimator = FeeEstimator.new_impl(YourFeeEstimator)
<template v-slot:swift>

```Swift
class MyFeeEstimator: FeeEstimator {
class MyFeeEstimator: FeeEstimator {
override func getEstSatPer1000Weight(confirmationTarget: Bindings.ConfirmationTarget) -> UInt32 {
if confirmationTarget == .Background {
// Fetch Background Feerate
} else if confirmationTarget == .Normal {
// Fetch Normal Feerate (~6 blocks)
} else if confirmationTarget == .HighPriority {
// Fetch High Feerate
}
// Fetch Default Feerate
if confirmationTarget == .MinAllowedNonAnchorChannelRemoteFee {
return 253
} else if confirmationTarget == .ChannelCloseMinimum {
return 1000
} else if confirmationTarget == .NonAnchorChannelFee {
return 7500
} else if confirmationTarget == .OnChainSweep {
return 7500
}
return 7500
}
}

Expand Down

0 comments on commit a95f30c

Please sign in to comment.