Skip to content

Commit

Permalink
feat: add creator into x/token EventIssue (#636)
Browse files Browse the repository at this point in the history
* Add a field `creator` into /lbm.token.v1.EventIssue

* Update CHANGELOG.md
  • Loading branch information
0Tech authored Aug 16, 2022
1 parent 7376b87 commit 09aace5
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/collection) [\#608](https://github.com/line/lbm-sdk/pull/608) remove new APIs on x/collection
* (x/token) [\#609](https://github.com/line/lbm-sdk/pull/609) remove new APIs on x/token
* (x/collection) [\#621](https://github.com/line/lbm-sdk/pull/621) add additional information into EventXXXChanged
* (x/token) [\#636](https://github.com/line/lbm-sdk/pull/636) add creator into x/token EventIssue

### Bug Fixes
* (x/wasm) [\#453](https://github.com/line/lbm-sdk/pull/453) modify wasm grpc query api path
Expand Down
1 change: 1 addition & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17554,6 +17554,7 @@ Since: 0.46.0 (finschia)

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `creator` | [string](#string) | | address which created the contract. |
| `contract_id` | [string](#string) | | contract id associated with the token class. |
| `name` | [string](#string) | | name defines the human-readable name of the token class. |
| `symbol` | [string](#string) | | symbol is an abbreviated name for token class. |
Expand Down
16 changes: 9 additions & 7 deletions proto/lbm/token/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,22 @@ message EventRevokedOperator {
//
// Since: 0.46.0 (finschia)
message EventIssue {
// address which created the contract.
string creator = 1;
// contract id associated with the token class.
string contract_id = 1;
string contract_id = 2;
// name defines the human-readable name of the token class.
string name = 2;
string name = 3;
// symbol is an abbreviated name for token class.
string symbol = 3;
string symbol = 4;
// uri is an uri for the resource of the token class stored off chain.
string uri = 4;
string uri = 5;
// meta is a brief description of token class.
string meta = 5;
string meta = 6;
// decimals is the number of decimals which one must divide the amount by to get its user representation.
int32 decimals = 6;
int32 decimals = 7;
// mintable represents whether the token is allowed to mint.
bool mintable = 7;
bool mintable = 8;
}

// EventGrant is emitted when a granter grants its permission to a grantee.
Expand Down
4 changes: 2 additions & 2 deletions x/token/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func AttributeKeyFromString(name string) AttributeKey {
return AttributeKey(AttributeKey_value[attributeKeyName])
}

func NewEventIssueToken(event EventIssue, grantee, to sdk.AccAddress, amount sdk.Int) sdk.Event {
func NewEventIssueToken(event EventIssue, to sdk.AccAddress, amount sdk.Int) sdk.Event {
eventType := EventTypeIssueToken.String()
attributes := map[AttributeKey]string{
AttributeKeyContractID: event.ContractId,
Expand All @@ -43,7 +43,7 @@ func NewEventIssueToken(event EventIssue, grantee, to sdk.AccAddress, amount sdk
AttributeKeyDecimals: fmt.Sprintf("%d", event.Decimals),
AttributeKeyMintable: fmt.Sprintf("%t", event.Mintable),

AttributeKeyOwner: grantee.String(),
AttributeKeyOwner: event.Creator,
AttributeKeyTo: to.String(),
AttributeKeyAmount: amount.String(),
}
Expand Down
233 changes: 143 additions & 90 deletions x/token/event.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions x/token/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestNewEventIssueToken(t *testing.T) {
str := func() string { return randomString(8) }

event := token.EventIssue{
Creator: str(),
ContractId: str(),
Name: str(),
Symbol: str(),
Expand All @@ -59,10 +60,9 @@ func TestNewEventIssueToken(t *testing.T) {
Decimals: 0,
Mintable: true,
}
operator := sdk.AccAddress(str())
to := sdk.AccAddress(str())
amount := sdk.OneInt()
legacy := token.NewEventIssueToken(event, operator, to, amount)
legacy := token.NewEventIssueToken(event, to, amount)

require.Equal(t, token.EventTypeIssueToken.String(), legacy.Type)

Expand All @@ -75,7 +75,7 @@ func TestNewEventIssueToken(t *testing.T) {
token.AttributeKeyMintable: fmt.Sprintf("%v", event.Mintable),
token.AttributeKeyDecimals: fmt.Sprintf("%d", event.Decimals),
token.AttributeKeyAmount: amount.String(),
token.AttributeKeyOwner: operator.String(),
token.AttributeKeyOwner: event.Creator,
token.AttributeKeyTo: to.String(),
}
for key, value := range attributes {
Expand Down
3 changes: 2 additions & 1 deletion x/token/keeper/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func (k Keeper) Issue(ctx sdk.Context, class token.TokenClass, owner, to sdk.Acc
k.issue(ctx, class)

event := token.EventIssue{
Creator: owner.String(),
ContractId: class.ContractId,
Name: class.Name,
Symbol: class.Symbol,
Expand All @@ -18,7 +19,7 @@ func (k Keeper) Issue(ctx sdk.Context, class token.TokenClass, owner, to sdk.Acc
Decimals: class.Decimals,
Mintable: class.Mintable,
}
ctx.EventManager().EmitEvent(token.NewEventIssueToken(event, owner, to, amount)) // deprecated
ctx.EventManager().EmitEvent(token.NewEventIssueToken(event, to, amount)) // deprecated
if err := ctx.EventManager().EmitTypedEvent(&event); err != nil {
panic(err)
}
Expand Down

0 comments on commit 09aace5

Please sign in to comment.