mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 14:24:19 +01:00
python snippets
This commit is contained in:
@@ -65,13 +65,8 @@ try {
|
||||
<div slot="title">Python</div>
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
buy_bitcoin_resp = sdk_services.buy_bitcoin(
|
||||
breez_sdk.BuyBitcoinRequest(
|
||||
breez_sdk.BuyBitcoinProvider.MOONPAY))
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```python,ignore
|
||||
{{#include ../../snippets/python_snippets/buy_btc.py:buy-btc}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -60,13 +60,8 @@ try {
|
||||
<div slot="title">Python</div>
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
try:
|
||||
lsp_id = sdk_services.lsp_id()
|
||||
lsp_info = sdk_services.lsp_info()
|
||||
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```python,ignore
|
||||
{{#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