diff --git a/cli/server/dump.go b/cli/server/dump.go index ead0b3b33..233684985 100644 --- a/cli/server/dump.go +++ b/cli/server/dump.go @@ -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 }