Skip to content

Commit

Permalink
Merge branch 'feat/header-proof' of https://github.com/multiversx/mx-…
Browse files Browse the repository at this point in the history
…chain-core-go into header_proof_on_chain_handler_interface
  • Loading branch information
sstanculeanu committed Jul 8, 2024
2 parents 308e43d + d9127b8 commit 91bbc15
Show file tree
Hide file tree
Showing 14 changed files with 511 additions and 63 deletions.
87 changes: 87 additions & 0 deletions core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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

Expand All @@ -167,17 +200,71 @@ 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
)

// String will convert number type in string
func (t ESDTType) String() string {
switch t {
case Fungible:
return FungibleESDT
case NonFungible:
return NonFungibleESDT
case NonFungibleV2:
return NonFungibleESDTv2
case SemiFungible:
return SemiFungibleESDT
case MetaFungible:
return MetaESDT
case DynamicNFT:
return DynamicNFTESDT
case DynamicSFT:
return DynamicSFTESDT
case DynamicMeta:
return DynamicMetaESDT
default:
return "Unknown"
}
}

// FungibleESDT defines the string for the token type of fungible ESDT
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)

Expand Down
29 changes: 29 additions & 0 deletions core/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
53 changes: 53 additions & 0 deletions core/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Loading

0 comments on commit 91bbc15

Please sign in to comment.