Skip to content

Commit

Permalink
feat: add new button to create validator address on pactos GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Jemilu Mohammed committed Oct 20, 2023
1 parent 1c59a2d commit 07b9130
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
15 changes: 15 additions & 0 deletions cmd/gtk/assets/ui/widget_wallet.ui
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="id_button_new_validator_address">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Create new validator address</property>
<property name="is-important">True</property>
<property name="label" translatable="yes">_New Validator Address</property>
<property name="use-underline">True</property>
<signal name="clicked" handler="on_new_validator_address" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="id_button_change_password">
<property name="visible">True</property>
Expand Down
12 changes: 10 additions & 2 deletions cmd/gtk/model_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 12 additions & 4 deletions cmd/gtk/widget_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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)

Expand All @@ -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)
}

Expand Down
17 changes: 9 additions & 8 deletions cmd/wallet/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down
11 changes: 11 additions & 0 deletions wallet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 23 in wallet/client.go

View check run for this annotation

Codecov / codecov/patch

wallet/client.go#L23

Added line #L23 was not covered by tests
}

type grpcClient struct {
blockchainClient pactus.BlockchainClient
transactionClient pactus.TransactionClient
Expand Down

0 comments on commit 07b9130

Please sign in to comment.