-
Notifications
You must be signed in to change notification settings - Fork 31
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
refactor MT #263
refactor MT #263
Conversation
# Conflicts: # modules/mt/keeper/keeper.go
modules/mt/keeper/keeper.go
Outdated
denomID, tokenID string, | ||
amout uint64, | ||
data []byte, | ||
owner sdk.AccAddress, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
owner -> recipient
modules/mt/keeper/keeper.go
Outdated
types.MT{ | ||
Id: mt.GetID(), | ||
Supply: amout + mt.GetSupply(), | ||
Data: owner, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why data = owner?
modules/mt/keeper/keeper.go
Outdated
ctx, denomID, | ||
types.MT{ | ||
Id: mt.GetID(), | ||
Supply: amout + mt.GetSupply(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amout -> amount
modules/mt/keeper/keeper.go
Outdated
) error { | ||
|
||
// TODO create if not exists, mint if exists | ||
if k.HasMT(ctx, denomID, tokenID) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked that denom exists or not?
modules/mt/keeper/keeper.go
Outdated
if denom.Owner != owner.String() { | ||
return sdkerrors.Wrapf(types.ErrUnauthorized, "Denom is owned by %s", denom.Owner) | ||
} | ||
|
||
mt, err := k.Authorize(ctx, denomID, tokenID, owner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authorize
checks if the sender is the owner of the given MT
, but not of the given denom
, so I guess here is a bug when the denom owner is not the MT owner.
Maybe we do not need the owner
property in the MT
structure, because the MT
is owned by the denom
modules/mt/keeper/keeper.go
Outdated
mt, err := k.Authorize(ctx, denomID, tokenID, srcOwner) | ||
if err != nil { | ||
return err | ||
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, srcOwner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to use getBalance
instead of getOwner
modules/mt/keeper/keeper.go
Outdated
return err | ||
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, srcOwner) | ||
if srcOwnerAmount < amount { | ||
return sdkerrors.Wrapf(types.ErrInvalidCollection, "Lack of mt: %", srcOwnerAmount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrInsufficientFunds
modules/mt/keeper/keeper.go
Outdated
|
||
k.setMT(ctx, denomID, mt) | ||
k.swapOwner(ctx, denomID, tokenID, srcOwner, dstOwner) | ||
k.swapOwner(ctx, denomID, tokenID, amount, srcOwner, dstOwner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the swapOwner
to transferMT
modules/mt/keeper/keeper.go
Outdated
k.deleteMT(ctx, denomID, mt) | ||
k.deleteOwner(ctx, denomID, tokenID, owner) | ||
k.decreaseSupply(ctx, denomID) | ||
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, owner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
modules/mt/keeper/keeper.go
Outdated
k.decreaseSupply(ctx, denomID) | ||
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, owner) | ||
if srcOwnerAmount < amount { | ||
return sdkerrors.Wrapf(types.ErrInvalidCollection, "Lack of mt: %", srcOwnerAmount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeMintMT, | ||
sdk.NewAttribute(types.AttributeKeyTokenID, msg.Id), | ||
sdk.NewAttribute(types.AttributeKeyDenomID, msg.DenomId), | ||
sdk.NewAttribute(types.AttributeKeyRecipient, msg.Recipient), | ||
sdk.NewAttribute(types.AttributeKeySupply, strconv.FormatUint(mt.GetSupply(), 10)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the events should be redesigned. Let's do that in another PR.
sender, | ||
recipient, | ||
); err != nil { | ||
if err := m.Keeper.TransferOwner(ctx, msg.DenomId, msg.Id, msg.Amount, sender, recipient); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, rename TransferOwner
to Transfer
or TransferMT
modules/mt/keeper/owners.go
Outdated
"github.com/irisnet/irismod/modules/mt/types" | ||
) | ||
|
||
func (k Keeper) deleteOwner(ctx sdk.Context, denomID, tokenID string, owner sdk.AccAddress) { | ||
func (k Keeper) deleteOwner(ctx sdk.Context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
modules/mt/keeper/owners.go
Outdated
store.Set(types.KeyOwner(owner, denomID, tokenID), bz) | ||
} | ||
|
||
func (k Keeper) swapOwner(ctx sdk.Context, denomID, tokenID string, srcOwner, dstOwner sdk.AccAddress) { | ||
func (k Keeper) swapOwner(ctx sdk.Context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, this is not a swap
operation, just a transfer
that combines subMT
from sender and addMT
to recipient.
@@ -16,7 +16,8 @@ var ( | |||
AttributeKeyRecipient = "recipient" | |||
AttributeKeyOwner = "owner" | |||
AttributeKeyTokenID = "token_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttributeKeyMTID = "mt_id"
Refactor MT Module
No description provided.