From 1133dc537f187901b3687f12d4243c8e0099bcfc Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 1 Nov 2023 15:22:38 +0200 Subject: [PATCH 01/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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 011c96ab2548aee8ee900eaa4f5eeac39aca42a2 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 22 Feb 2024 10:15:23 +0200 Subject: [PATCH 10/16] - extended shard header handler definition --- data/block/block.go | 14 +++++++++++++- data/block/blockV2.go | 9 +++++++++ data/block/blockV2_test.go | 26 ++++++++++++++++++++++++++ data/block/block_test.go | 24 ++++++++++++++++++++++++ data/interface.go | 1 + 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/data/block/block.go b/data/block/block.go index 0ac8fd2a..8a32462d 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -14,7 +14,8 @@ var _ = data.HeaderHandler(&Header{}) var _ = data.ShardHeaderHandler(&Header{}) // MiniBlockSlice should be used when referring to subset of mini blocks that is not -// necessarily representing a full block body +// +// necessarily representing a full block body type MiniBlockSlice []*MiniBlock // MiniblockAndHash holds the info related to a miniblock and its hash @@ -278,6 +279,17 @@ func (h *Header) ShallowClone() data.HeaderHandler { return &headerCopy } +// SetBlockBodyTypeInt32 sets the blockBodyType in the header +func (h *Header) SetBlockBodyTypeInt32(blockBodyType int32) error { + if h == nil { + return data.ErrNilPointerReceiver + } + + h.BlockBodyType = Type(blockBodyType) + + return nil +} + // IsInterfaceNil returns true if there is no value under the interface func (h *Header) IsInterfaceNil() bool { return h == nil diff --git a/data/block/blockV2.go b/data/block/blockV2.go index 0a690e2e..4fb87a15 100644 --- a/data/block/blockV2.go +++ b/data/block/blockV2.go @@ -401,6 +401,15 @@ func (hv2 *HeaderV2) ShallowClone() data.HeaderHandler { return &headerCopy } +// SetBlockBodyTypeInt32 sets the blockBodyType in the header +func (hv2 *HeaderV2) SetBlockBodyTypeInt32(blockBodyType int32) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetBlockBodyTypeInt32(blockBodyType) +} + // IsInterfaceNil returns true if there is no value under the interface func (hv2 *HeaderV2) IsInterfaceNil() bool { return hv2 == nil diff --git a/data/block/blockV2_test.go b/data/block/blockV2_test.go index a0e28f58..6cedd08a 100644 --- a/data/block/blockV2_test.go +++ b/data/block/blockV2_test.go @@ -1217,3 +1217,29 @@ func TestHeaderV2_HasScheduledMiniBlocks(t *testing.T) { require.False(t, shardBlock.HasScheduledMiniBlocks()) } + +func TestHeaderV2_SetBlockBodyTypeInt32(t *testing.T) { + t.Parallel() + + t.Run("nil header should error", func(t *testing.T) { + t.Parallel() + + var header *block.HeaderV2 + err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock)) + require.Equal(t, data.ErrNilPointerReceiver, err) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + + header := &block.HeaderV2{ + Header: &block.Header{}, + } + err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock)) + require.Nil(t, err) + require.Equal(t, int32(block.ReceiptBlock), header.GetBlockBodyTypeInt32()) + + err = header.SetBlockBodyTypeInt32(int32(block.TxBlock)) + require.Nil(t, err) + require.Equal(t, int32(block.TxBlock), header.GetBlockBodyTypeInt32()) + }) +} diff --git a/data/block/block_test.go b/data/block/block_test.go index 980543b2..c83d88e7 100644 --- a/data/block/block_test.go +++ b/data/block/block_test.go @@ -845,3 +845,27 @@ func TestMiniBlockHeader_GetMiniBlockHeaderReservedShouldErrWhenReservedFieldIsN assert.Nil(t, mbhr) assert.Equal(t, data.ErrNilReservedField, err) } + +func TestHeader_SetBlockBodyTypeInt32(t *testing.T) { + t.Parallel() + + t.Run("nil header should error", func(t *testing.T) { + t.Parallel() + + var header *block.Header + err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock)) + require.Equal(t, data.ErrNilPointerReceiver, err) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + + header := &block.Header{} + err := header.SetBlockBodyTypeInt32(int32(block.ReceiptBlock)) + require.Nil(t, err) + require.Equal(t, block.ReceiptBlock, header.BlockBodyType) + + err = header.SetBlockBodyTypeInt32(int32(block.TxBlock)) + require.Nil(t, err) + require.Equal(t, block.TxBlock, header.BlockBodyType) + }) +} diff --git a/data/interface.go b/data/interface.go index 80b039da..97f5ecd7 100644 --- a/data/interface.go +++ b/data/interface.go @@ -95,6 +95,7 @@ type ShardHeaderHandler interface { GetBlockBodyTypeInt32() int32 SetMetaBlockHashes(hashes [][]byte) error MapMiniBlockHashesToShards() map[string]uint32 + SetBlockBodyTypeInt32(blockBodyType int32) error } // MetaHeaderHandler defines getters and setters for the meta block header From 5960a8922b181f04ded50319f0f1071cbb50b261 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 21 Mar 2024 17:05:32 +0200 Subject: [PATCH 11/16] fix indentation --- data/block/block.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/data/block/block.go b/data/block/block.go index 8a32462d..b1b305a8 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -14,8 +14,7 @@ var _ = data.HeaderHandler(&Header{}) var _ = data.ShardHeaderHandler(&Header{}) // MiniBlockSlice should be used when referring to subset of mini blocks that is not -// -// necessarily representing a full block body +// necessarily representing a full block body type MiniBlockSlice []*MiniBlock // MiniblockAndHash holds the info related to a miniblock and its hash From 6970013b49d97b4bdb9e9cb094b1321901375506 Mon Sep 17 00:00:00 2001 From: radu chis Date: Thu, 18 Apr 2024 15:10:49 +0300 Subject: [PATCH 12/16] 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 From 9ba698bcdbd282c18533be664cf20babe059105f Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 23 Apr 2024 12:19:37 +0300 Subject: [PATCH 13/16] FEAT: Common token prefix utility func --- data/esdt/common.go | 84 ++++++++++++++++++++++++++++++++++++++++ data/esdt/common_test.go | 62 +++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 data/esdt/common.go create mode 100644 data/esdt/common_test.go diff --git a/data/esdt/common.go b/data/esdt/common.go new file mode 100644 index 00000000..9af4a4fb --- /dev/null +++ b/data/esdt/common.go @@ -0,0 +1,84 @@ +package esdt + +import "strings" + +const ( + // esdtTickerNumRandChars represents the number of hex-encoded random characters sequence of a ticker + esdtTickerNumRandChars = 6 + // separatorChar represents the character that separated the token ticker by the random sequence + separatorChar = "-" + // minLengthForTickerName represents the minimum number of characters a token's ticker can have + minLengthForTickerName = 3 + // maxLengthForTickerName represents the maximum number of characters a token's ticker can have + maxLengthForTickerName = 10 + // maxLengthESDTPrefix represents the maximum number of characters a token's prefix can have + maxLengthESDTPrefix = 4 + // minLengthESDTPrefix represents the minimum number of characters a token's prefix can have + minLengthESDTPrefix = 1 +) + +func IsValidPrefixedToken(token string) (string, bool) { + tokenSplit := strings.Split(token, separatorChar) + if len(tokenSplit) < 3 { + return "", false + } + + prefix := tokenSplit[0] + if !IsValidTokenPrefix(prefix) { + return "", false + } + + tokenTicker := tokenSplit[1] + if !IsTickerValid(tokenTicker) { + return "", false + } + + tokenRandSeq := tokenSplit[2] + if !(len(tokenRandSeq) >= esdtTickerNumRandChars) { + return "", false + } + + return prefix, true +} + +// IsValidTokenPrefix checks if the token prefix is valid +func IsValidTokenPrefix(prefix string) bool { + prefixLen := len(prefix) + if prefixLen > maxLengthESDTPrefix || prefixLen < minLengthESDTPrefix { + return false + } + + for _, ch := range prefix { + isLowerCaseCharacter := ch >= 'a' && ch <= 'z' + isNumber := ch >= '0' && ch <= '9' + isAllowedChar := isLowerCaseCharacter || isNumber + if !isAllowedChar { + return false + } + } + + return true +} + +// IsTickerValid checks if the token ticker is valid +func IsTickerValid(ticker string) bool { + if !IsTokenTickerLenCorrect(len(ticker)) { + return false + } + + for _, ch := range ticker { + isUpperCaseCharacter := ch >= 'A' && ch <= 'Z' + isNumber := ch >= '0' && ch <= '9' + isAllowedChar := isUpperCaseCharacter || isNumber + if !isAllowedChar { + return false + } + } + + return true +} + +// IsTokenTickerLenCorrect checks if the token ticker len is correct +func IsTokenTickerLenCorrect(tokenTickerLen int) bool { + return !(tokenTickerLen < minLengthForTickerName || tokenTickerLen > maxLengthForTickerName) +} diff --git a/data/esdt/common_test.go b/data/esdt/common_test.go new file mode 100644 index 00000000..8052c23a --- /dev/null +++ b/data/esdt/common_test.go @@ -0,0 +1,62 @@ +package esdt + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIsValidPrefixedToken(t *testing.T) { + prefix, valid := IsValidPrefixedToken("sov1-TKN-coffee") + require.True(t, valid) + require.Equal(t, "sov1", prefix) + + prefix, valid = IsValidPrefixedToken("sOv1-TKN-coffee") + require.False(t, valid) + require.Equal(t, "", prefix) + + prefix, valid = IsValidPrefixedToken("sov1-TkN-coffee") + require.False(t, valid) + require.Equal(t, "", prefix) + + prefix, valid = IsValidPrefixedToken("sov1-TKN-coffe") + require.False(t, valid) + require.Equal(t, "", prefix) + + prefix, valid = IsValidPrefixedToken("sov1-TKN") + require.False(t, valid) + require.Equal(t, "", prefix) + + prefix, valid = IsValidPrefixedToken("TKN-coffee") + require.False(t, valid) + require.Equal(t, "", prefix) +} + +func TestIsValidTokenPrefix(t *testing.T) { + require.False(t, IsValidTokenPrefix("")) + require.False(t, IsValidTokenPrefix("-")) + require.False(t, IsValidTokenPrefix("prefix")) + require.False(t, IsValidTokenPrefix("prefi")) + require.False(t, IsValidTokenPrefix("Prfx")) + require.False(t, IsValidTokenPrefix("pX4")) + require.False(t, IsValidTokenPrefix("px-4")) + + require.True(t, IsValidTokenPrefix("pref")) + require.True(t, IsValidTokenPrefix("sv1")) +} + +func TestIsTickerValid(t *testing.T) { + require.False(t, IsTickerValid("TK")) + require.False(t, IsTickerValid("TKn")) + require.False(t, IsTickerValid("T0KEN-")) + + require.True(t, IsTickerValid("T0KEN")) +} + +func TestIsTokenTickerLenCorrect(t *testing.T) { + require.False(t, IsTokenTickerLenCorrect(len("TOKENALICEALICE"))) + require.False(t, IsTokenTickerLenCorrect(len("AL"))) + + require.True(t, IsTokenTickerLenCorrect(len("ALC"))) + require.True(t, IsTokenTickerLenCorrect(len("ALICE"))) +} From 2f768609cec07168f37392006e2740c413d1c16d Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 17 May 2024 13:15:13 +0300 Subject: [PATCH 14/16] FIX: Comm --- data/esdt/common.go | 1 + 1 file changed, 1 insertion(+) diff --git a/data/esdt/common.go b/data/esdt/common.go index 9af4a4fb..d2467ec4 100644 --- a/data/esdt/common.go +++ b/data/esdt/common.go @@ -17,6 +17,7 @@ const ( minLengthESDTPrefix = 1 ) +// IsValidPrefixedToken checks if the provided token is valid, and returns if prefix if so func IsValidPrefixedToken(token string) (string, bool) { tokenSplit := strings.Split(token, separatorChar) if len(tokenSplit) < 3 { From f6c188ad86c2077a445cc08c3af620ac6dd0b6ae Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 30 May 2024 13:34:21 +0300 Subject: [PATCH 15/16] type in altered account --- data/alteredAccount/alteredAccount.pb.go | 164 +++++++++++++++-------- data/alteredAccount/alteredAccount.proto | 1 + 2 files changed, 112 insertions(+), 53 deletions(-) diff --git a/data/alteredAccount/alteredAccount.pb.go b/data/alteredAccount/alteredAccount.pb.go index 231e1957..882eacef 100644 --- a/data/alteredAccount/alteredAccount.pb.go +++ b/data/alteredAccount/alteredAccount.pb.go @@ -104,6 +104,7 @@ type AccountTokenData struct { Properties string `protobuf:"bytes,4,opt,name=Properties,proto3" json:"properties"` MetaData *TokenMetaData `protobuf:"bytes,5,opt,name=MetaData,proto3" json:"metaData,omitempty"` AdditionalData *AdditionalAccountTokenData `protobuf:"bytes,6,opt,name=AdditionalData,proto3" json:"additionalData,omitempty"` + Type string `protobuf:"bytes,7,opt,name=Type,proto3" json:"type,omitempty"` } func (m *AccountTokenData) Reset() { *m = AccountTokenData{} } @@ -176,6 +177,13 @@ func (m *AccountTokenData) GetAdditionalData() *AdditionalAccountTokenData { return nil } +func (m *AccountTokenData) GetType() string { + if m != nil { + return m.Type + } + return "" +} + type TokenMetaData struct { Nonce uint64 `protobuf:"varint,1,opt,name=Nonce,proto3" json:"nonce"` Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"name"` @@ -408,58 +416,60 @@ func init() { func init() { proto.RegisterFile("alteredAccount.proto", fileDescriptor_804e04a1cde31bca) } var fileDescriptor_804e04a1cde31bca = []byte{ - // 810 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x95, 0xcd, 0x6a, 0xeb, 0x46, - 0x14, 0xc7, 0x2d, 0x7f, 0x7b, 0x9c, 0x98, 0x54, 0x24, 0xa9, 0x6b, 0x82, 0xe4, 0xba, 0x14, 0x0c, - 0xad, 0x6d, 0x48, 0x97, 0x81, 0x82, 0xe5, 0xb4, 0xc4, 0x85, 0xa6, 0x45, 0x4d, 0x16, 0xed, 0x6e, - 0x2c, 0x4d, 0x6c, 0x51, 0x4b, 0x63, 0x46, 0xa3, 0x7c, 0xec, 0x0a, 0xdd, 0x97, 0x3e, 0x46, 0xdf, - 0xa1, 0x2f, 0xd0, 0x65, 0x96, 0x59, 0x89, 0x46, 0xd9, 0x5c, 0x04, 0x17, 0xb2, 0xbd, 0xbb, 0xcb, - 0x1c, 0x49, 0xf6, 0x28, 0x1f, 0xf7, 0xae, 0x92, 0xf9, 0x9f, 0x73, 0xfe, 0xe7, 0xf8, 0x77, 0x66, - 0x6c, 0xb4, 0x8b, 0x97, 0x9c, 0x30, 0x62, 0x8f, 0x2d, 0x8b, 0x06, 0x1e, 0x1f, 0xae, 0x18, 0xe5, - 0x54, 0xad, 0xc0, 0x9f, 0xce, 0x60, 0xee, 0xf0, 0x45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xfd, 0xb3, 0x3c, - 0x51, 0x63, 0x52, 0xca, 0xa1, 0xa6, 0xb6, 0xa9, 0x61, 0xa9, 0x26, 0xd7, 0x64, 0x79, 0xc0, 0x89, - 0xda, 0x44, 0xbc, 0x12, 0x5b, 0x3c, 0xc7, 0x3a, 0xd4, 0x25, 0x9c, 0x24, 0x3d, 0xc7, 0x49, 0xd2, - 0x8d, 0x3f, 0x95, 0xdb, 0x7b, 0xad, 0x70, 0x77, 0xaf, 0x15, 0x1e, 0xef, 0x35, 0xe5, 0x8f, 0x48, - 0x53, 0xfe, 0x89, 0x34, 0xe5, 0xbf, 0x48, 0x53, 0x6e, 0x23, 0x4d, 0xb9, 0x8b, 0x34, 0xe5, 0xff, - 0x48, 0x53, 0xde, 0x44, 0x5a, 0xe1, 0x31, 0xd2, 0x94, 0xbf, 0x1f, 0xb4, 0xc2, 0xed, 0x83, 0x56, - 0xb8, 0x7b, 0xd0, 0x0a, 0xbf, 0x4d, 0xa5, 0xdf, 0x1f, 0x37, 0x58, 0x72, 0xe7, 0x92, 0x30, 0xff, - 0x7a, 0xe4, 0x5e, 0x0f, 0xac, 0x05, 0x76, 0xbc, 0x81, 0x45, 0x19, 0x19, 0xcc, 0xe9, 0x48, 0xf4, - 0x19, 0xe5, 0x7f, 0xc8, 0x8e, 0xf2, 0xc7, 0x59, 0x15, 0xbe, 0x3d, 0xbe, 0x79, 0x1f, 0x00, 0x00, - 0xff, 0xff, 0xf3, 0xb4, 0x64, 0x47, 0xf0, 0x06, 0x00, 0x00, + // 833 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x55, 0x4d, 0x6f, 0xe3, 0x44, + 0x18, 0x8e, 0x9b, 0x34, 0x1f, 0xd3, 0x36, 0x2a, 0xa3, 0x76, 0x09, 0x51, 0xe5, 0x09, 0x41, 0xa0, + 0x48, 0x90, 0x44, 0x2a, 0xc7, 0x95, 0x90, 0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, 0x04, 0xd5, 0x6e, 0x36, 0x6b, 0xd6, 0x69, 0xc0, 0xe5, 0x70, 0x1a, 0x93, 0xb6, 0xdc, 0xac, + 0xf5, 0x65, 0x82, 0x78, 0xff, 0xd7, 0x03, 0x74, 0x52, 0xba, 0xc4, 0xff, 0x9b, 0x72, 0x81, 0x6a, + 0xd7, 0xd4, 0x67, 0xb9, 0x1d, 0xcd, 0x34, 0x26, 0xb5, 0x80, 0xfa, 0xcc, 0x06, 0x54, 0x59, 0x30, + 0x15, 0x8c, 0x4a, 0x2e, 0x74, 0x0b, 0x9c, 0x0c, 0xb2, 0x8b, 0x18, 0xfe, 0x14, 0xb5, 0x6c, 0xbe, + 0xa1, 0xab, 0xad, 0x03, 0x27, 0xd6, 0x49, 0x1a, 0x93, 0x96, 0x28, 0x40, 0x7b, 0x17, 0x57, 0x1d, + 0x9f, 0xd1, 0x70, 0x09, 0xda, 0x1f, 0x67, 0x1d, 0x97, 0x34, 0x5c, 0xda, 0x80, 0xaa, 0xe8, 0x73, + 0x7b, 0x16, 0x76, 0xea, 0xbd, 0x6a, 0x11, 0x8d, 0x84, 0x17, 0xda, 0x80, 0x2a, 0xaf, 0x27, 0x52, + 0x0a, 0x6f, 0x1e, 0x49, 0x16, 0x82, 0x1c, 0xc7, 0x99, 0xd7, 0x74, 0x8b, 0xda, 0x1a, 0xa3, 0xff, + 0x03, 0xea, 0xee, 0x37, 0x01, 0x3f, 0x45, 0x47, 0xb3, 0xf0, 0xfa, 0xab, 0x1b, 0xb8, 0x46, 0x26, + 0x51, 0xd3, 0xfa, 0x20, 0x8d, 0xc9, 0xb9, 0xb7, 0x83, 0x35, 0x91, 0x75, 0x76, 0xff, 0xdf, 0x2a, + 0x3a, 0x7f, 0xe7, 0x93, 0xc2, 0x97, 0xa8, 0x39, 0x0b, 0xbf, 0x67, 0x81, 0xcb, 0x44, 0x5e, 0x13, + 0x56, 0xc9, 0xcb, 0x31, 0x7d, 0x95, 0x0a, 0x1e, 0xbe, 0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6f, + 0x0f, 0x66, 0xe5, 0xf6, 0xc1, 0xac, 0xdc, 0x3d, 0x98, 0x95, 0x1f, 0x67, 0xda, 0x77, 0xca, 0x8f, + 0x56, 0xd2, 0x7b, 0xc9, 0x44, 0xf8, 0x7a, 0xec, 0xbf, 0x1e, 0x3a, 0x4b, 0xea, 0x05, 0x43, 0x87, + 0x0b, 0x36, 0x5c, 0xf0, 0xb1, 0xea, 0x33, 0x2e, 0x7f, 0xf0, 0x9e, 0x96, 0x8f, 0xf3, 0x3a, 0xfc, + 0xca, 0x7c, 0xfe, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbe, 0xdc, 0x2f, 0xaa, 0x18, 0x07, 0x00, + 0x00, } func (this *AlteredAccount) Equal(that interface{}) bool { @@ -540,6 +550,9 @@ func (this *AccountTokenData) Equal(that interface{}) bool { if !this.AdditionalData.Equal(that1.AdditionalData) { return false } + if this.Type != that1.Type { + return false + } return true } func (this *TokenMetaData) Equal(that interface{}) bool { @@ -680,7 +693,7 @@ func (this *AccountTokenData) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 10) + s := make([]string, 0, 11) s = append(s, "&alteredAccount.AccountTokenData{") s = append(s, "Nonce: "+fmt.Sprintf("%#v", this.Nonce)+",\n") s = append(s, "Identifier: "+fmt.Sprintf("%#v", this.Identifier)+",\n") @@ -692,6 +705,7 @@ func (this *AccountTokenData) GoString() string { if this.AdditionalData != nil { s = append(s, "AdditionalData: "+fmt.Sprintf("%#v", this.AdditionalData)+",\n") } + s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -834,6 +848,13 @@ func (m *AccountTokenData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintAlteredAccount(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0x3a + } if m.AdditionalData != nil { { size, err := m.AdditionalData.MarshalToSizedBuffer(dAtA[:i]) @@ -1145,6 +1166,10 @@ func (m *AccountTokenData) Size() (n int) { l = m.AdditionalData.Size() n += 1 + l + sovAlteredAccount(uint64(l)) } + l = len(m.Type) + if l > 0 { + n += 1 + l + sovAlteredAccount(uint64(l)) + } return n } @@ -1272,6 +1297,7 @@ func (this *AccountTokenData) String() string { `Properties:` + fmt.Sprintf("%v", this.Properties) + `,`, `MetaData:` + strings.Replace(this.MetaData.String(), "TokenMetaData", "TokenMetaData", 1) + `,`, `AdditionalData:` + strings.Replace(this.AdditionalData.String(), "AdditionalAccountTokenData", "AdditionalAccountTokenData", 1) + `,`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `}`, }, "") return s @@ -1749,6 +1775,38 @@ func (m *AccountTokenData) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAlteredAccount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAlteredAccount + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAlteredAccount + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipAlteredAccount(dAtA[iNdEx:]) diff --git a/data/alteredAccount/alteredAccount.proto b/data/alteredAccount/alteredAccount.proto index 08e6c0af..01242c11 100644 --- a/data/alteredAccount/alteredAccount.proto +++ b/data/alteredAccount/alteredAccount.proto @@ -22,6 +22,7 @@ message AccountTokenData { string Properties = 4 [(gogoproto.jsontag) = "properties"]; TokenMetaData MetaData = 5 [(gogoproto.jsontag) = "metaData,omitempty"]; AdditionalAccountTokenData AdditionalData = 6 [(gogoproto.jsontag) = "additionalData,omitempty"]; + string Type = 7 [(gogoproto.jsontag) = "type,omitempty"]; } message TokenMetaData { From 45870512bfbeb21300e241c9d8345ede72fc1824 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 30 May 2024 14:12:58 +0300 Subject: [PATCH 16/16] string method --- core/constants.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/constants.go b/core/constants.go index e022eea3..e1861bee 100644 --- a/core/constants.go +++ b/core/constants.go @@ -214,6 +214,30 @@ const ( 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"