diff --git a/core/constants.go b/core/constants.go index bff20dd6..e022eea3 100644 --- a/core/constants.go +++ b/core/constants.go @@ -132,6 +132,24 @@ const BuiltInFunctionUnGuardAccount = "UnGuardAccount" // BuiltInFunctionMigrateDataTrie is the built-in function key for migrating the data trie const BuiltInFunctionMigrateDataTrie = "MigrateDataTrie" +// ESDTSetTokenType represents the builtin function name to set token type +const ESDTSetTokenType = "ESDTSetTokenType" + +// ESDTModifyRoyalties represents the builtin function name to modify royalties +const ESDTModifyRoyalties = "ESDTModifyRoyalties" + +// ESDTSetNewURIs represents the builtin function name to set new URIs for NFTs +const ESDTSetNewURIs = "ESDTSetNewURIs" + +// ESDTModifyCreator represents the builtin function name to modify creator for NFTs +const ESDTModifyCreator = "ESDTModifyCreator" + +// ESDTMetaDataRecreate represents the builtin function name to recreate the metadata for ESDT tokens +const ESDTMetaDataRecreate = "ESDTMetaDataRecreate" + +// ESDTMetaDataUpdate represents the builtin function name to update the metadata for ESDT tokens +const ESDTMetaDataUpdate = "ESDTMetaDataUpdate" + // ESDTRoleLocalMint is the constant string for the local role of mint for ESDT tokens const ESDTRoleLocalMint = "ESDTRoleLocalMint" @@ -159,6 +177,21 @@ const ESDTRoleNFTUpdateAttributes = "ESDTRoleNFTUpdateAttributes" // ESDTRoleTransfer is the constant string for the local role to transfer ESDT, only for special tokens const ESDTRoleTransfer = "ESDTTransferRole" +// ESDTRoleSetNewURI represents the role which can rewrite the URI in the token metadata +const ESDTRoleSetNewURI = "ESDTRoleSetNewURI" + +// ESDTRoleModifyRoyalties represents the role which can rewrite the royalties of a token +const ESDTRoleModifyRoyalties = "ESDTRoleModifyRoyalties" + +// ESDTRoleModifyCreator represents the role which can rewrite the creator in the token metadata +const ESDTRoleModifyCreator = "ESDTRoleModifyCreator" + +// ESDTRoleNFTRecreate represents the role which can recreate the token metadata +const ESDTRoleNFTRecreate = "ESDTRoleNFTRecreate" + +// ESDTRoleNFTUpdate represents the role which can update the token metadata +const ESDTRoleNFTUpdate = "ESDTRoleNFTUpdate" + // ESDTType defines the possible types in case of ESDT tokens type ESDTType uint32 @@ -167,6 +200,18 @@ const ( Fungible ESDTType = iota // NonFungible defines the token type for ESDT non fungible tokens NonFungible + // NonFungibleV2 defines the token type for ESDT non fungible tokens + NonFungibleV2 + // SemiFungible defines the token type for ESDT semi fungible tokens + SemiFungible + // MetaFungible defines the token type for ESDT meta fungible tokens + MetaFungible + // DynamicNFT defines the token type for ESDT dynamic NFT tokens + DynamicNFT + // DynamicSFT defines the token type for ESDT dynamic SFT tokens + DynamicSFT + // DynamicMeta defines the token type for ESDT dynamic meta tokens + DynamicMeta ) // FungibleESDT defines the string for the token type of fungible ESDT @@ -175,9 +220,27 @@ const FungibleESDT = "FungibleESDT" // NonFungibleESDT defines the string for the token type of non fungible ESDT const NonFungibleESDT = "NonFungibleESDT" +// NonFungibleESDTv2 defines the string for the token type of non fungible ESDT +const NonFungibleESDTv2 = "NonFungibleESDTv2" + +// MetaESDT defines the string for the token type of meta ESDT +const MetaESDT = "MetaESDT" + // SemiFungibleESDT defines the string for the token type of semi fungible ESDT const SemiFungibleESDT = "SemiFungibleESDT" +// Dynamic is the prefix used for dynamic ESDT tokens +const Dynamic = "Dynamic" + +// DynamicNFTESDT defines the string for the token type of dynamic NFT ESDT +const DynamicNFTESDT = Dynamic + NonFungibleESDT + +// DynamicSFTESDT defines the string for the token type of dynamic SFT ESDT +const DynamicSFTESDT = Dynamic + SemiFungibleESDT + +// DynamicMetaESDT defines the string for the token type of dynamic meta ESDT +const DynamicMetaESDT = Dynamic + MetaESDT + // MaxRoyalty defines 100% as uint32 const MaxRoyalty = uint32(10000) diff --git a/core/converters.go b/core/converters.go index f3e39519..9f3d6dfa 100644 --- a/core/converters.go +++ b/core/converters.go @@ -177,3 +177,32 @@ func ConvertToEvenHexBigInt(value *big.Int) string { return str } + +// ConvertESDTTypeToUint32 converts the esdt type to uint32 +func ConvertESDTTypeToUint32(esdtType string) (uint32, error) { + switch esdtType { + case FungibleESDT: + return uint32(Fungible), nil + case NonFungibleESDT: + return uint32(NonFungible), nil + case NonFungibleESDTv2: + return uint32(NonFungibleV2), nil + case MetaESDT: + return uint32(MetaFungible), nil + case SemiFungibleESDT: + return uint32(SemiFungible), nil + case DynamicNFTESDT: + return uint32(DynamicNFT), nil + case DynamicSFTESDT: + return uint32(DynamicSFT), nil + case DynamicMetaESDT: + return uint32(DynamicMeta), nil + default: + return math.MaxUint32, fmt.Errorf("invalid esdt type: %s", esdtType) + } +} + +// IsDynamicESDT returns true if the esdt type is dynamic +func IsDynamicESDT(esdtType uint32) bool { + return esdtType == uint32(DynamicNFT) || esdtType == uint32(DynamicSFT) || esdtType == uint32(DynamicMeta) +} diff --git a/core/converters_test.go b/core/converters_test.go index dc095176..a6f75d3b 100644 --- a/core/converters_test.go +++ b/core/converters_test.go @@ -255,3 +255,56 @@ func TestConvertShardIDToUint32(t *testing.T) { assert.Error(t, err) assert.Equal(t, uint32(0), shardID) } + +func TestConvertESDTTypeToUint32(t *testing.T) { + t.Parallel() + + tokenTypeId, err := core.ConvertESDTTypeToUint32(core.FungibleESDT) + assert.Nil(t, err) + assert.Equal(t, uint32(core.Fungible), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32(core.NonFungibleESDT) + assert.Nil(t, err) + assert.Equal(t, uint32(core.NonFungible), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32(core.NonFungibleESDTv2) + assert.Nil(t, err) + assert.Equal(t, uint32(core.NonFungibleV2), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32(core.MetaESDT) + assert.Nil(t, err) + assert.Equal(t, uint32(core.MetaFungible), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32(core.SemiFungibleESDT) + assert.Nil(t, err) + assert.Equal(t, uint32(core.SemiFungible), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32(core.DynamicNFTESDT) + assert.Nil(t, err) + assert.Equal(t, uint32(core.DynamicNFT), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32(core.DynamicSFTESDT) + assert.Nil(t, err) + assert.Equal(t, uint32(core.DynamicSFT), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32(core.DynamicMetaESDT) + assert.Nil(t, err) + assert.Equal(t, uint32(core.DynamicMeta), tokenTypeId) + + tokenTypeId, err = core.ConvertESDTTypeToUint32("wrongType") + assert.NotNil(t, err) + assert.Equal(t, uint32(math.MaxUint32), tokenTypeId) +} + +func TestIsDynamicESDT(t *testing.T) { + t.Parallel() + + assert.True(t, core.IsDynamicESDT(uint32(core.DynamicNFT))) + assert.True(t, core.IsDynamicESDT(uint32(core.DynamicSFT))) + assert.True(t, core.IsDynamicESDT(uint32(core.DynamicMeta))) + assert.False(t, core.IsDynamicESDT(uint32(core.Fungible))) + assert.False(t, core.IsDynamicESDT(uint32(core.NonFungible))) + assert.False(t, core.IsDynamicESDT(uint32(core.NonFungibleV2))) + assert.False(t, core.IsDynamicESDT(uint32(core.SemiFungible))) + assert.False(t, core.IsDynamicESDT(uint32(core.MetaFungible))) +}