Skip to content

Commit

Permalink
add missing esdt roles for cyrpto opcodes v2
Browse files Browse the repository at this point in the history
  • Loading branch information
laurci committed May 20, 2024
1 parent 7b95ee6 commit 0fd1321
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
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

0 comments on commit 0fd1321

Please sign in to comment.