forked from TrueCloudLab/neoneo-go
cli/server: update toNeoStorageKey key conversion for Neo 3
Follow #1037 changes with contract IDs and update padding, the number of value bytes is being stored now as 17th byte instead of number of zeroes.
This commit is contained in:
parent
0fdeafb8f7
commit
fb18eda515
1 changed files with 10 additions and 13 deletions
|
@ -9,7 +9,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type dump []blockDump
|
type dump []blockDump
|
||||||
|
@ -26,26 +25,24 @@ type storageOp struct {
|
||||||
Value string `json:"value,omitempty"`
|
Value string `json:"value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEO has some differences of key storing.
|
// NEO has some differences of key storing (that should go away post-preview2).
|
||||||
// out format: script hash in LE + key
|
// ours format: contract's ID (uint32le) + key
|
||||||
// neo format: script hash in BE + byte(0) + key with 0 between every 16 bytes, padded to len 16.
|
// theirs format: contract's ID (uint32le) + key with 16 between every 16 bytes, padded to len 16.
|
||||||
func toNeoStorageKey(key []byte) []byte {
|
func toNeoStorageKey(key []byte) []byte {
|
||||||
if len(key) < util.Uint160Size {
|
if len(key) < 4 {
|
||||||
panic("invalid key in storage")
|
panic("invalid key in storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
var nkey []byte
|
// Prefix is a contract's ID in LE.
|
||||||
for i := util.Uint160Size - 1; i >= 0; i-- {
|
nkey := make([]byte, 4, len(key))
|
||||||
nkey = append(nkey, key[i])
|
copy(nkey, key[:4])
|
||||||
}
|
key = key[4:]
|
||||||
|
|
||||||
key = key[util.Uint160Size:]
|
|
||||||
|
|
||||||
index := 0
|
index := 0
|
||||||
remain := len(key)
|
remain := len(key)
|
||||||
for remain >= 16 {
|
for remain >= 16 {
|
||||||
nkey = append(nkey, key[index:index+16]...)
|
nkey = append(nkey, key[index:index+16]...)
|
||||||
nkey = append(nkey, 0)
|
nkey = append(nkey, 16)
|
||||||
index += 16
|
index += 16
|
||||||
remain -= 16
|
remain -= 16
|
||||||
}
|
}
|
||||||
|
@ -59,7 +56,7 @@ func toNeoStorageKey(key []byte) []byte {
|
||||||
nkey = append(nkey, 0)
|
nkey = append(nkey, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
nkey = append(nkey, byte(padding))
|
nkey = append(nkey, byte(remain))
|
||||||
|
|
||||||
return nkey
|
return nkey
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue