mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-30 15:01:35 +00:00
a796f2b61d
Allow to convert interop id to it's name.
25 lines
502 B
Go
25 lines
502 B
Go
package interopnames
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/binary"
|
|
"errors"
|
|
)
|
|
|
|
var errNotFound = errors.New("interop not found")
|
|
|
|
// ToID returns an identificator of the method based on its name.
|
|
func ToID(name []byte) uint32 {
|
|
h := sha256.Sum256(name)
|
|
return binary.LittleEndian.Uint32(h[:4])
|
|
}
|
|
|
|
// FromID returns interop name from its id.
|
|
func FromID(id uint32) (string, error) {
|
|
for i := range names {
|
|
if id == ToID([]byte(names[i])) {
|
|
return names[i], nil
|
|
}
|
|
}
|
|
return "", errNotFound
|
|
}
|