Skip to content

Commit

Permalink
Update snippets with new connect() signature (#136)
Browse files Browse the repository at this point in the history
* Update snippets with new connect() signature

* Update getting started and include restore only example

* CI: Use matching SDK commit

* Fix dart snippet

* Fix go snippet

* Update SDK ref commit post RN codegen

* Fix RN call to connect()

---------

Co-authored-by: Ross Savage <[email protected]>
  • Loading branch information
ok300 and dangeross authored Mar 12, 2024
1 parent cb00524 commit 216763e
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: setup
runs-on: ubuntu-latest
outputs:
sdk-ref: ${{ inputs.sdk-ref || '0.3.1' }}
sdk-ref: ${{ inputs.sdk-ref || '05307d0c764a1efe73d7e546f77e1fcc03d63b23' }}
package-version: '0.3.1'
steps:
- run: echo "set pre-setup output variables"
Expand Down
19 changes: 18 additions & 1 deletion snippets/csharp/GettingStarted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void GettingStarted()
try
{
// Connect to the Breez SDK make it ready for use
sdk = BreezSdkMethods.Connect(config, seed, new SdkListener());
var connectRequest = new ConnectRequest(config, seed);
sdk = BreezSdkMethods.Connect(connectRequest, new SdkListener());
}
catch (Exception)
{
Expand All @@ -44,6 +45,22 @@ public void OnEvent(BreezEvent e)
}
// ANCHOR_END: init-sdk

public void GettingStartedRestoreOnly(Config config, List<byte> seed)
{
BlockingBreezServices sdk;
try
{
// ANCHOR: init-sdk-restore-only
var connectRequest = new ConnectRequest(config, seed, true);
sdk = BreezSdkMethods.Connect(connectRequest, new SdkListener());
// ANCHOR_END: init-sdk-restore-only
}
catch (Exception)
{
// Handle error
}
}

public void FetchNodeInfo(BlockingBreezServices sdk)
{
// ANCHOR: fetch-balance
Expand Down
10 changes: 9 additions & 1 deletion snippets/dart_snippets/lib/getting_started.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ Future<void> initializeSDK() async {
config = config.copyWith(workingDir: "path to an existing directory");

// Connect to the Breez SDK make it ready for use
return await BreezSDK().connect(config: config, seed: seed);
ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed);
return await BreezSDK().connect(req: connectRequest);
// ANCHOR_END: init-sdk
}

Future<void> connectRestoreOnly(Config config, Uint8List seed) async {
// ANCHOR: init-sdk-restore-only
ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed, restoreOnly: true);
return await BreezSDK().connect(req: connectRequest);
// ANCHOR_END: init-sdk-restore-only
}

Future<void> fetchBalance(String lspId) async {
// ANCHOR: fetch-balance
NodeState? nodeInfo = await BreezSDK().nodeInfo();
Expand Down
20 changes: 19 additions & 1 deletion snippets/go/getting_started.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func GettingStarted() *breez_sdk.BlockingBreezServices {
// Customize the config object according to your needs
config.WorkingDir = "path to an existing directory"

sdk, err := breez_sdk.Connect(config, seed, BreezListener{})
connectRequest := breez_sdk.ConnectRequest{Config: config, Seed: seed}
sdk, err := breez_sdk.Connect(connectRequest, BreezListener{})
if err != nil {
log.Fatalf("Connect failed: %#v", err)
}
Expand All @@ -43,6 +44,23 @@ func GettingStarted() *breez_sdk.BlockingBreezServices {
}

// ANCHOR_END: init-sdk

func GettingStartedRestoreOnly(config breez_sdk.Config, seed []uint8) *breez_sdk.BlockingBreezServices {
// ANCHOR: init-sdk-restore-only
restoreOnly := true
connectRequest := breez_sdk.ConnectRequest{
Config: config,
Seed: seed,
RestoreOnly: &restoreOnly,
}
sdk, err := breez_sdk.Connect(connectRequest, BreezListener{})
// ANCHOR_END: init-sdk-restore-only
if err != nil {
log.Fatalf("Connect failed: %#v", err)
}
return sdk
}

func FetchBalance() {
// ANCHOR: fetch-balance
if nodeInfo, err := sdk.NodeInfo(); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@ class GettingStarted {

try {
// Connect to the Breez SDK make it ready for use
val sdk = connect(config, seed, SDKListener())
val connectRequest = ConnectRequest(config, seed)
val sdk = connect(connectRequest, SDKListener())
} catch (e: Exception) {
// handle error
}
// ANCHOR_END: init-sdk
}

fun start_restore_only(config: Config, seed: List<UByte>) {
try {
// ANCHOR: init-sdk-restore-only
val connectRequest = ConnectRequest(config, seed, true)
val sdk = connect(connectRequest, SDKListener())
// ANCHOR_END: init-sdk-restore-only
} catch (e: Exception) {
// handle error
}
}

fun fetch_balance(sdk: BlockingBreezServices) {
// ANCHOR: fetch-balance
try {
Expand Down
14 changes: 13 additions & 1 deletion snippets/python/src/getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ def getting_started(API_KEY,mnemonic,temp_dir):

try:
# Connect to the Breez SDK make it ready for use
sdk_services = breez_sdk.connect(config, seed, SDKListener())
connect_request = breez_sdk.ConnectRequest(config, seed)
sdk_services = breez_sdk.connect(connect_request, SDKListener())

return sdk_services
except Exception as error:
logging.error(error)
raise
# ANCHOR_END: init-sdk

def getting_started_restore_only(config, seed):
try:
# ANCHOR: init-sdk-restore-only
connect_request = breez_sdk.ConnectRequest(config, seed, restore_only=True)
sdk_services = breez_sdk.connect(connect_request, SDKListener())
# ANCHOR_END: init-sdk-restore-only
return sdk_services
except Exception as error:
logging.error(error)
raise

def getting_started_node_info(sdk_services):

try:
Expand Down
20 changes: 19 additions & 1 deletion snippets/react-native/getting_started.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
type BreezEvent,
connect,
type Config,
type ConnectRequest,
defaultConfig,
EnvironmentType,
mnemonicToSeed,
Expand Down Expand Up @@ -35,13 +37,29 @@ const exampleGettingStarted = async () => {
)

// Connect to the Breez SDK make it ready for use
await connect(config, seed, onBreezEvent)
const connectRequest: ConnectRequest = { config, seed }
await connect(connectRequest, onBreezEvent)
} catch (err) {
console.error(err)
}
// ANCHOR_END: init-sdk
}

const onBreezEvent = (e: BreezEvent) => {
console.log(`Received event ${e.type}`)
}

const exampleGettingRestoreOnly = async (config: Config, seed: number[]) => {
try {
// ANCHOR: init-sdk-restore-only
const connectRequest: ConnectRequest = { config, seed, restoreOnly: true }
await connect(connectRequest, onBreezEvent)
// ANCHOR_END: init-sdk-restore-only
} catch (err) {
console.error(err)
}
}

const exampleFetchNodeInfo = async () => {
// ANCHOR: fetch-balance
try {
Expand Down
Loading

0 comments on commit 216763e

Please sign in to comment.