Skip to content

Commit

Permalink
Add restricted status info to name cli queries and events (#834)
Browse files Browse the repository at this point in the history
* add restricted info to name record events

* add restricted status to name query result

* add restricted output expectations to tests

* changelog
  • Loading branch information
iramiller authored May 26, 2022
1 parent dd50eab commit 2400474
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 84 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* Add restricted status info to name module cli queries [#806](https://github.com/provenance-io/provenance/issues/806)

---

## [v1.10.0](https://github.com/provenance-io/provenance/releases/tag/v1.10.0) - 2022-05-11
Expand Down
3 changes: 3 additions & 0 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5460,6 +5460,7 @@ Event emitted when name is bound.
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | |
| `name` | [string](#string) | | |
| `restricted` | [bool](#bool) | | |



Expand All @@ -5476,6 +5477,7 @@ Event emitted when name is unbound.
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | |
| `name` | [string](#string) | | |
| `restricted` | [bool](#bool) | | |



Expand Down Expand Up @@ -5614,6 +5616,7 @@ QueryResolveResponse is the response type for the Query/Resolve method.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | a string containing the address the name resolves to |
| `restricted` | [bool](#bool) | | Whether owner signature is required to add sub-names. |



Expand Down
10 changes: 6 additions & 4 deletions proto/provenance/name/v1/name.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ message CreateRootNameProposal {

// Event emitted when name is bound.
message EventNameBound {
string address = 1;
string name = 2;
string address = 1;
string name = 2;
bool restricted = 3;
}

// Event emitted when name is unbound.
message EventNameUnbound {
string address = 1;
string name = 2;
string address = 1;
string name = 2;
bool restricted = 3;
}
2 changes: 2 additions & 0 deletions proto/provenance/name/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ message QueryResolveRequest {
message QueryResolveResponse {
// a string containing the address the name resolves to
string address = 1;
// Whether owner signature is required to add sub-names.
bool restricted = 2;
}

// QueryReverseLookupRequest is the request type for the Query/ReverseLookup method.
Expand Down
4 changes: 2 additions & 2 deletions x/name/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ func (s *IntegrationTestSuite) TestResolveNameCommand() {
{
"query name, json output",
[]string{"attribute", fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
fmt.Sprintf("{\"address\":\"%s\"}", s.accountAddr.String()),
fmt.Sprintf("{\"address\":\"%s\",\"restricted\":false}", s.accountAddr.String()),
},
{
"query name, text output",
[]string{"attribute", fmt.Sprintf("--%s=text", tmcli.OutputFlag)},
fmt.Sprintf("address: %s", s.accountAddr.String()),
fmt.Sprintf("address: %s\nrestricted: false", s.accountAddr.String()),
},
{
"query name that does not exist, text output",
Expand Down
4 changes: 2 additions & 2 deletions x/name/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestCreateName(t *testing.T) {
name: "create name record",
msg: nametypes.NewMsgBindNameRequest(nametypes.NewNameRecord("new", addr2, false), nametypes.NewNameRecord("example.name", addr1, false)),
expectedError: nil,
expectedEvent: nametypes.NewEventNameBound(addr2.String(), "new.example.name"),
expectedEvent: nametypes.NewEventNameBound(addr2.String(), "new.example.name", false),
},
{
name: "create bad name record",
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestDeleteName(t *testing.T) {
name: "delete name record",
msg: nametypes.NewMsgDeleteNameRequest(nametypes.NewNameRecord("example.name", addr1, false)),
expectedError: nil,
expectedEvent: nametypes.NewEventNameUnbound(addr1.String(), "example.name"),
expectedEvent: nametypes.NewEventNameUnbound(addr1.String(), "example.name", false),
},
{
name: "create bad name record",
Expand Down
4 changes: 2 additions & 2 deletions x/name/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (keeper Keeper) SetNameRecord(ctx sdk.Context, name string, addr sdk.AccAdd
addrPrefix = append(addrPrefix, key...) // [0x04] :: [addr-bytes] :: [name-key-bytes]
store.Set(addrPrefix, bz)

nameBoundEvent := types.NewEventNameBound(record.Address, name)
nameBoundEvent := types.NewEventNameBound(record.Address, name, record.Restricted)

if err := ctx.EventManager().EmitTypedEvent(nameBoundEvent); err != nil {
return err
Expand Down Expand Up @@ -201,7 +201,7 @@ func (keeper Keeper) DeleteRecord(ctx sdk.Context, name string) error {
store.Delete(addrPrefix)
}

nameUnboundEvent := types.NewEventNameUnbound(record.Address, name)
nameUnboundEvent := types.NewEventNameUnbound(record.Address, name, record.Restricted)

if err := ctx.EventManager().EmitTypedEvent(nameUnboundEvent); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/name/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (keeper Keeper) Resolve(c context.Context, request *types.QueryResolveReque
if record == nil {
return nil, types.ErrNameNotBound
}
return &types.QueryResolveResponse{Address: record.Address}, nil
return &types.QueryResolveResponse{Address: record.Address, Restricted: record.Restricted}, nil
}

// ReverseLookup gets all names bound to an address.
Expand Down
14 changes: 8 additions & 6 deletions x/name/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ const (
KeyAttributeAddress string = "address"
)

func NewEventNameBound(address string, name string) *EventNameBound {
func NewEventNameBound(address string, name string, restricted bool) *EventNameBound {
return &EventNameBound{
Address: address,
Name: name,
Address: address,
Name: name,
Restricted: restricted,
}
}

func NewEventNameUnbound(address string, name string) *EventNameUnbound {
func NewEventNameUnbound(address string, name string, restricted bool) *EventNameUnbound {
return &EventNameUnbound{
Address: address,
Name: name,
Address: address,
Name: name,
Restricted: restricted,
}
}
149 changes: 116 additions & 33 deletions x/name/types/name.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2400474

Please sign in to comment.