Skip to content

Commit

Permalink
Addressed remaining PR comments - different types than sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Aug 11, 2021
1 parent a63681f commit 0a21e3f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
7 changes: 4 additions & 3 deletions x/poe/contract/contractio.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ type Executor interface {
}

// RegisterValidator calls valset contract to register a new validator key and address
func RegisterValidator(ctx sdk.Context, contractAddr sdk.AccAddress, pk cryptotypes.PubKey, delegatorAddress sdk.AccAddress, metadata stakingtypes.Description, k Executor) error {
func RegisterValidator(ctx sdk.Context, contractAddr sdk.AccAddress, pk cryptotypes.PubKey, delegatorAddress sdk.AccAddress, description stakingtypes.Description, k Executor) error {
pub, err := NewValidatorPubkey(pk)
if err != nil {
return err
}
registerValidator := TG4ValsetExecute{
RegisterValidatorKey: &RegisterValidatorKey{
PubKey: pub,
Metadata: metadata,
Metadata: MetadataFromDescription(description),
},
}
payloadBz, err := json.Marshal(&registerValidator)
Expand All @@ -43,7 +43,8 @@ func RegisterValidator(ctx sdk.Context, contractAddr sdk.AccAddress, pk cryptoty
}

// UpdateValidator calls valset contract to change validator's metadata
func UpdateValidator(ctx sdk.Context, contractAddr sdk.AccAddress, delegatorAddress sdk.AccAddress, metadata stakingtypes.Description, k Executor) error {
func UpdateValidator(ctx sdk.Context, contractAddr sdk.AccAddress, delegatorAddress sdk.AccAddress, description stakingtypes.Description, k Executor) error {
metadata := MetadataFromDescription(description)
updateValidator := TG4ValsetExecute{
UpdateMetadata: &metadata,
}
Expand Down
38 changes: 36 additions & 2 deletions x/poe/contract/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,44 @@ func asJson(t *testing.T, m interface{}) string {
// See https://github.com/confio/tgrade-contracts/blob/main/contracts/tgrade-valset/schema/execute_msg.json
type TG4ValsetExecute struct {
RegisterValidatorKey *RegisterValidatorKey `json:"register_validator_key,omitempty"`
UpdateMetadata *stakingtypes.Description `json:"update_metadata,omitempty"`
UpdateMetadata *ValidatorMetadata `json:"update_metadata,omitempty"`
}

type RegisterValidatorKey struct {
PubKey ValidatorPubkey `json:"pubkey"`
Metadata stakingtypes.Description `json:"metadata"`
Metadata ValidatorMetadata `json:"metadata"`
}

type ValidatorMetadata struct {
// moniker defines a human-readable name for the validator.
Moniker string `json:"moniker"`
// identity defines an optional identity signature (ex. UPort or Keybase).
Identity string `json:"identity,omitempty"`
// website defines an optional website link.
Website string `json:"website,omitempty"`
// security_contact defines an optional email for security contact.
SecurityContact string `json:"security_contact,omitempty"`
// details define other optional details.
Details string `json:"details,omitempty"`
}

func MetadataFromDescription(description stakingtypes.Description) ValidatorMetadata {
return ValidatorMetadata{
Moniker: description.Moniker,
Identity: description.Identity,
Website: description.Website,
SecurityContact: description.SecurityContact,
Details: description.Details,
}
}

func (m ValidatorMetadata) ToDescription() stakingtypes.Description {
return stakingtypes.Description{
Moniker: m.Moniker,
Identity: m.Identity,
Website: m.Website,
SecurityContact: m.SecurityContact,
Details: m.Details,
}

}

0 comments on commit 0a21e3f

Please sign in to comment.