Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing esdt roles for cyrpto opcodes v2 #848

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion vmhost/vmhooks/baseOps.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ func (context *VMHooksImpl) GetESDTLocalRoles(tokenIdHandle int32) int64 {
return -1
}

return getESDTRoles(data)
enableEpochsHandler := context.host.EnableEpochsHandler()
return getESDTRoles(data, enableEpochsHandler.IsFlagEnabled(vmhost.CryptoOpcodesV2Flag))
}

// ValidateTokenIdentifier VMHooks implementation.
Expand Down
50 changes: 48 additions & 2 deletions vmhost/vmhooks/eei_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const esdtRoleLocalBurn = "ESDTRoleLocalBurn"
const esdtRoleNFTCreate = "ESDTRoleNFTCreate"
const esdtRoleNFTAddQuantity = "ESDTRoleNFTAddQuantity"
const esdtRoleNFTBurn = "ESDTRoleNFTBurn"
const esdtRoleNFTUpdateAttributes = "ESDTRoleNFTUpdateAttributes"
const esdtRoleNFTAddURI = "ESDTRoleNFTAddURI"
const esdtRoleNFTRecreate = "ESDTRoleNFTRecreate"
const esdtRoleModifyCreator = "ESDTRoleModifyCreator"
const esdtRoleModifyRoyalties = "ESDTRoleModifyRoyalties"
const esdtRoleSetNewURI = "ESDTRoleSetNewURI"

const tickerMinLength = 3
const tickerMaxLength = 10
Expand All @@ -19,6 +25,12 @@ const (
RoleNFTCreate
RoleNFTAddQuantity
RoleNFTBurn
RoleNFTUpdateAttributes
RoleNFTAddURI
RoleNFTRecreate
RoleModifyCreator
RoleModifyRoyalties
RoleSetNewURI
)

func roleFromByteArray(bytes []byte) int64 {
Expand All @@ -39,7 +51,37 @@ func roleFromByteArray(bytes []byte) int64 {
}
}

func getESDTRoles(dataBuffer []byte) int64 {
func roleFromByteArrayV2(bytes []byte) int64 {
stringValue := string(bytes)
switch stringValue {
case esdtRoleLocalMint:
return RoleMint
case esdtRoleLocalBurn:
return RoleBurn
case esdtRoleNFTCreate:
return RoleNFTCreate
case esdtRoleNFTAddQuantity:
return RoleNFTAddQuantity
case esdtRoleNFTBurn:
return RoleNFTBurn
case esdtRoleNFTUpdateAttributes:
return RoleNFTUpdateAttributes
case esdtRoleNFTAddURI:
return RoleNFTAddURI
case esdtRoleNFTRecreate:
return RoleNFTRecreate
case esdtRoleModifyCreator:
return RoleModifyCreator
case esdtRoleModifyRoyalties:
return RoleModifyRoyalties
case esdtRoleSetNewURI:
return RoleSetNewURI
default:
return 0
}
}

func getESDTRoles(dataBuffer []byte, cryptoOpcodesV2Enabled bool) int64 {
result := int64(0)
currentIndex := 0
valueLen := len(dataBuffer)
Expand All @@ -57,7 +99,11 @@ func getESDTRoles(dataBuffer []byte) int64 {
roleName := dataBuffer[currentIndex:endIndex]
currentIndex = endIndex

result |= roleFromByteArray(roleName)
if cryptoOpcodesV2Enabled {
result |= roleFromByteArrayV2(roleName)
} else {
result |= roleFromByteArray(roleName)
}
}
return result
}
Expand Down
Loading