mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 12:44:19 +01:00
CLI with ARK Sdk (#307)
* Export new methods * Use sdk in CLI * pr review refactor * go sync * Fixes * run integration test on every change * fixes * go sync * fix * Persist explorer url * Fix decoding bitcoin address * Add missing timeout to e2e test * Fix * Fixes --------- Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ark-network/ark/common"
|
||||
"github.com/ark-network/ark/pkg/client-sdk/client"
|
||||
"github.com/ark-network/ark/pkg/client-sdk/explorer"
|
||||
"github.com/ark-network/ark/pkg/client-sdk/internal/utils"
|
||||
@@ -38,6 +39,18 @@ var (
|
||||
ErrNotInitialized = fmt.Errorf("client not initialized")
|
||||
)
|
||||
|
||||
var (
|
||||
defaultNetworks = utils.SupportedType[string]{
|
||||
common.Liquid.Name: "https://blockstream.info/liquid/api",
|
||||
common.LiquidTestNet.Name: "https://blockstream.info/liquidtestnet/api",
|
||||
common.LiquidRegTest.Name: "http://localhost:3001",
|
||||
common.Bitcoin.Name: "https://blockstream.info/api",
|
||||
common.BitcoinTestNet.Name: "https://blockstream.info/testnet/api",
|
||||
common.BitcoinRegTest.Name: "http://localhost:3000",
|
||||
common.BitcoinSigNet.Name: "https://mutinynet.com/api",
|
||||
}
|
||||
)
|
||||
|
||||
type arkClient struct {
|
||||
*store.StoreData
|
||||
wallet wallet.WalletService
|
||||
@@ -74,7 +87,7 @@ func (a *arkClient) InitWithWallet(
|
||||
return fmt.Errorf("failed to connect to asp: %s", err)
|
||||
}
|
||||
|
||||
explorerSvc, err := getExplorer(supportedNetworks, info.Network)
|
||||
explorerSvc, err := getExplorer(args.ExplorerURL, info.Network)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to setup explorer: %s", err)
|
||||
}
|
||||
@@ -138,7 +151,7 @@ func (a *arkClient) Init(
|
||||
return fmt.Errorf("failed to connect to asp: %s", err)
|
||||
}
|
||||
|
||||
explorerSvc, err := getExplorer(supportedNetworks, info.Network)
|
||||
explorerSvc, err := getExplorer(args.ExplorerURL, info.Network)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to setup explorer: %s", err)
|
||||
}
|
||||
@@ -164,6 +177,7 @@ func (a *arkClient) Init(
|
||||
UnilateralExitDelay: info.UnilateralExitDelay,
|
||||
Dust: info.Dust,
|
||||
BoardingDescriptorTemplate: info.BoardingDescriptorTemplate,
|
||||
ExplorerURL: args.ExplorerURL,
|
||||
}
|
||||
walletSvc, err := getWallet(a.store, &storeData, supportedWallets)
|
||||
if err != nil {
|
||||
@@ -201,6 +215,10 @@ func (a *arkClient) IsLocked(ctx context.Context) bool {
|
||||
return a.wallet.IsLocked()
|
||||
}
|
||||
|
||||
func (a *arkClient) Dump(ctx context.Context) (string, error) {
|
||||
return a.wallet.Dump(ctx)
|
||||
}
|
||||
|
||||
func (a *arkClient) Receive(ctx context.Context) (string, string, error) {
|
||||
offchainAddr, boardingAddr, err := a.wallet.NewAddress(ctx, false)
|
||||
if err != nil {
|
||||
@@ -254,15 +272,14 @@ func getClient(
|
||||
return factory(aspUrl)
|
||||
}
|
||||
|
||||
func getExplorer(
|
||||
supportedNetworks utils.SupportedType[string], network string,
|
||||
) (explorer.Explorer, error) {
|
||||
url, ok := supportedNetworks[network]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid network")
|
||||
func getExplorer(explorerURL, network string) (explorer.Explorer, error) {
|
||||
if explorerURL == "" {
|
||||
var ok bool
|
||||
if explorerURL, ok = defaultNetworks[network]; !ok {
|
||||
return nil, fmt.Errorf("invalid network")
|
||||
}
|
||||
}
|
||||
|
||||
return explorer.NewExplorer(url, utils.NetworkFromString(network)), nil
|
||||
return explorer.NewExplorer(explorerURL, utils.NetworkFromString(network)), nil
|
||||
}
|
||||
|
||||
func getWallet(
|
||||
|
||||
Reference in New Issue
Block a user