python snippets

This commit is contained in:
ruben beck
2023-10-25 17:17:08 +02:00
committed by ok300
parent f16fd23a21
commit 1f6c87c774
26 changed files with 388 additions and 175 deletions

View 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