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"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
type dump []blockDump
|
||||
|
@ -26,26 +25,24 @@ type storageOp struct {
|
|||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
// NEO has some differences of key storing.
|
||||
// out format: script hash in LE + key
|
||||
// neo format: script hash in BE + byte(0) + key with 0 between every 16 bytes, padded to len 16.
|
||||
// NEO has some differences of key storing (that should go away post-preview2).
|
||||
// ours format: contract's ID (uint32le) + key
|
||||
// theirs format: contract's ID (uint32le) + key with 16 between every 16 bytes, padded to len 16.
|
||||
func toNeoStorageKey(key []byte) []byte {
|
||||
if len(key) < util.Uint160Size {
|
||||
if len(key) < 4 {
|
||||
panic("invalid key in storage")
|
||||
}
|
||||
|
||||
var nkey []byte
|
||||
for i := util.Uint160Size - 1; i >= 0; i-- {
|
||||
nkey = append(nkey, key[i])
|
||||
}
|
||||
|
||||
key = key[util.Uint160Size:]
|
||||
// Prefix is a contract's ID in LE.
|
||||
nkey := make([]byte, 4, len(key))
|
||||
copy(nkey, key[:4])
|
||||
key = key[4:]
|
||||
|
||||
index := 0
|
||||
remain := len(key)
|
||||
for remain >= 16 {
|
||||
nkey = append(nkey, key[index:index+16]...)
|
||||
nkey = append(nkey, 0)
|
||||
nkey = append(nkey, 16)
|
||||
index += 16
|
||||
remain -= 16
|
||||
}
|
||||
|
@ -59,7 +56,7 @@ func toNeoStorageKey(key []byte) []byte {
|
|||
nkey = append(nkey, 0)
|
||||
}
|
||||
|
||||
nkey = append(nkey, byte(padding))
|
||||
nkey = append(nkey, byte(remain))
|
||||
|
||||
return nkey
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue