Skip to content

Commit

Permalink
cli/server: drop key mangler from dumper
Browse files Browse the repository at this point in the history
It's no longer needed (yay!)
  • Loading branch information
roman-khimov committed Aug 10, 2020
1 parent 5a42b5c commit 98888de
Showing 1 changed file with 2 additions and 40 deletions.
42 changes: 2 additions & 40 deletions cli/server/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,6 @@ type storageOp struct {
Value string `json:"value,omitempty"`
}

// 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) < 4 {
panic("invalid key in storage")
}

// 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, 16)
index += 16
remain -= 16
}

if remain > 0 {
nkey = append(nkey, key[index:]...)
}

padding := 16 - remain
for i := 0; i < padding; i++ {
nkey = append(nkey, 0)
}

nkey = append(nkey, byte(remain))

return nkey
}

// batchToMap converts batch to a map so that JSON is compatible
// with https://github.com/NeoResearch/neo-storage-audit/
func batchToMap(index uint32, batch *storage.MemBatch) blockDump {
Expand All @@ -77,10 +41,9 @@ func batchToMap(index uint32, batch *storage.MemBatch) blockDump {
op = "Changed"
}

key = toNeoStorageKey(key[1:])
ops = append(ops, storageOp{
State: op,
Key: hex.EncodeToString(key),
Key: hex.EncodeToString(key[1:]),
Value: hex.EncodeToString(batch.Put[i].Value),
})
}
Expand All @@ -91,10 +54,9 @@ func batchToMap(index uint32, batch *storage.MemBatch) blockDump {
continue
}

key = toNeoStorageKey(key[1:])
ops = append(ops, storageOp{
State: "Deleted",
Key: hex.EncodeToString(key),
Key: hex.EncodeToString(key[1:]),
})
}

Expand Down

0 comments on commit 98888de

Please sign in to comment.