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

refactor MT #263

Merged
merged 16 commits into from
Feb 20, 2022
Merged

refactor MT #263

merged 16 commits into from
Feb 20, 2022

Conversation

cyilong
Copy link
Member

@cyilong cyilong commented Feb 19, 2022

No description provided.

denomID, tokenID string,
amout uint64,
data []byte,
owner sdk.AccAddress,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

owner -> recipient

types.MT{
Id: mt.GetID(),
Supply: amout + mt.GetSupply(),
Data: owner,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why data = owner?

ctx, denomID,
types.MT{
Id: mt.GetID(),
Supply: amout + mt.GetSupply(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amout -> amount

) error {

// TODO create if not exists, mint if exists
if k.HasMT(ctx, denomID, tokenID) {
Copy link
Contributor

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?

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)
Copy link
Contributor

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

mt, err := k.Authorize(ctx, denomID, tokenID, srcOwner)
if err != nil {
return err
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, srcOwner)
Copy link
Contributor

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

return err
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, srcOwner)
if srcOwnerAmount < amount {
return sdkerrors.Wrapf(types.ErrInvalidCollection, "Lack of mt: %", srcOwnerAmount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrInsufficientFunds


k.setMT(ctx, denomID, mt)
k.swapOwner(ctx, denomID, tokenID, srcOwner, dstOwner)
k.swapOwner(ctx, denomID, tokenID, amount, srcOwner, dstOwner)
Copy link
Contributor

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

k.deleteMT(ctx, denomID, mt)
k.deleteOwner(ctx, denomID, tokenID, owner)
k.decreaseSupply(ctx, denomID)
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, owner)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

k.decreaseSupply(ctx, denomID)
srcOwnerAmount := k.getOwner(ctx, denomID, tokenID, owner)
if srcOwnerAmount < amount {
return sdkerrors.Wrapf(types.ErrInvalidCollection, "Lack of mt: %", srcOwnerAmount)
Copy link
Contributor

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)),
Copy link
Contributor

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 {
Copy link
Contributor

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

"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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

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,
Copy link
Contributor

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeKeyMTID = "mt_id"

@zhangyelong zhangyelong merged commit 99f9738 into feature/mt Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants