Skip to content

Commit

Permalink
Merge pull request #303 from multiversx/merge-rc-1-7-next-into-sovere…
Browse files Browse the repository at this point in the history
…ign-14-may-2024

Merge rc 1 7 next into sovereign 14 may 2024
  • Loading branch information
mariusmihaic authored May 15, 2024
2 parents 01e22e9 + 72b1cac commit 2ee16f8
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 10 deletions.
63 changes: 63 additions & 0 deletions core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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 @@ -155,6 +173,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 @@ -163,6 +196,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
Expand All @@ -171,9 +216,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)

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)))
}
21 changes: 11 additions & 10 deletions data/api/apiAccountResponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package api

// AccountResponse is the data transfer object to be returned on API when requesting an address data
type AccountResponse struct {
Address string `json:"address"`
Nonce uint64 `json:"nonce"`
Balance string `json:"balance"`
Username string `json:"username"`
Code string `json:"code"`
CodeHash []byte `json:"codeHash"`
RootHash []byte `json:"rootHash"`
CodeMetadata []byte `json:"codeMetadata"`
DeveloperReward string `json:"developerReward"`
OwnerAddress string `json:"ownerAddress"`
Address string `json:"address"`
Nonce uint64 `json:"nonce"`
Balance string `json:"balance"`
Username string `json:"username"`
Code string `json:"code"`
CodeHash []byte `json:"codeHash"`
RootHash []byte `json:"rootHash"`
CodeMetadata []byte `json:"codeMetadata"`
DeveloperReward string `json:"developerReward"`
OwnerAddress string `json:"ownerAddress"`
Pairs map[string]string `json:"pairs,omitempty"`
}
1 change: 1 addition & 0 deletions data/api/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type AccountQueryOptions struct {
BlockHash []byte
BlockRootHash []byte
HintEpoch core.OptionalUint32
WithKeys bool
}

// BlockQueryOptions holds options for block queries
Expand Down

0 comments on commit 2ee16f8

Please sign in to comment.