mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 13:54:20 +01:00
python snippets
This commit is contained in:
15
snippets/python_snippets/buy_btc.py
Normal file
15
snippets/python_snippets/buy_btc.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from breez_sdk import BlockingBreezServices
|
||||
import logging
|
||||
import breez_sdk
|
||||
|
||||
sdk_services = BlockingBreezServices
|
||||
|
||||
|
||||
try:
|
||||
# ANCHOR: buy-btc
|
||||
req = breez_sdk.BuyBitcoinRequest(breez_sdk.BuyBitcoinProvider.MOONPAY)
|
||||
buy_bitcoin_resp = sdk_services.buy_bitcoin(req)
|
||||
# ANCHOR_END: buy-btc
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
24
snippets/python_snippets/connecting_lsp.py
Normal file
24
snippets/python_snippets/connecting_lsp.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import logging
|
||||
from breez_sdk import BlockingBreezServices
|
||||
|
||||
sdk_services = BlockingBreezServices
|
||||
|
||||
def get_lsp_info():
|
||||
try:
|
||||
# ANCHOR: get-lsp-info
|
||||
lsp_id = sdk_services.lsp_id()
|
||||
lsp_info = sdk_services.lsp_info()
|
||||
# ANCHOR_END: get-lsp-info
|
||||
return lsp_info
|
||||
except Exception as error:
|
||||
logging.log(error)
|
||||
raise
|
||||
|
||||
def connect_lsp(lsp_id):
|
||||
try:
|
||||
# ANCHOR: connect-lsp
|
||||
sdk_services.connect_lsp(lsp_id)
|
||||
# ANCHOR_END: connect-lsp
|
||||
except Exception as error:
|
||||
logging.log(error)
|
||||
raise
|
||||
25
snippets/python_snippets/fiat_currencies.py
Normal file
25
snippets/python_snippets/fiat_currencies.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import breez_sdk
|
||||
from breez_sdk import BlockingBreezServices
|
||||
import logging
|
||||
|
||||
sdk_services = BlockingBreezServices
|
||||
|
||||
def list_supported_fiat_currencies():
|
||||
try:
|
||||
# ANCHOR: list-fiat-currencies
|
||||
supported_fiat_currencies = sdk_services.list_fiat_currencies()
|
||||
# ANCHOR_END: list-fiat-currencies
|
||||
return supported_fiat_currencies
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
def get_current_rates():
|
||||
try:
|
||||
# ANCHOR: fetch-fiat-rates
|
||||
fiat_rates = sdk_services.fetch_fiat_rates
|
||||
# ANCHOR_END: fetch-fiat-rates
|
||||
return fiat_rates
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
46
snippets/python_snippets/getting_started.py
Normal file
46
snippets/python_snippets/getting_started.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import breez_sdk
|
||||
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
# ANCHOR: init-sdk
|
||||
class SDKListener(breez_sdk.EventListener):
|
||||
def on_event(self, event):
|
||||
logging.info(event)
|
||||
|
||||
def getting_started():
|
||||
|
||||
seed = breez_sdk.mnemonic_to_seed("<mnemonic words>")
|
||||
invite_code = "<invite code>"
|
||||
api_key = "<api key>"
|
||||
config = breez_sdk.default_config(
|
||||
breez_sdk.EnvironmentType.PRODUCTION,
|
||||
api_key,
|
||||
breez_sdk.NodeConfig.GREENLIGHT(breez_sdk.GreenlightNodeConfig(None, invite_code)))
|
||||
|
||||
# Customize the config object according to your needs
|
||||
config.working_dir = "path to an existing directory"
|
||||
|
||||
try:
|
||||
# Connect to the Breez SDK make it ready for use
|
||||
sdk_services = breez_sdk.connect(config, seed, SDKListener())
|
||||
|
||||
return sdk_services
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
# ANCHOR_END: init-sdk
|
||||
|
||||
def getting_started_node_info():
|
||||
|
||||
try:
|
||||
# ANCHOR: fetch-balance
|
||||
node_info = node_info()
|
||||
ln_balance = node_info.channels_balance_msat
|
||||
onchain_balance = node_info.onchain_balance_msat
|
||||
# ANCHOR_END: fetch-balance
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
|
||||
27
snippets/python_snippets/list_payments.py
Normal file
27
snippets/python_snippets/list_payments.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
|
||||
def list_payments():
|
||||
try:
|
||||
# ANCHOR: list-payments
|
||||
sdk_services.list_payments(breez_sdk.ListPaymentsRequest(breez_sdk.PaymentTypeFilter.All))
|
||||
# ANCHOR_END: list-payments
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
def list_payments_filtered():
|
||||
try:
|
||||
# ANCHOR: list-payments-filtered
|
||||
req = breez_sdk.ListPaymentsRequest(
|
||||
breez_sdk.PaymentTypeFilter.Sent,
|
||||
from_timestamp = 1696880000,
|
||||
include_failures = True)
|
||||
sdk_services.list_payments(req)
|
||||
# ANCHOR_END: list-payments-filtered
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
24
snippets/python_snippets/lnurl_auth.py
Normal file
24
snippets/python_snippets/lnurl_auth.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
def auth():
|
||||
# ANCHOR: lnurl-auth
|
||||
# Endpoint can also be of the form:
|
||||
# keyauth://domain.com/auth?key=val
|
||||
lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
|
||||
|
||||
try:
|
||||
parsed_input = breez_sdk.parse_input(lnurl_auth_url)
|
||||
if isinstance(parsed_input, breez_sdk.InputType.LN_URL_AUTH):
|
||||
req = breez_sdk
|
||||
result = sdk_services.lnurl_auth(parsed_input.data)
|
||||
if result.is_ok():
|
||||
logging.info("Successfully authenticated")
|
||||
else:
|
||||
logging.error("Failed to authenticate")
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
# ANCHOR_END: lnurl-auth
|
||||
22
snippets/python_snippets/lnurl_pay.py
Normal file
22
snippets/python_snippets/lnurl_pay.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
def pay():
|
||||
# ANCHOR: lnurl-pay
|
||||
# Endpoint can also be of the form:
|
||||
# lnurlp://domain.com/lnurl-pay?key=val
|
||||
# lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||
lnurl_pay_url = "lightning@address.com"
|
||||
try:
|
||||
parsed_input = breez_sdk.parse_input(lnurl_pay_url)
|
||||
if isinstance(parsed_input, breez_sdk.InputType.LN_URL_PAY):
|
||||
amount_msat = parsed_input.data.min_sendable
|
||||
req = breez_sdk.LnUrlPayRequest(parsed_input.data,amount_msat,"comment")
|
||||
result = sdk_services.pay_lnurl(req)
|
||||
# ANCHOR_END: lnurl-pay
|
||||
return result
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
21
snippets/python_snippets/lnurl_withdraw.py
Normal file
21
snippets/python_snippets/lnurl_withdraw.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
def withdraw():
|
||||
# ANCHOR: lnurl-withdraw
|
||||
# Endpoint can also be of the form:
|
||||
# lnurlw://domain.com/lnurl-withdraw?key=val
|
||||
lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
|
||||
|
||||
try:
|
||||
parsed_input = breez_sdk.parse_input(lnurl_withdraw_url)
|
||||
if isinstance(parsed_input, breez_sdk.InputType.LN_URL_WITHDRAW):
|
||||
amount_msat = parsed_input.data.min_withdrawable
|
||||
result = sdk_services.withdraw_lnurl(parsed_input.data, amount_msat, "comment")
|
||||
# ANCHOR_END: lnurl-withdraw
|
||||
return result
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
62
snippets/python_snippets/receive_onchain.py
Normal file
62
snippets/python_snippets/receive_onchain.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
def generate_receive_onchain_address():
|
||||
try:
|
||||
# ANCHOR: generate-receive-onchain-address
|
||||
swap_info = sdk_services.receive_onchain(breez_sdk.ReceiveOnchainRequest())
|
||||
|
||||
# Send your funds to the below bitcoin address
|
||||
address = swap_info.bitcoin_address
|
||||
# ANCHOR_END: generate-receive-onchain-address
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
def get_in_progress_swap():
|
||||
try:
|
||||
# ANCHOR: in-progress-swap
|
||||
swap_info = sdk_services.in_progress_swap()
|
||||
# ANCHOR_END: in-progress-swap
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
|
||||
def list_refundables():
|
||||
try:
|
||||
# ANCHOR: list-refundables
|
||||
refundables = sdk_services.list_refundables()
|
||||
# ANCHOR_END: list-refundables
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
def execute_refund(refundable):
|
||||
if refundable is breez_sdk.SwapInfo:
|
||||
# ANCHOR: execute-refund
|
||||
destination_address = "..."
|
||||
|
||||
sat_per_vbyte = 5
|
||||
try:
|
||||
result = sdk_services.refund(
|
||||
swap_address=refundable.bitcoin_address,
|
||||
to_address=destination_address,
|
||||
sat_per_vbyte=sat_per_vbyte)
|
||||
# ANCHOR_END: execute-refund
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
def get_channel_opening_fees(amount_msat,):
|
||||
try:
|
||||
# ANCHOR: get-channel-opening-fees
|
||||
req = breez_sdk.OpenChannelFeeRequest(amount_msat)
|
||||
channel_fees = sdk_services.open_channel_fee(req)
|
||||
# ANCHOR_END: get-channel-opening-fees
|
||||
return channel_fees
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
17
snippets/python_snippets/receive_payment.py
Normal file
17
snippets/python_snippets/receive_payment.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
def receive_payment():
|
||||
try:
|
||||
# ANCHOR: receive-payment
|
||||
req = breez_sdk.ReceivePaymentRequest(
|
||||
amount_msat=300000,
|
||||
description="Invoice for 300 000 sats")
|
||||
result = sdk_services.receive_payment(req)
|
||||
# ANCHOR_END: receive-payment
|
||||
return result
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
47
snippets/python_snippets/send_onchain.py
Normal file
47
snippets/python_snippets/send_onchain.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
def get_current_fees():
|
||||
try:
|
||||
# ANCHOR: estimate-current-reverse-swap-total-fees
|
||||
req = breez_sdk.ReverseSwapFeesRequest(send_amount_sat=50000)
|
||||
current_fees = sdk_services.fetch_reverse_swap_fees(req)
|
||||
logging.info("Total estimated fees for reverseswap: ", current_fees.total_estimated_fees)
|
||||
# ANCHOR_END: estimate-current-reverse-swap-total-fees
|
||||
return current_fees
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
def list_current_fees(current_fees):
|
||||
# ANCHOR: get-current-reverse-swap-min-max
|
||||
print("Minimum amount, in sats: ", current_fees.min)
|
||||
print("Maximum amount, in sats: ", current_fees.max)
|
||||
# ANCHOR_END: get-current-reverse-swap-min-max
|
||||
|
||||
def start_reverse_swap(current_fees,fee_rate):
|
||||
# ANCHOR: start-reverse-swap
|
||||
destination_address = "bc1.."
|
||||
amount_sat = 50000
|
||||
sat_per_vbyte = fee_rate
|
||||
try:
|
||||
req = breez_sdk.SendOnchainRequest(amount_sat, destination_address, current_fees.fee_hash, sat_per_vbyte)
|
||||
sdk_services.send_onchain(req)
|
||||
# ANCHOR_END: start-reverse-swap
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
def check_reverse_swap_status():
|
||||
try:
|
||||
# ANCHOR: check-reverse-swaps-status
|
||||
reverse_swaps = sdk_services.in_progress_reverse_swaps()
|
||||
for rs in reverse_swaps:
|
||||
logging.info("Reverse swap ",rs.id , " in progress, status is ", rs.status)
|
||||
# ANCHOR_END: check-reverse-swaps-status
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
|
||||
17
snippets/python_snippets/send_spontaneous_payment.py
Normal file
17
snippets/python_snippets/send_spontaneous_payment.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
def send_spontaneous_payment():
|
||||
# ANCHOR: send-spontaneous-payment
|
||||
node_id = "..."
|
||||
amount_msat = 300000
|
||||
try:
|
||||
req = breez_sdk.SendSpontaneousPaymentRequest(node_id,amount_msat)
|
||||
result = sdk_services.send_spontaneous_payment(req)
|
||||
return result
|
||||
# ANCHOR: send-spontaneous-payment
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
16
snippets/python_snippets/static_channel_backup.py
Normal file
16
snippets/python_snippets/static_channel_backup.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import breez_sdk
|
||||
import logging
|
||||
|
||||
sdk_services = breez_sdk.BlockingBreezServices
|
||||
|
||||
|
||||
def retrieve_backup_files():
|
||||
try:
|
||||
# ANCHOR: static-channel-backup
|
||||
req = breez_sdk.StaticBackupRequest(working_dir="<working directory>")
|
||||
backup_data = breez_sdk.static_backup(req)
|
||||
# ANCHOR_END: static-channel-backup
|
||||
return backup_data
|
||||
except Exception as error:
|
||||
logging.error(error)
|
||||
raise
|
||||
@@ -66,12 +66,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
buy_bitcoin_resp = sdk_services.buy_bitcoin(
|
||||
breez_sdk.BuyBitcoinRequest(
|
||||
breez_sdk.BuyBitcoinProvider.MOONPAY))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/buy_btc.py:buy-btc}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -61,12 +61,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
lsp_id = sdk_services.lsp_id()
|
||||
lsp_info = sdk_services.lsp_info()
|
||||
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/connecting_lsp.py:get-lsp-info}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -142,10 +137,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
sdk_services.connect_lsp(lsp_id)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/connecting_lsp.py:connect-lsp}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -43,11 +43,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
fiat_currencies = sdk_services.list_fiat_currencies()
|
||||
|
||||
except Exception as error:
|
||||
#Handle error
|
||||
{{#include ../../snippets/python_snippets/fiat_currencies.py:list-fiat-currencies}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -134,26 +134,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
# SDK events listener
|
||||
class SDKListener(breez_sdk.EventListener):
|
||||
def on_event(self, event):
|
||||
print(event)
|
||||
|
||||
# Create the default config
|
||||
seed = mnemonic_to_seed("<mnemonic words>")
|
||||
invite_code = "<invite code>"
|
||||
api_key = "<api key>"
|
||||
config = breez_sdk.default_config(breez_sdk.EnvironmentType.PRODUCTION, apiKey,
|
||||
breez_sdk.NodeConfig.GREENLIGHT(breez_sdk.GreenlightNodeConfig(None, invite_code)))
|
||||
|
||||
# Customize the config object according to your needs
|
||||
config.working_dir = "path to an existing directory"
|
||||
|
||||
try:
|
||||
# Connect to the Breez SDK make it ready for use
|
||||
sdk_services = breez_sdk.connect(config, seed, SDKListener())
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/getting_started.py:init-sdk}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -233,12 +214,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
node_info = node_info()
|
||||
ln_balance = node_info.channels_balance_msat
|
||||
onchain_balance = node_info.onchain_balance_msat
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/getting_started.py:fetch-balance}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -55,10 +55,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
sdk_services.list_payments(breez_sdk.ListPaymentsRequest(breez_sdk.PaymentTypeFilter.All))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/list_payments.py:list-payments}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -140,14 +137,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
sdk_services.list_payments(
|
||||
breez_sdk.ListPaymentsRequest(
|
||||
breez_sdk.PaymentTypeFilter.Sent,
|
||||
from_timestamp = 1696880000,
|
||||
include_failures = True))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/list_payments.py:list-payments-filtered}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -77,20 +77,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
# Endpoint can also be of the form:
|
||||
# keyauth://domain.com/auth?key=val
|
||||
lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
|
||||
|
||||
try:
|
||||
parsed_input = breez_sdk.parse_input(lnurl_auth_url)
|
||||
if isinstance(parsed_input, breez_sdk.InputType.LN_URL_AUTH):
|
||||
result = sdk_services.lnurl_auth(parsed_input.data)
|
||||
if result.is_ok():
|
||||
print("Successfully authenticated")
|
||||
else:
|
||||
print("Failed to authenticate")
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/lnurl_auth.py:lnurl-auth}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -75,22 +75,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
# Endpoint can also be of the form:
|
||||
# lnurlp://domain.com/lnurl-pay?key=val
|
||||
# lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||
lnurl_pay_url = "lightning@address.com"
|
||||
|
||||
try:
|
||||
parsed_input = breez_sdk.parse_input(lnurl_pay_url)
|
||||
if isinstance(parsed_input, breez_sdk.InputType.LN_URL_PAY):
|
||||
amount_msat = parsed_input.data.min_sendable
|
||||
result = sdk_service.pay_lnurl(
|
||||
breez_sdk.LnUrlPayRequest(
|
||||
data=parsed_input.data,
|
||||
amount_msat=amount_msat,
|
||||
comment="comment"))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/lnurl_pay.py:lnurl-pay}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -79,17 +79,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
# Endpoint can also be of the form:
|
||||
# lnurlw://domain.com/lnurl-withdraw?key=val
|
||||
lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
|
||||
|
||||
try:
|
||||
parsed_input = breez_sdk.parse_input(lnurl_withdraw_url)
|
||||
if isinstance(parsed_input, breez_sdk.InputType.LN_URL_WITHDRAW):
|
||||
amount_msat = parsed_input.data.min_withdrawable
|
||||
result = sdk_services.withdraw_lnurl(breez_sdk.LnUrlWithdrawRequest(data=parsed_input.data, amount_msat=amount_msat, description="comment"))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/lnurl_withdraw.py:lnurl-withdraw}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -63,13 +63,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
swap_info = sdk_services.receive_onchain(breez_sdk.ReceiveOnchainRequest())
|
||||
|
||||
# Send your funds to the below bitcoin address
|
||||
address = swap_info.bitcoin_address
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/receive_onchain.py:generate-receive-onchain-address}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -145,10 +139,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
swap_info = sdk_services.in_progress_swap()
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/receive_onchain.py:in-progress-swap}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -230,10 +221,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
refundables = sdk_services.list_refundables()
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/receive_onchain.py:list-refundables}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -318,15 +306,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
destination_address = "..."
|
||||
sat_per_vbyte = 5
|
||||
|
||||
try:
|
||||
result = sdk_services.refund(swap_address=refundable.bitcoin_address,
|
||||
to_address=destination_address,
|
||||
sat_per_vbyte=sat_per_vbyte)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/receive_onchain.py:execute-refund}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -404,13 +384,7 @@ do {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
amount_msat = <amount msats>
|
||||
try:
|
||||
channel_fees = sdk_services.open_channel_fee(
|
||||
breez_sdk.OpenChannelFeeRequest(
|
||||
amount_msat=amount_msat))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/receive_onchain.py:get-channel-opening-fees}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -62,13 +62,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
receive_payment_response = sdk_services.receive_payment(
|
||||
breez_sdk.ReceivePaymentRequest(
|
||||
amount_msat=3_000_000,
|
||||
description="Invoice for 3000 sats"))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/receive_payment.py:receive-payment}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -61,12 +61,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
current_fees = sdk_services.fetch_reverse_swap_fees(
|
||||
breez_sdk.ReverseSwapFeesRequest(send_amount_sat=50000))
|
||||
print("Total estimated fees for reverseswap: ", current_fees.total_estimated_fees)
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/send_onchain.py:estimate-current-reverse-swap-total-fees}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -140,8 +135,7 @@ Log.v("Breez", "Maximum amount, in sats: ${fees.max}")
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
print("Minimum amount, in sats: ", current_fees.min)
|
||||
print("Maximum amount, in sats: ", current_fees.max)
|
||||
{{#include ../../snippets/python_snippets/send_onchain.py:get-current-reverse-swap-min-max}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -227,16 +221,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
destination_address = "bc1.."
|
||||
amount_sat = 50000
|
||||
sat_per_vbyte = 5
|
||||
try:
|
||||
sdk_services.send_onchain(amount_sat=amount_sat,
|
||||
onchain_recipient_address=destination_address,
|
||||
pair_hash=current_fees.fee_hash,
|
||||
sat_per_vbyte=sat_per_vbyte)
|
||||
except Exception as error:
|
||||
# Handle erorr
|
||||
{{#include ../../snippets/python_snippets/send_onchain.py:start-reverse-swap}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -312,12 +297,7 @@ for (rs in sdk.inProgressReverseSwaps()) {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
reverse_swaps = sdk_services.in_progress_reverse_swaps()
|
||||
for rs in reverse_swaps:
|
||||
print("Reverse swap ",rs.id , " in progress, status is ", rs.status)
|
||||
except Exception as error:
|
||||
# Handle erorr
|
||||
{{#include ../../snippets/python_snippets/send_onchain.py:check-reverse-swaps-status}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -62,13 +62,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
sdk_services.send_spontaneous_payment(
|
||||
breez_sdk.SendSpontaneousPaymentRequest(
|
||||
node_id="...",
|
||||
amount_msat=3000000))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/send_spontaneous_payment.py:send-spontaneous-payment}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -64,10 +64,7 @@ try {
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
backup_data = breez_sdk.static_backup(breez_sdk.StaticBackupRequest(working_dir="<working directory>"))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
{{#include ../../snippets/python_snippets/static_channel_backup.py:static-channel-backup}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user