storage: move Operation into package of its own
Don't use storage.* types in rpc/response/result.
This commit is contained in:
parent
1e62474514
commit
96c4e61063
6 changed files with 33 additions and 25 deletions
|
@ -7,14 +7,15 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dboper"
|
||||
)
|
||||
|
||||
type dump []blockDump
|
||||
|
||||
type blockDump struct {
|
||||
Block uint32 `json:"block"`
|
||||
Size int `json:"size"`
|
||||
Storage []storage.Operation `json:"storage"`
|
||||
Block uint32 `json:"block"`
|
||||
Size int `json:"size"`
|
||||
Storage []dboper.Operation `json:"storage"`
|
||||
}
|
||||
|
||||
func newDump() *dump {
|
||||
|
|
13
pkg/core/storage/dboper/operation.go
Normal file
13
pkg/core/storage/dboper/operation.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
Package dboper contains a type used to represent single DB operation.
|
||||
*/
|
||||
package dboper
|
||||
|
||||
// Operation represents a single KV operation (add/del/change) performed
|
||||
// in the DB.
|
||||
type Operation struct {
|
||||
// State can be Added, Changed or Deleted.
|
||||
State string `json:"state"`
|
||||
Key []byte `json:"key"`
|
||||
Value []byte `json:"value,omitempty"`
|
||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dboper"
|
||||
"github.com/syndtr/goleveldb/leveldb/util"
|
||||
)
|
||||
|
||||
|
@ -41,15 +42,6 @@ const (
|
|||
ExecTransaction byte = 2
|
||||
)
|
||||
|
||||
// Operation represents a single KV operation (add/del/change) performed
|
||||
// in the DB.
|
||||
type Operation struct {
|
||||
// State can be Added, Changed or Deleted.
|
||||
State string `json:"state"`
|
||||
Key []byte `json:"key"`
|
||||
Value []byte `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
// SeekRange represents options for Store.Seek operation.
|
||||
type SeekRange struct {
|
||||
// Prefix denotes the Seek's lookup key.
|
||||
|
@ -134,10 +126,10 @@ func NewStore(cfg dbconfig.DBConfiguration) (Store, error) {
|
|||
return store, err
|
||||
}
|
||||
|
||||
// BatchToOperations converts a batch of changes into array of Operations.
|
||||
func BatchToOperations(batch *MemBatch) []Operation {
|
||||
// BatchToOperations converts a batch of changes into array of dboper.Operation.
|
||||
func BatchToOperations(batch *MemBatch) []dboper.Operation {
|
||||
size := len(batch.Put) + len(batch.Deleted)
|
||||
ops := make([]Operation, 0, size)
|
||||
ops := make([]dboper.Operation, 0, size)
|
||||
for i := range batch.Put {
|
||||
key := batch.Put[i].Key
|
||||
if len(key) == 0 || key[0] != byte(STStorage) && key[0] != byte(STTempStorage) {
|
||||
|
@ -149,7 +141,7 @@ func BatchToOperations(batch *MemBatch) []Operation {
|
|||
op = "Changed"
|
||||
}
|
||||
|
||||
ops = append(ops, Operation{
|
||||
ops = append(ops, dboper.Operation{
|
||||
State: op,
|
||||
Key: key[1:],
|
||||
Value: batch.Put[i].Value,
|
||||
|
@ -163,7 +155,7 @@ func BatchToOperations(batch *MemBatch) []Operation {
|
|||
continue
|
||||
}
|
||||
|
||||
ops = append(ops, Operation{
|
||||
ops = append(ops, dboper.Operation{
|
||||
State: "Deleted",
|
||||
Key: key[1:],
|
||||
})
|
||||
|
|
|
@ -3,6 +3,7 @@ package storage
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dboper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -19,7 +20,7 @@ func TestBatchToOperations(t *testing.T) {
|
|||
{KeyValue: KeyValue{Key: []byte{byte(STStorage), 0x06}, Value: []byte{0x06}}, Exists: true},
|
||||
},
|
||||
}
|
||||
o := []Operation{
|
||||
o := []dboper.Operation{
|
||||
{State: "Added", Key: []byte{0x01}, Value: []byte{0x01}},
|
||||
{State: "Changed", Key: []byte{0x03}, Value: []byte{0x03}},
|
||||
{State: "Deleted", Key: []byte{0x06}},
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/interop/iterator"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dboper"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/invocations"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
|
@ -36,7 +37,7 @@ type RegisterIterator func(sessionID string, item stackitem.Item, id int, finali
|
|||
|
||||
// InvokeDiag is an additional diagnostic data for invocation.
|
||||
type InvokeDiag struct {
|
||||
Changes []storage.Operation `json:"storagechanges"`
|
||||
Changes []dboper.Operation `json:"storagechanges"`
|
||||
Invocations []*invocations.Tree `json:"invokedcontracts"`
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dboper"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
|
@ -926,7 +926,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
assert.Equal(t, "HALT", res.State)
|
||||
assert.Equal(t, []stackitem.Item{stackitem.Make(true)}, res.Stack)
|
||||
assert.NotEqual(t, 0, res.GasConsumed)
|
||||
chg := []storage.Operation{{
|
||||
chg := []dboper.Operation{{
|
||||
State: "Changed",
|
||||
Key: []byte{0xfa, 0xff, 0xff, 0xff, 0xb},
|
||||
Value: []byte{0x70, 0xd9, 0x59, 0x9d, 0x51, 0x79, 0x12},
|
||||
|
@ -961,7 +961,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
Stack: []stackitem.Item{stackitem.Make("1.2.3.4")},
|
||||
Notifications: []state.NotificationEvent{},
|
||||
Diagnostics: &result.InvokeDiag{
|
||||
Changes: []storage.Operation{},
|
||||
Changes: []dboper.Operation{},
|
||||
Invocations: []*invocations.Tree{{
|
||||
Current: hash.Hash160(script),
|
||||
Calls: []*invocations.Tree{
|
||||
|
@ -1074,7 +1074,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
Stack: []stackitem.Item{stackitem.Make("1.2.3.4")},
|
||||
Notifications: []state.NotificationEvent{},
|
||||
Diagnostics: &result.InvokeDiag{
|
||||
Changes: []storage.Operation{},
|
||||
Changes: []dboper.Operation{},
|
||||
Invocations: []*invocations.Tree{{
|
||||
Current: hash.Hash160(script),
|
||||
Calls: []*invocations.Tree{
|
||||
|
@ -1166,7 +1166,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
FaultException: "at instruction 0 (ROT): too big index",
|
||||
Notifications: []state.NotificationEvent{},
|
||||
Diagnostics: &result.InvokeDiag{
|
||||
Changes: []storage.Operation{},
|
||||
Changes: []dboper.Operation{},
|
||||
Invocations: []*invocations.Tree{{
|
||||
Current: hash.Hash160(script),
|
||||
}},
|
||||
|
@ -1277,7 +1277,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
FaultException: "at instruction 0 (ROT): too big index",
|
||||
Notifications: []state.NotificationEvent{},
|
||||
Diagnostics: &result.InvokeDiag{
|
||||
Changes: []storage.Operation{},
|
||||
Changes: []dboper.Operation{},
|
||||
Invocations: []*invocations.Tree{{
|
||||
Current: hash.Hash160(script),
|
||||
}},
|
||||
|
|
Loading…
Reference in a new issue