Skip to content

Commit

Permalink
Merge pull request #177 from maxonrow/develop
Browse files Browse the repository at this point in the history
Merging latest change which patched in mainnet into master
  • Loading branch information
b00f authored Aug 28, 2020
2 parents e209afe + 0ccebcb commit ae00368
Show file tree
Hide file tree
Showing 19 changed files with 834 additions and 613 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Version 1.3.6
- Enhancement move UpdateNFTItemMetadata into token action (Fixing #178)
- check endorserlist limit during approval and update endorser list (Fixing #179)
- New NFT test-cases by checking for Endorser List Limit Setting
- Update with meaningful error messages in validation.go and keeper files in the modules
- remove default endorser list limit

# Version 1.3.5
- implement length limit for itemID(128)
- implement validation for burn flag upon burning token (ft/nft)
- implement length limit for nft endorser list(10)
- Fix spelling error for "APPROVE_TRANSFER_TOKEN_OWNERSHIP" and "REJECT_TRANSFER_TOKEN_OWNERSHIP"

# Version 1.3.4
- fix when burn and item is frozen, burn is not allowed
- fix when ft/nft token if frozen there is no other action can be done until it is unfrozen. Except for nft
Expand Down
8 changes: 7 additions & 1 deletion app/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (app *mxwApp) CalculateFee(ctx sdkTypes.Context, tx sdkTypes.Tx) (sdkTypes.
msg == nft.MsgTypeTransferNonFungibleTokenOwnership ||
msg == nft.MsgTypeAcceptNonFungibleTokenOwnership ||
msg == nft.MsgTypeEndorsement ||
msg == nft.MsgTypeUpdateEndorserList
msg == nft.MsgTypeUpdateEndorserList ||
msg == nft.MsgTypeUpdateItemMetadata
}
r := msg.Route()
t := msg.Type()
Expand Down Expand Up @@ -253,6 +254,11 @@ func (app *mxwApp) getTokenFeeSetting(msg sdkTypes.Msg, ctx sdkTypes.Context) (*
if feeSettingErr != nil {
return nil, nil, feeSettingErr
}
case nft.MsgUpdateItemMetadata:
feeSetting, feeSettingErr = app.feeKeeper.GetNonFungibleTokenFeeSetting(ctx, msgType.Symbol, fee.UpdateNFTItemMetadata)
if feeSettingErr != nil {
return nil, nil, feeSettingErr
}
}

return feeSetting, amt, nil
Expand Down
77 changes: 59 additions & 18 deletions app/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
}
}
case fungible.MsgTransferFungibleToken:

if !app.kycKeeper.IsWhitelisted(ctx, msg.To) {
return types.ErrReceiverNotKyc()
}

if !app.fungibleTokenKeeper.CheckApprovedToken(ctx, msg.Symbol) {
return types.ErrTokenInvalid()
}
Expand All @@ -166,6 +171,11 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return types.ErrTokenAccountFrozen()
}
case fungible.MsgMintFungibleToken:

if !app.kycKeeper.IsWhitelisted(ctx, msg.To) {
return types.ErrReceiverNotKyc()
}

if !app.fungibleTokenKeeper.CheckApprovedToken(ctx, msg.Symbol) {
return types.ErrTokenInvalid()
}
Expand Down Expand Up @@ -194,7 +204,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
}

// (FixedSupply-FungibleToken) MintFlag - types.Bitmask = 0x0002
if !fungibleToken.Flags.HasFlag(0x0002) {
if !fungibleToken.Flags.HasFlag(fungible.MintFlag) {
return types.ErrInvalidTokenAction()
}

Expand All @@ -206,6 +216,13 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return types.ErrTokenFrozen()
}

var fungibleToken = new(fungible.Token)
app.fungibleTokenKeeper.GetFungibleTokenDataInfo(ctx, msg.Symbol, fungibleToken)
fungibleToken.TotalSupply = fungibleToken.TotalSupply.Add(msg.Value)
if !fungibleToken.Flags.HasFlag(fungible.BurnFlag) {
return types.ErrInvalidTokenAction()
}

var account = new(fungible.FungibleTokenAccount)
account = app.fungibleTokenKeeper.GetFungibleAccount(ctx, msg.Symbol, msg.From)

Expand All @@ -214,10 +231,15 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
}

if account.Balance.LT(msg.Value) {
return types.ErrInvalidTokenAccountBalance(fmt.Sprintf("Not enough tokens. Have only %v", account.Balance.String()))
return types.ErrInvalidTokenAccountBalance(fmt.Sprintf("Not enough tokens. Have only %v.", account.Balance.String()))
}

case fungible.MsgTransferFungibleTokenOwnership:

if !app.kycKeeper.IsWhitelisted(ctx, msg.To) {
return types.ErrReceiverNotKyc()
}

if app.fungibleTokenKeeper.IsTokenFrozen(ctx, msg.Symbol) {
return types.ErrTokenFrozen()
}
Expand Down Expand Up @@ -292,6 +314,12 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
if app.nonFungibleTokenKeeper.CheckApprovedToken(ctx, msg.Payload.Token.Symbol) {
return types.ErrTokenAlreadyApproved(msg.Payload.Token.Symbol)
}

