Skip to content

Commit

Permalink
Add scheme configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoe committed Jul 3, 2023
1 parent 9d68b43 commit a384dba
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
8 changes: 8 additions & 0 deletions tools/wasp-cli/cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,11 @@ func GetChain(name string) isc.ChainID {
log.Check(err)
return chainID
}

func GetWalletSchemeString() string {
return viper.GetString("wallet.scheme")
}

func SetWalletSchemeString(scheme string) {
Set("wallet.scheme", scheme)
}
43 changes: 36 additions & 7 deletions tools/wasp-cli/cli/wallet/wallet.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package wallet

import (
"github.com/spf13/viper"
"errors"
"fmt"
"runtime"

wasp_wallet_sdk "github.com/iotaledger/wasp-wallet-sdk"
"github.com/iotaledger/wasp/tools/wasp-cli/cli/config"
"github.com/iotaledger/wasp/tools/wasp-cli/cli/wallet/providers"
"github.com/iotaledger/wasp/tools/wasp-cli/cli/wallet/wallets"
"github.com/iotaledger/wasp/tools/wasp-cli/log"
)

var AddressIndex uint32

type WalletScheme string

const (
SchemeInMemory = "in_memory"
SchemeLedger = "sdk_ledger"
SchemeStronghold = "sdk_stronghold"
SchemeInMemory WalletScheme = "in_memory"
SchemeLedger WalletScheme = "sdk_ledger"
SchemeStronghold WalletScheme = "sdk_stronghold"
)

func GetWalletScheme() string {
scheme := viper.GetString("wallet.scheme")
func GetWalletScheme() WalletScheme {
scheme := WalletScheme(config.GetWalletSchemeString())

switch scheme {
case SchemeLedger, SchemeInMemory, SchemeStronghold:
Expand All @@ -27,8 +32,32 @@ func GetWalletScheme() string {
return SchemeInMemory
}

func SetWalletScheme(scheme WalletScheme) error {
switch scheme {
case SchemeLedger, SchemeInMemory, SchemeStronghold:
config.SetWalletSchemeString(string(scheme))
return nil
}
return errors.New("invalid wallet scheme provided")
}

func getIotaSDKLibName() string {
switch runtime.GOOS {
case "windows":
return "iota_sdk_native.dll"
case "linux":
return "libiota_sdk_native.so"
case "darwin":
return "libiota_sdk_native.dylib"
default:
panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS))
}
}

func getIotaSDK() *wasp_wallet_sdk.IOTASDK {
sdk, err := wasp_wallet_sdk.NewIotaSDK("/home/luke/dev/iota-sdk/target/release/libiota_sdk_go.so")
// LoadLibrary (windows) and dlLoad (linux) have different search path behaviors
// For now, use a relative path - as it will eventually be shipped with a release.
sdk, err := wasp_wallet_sdk.NewIotaSDK(getIotaSDKLibName())
log.Check(err)
return sdk
}
Expand Down
1 change: 1 addition & 0 deletions tools/wasp-cli/wallet/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func Init(rootCmd *cobra.Command) {
rootCmd.AddCommand(initBalanceCmd())
rootCmd.AddCommand(initSendFundsCmd())
rootCmd.AddCommand(initRequestFundsCmd())
rootCmd.AddCommand(initSchemeCmd())

rootCmd.PersistentFlags().Uint32VarP(&wallet.AddressIndex, "address-index", "i", 0, "address index")
}
24 changes: 24 additions & 0 deletions tools/wasp-cli/wallet/scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package wallet

import (
"github.com/spf13/cobra"

"github.com/iotaledger/wasp/tools/wasp-cli/cli/wallet"
"github.com/iotaledger/wasp/tools/wasp-cli/log"
)

func initSchemeCmd() *cobra.Command {
return &cobra.Command{
Use: "wallet-scheme (in_memory, sdk_ledger, sdk_stronghold)",
Short: "Get or set wallet scheme (in_memory, sdk_ledger, sdk_stronghold)",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
log.Printf("Wallet scheme: %s\n", string(wallet.GetWalletScheme()))
return
}

log.Check(wallet.SetWalletScheme(wallet.WalletScheme(args[0])))
},
}
}

0 comments on commit a384dba

Please sign in to comment.