diff --git a/cmd/gtk/assets/ui/widget_wallet.ui b/cmd/gtk/assets/ui/widget_wallet.ui index fb8143dd9..3eb89b4f3 100644 --- a/cmd/gtk/assets/ui/widget_wallet.ui +++ b/cmd/gtk/assets/ui/widget_wallet.ui @@ -253,6 +253,21 @@ True + + + True + False + Create new validator address + True + _New Validator Address + True + + + + False + True + + True diff --git a/cmd/gtk/model_wallet.go b/cmd/gtk/model_wallet.go index d87f4b653..3783d90dc 100644 --- a/cmd/gtk/model_wallet.go +++ b/cmd/gtk/model_wallet.go @@ -85,8 +85,16 @@ func (model *walletModel) rebuildModel() { }() } -func (model *walletModel) createAddress() error { - address, err := model.wallet.NewBLSAccountAddress("") +func (model *walletModel) createAddress(accountType wallet.AddressType) error { + var address string + var err error + + if accountType == wallet.AddressTypeBLSAccount { + address, err = model.wallet.NewBLSAccountAddress("") + } else { + address, err = model.wallet.NewValidatorAddress("") + } + if err != nil { return err } diff --git a/cmd/gtk/widget_wallet.go b/cmd/gtk/widget_wallet.go index 6bb07efaa..78e19079a 100644 --- a/cmd/gtk/widget_wallet.go +++ b/cmd/gtk/widget_wallet.go @@ -8,6 +8,7 @@ import ( "github.com/gotk3/gotk3/gdk" "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" + "github.com/pactus-project/pactus/wallet" ) // IDs to access the tree view columns. @@ -55,6 +56,7 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) { labelEncrypted := getLabelObj(builder, "id_label_wallet_encrypted") getToolButtonObj(builder, "id_button_new_address").SetIconWidget(AddIcon()) + getToolButtonObj(builder, "id_button_new_validator_address").SetIconWidget(AddIcon()) getToolButtonObj(builder, "id_button_change_password").SetIconWidget(PasswordIcon()) getToolButtonObj(builder, "id_button_show_seed").SetIconWidget(SeedIcon()) @@ -136,9 +138,10 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) { }) signals := map[string]interface{}{ - "on_new_address": w.onNewAddress, - "on_change_password": w.onChangePassword, - "on_show_seed": w.onShowSeed, + "on_new_address": w.onNewAddress, + "on_new_validator_address": w.onNewValidatorAddress, + "on_change_password": w.onChangePassword, + "on_show_seed": w.onShowSeed, } builder.ConnectSignals(signals) @@ -148,7 +151,12 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) { } func (ww *widgetWallet) onNewAddress() { - err := ww.model.createAddress() + err := ww.model.createAddress(wallet.AddressTypeBLSAccount) + errorCheck(err) +} + +func (ww *widgetWallet) onNewValidatorAddress() { + err := ww.model.createAddress(wallet.AddressTypeValidator) errorCheck(err) } diff --git a/cmd/wallet/address.go b/cmd/wallet/address.go index e1d5ae58b..cd85e2c13 100644 --- a/cmd/wallet/address.go +++ b/cmd/wallet/address.go @@ -6,6 +6,7 @@ import ( "github.com/pactus-project/pactus/cmd" "github.com/pactus-project/pactus/crypto/bls" "github.com/pactus-project/pactus/util" + w "github.com/pactus-project/pactus/wallet" "github.com/spf13/cobra" ) @@ -76,11 +77,8 @@ func buildNewAddressCmd(parentCmd *cobra.Command) { } parentCmd.AddCommand(newAddressCmd) - blsAddressOption := "bls_account" - validatorAddressOption := "validator" - addressType := newAddressCmd.Flags().String("address_type", - blsAddressOption, "Address type to create") + w.AddressTypeBLSAccount.String(), "Address type to create") newAddressCmd.Run = func(_ *cobra.Command, _ []string) { var addr string @@ -90,16 +88,19 @@ func buildNewAddressCmd(parentCmd *cobra.Command) { wallet, err := openWallet() cmd.FatalErrorCheck(err) - if *addressType != blsAddressOption || *addressType != validatorAddressOption { - cmd.PrintErrorMsgf("Invalid address type. Supported address types are 'validator' and 'bls_account'") + isForBLSAccount := *addressType == w.AddressTypeBLSAccount.String() + isForValidatorAccount := *addressType == w.AddressTypeValidator.String() + + if !isForBLSAccount || !isForValidatorAccount { + cmd.PrintErrorMsgf("Invalid address type. Supported address types are '%s' and '%s'", w.AddressTypeBLSAccount, w.AddressTypeValidator) return } - if *addressType == blsAddressOption { + if isForBLSAccount { addr, err = wallet.NewBLSAccountAddress(label) } - if *addressType == validatorAddressOption { + if isForValidatorAccount { addr, err = wallet.NewValidatorAddress(label) } diff --git a/wallet/client.go b/wallet/client.go index e7e6c8480..3ca2c955c 100644 --- a/wallet/client.go +++ b/wallet/client.go @@ -12,6 +12,17 @@ import ( "google.golang.org/grpc/credentials/insecure" ) +type AddressType string + +var ( + AddressTypeBLSAccount AddressType = "bls_account" + AddressTypeValidator AddressType = "validator" +) + +func (a AddressType) String() string { + return string(a) +} + type grpcClient struct { blockchainClient pactus.BlockchainClient transactionClient pactus.TransactionClient