for _, v := range msg.Payload.Token.EndorserList {
if !app.kycKeeper.IsWhitelisted(ctx, v) {
return types.ErrUnauthorisedEndorser()
}
}
}

if msg.Payload.Token.Status == nonFungible.RejectToken {
Expand Down Expand Up @@ -334,11 +362,11 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.

nonFungibleItem := app.nonFungibleTokenKeeper.GetNonFungibleItem(ctx, msg.ItemPayload.Item.Symbol, msg.ItemPayload.Item.ItemID)
if nonFungibleItem == nil {
return sdkTypes.ErrUnknownRequest("No such item to freeze.")
return sdkTypes.ErrUnknownRequest("No such non-fungible item to freeze.")
}

if !app.nonFungibleTokenKeeper.IsAuthorised(ctx, msg.Owner) {
return sdkTypes.ErrUnauthorized("Not authorised to unfreeze token account.")
return sdkTypes.ErrUnauthorized("Not authorised to unfreeze non-fungible token account.")
}

signatureErr := app.nonFungibleTokenKeeper.ValidateSignatures(ctx, msg)
Expand All @@ -348,12 +376,12 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.

if msg.ItemPayload.Item.Status == nonFungible.FreezeItem {
if app.nonFungibleTokenKeeper.IsNonFungibleItemFrozen(ctx, msg.ItemPayload.Item.Symbol, msg.ItemPayload.Item.ItemID) {
return types.ErrTokenAccountFrozen()
return types.ErrTokenItemFrozen()
}
}
if msg.ItemPayload.Item.Status == nonFungible.UnfreezeItem {
if !app.nonFungibleTokenKeeper.IsNonFungibleItemFrozen(ctx, msg.ItemPayload.Item.Symbol, msg.ItemPayload.Item.ItemID) {
return types.ErrTokenAccountUnFrozen()
return types.ErrTokenItemUnFrozen()
}
}

Expand All @@ -380,7 +408,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
// 1. [Transfer non fungible token item - Invalid Item-ID]
nonFungibleItem := app.nonFungibleTokenKeeper.GetNonFungibleItem(ctx, msg.Symbol, msg.ItemID)
if nonFungibleItem == nil {
return sdkTypes.ErrUnknownRequest("Invalid Item ID.")
return sdkTypes.ErrUnknownRequest("Invalid non-fungible Item ID.")
}

if app.nonFungibleTokenKeeper.IsItemTransferLimitExceeded(ctx, msg.Symbol, msg.ItemID) {
Expand All @@ -406,7 +434,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
//1. checking: (flag of Public equals to TRUE)
var token = new(nonFungible.Token)
app.nonFungibleTokenKeeper.GetNonfungibleTokenDataInfo(ctx, msg.Symbol, token)
if token.Flags.HasFlag(0x0080) {
if token.Flags.HasFlag(nonFungible.PubFlag) {
ownerAcc := msg.Owner
newOwnerAcc := msg.To
if !ownerAcc.Equals(newOwnerAcc) {
Expand All @@ -426,6 +454,13 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
if app.nonFungibleTokenKeeper.IsTokenFrozen(ctx, msg.Symbol) {
return types.ErrTokenFrozen()
}

var token = new(nonFungible.Token)
app.nonFungibleTokenKeeper.GetNonfungibleTokenDataInfo(ctx, msg.Symbol, token)
if !token.Flags.HasFlag(nonFungible.BurnFlag) {
return types.ErrInvalidTokenAction()
}

// 1. [Burn non fungible token item - Invalid Item-owner]
item := app.nonFungibleTokenKeeper.GetNonFungibleItem(ctx, msg.Symbol, msg.ItemID)
if item == nil {
Expand All @@ -442,6 +477,10 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.

case nonFungible.MsgTransferNonFungibleTokenOwnership:

if !app.kycKeeper.IsWhitelisted(ctx, msg.To) {
return types.ErrReceiverNotKyc()
}

if app.nonFungibleTokenKeeper.IsTokenFrozen(ctx, msg.Symbol) {
return types.ErrTokenFrozen()
}
Expand Down Expand Up @@ -482,10 +521,6 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
if item == nil {
return types.ErrTokenInvalid()
}
// 2. [endorse a nonfungible item - Invalid Token Symbol]
if err := nonFungible.ValidateSymbol(msg.Symbol); err != nil {
return err
}

case nonFungible.MsgUpdateNFTMetadata:
if !app.nonFungibleTokenKeeper.CheckApprovedToken(ctx, msg.Symbol) {
Expand All @@ -508,7 +543,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return types.ErrTokenFrozen()
}
if !app.nonFungibleTokenKeeper.IsItemMetadataModifiable(ctx, msg.Symbol, msg.From, msg.ItemID) {
return sdkTypes.ErrInternal("Non fungible item metadata is not modifiable.")
return sdkTypes.ErrInternal("Non-fungible item metadata is not modifiable.")
}
case nonFungible.MsgUpdateEndorserList:
if !app.nonFungibleTokenKeeper.CheckApprovedToken(ctx, msg.Symbol) {
Expand All @@ -526,6 +561,12 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
}
}

var token = new(nonFungible.Token)
app.nonFungibleTokenKeeper.GetNonfungibleTokenDataInfo(ctx, msg.Symbol, token)
if sdkTypes.NewUint(uint64(len(msg.Endorsers))).GT(token.EndorserListLimit) {
return sdkTypes.ErrUnauthorized("Endorserlist limit exceeded.")
}

case maintenance.MsgProposal:
if !app.maintenanceKeeper.IsMaintainers(ctx, msg.Proposer) {
return sdkTypes.ErrUnauthorized("Not authorised to submit proposal.")
Expand Down Expand Up @@ -553,7 +594,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return sdkTypes.ErrInternal("Group account not found.")
}
if !groupAcc.IsMultiSig() {
return sdkTypes.ErrInternal("MultiSig Tx create failed, group address is not a multisig account.")
return sdkTypes.ErrInternal("MultiSig Tx create failed, as group address is not a multisig account.")
}
if !groupAcc.IsSigner(msg.Sender) {
return sdkTypes.ErrInternal("Sender is not group account's signer.")
Expand All @@ -576,7 +617,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return sdkTypes.ErrInternal("Group account not found.")
}
if !groupAcc.IsMultiSig() {
return sdkTypes.ErrInternal("MultiSig Tx update failed, group address is not a multisig account.")
return sdkTypes.ErrInternal("MultiSig Tx update failed, as group address is not a multisig account.")
}
if !groupAcc.GetMultiSig().GetOwner().Equals(msg.Owner) {
return sdkTypes.ErrUnknownRequest("Owner address invalid.")
Expand All @@ -587,7 +628,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return sdkTypes.ErrInternal("Group account not found.")
}
if !groupAcc.IsMultiSig() {
return sdkTypes.ErrInternal("MultiSig Tx update failed, group address is not a multisig account.")
return sdkTypes.ErrInternal("MultiSig Tx update failed, as group address is not a multisig account.")
}
if !groupAcc.GetMultiSig().IsOwner(msg.Owner) {
return sdkTypes.ErrUnknownRequest("Owner of group address invalid.")
Expand All @@ -598,7 +639,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return sdkTypes.ErrInternal("Group account not found.")
}
if !groupAcc.IsMultiSig() {
return sdkTypes.ErrInternal("MultiSig Tx update failed, group address is not a multisig account.")
return sdkTypes.ErrInternal("MultiSig Tx update failed, as group address is not a multisig account.")
}
if !groupAcc.GetMultiSig().IsOwner(msg.Sender) {
return sdkTypes.ErrUnknownRequest("Only group account owner can remove pending tx.")
Expand All @@ -613,7 +654,7 @@ func (app *mxwApp) validateMsg(ctx sdkTypes.Context, msg sdkTypes.Msg) sdkTypes.
return sdkTypes.ErrInternal("Group account not found.")
}
if !groupAcc.IsMultiSig() {
return sdkTypes.ErrInternal("MultiSig Tx sign failed, group address is not a multisig account.")
return sdkTypes.ErrInternal("MultiSig Tx sign failed, as group address is not a multisig account.")
}
if !groupAcc.IsSigner(msg.Sender) {
return sdkTypes.ErrInternal("Sender is not group account's signer.")
Expand Down
1 change: 1 addition & 0 deletions tests/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func makeFeeTxs() []*testCase {
{"fee", false, false, "Create nft acceptOwnership action fee setting", "fee-auth", "0cin", 0, feeInfo{"sys-fee", "nft_acceptOwnership_default", "", "", "400000000cin", "2000000000cin", "0.001", "fee-auth"}, "", nil},
{"fee", false, false, "Create nft endorse action fee setting", "fee-auth", "0cin", 0, feeInfo{"sys-fee", "nft_endorse_default", "", "", "400000000cin", "2000000000cin", "0.001", "fee-auth"}, "", nil},
{"fee", false, false, "Create nft updateEndorserList action fee setting", "fee-auth", "0cin", 0, feeInfo{"sys-fee", "nft_updateNFTEndorserList_default", "", "", "400000000cin", "2000000000cin", "0.001", "fee-auth"}, "", nil},
{"fee", false, false, "Create nft updateNFTItemMetadata action fee setting", "fee-auth", "0cin", 0, feeInfo{"sys-fee", "nft_updateNFTItemMetadata_default", "", "", "100000000cin", "2000000000cin", "0.001", "fee-auth"}, "", nil},

//add token fee multiplier
{"fee", false, false, "create fungible token fee multiplier. commit", "fee-auth", "0cin", 0, feeInfo{"fungible-token-fee-multiplier", "", "", "1", "", "", "", "fee-auth"}, "", nil},
Expand Down
Loading

0 comments on commit ae00368

Please sign in to comment.