dump

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package dump provides I/O operations for collected states of the Neo smart contracts.

State collection (including storage) allows you to emulate work with "live" contract. First of all, it is in demand for testing. For state reproducibility, it is necessary to be able to persist (dump) information about the contract along with its data, as well as read ready-made dumps.

The package works with dumps stored in the file system using human-readable encoding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IterateDumps

func IterateDumps(dir string, f func(ID, *Reader)) error

IterateDumps iterates over all contracts collected by the Creator model in the specified directory, and passes ID and Reader of each dump into f.

Types

type Creator

type Creator struct {
	// contains filtered or unexported fields
}

Creator dumps states of the Neo smart contracts. Output file format:

'<label>-<block>-contracts.json': JSON array of contracts' states
'<label>-<block>-storage.csv': CSV of contracts' storages

Storage CSV are 'name,key,value' where name stands for contract name and binary key-value are base64-encoded.

Use IterateDumps to access existing dumps.

func NewCreator

func NewCreator(dir string, id ID) (*Creator, error)

NewCreator returns Creator which dumps contracts into given directory. The dump is identified by specified ID. Resulting Creator should be closed when finished working with it.

NewCreator fails if dump with provided ID already exists.

func (*Creator) AddContract

func (x *Creator) AddContract(name string, st state.Contract) *StorageWriter

AddContract adds given state of the named Neo contract to the resulting dump and returns StorageWriter for the contract storage. After all needed contracts are added, they should be flushed via Flush method.

func (*Creator) Close

func (x *Creator) Close()

Close releases underlying resources of the Creator and makes it unusable.

func (*Creator) Flush

func (x *Creator) Flush() error

Flush flushes accumulated dump to the file system.

type ID

type ID struct {
	// Label of the dump source (e.g. testnet, mainnet).
	Label string
	// Blockchain height at which the state was pulled.
	Block uint32
}

ID is a unique identifier of the dump prepared according to the model described in the current package.

func (ID) String

func (x ID) String() string

String returns hyphen-separated ID fields.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads contracts collected in the superior dump.

func (*Reader) IterateContractStates

func (x *Reader) IterateContractStates(f func(name string, _state state.Contract)) (err error)

IterateContractStates iterates over all contracts from the superior dump and passes their states into f.

func (*Reader) IterateContractStorages

func (x *Reader) IterateContractStorages(f func(name string, key, value []byte)) error

IterateContractStorages iterates over all contracts from the superior dump and passes their storage items into f.

type StorageWriter

type StorageWriter struct {
	// contains filtered or unexported fields
}

StorageWriter writes data into the superior contract's storage dump.

func (*StorageWriter) Write

func (x *StorageWriter) Write(key, value []byte) error

Write saves given binary key-value into the contract dump as storage item.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL