mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 22:04:21 +01:00
update python and swift example
This commit is contained in:
@@ -5,9 +5,10 @@
|
||||
- [Installing](guide/install.md)
|
||||
- [Getting Started](guide/getting_started.md)
|
||||
- [Lightning payments](guide/payments.md)
|
||||
- [Connecting to an LSP](guide/connecting_lsp.md)
|
||||
- [Receiving an on-chain transaction](guide/receive_onchain.md)
|
||||
- [Sending an on-chain transaction](guide/send_onchain.md)
|
||||
- [Connecting to an LSP](guide/connecting_lsp.md)
|
||||
|
||||
- [Using LNURL](guide/lnurl.md)
|
||||
- [LNURL-Pay](guide/lnurl_pay.md)
|
||||
- [LNURL-Withdraw](guide/lnurl_withdraw.md)
|
||||
|
||||
@@ -9,7 +9,7 @@ Based on the API key provided to the Breez SDK, a default LSP is selected for yo
|
||||
```swift
|
||||
do {
|
||||
let lspId = try sdk.lspId()
|
||||
let lspInfo = try sdk.fetchLspInfo(lspId: lspId!)
|
||||
let lspInfo = try sdk.lspInfo()
|
||||
} catch {
|
||||
// Handle error
|
||||
}
|
||||
@@ -65,7 +65,7 @@ try {
|
||||
```python
|
||||
try:
|
||||
lsp_id = sdk_services.lsp_id()
|
||||
lsp_info = sdk_services.fetch_lsp_info(lsp_id)
|
||||
lsp_info = sdk_services.lsp_info()
|
||||
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
|
||||
@@ -18,8 +18,9 @@ let invoice = sdk.receive_payment(3000, "Invoice for 3000 sats".into()).await?;
|
||||
<section>
|
||||
|
||||
```swift
|
||||
let reqData = ReceivePaymentRequest(amountSats: 3000, description: "Invoice for 3000 sats")
|
||||
do {
|
||||
let invoice = try sdk.receivePayment(amountSats: 3000, description: "Invoice for 3000 sats")
|
||||
let invoice = try sdk.receivePayment(reqData: reqData )
|
||||
} catch {
|
||||
// handle error
|
||||
}
|
||||
@@ -68,7 +69,8 @@ try {
|
||||
|
||||
```python
|
||||
try:
|
||||
invoice = sdk_services.receive_payment(3000, "Invoice for 3000 sats")
|
||||
req_data = breez_sdk.ReceivePaymentRequest(amount_sats=3000, description="Invoice for 3000 sats")
|
||||
receive_payment_response = sdk_services.receive_payment(req_data=req_data)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```
|
||||
@@ -116,7 +118,9 @@ sdk.send_payment(bolt11.into(), Some(3000)).await?;
|
||||
```swift
|
||||
let bolt11 = "...";
|
||||
do {
|
||||
let payment = try sdk.sendPayment(bolt11: bolt11, amountSats: 3000)
|
||||
// The `amountSats` param is optional so nil can be passed if the
|
||||
// bolt11 invoice spesifies an amount.
|
||||
let payment = try sdk.sendPayment(bolt11: bolt11, amountSats: 3000)
|
||||
} catch {
|
||||
// handle error
|
||||
}
|
||||
@@ -171,7 +175,7 @@ try {
|
||||
```python
|
||||
bolt11 = "..."
|
||||
try:
|
||||
sdk_services.send_payment(bolt11, 3000)
|
||||
sdk_services.send_payment(bolt11=bolt11, amount_sats=3000)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```
|
||||
@@ -274,9 +278,9 @@ try {
|
||||
<section>
|
||||
|
||||
```python
|
||||
let node_id = "..."
|
||||
node_id = "..."
|
||||
try:
|
||||
sdk_services.send_spontaneous_payment(node_id, 3000)
|
||||
sdk_services.send_spontaneous_payment(node_id=node_id, amount_sats=3000)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```
|
||||
|
||||
@@ -3,6 +3,7 @@ There are cases when you have funds in some bitcoin address and you would like t
|
||||
|
||||
In such cases, the SDK might have to open a new channel, for which case you can specify an optional user-selected
|
||||
channel opening fee[^1]. For simplicity, the examples below use the cheapest fee available.
|
||||
In order to receive funds you first have to be connected to an [LSP](connecting_lsp.md).
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
@@ -24,11 +25,9 @@ let address = swap_info.bitcoin_address;
|
||||
|
||||
```swift
|
||||
do {
|
||||
// Optional user-selected dynamic fees (see Connecting to LSP section for details)
|
||||
let opening_fee_params = nil;
|
||||
let request = ReceiveOnchainRequest(opening_fee_params: opening_fee_params);
|
||||
|
||||
let swapInfo = try sdk.receiveOnchain(req: request)
|
||||
let openingFeeParams:OpeningFeeParams? = nil
|
||||
let req = ReceiveOnchainRequest(openingFeeParams: openingFeeParams)
|
||||
let swapInfo = try sdk.receiveOnchain(req: req)
|
||||
|
||||
// Send your funds to the bellow bitcoin address
|
||||
let address = swapInfo.bitcoinAddress;
|
||||
@@ -95,12 +94,9 @@ try {
|
||||
|
||||
```python
|
||||
try:
|
||||
# Optional user-selected dynamic fees (see Connecting to LSP section for details)
|
||||
opening_fee_params = None
|
||||
request = ReceiveOnchainRequest(opening_fee_params=opening_fee_params)
|
||||
|
||||
swap_info = sdk_services.receive_onchain(req=request)
|
||||
opening_fee_param = lsp_info.opening_fee_params_list.values[0]
|
||||
|
||||
swap_info = sdk_services.receive_onchain(opening_fee_params=opening_fee_param)
|
||||
# Send your funds to the below bitcoin address
|
||||
address = sdk_services.swap_info.bitcoin_address
|
||||
except Exception as error:
|
||||
@@ -362,9 +358,9 @@ let satPerVbyte = <refund tx fee rate>
|
||||
|
||||
do {
|
||||
try sdk.refund(
|
||||
swapAddress: "",
|
||||
toAddress: destinationAddress,
|
||||
satPerVbyte: satPerVbyte)
|
||||
swapAddress: refundable?.bitcoinAddress,
|
||||
toAddress: "...",
|
||||
satPerVbyte: satPerVbyte)
|
||||
} catch {
|
||||
// handle error
|
||||
}
|
||||
@@ -426,7 +422,7 @@ destination_address = "..."
|
||||
sat_per_vbyte = <refund tx fee rate>
|
||||
|
||||
try:
|
||||
sdk_services.refund(refundable.bitcoin_address, destination_address, sat_per_vbyte)
|
||||
result = sdk_services.refund(swap_address=refundable.bitcoin_address, to_address=to_address, sat_per_vbyte=sat_per_vbyte)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```
|
||||
|
||||
@@ -21,12 +21,14 @@ info!("Estimated miner fees in sats for claiming funds: {}", current_fees.fees_c
|
||||
<section>
|
||||
|
||||
```swift
|
||||
let sendAmountSat:UInt64 = 1_000_000
|
||||
try {
|
||||
let currentFees = try sdk.fetchReverseSwapFees()
|
||||
|
||||
println("Percentage fee for the reverse swap service: \(currentFees.feesPercentage)")
|
||||
println("Estimated miner fees in sats for locking up funds: \(currentFees.feesLockup)")
|
||||
println("Estimated miner fees in sats for claiming funds: \(currentFees.feesClaim)")
|
||||
let currentFees = try sdk.fetchReverseSwapFees(
|
||||
req: ReverseSwapFeesRequest(sendAmountSat: sendAmountSat))
|
||||
print("Percentage fee for the reverse swap service: \(currentFees.feesPercentage)")
|
||||
print("Estimated miner fees in sats for locking up funds: \(currentFees.feesLockup)")
|
||||
print("Estimated miner fees in sats for claiming funds: \(currentFees.feesClaim)")
|
||||
print("In order to verify that the fetched fee hasn't changed we pass the fee hash: \(currentFees.feesHash)")
|
||||
} catch {
|
||||
// handle error
|
||||
}
|
||||
@@ -84,11 +86,13 @@ try {
|
||||
<section>
|
||||
|
||||
```python
|
||||
send_amount_sat = 1000000
|
||||
try:
|
||||
current_fees = sdk_services.fetch_reverse_swap_fees()
|
||||
print("Percentage fee for the reverse swap service: ", current_fees.fees_percentage)
|
||||
print("Estimated miner fees in sats for locking up funds: ", current_fees.fees_lockup)
|
||||
print("Estimated miner fees in sats for claiming funds: ", current_fees.fees_claim)
|
||||
current_fees = sdk_services.fetch_reverse_swap_fees(breez_sdk.ReverseSwapFeesRequest(send_amount_sat=send_amount_sat))
|
||||
print("Percentage fee for the reverse swap service:", current_fees.fees_percentage)
|
||||
print("Estimated miner fees in sats for locking up funds:", current_fees.fees_lockup)
|
||||
print("Estimated miner fees in sats for claiming funds:", current_fees.fees_claim)
|
||||
print("In order to verify that the fetched fee hasn't changed we pass the" ,current_fees.fee_hash)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```
|
||||
@@ -290,9 +294,10 @@ try {
|
||||
```python
|
||||
destination_address = "bc1.."
|
||||
amount_sat = current_fees.min
|
||||
fee_hash = current_fees.fee_hash
|
||||
|
||||
try:
|
||||
sdk.send_onchain(amount_sat, destination_address, current_fees.fees_hash)
|
||||
sdk_services.send_onchain(amount_sat=amount_msats, onchain_recipient_address="...", pair_hash=fee_hash)
|
||||
except Exception as error:
|
||||
# Handle erorr
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user