Merge pull request #60 from breez/savage-python-fixes

Python fixes and getting started consistency between examples
This commit is contained in:
Ross Savage
2023-10-09 10:01:59 +02:00
committed by GitHub
5 changed files with 42 additions and 41 deletions

View File

@@ -40,12 +40,13 @@ Now your SDK is ready to be used.
```rust,ignore
let mnemonic = Mnemonic::generate_in(Language::English, 12)?;
let seed = mnemonic.to_seed("");
let invite_code = Some("...".into());
let invite_code = Some("<invite code>".into());
let api_key = "<api key>".into()
// Create the default config
let mut config = BreezServices::default_config(
EnvironmentType::Production,
"your API key".into(),
api_key,
breez_sdk_core::NodeConfig::Greenlight {
config: GreenlightNodeConfig {
partner_credentials: None,
@@ -80,11 +81,12 @@ class SDKListener: EventListener {
}
// Create the default config
let seed = try mnemonicToSeed(phrase: "<mnemonics words>")
let inviteCode = "your invite code"
let config = breez_sdk.defaultConfig(envType: EnvironmentType.production, apiKey: "",
let seed = try mnemonicToSeed(phrase: "<mnemonic words>")
let inviteCode = "<invite code>"
let apiKey = "<api key>"
let config = breez_sdk.defaultConfig(envType: EnvironmentType.production, apiKey: apiKey,
nodeConfig: NodeConfig.greenlight(
config: GreenlightNodeConfig(partnerCredentials: nil,inviteCode: inviteCode)));
config: GreenlightNodeConfig(partnerCredentials: nil, inviteCode: inviteCode)));
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
@@ -111,14 +113,14 @@ class SDKListener : EventListener {
}
// Select your seed, invite code and eviroment
val seed = mnemonicToSeed("<mnemonics words>")
val inviteCode = "your invite code"
val environmentType = EnvironmentType.PRODUCTION
val seed = mnemonicToSeed("<mnemonic words>")
val inviteCode = "<invite code>"
val apiKey = "<api key>"
// Create the default config
val greenlightNodeConfig = GreenlightNodeConfig(null, inviteCode)
val nodeConfig = NodeConfig.Greenlight(greenlightNodeConfig)
val config = defaultConfig(environmentType, inviteCode, nodeConfig)
val config = defaultConfig(EnvironmentType.PRODUCTION, apiKey, nodeConfig)
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
@@ -143,15 +145,16 @@ const onBreezEvent = (event: BreezEvent) => {
})
// Create the default config
const seed = await mnemonicToSeed("<mnemonics words>")
const inviteCode = "<your greenlight invite code>"
const seed = await mnemonicToSeed("<mnemonic words>")
const inviteCode = "<invite code>"
const apiKey = "<api key>"
const nodeConfig : NodeConfig = {
type: NodeConfigVariant.GREENLIGHT,
config: {
inviteCode: "your invite code"
inviteCode: inviteCode
}
}
let config = await defaultConfig(EnvironmentType.PRODUCTION, "api key", nodeConfig)
let config = await defaultConfig(EnvironmentType.PRODUCTION, apiKey, nodeConfig)
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
@@ -182,9 +185,10 @@ breezLogStream().listen((log) {
// Create the default config
Uint8List seed = await mnemonicToSeed(phrase: "<mnemonic words>");
String inviteCode = "<your greenlight invite code>";
String inviteCode = "<invite code>";
String apiKey = "<api key>"
NodeConfg nodeConfig = NodeConfig.greenlight(config: GreenlightNodeConfig(partnerCredentials: null, inviteCode: inviteCode));
Config config = await defaultConfig(configType: EnvironmentType.Production, apiKey: "<your API key>", nodeConfig: nodeConfig);
Config config = await defaultConfig(configType: EnvironmentType.Production, apiKey: apiKey, nodeConfig: nodeConfig);
// Customize the config object according to your needs
config.workingDir = "path to an existing directory";
@@ -208,9 +212,10 @@ class SDKListener(breez_sdk.EventListener):
print(event)
# Create the default config
seed = mnemonic_to_seed("<mnemonics words>")
invite_code = "<your greenlight invite code>"
config = breez_sdk.default_config(breez_sdk.EnvironmentType.PRODUCTION, "api key",
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
@@ -236,13 +241,13 @@ func (BreezListener) OnEvent(e breez_sdk.BreezEvent) {
}
// Create the default config
seed, err := breez_sdk.MnemonicToSeed("<mnemonics words>")
seed, err := breez_sdk.MnemonicToSeed("<mnemonic words>")
if err != nil {
log.Fatalf("MnemonicToSeed failed: %#v", err)
}
apiKey := "<your breez api key>"
inviteCode := "<your greenlight invite code>"
inviteCode := "<invite code>"
apiKey := "<api key>"
nodeConfig := breez_sdk.NodeConfigGreenlight{
Config: breez_sdk.GreenlightNodeConfig{
PartnerCredentials: nil,
@@ -273,7 +278,7 @@ if err != nil {
using Breez.Sdk;
// Create the default config
var seed = BreezSdkMethods.MnemonicToSeed("<mnemonics words>");
var seed = BreezSdkMethods.MnemonicToSeed("<mnemonic words>");
var inviteCode = "<invite code>";
var apiKey = "<api key>";
var nodeConfig = new NodeConfig.Greenlight(

View File

@@ -127,7 +127,7 @@ try {
```python
# Endpoint can also be of the form:
# keyauth://domain.com/auth?key=val
lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
try:
parsed_input = breez_sdk.parse_input(lnurl_auth_url)

View File

@@ -117,7 +117,7 @@ try {
lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
try:
parsed_input = parse_input(lnurl_withdraw_url)
parsed_input = breez_sdk.parse_input(lnurl_withdraw_url)
if isinstance(parsed_input, breez_sdk.InputType.LN_URL_WITHDRAW):
amount_sats = parsed_input.data.min_withdrawable
result = sdk_services.withdraw_lnurl(parsed_input.data, amount_sats, "comment")

View File

@@ -88,7 +88,7 @@ try:
swap_info = sdk_services.receive_onchain(breez_sdk.ReceiveOnchainRequest())
# Send your funds to the below bitcoin address
address = sdk_services.swap_info.bitcoin_address
address = swap_info.bitcoin_address
except Exception as error:
# Handle error
```
@@ -405,13 +405,12 @@ try {
```python
destination_address = "..."
sat_per_vbyte = <refund tx fee rate>
sat_per_vbyte = 5
try:
result = sdk_services.refund(
swap_address=refundable.bitcoin_address,
to_address=to_address,
sat_per_vbyte=sat_per_vbyte)
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
```

View File

@@ -86,7 +86,7 @@ try {
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)
print("Total estimated fees for reverseswap: ", current_fees.total_estimated_fees)
except Exception as error:
# Handle error
```
@@ -294,16 +294,13 @@ try {
```python
destination_address = "bc1.."
amount_sat = current_fees.min
fee_hash = current_fees.fee_hash
sat_per_vbyte = <fee rate>
amount_sat = 50000
sat_per_vbyte = 5
try:
sdk_services.send_onchain(
amount_sat=amount_msats,
onchain_recipient_address="...",
pair_hash=current_fees.fee_hash,
sat_per_vbyte=sat_per_vbyte)
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
```