Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add creator into x/token EventIssue #636

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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