From 1133dc537f187901b3687f12d4243c8e0099bcfc Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 1 Nov 2023 15:22:38 +0200 Subject: [PATCH 01/10] add NonFungibleESDTv2 to constants --- core/constants.go | 10 ++++++++++ core/converters.go | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/constants.go b/core/constants.go index bff20dd6..17c05ea2 100644 --- a/core/constants.go +++ b/core/constants.go @@ -167,6 +167,10 @@ 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 + // Meta defines the token type for ESDT meta tokens + Meta ) // FungibleESDT defines the string for the token type of fungible ESDT @@ -175,6 +179,12 @@ 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" diff --git a/core/converters.go b/core/converters.go index f3e39519..06599a53 100644 --- a/core/converters.go +++ b/core/converters.go @@ -177,3 +177,19 @@ 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(Meta), nil + default: + return math.MaxUint32, fmt.Errorf("invalid esdt type: %s", esdtType) + } +} From fd0a9006620891f0d121008c7fc03cec9006a99b Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 2 Nov 2023 10:56:00 +0200 Subject: [PATCH 02/10] add more token types in constants --- core/constants.go | 17 +++++++++++++++++ core/converters.go | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/core/constants.go b/core/constants.go index 17c05ea2..e459f565 100644 --- a/core/constants.go +++ b/core/constants.go @@ -171,6 +171,14 @@ const ( NonFungibleV2 // Meta defines the token type for ESDT meta tokens Meta + // SemiFungible defines the token type for ESDT semi fungible tokens + SemiFungible + // 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 @@ -188,6 +196,15 @@ const MetaESDT = "MetaESDT" // SemiFungibleESDT defines the string for the token type of semi fungible ESDT const SemiFungibleESDT = "SemiFungibleESDT" +// DynamicNFTESDT defines the string for the token type of dynamic NFT ESDT +const DynamicNFTESDT = "DynamicNFTESDT" + +// DynamicSFTESDT defines the string for the token type of dynamic SFT ESDT +const DynamicSFTESDT = "DynamicSFTESDT" + +// DynamicMetaESDT defines the string for the token type of dynamic meta ESDT +const DynamicMetaESDT = "DynamicMetaESDT" + // MaxRoyalty defines 100% as uint32 const MaxRoyalty = uint32(10000) diff --git a/core/converters.go b/core/converters.go index 06599a53..9f41d000 100644 --- a/core/converters.go +++ b/core/converters.go @@ -189,6 +189,14 @@ func ConvertESDTTypeToUint32(esdtType string) (uint32, error) { return uint32(NonFungibleV2), nil case MetaESDT: return uint32(Meta), 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) } From eaf054b523727ab96d4a93c26320fdcd2924fc59 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 6 Nov 2023 15:26:46 +0200 Subject: [PATCH 03/10] update dynamic esdts --- core/constants.go | 9 ++++++--- core/converters.go | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/constants.go b/core/constants.go index e459f565..fce35032 100644 --- a/core/constants.go +++ b/core/constants.go @@ -196,14 +196,17 @@ 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 = "DynamicNFTESDT" +const DynamicNFTESDT = Dynamic + NonFungibleESDT // DynamicSFTESDT defines the string for the token type of dynamic SFT ESDT -const DynamicSFTESDT = "DynamicSFTESDT" +const DynamicSFTESDT = Dynamic + SemiFungibleESDT // DynamicMetaESDT defines the string for the token type of dynamic meta ESDT -const DynamicMetaESDT = "DynamicMetaESDT" +const DynamicMetaESDT = Dynamic + MetaESDT // MaxRoyalty defines 100% as uint32 const MaxRoyalty = uint32(10000) diff --git a/core/converters.go b/core/converters.go index 9f41d000..833f3828 100644 --- a/core/converters.go +++ b/core/converters.go @@ -201,3 +201,8 @@ func ConvertESDTTypeToUint32(esdtType string) (uint32, error) { 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) +} From 7efd30cd7aa914a51d7d17613800f51df0fefd3e Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 15 Nov 2023 14:53:33 +0200 Subject: [PATCH 04/10] add new esdt roles --- core/constants.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/constants.go b/core/constants.go index fce35032..60a39f6a 100644 --- a/core/constants.go +++ b/core/constants.go @@ -159,6 +159,21 @@ const ESDTRoleNFTUpdateAttributes = "ESDTRoleNFTUpdateAttributes" // ESDTRoleTransfer is the constant string for the local role to transfer ESDT, only for special tokens const ESDTRoleTransfer = "ESDTTransferRole" +// ESDTSetTokenType represents the builtin function name to set token type +const ESDTSetTokenType = "ESDTSetTokenType" + +// 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" + // ESDTType defines the possible types in case of ESDT tokens type ESDTType uint32 From 02b8c2d86e894503d0a8cd81281a3a4de22e7860 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 15 Nov 2023 14:55:58 +0200 Subject: [PATCH 05/10] add new built in functions --- core/constants.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/constants.go b/core/constants.go index 60a39f6a..f49e33d9 100644 --- a/core/constants.go +++ b/core/constants.go @@ -132,6 +132,21 @@ 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" + +// ESDTNFTSetNewURIs represents the builtin function name to set new URIs for NFTs +const ESDTNFTSetNewURIs = "ESDTNFTSetNewURIs" + +// ESDTNFTModifyCreator represents the builtin function name to modify creator for NFTs +const ESDTNFTModifyCreator = "ESDTNFTModifyCreator" + +// ESDTMetaDataRecreate represents the builtin function name to recreate the metadata for ESDT tokens +const ESDTMetaDataRecreate = "ESDTMetaDataRecreate" + // ESDTRoleLocalMint is the constant string for the local role of mint for ESDT tokens const ESDTRoleLocalMint = "ESDTRoleLocalMint" @@ -159,9 +174,6 @@ const ESDTRoleNFTUpdateAttributes = "ESDTRoleNFTUpdateAttributes" // ESDTRoleTransfer is the constant string for the local role to transfer ESDT, only for special tokens const ESDTRoleTransfer = "ESDTTransferRole" -// ESDTSetTokenType represents the builtin function name to set token type -const ESDTSetTokenType = "ESDTSetTokenType" - // ESDTRoleSetNewURI represents the role which can rewrite the URI in the token metadata const ESDTRoleSetNewURI = "ESDTRoleSetNewURI" From 3c058f8ff406a4370a3dc0b128f822aa5ab4dccd Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 21 Nov 2023 13:25:28 +0200 Subject: [PATCH 06/10] add new role --- core/constants.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/constants.go b/core/constants.go index f49e33d9..b4e04599 100644 --- a/core/constants.go +++ b/core/constants.go @@ -186,6 +186,9 @@ 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 From 6296aa54741ec607435a361283c6c4d57b3e6922 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 21 Nov 2023 13:34:44 +0200 Subject: [PATCH 07/10] add ESDTMetaDataUpdate --- core/constants.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/constants.go b/core/constants.go index b4e04599..7844c328 100644 --- a/core/constants.go +++ b/core/constants.go @@ -147,6 +147,9 @@ const ESDTNFTModifyCreator = "ESDTNFTModifyCreator" // 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" From f5725945d11bf758fa8c2063191622d1886d72f4 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 21 Nov 2023 15:11:41 +0200 Subject: [PATCH 08/10] refactor names --- core/constants.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/constants.go b/core/constants.go index 7844c328..c3d7bca4 100644 --- a/core/constants.go +++ b/core/constants.go @@ -138,11 +138,11 @@ const ESDTSetTokenType = "ESDTSetTokenType" // ESDTModifyRoyalties represents the builtin function name to modify royalties const ESDTModifyRoyalties = "ESDTModifyRoyalties" -// ESDTNFTSetNewURIs represents the builtin function name to set new URIs for NFTs -const ESDTNFTSetNewURIs = "ESDTNFTSetNewURIs" +// ESDTSetNewURIs represents the builtin function name to set new URIs for NFTs +const ESDTSetNewURIs = "ESDTSetNewURIs" -// ESDTNFTModifyCreator represents the builtin function name to modify creator for NFTs -const ESDTNFTModifyCreator = "ESDTNFTModifyCreator" +// 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" From 969a1a41a4044d245ef4e6c83e54f2c5e8a4f47e Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 30 Jan 2024 13:45:25 +0200 Subject: [PATCH 09/10] add unit tests --- core/constants.go | 4 ++-- core/converters.go | 2 +- core/converters_test.go | 53 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/core/constants.go b/core/constants.go index c3d7bca4..e022eea3 100644 --- a/core/constants.go +++ b/core/constants.go @@ -202,10 +202,10 @@ const ( NonFungible // NonFungibleV2 defines the token type for ESDT non fungible tokens NonFungibleV2 - // Meta defines the token type for ESDT meta tokens - Meta // 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 diff --git a/core/converters.go b/core/converters.go index 833f3828..9f3d6dfa 100644 --- a/core/converters.go +++ b/core/converters.go @@ -188,7 +188,7 @@ func ConvertESDTTypeToUint32(esdtType string) (uint32, error) { case NonFungibleESDTv2: return uint32(NonFungibleV2), nil case MetaESDT: - return uint32(Meta), nil + return uint32(MetaFungible), nil case SemiFungibleESDT: return uint32(SemiFungible), nil case DynamicNFTESDT: 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))) +} From 6970013b49d97b4bdb9e9cb094b1321901375506 Mon Sep 17 00:00:00 2001 From: radu chis Date: Thu, 18 Apr 2024 15:10:49 +0300 Subject: [PATCH 10/10] added options for account with keys --- data/api/apiAccountResponse.go | 21 +++++++++++---------- data/api/options.go | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/data/api/apiAccountResponse.go b/data/api/apiAccountResponse.go index 4cb66e02..77662c86 100644 --- a/data/api/apiAccountResponse.go +++ b/data/api/apiAccountResponse.go @@ -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"` } diff --git a/data/api/options.go b/data/api/options.go index 66ce40dd..9aaedb90 100644 --- a/data/api/options.go +++ b/data/api/options.go @@ -10,6 +10,7 @@ type AccountQueryOptions struct { BlockHash []byte BlockRootHash []byte HintEpoch core.OptionalUint32 + WithKeys bool } // BlockQueryOptions holds options for block queries