[#184] *: Add `ownerSize` constant

It consists of 1 byte prefix, script hash
and 4 byte hash of the previous bytes.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
enable-notary-in-public-chains
Pavel Karpy 2021-11-30 14:27:12 +03:00 committed by Alex Vanin
parent a2f5f7a74a
commit 5c4e44575a
1 changed files with 11 additions and 7 deletions

View File

@ -18,6 +18,10 @@ type (
}
)
const (
ownerSize = 1 + interop.Hash160Len + 4
)
const (
netmapContractKey = "netmapScriptHash"
containerContractKey = "containerScriptHash"
@ -33,7 +37,7 @@ func _deploy(data interface{}, isUpdate bool) {
for iterator.Next(it) {
kv := iterator.Value(it).([][]byte)
// V2 format
if len(kv[0]) == 25 {
if len(kv[0]) == ownerSize {
info := std.Deserialize(kv[1]).(UserInfo)
key := append([]byte{ownerKeysPrefix}, kv[0]...)
for i := range info.Keys {
@ -83,11 +87,11 @@ func Update(script []byte, manifest []byte, data interface{}) {
// AddKey binds list of provided public keys to OwnerID. Can be invoked only by
// Alphabet nodes.
//
// This method panics if OwnerID is not 25 byte or public key is not 33 byte long.
// This method panics if OwnerID is not ownerSize byte or public key is not 33 byte long.
// If key is already bound, ignores it.
func AddKey(owner []byte, keys []interop.PublicKey) {
// V2 format
if len(owner) != 25 {
if len(owner) != ownerSize {
panic("incorrect owner")
}
@ -147,11 +151,11 @@ func AddKey(owner []byte, keys []interop.PublicKey) {
// RemoveKey unbinds provided public keys from OwnerID. Can be invoked only by
// Alphabet nodes.
//
// This method panics if OwnerID is not 25 byte or public key is not 33 byte long.
// This method panics if OwnerID is not ownerSize byte or public key is not 33 byte long.
// If key is already unbound, ignores it.
func RemoveKey(owner []byte, keys []interop.PublicKey) {
// V2 format
if len(owner) != 25 {
if len(owner) != ownerSize {
panic("incorrect owner")
}
@ -201,10 +205,10 @@ func RemoveKey(owner []byte, keys []interop.PublicKey) {
// Key method returns list of 33-byte public keys bound with OwnerID.
//
// This method panics if owner is not 25 byte long.
// This method panics if owner is not ownerSize byte long.
func Key(owner []byte) [][]byte {
// V2 format
if len(owner) != 25 {
if len(owner) != ownerSize {
panic("incorrect owner")
}