cli: make dump more structured

This commit is contained in:
Evgenii Stratonikov 2020-03-16 12:47:26 +03:00
parent ae4dc12273
commit c25bdd8253

View file

@ -12,7 +12,13 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
) )
type dump []interface{} type dump []blockDump
type blockDump struct {
Block uint32 `json:"block"`
Size int `json:"size"`
Storage []storageOp `json:"storage"`
}
type storageOp struct { type storageOp struct {
State string `json:"state"` State string `json:"state"`
@ -60,7 +66,7 @@ func toNeoStorageKey(key []byte) []byte {
// batchToMap converts batch to a map so that JSON is compatible // batchToMap converts batch to a map so that JSON is compatible
// with https://github.com/NeoResearch/neo-storage-audit/ // with https://github.com/NeoResearch/neo-storage-audit/
func batchToMap(index uint32, batch *storage.MemBatch) map[string]interface{} { func batchToMap(index uint32, batch *storage.MemBatch) blockDump {
size := len(batch.Put) + len(batch.Deleted) size := len(batch.Put) + len(batch.Deleted)
ops := make([]storageOp, 0, size) ops := make([]storageOp, 0, size)
for i := range batch.Put { for i := range batch.Put {
@ -95,10 +101,10 @@ func batchToMap(index uint32, batch *storage.MemBatch) map[string]interface{} {
}) })
} }
return map[string]interface{}{ return blockDump{
"block": index, Block: index,
"size": len(ops), Size: len(ops),
"storage": ops, Storage: ops,
} }
} }