storage

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package storage defines structures for data storage and organistion in Ethereum smart contracts together with routines to generate them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatSol

func FormatSol(files []string) error

FormatSol formats a list of solidity files using the forge formatter.

func WriteBucketStorage

func WriteBucketStorage(s BucketStorage, w io.Writer) error

WriteBucketStorage writes the storage contract file for a given BucketStorage.

func WriteFeaturesContracts

func WriteFeaturesContracts[G FeatureGroup, S BucketStorage](groups []G, stores []S, mt *merkletree.MerkleTree, outputDir string) ([]string, error)

WriteFeaturesContracts is a convenience wrapper that writes all contracts relevant for storing and working with the features on-chain.

func WriteFeaturesJSON

func WriteFeaturesJSON[G FeatureGroup](gs []G, ts []types.Token, w io.Writer) error

WriteFeaturesJSON writes the features of a set of tokens as JSON. This is intended to be used with forge's vm.parseJson for testing.

func WriteFeaturesJSONToFile

func WriteFeaturesJSONToFile[G FeatureGroup](gs []G, ts []types.Token, path string) (retErr error)

WriteFeaturesJSONToFile is a convenience wrapper to write the JSON created by `WriteFeaturesJSON` to a file.

func WriteFeaturesLib

func WriteFeaturesLib[F FeatureGroup](groups []F, mt *merkletree.MerkleTree, w io.Writer) error

WriteFeaturesLib writes a solidity file defining the Features struct and a helper library to work with it.

func WriteGroupStorage

func WriteGroupStorage[G FieldsGroup, S BucketStorage](name string, groups []G, stores []S, outputDir string) ([]string, error)

WriteGroupStorage is a convenience wrapper that writes all contracts relating to a grouping of fields and corresponding BucketStorages to a given output directory. Returns the paths of then written files.

func WriteLabelledStorageMappingFeatures

func WriteLabelledStorageMappingFeatures[S BucketStorage](name string, stores []S, w io.Writer) error

WriteLabelledStorageMappingFeatures writes the storage mapping to retrieve data from storage contracts.

func WriteSequentialStorageMapping

func WriteSequentialStorageMapping[G FieldsGroup, S BucketStorage](name string, groups []G, stores []S, w io.Writer) error

WriteSequentialStorageMapping writes the storage mapping library translating between groups of fields (e.g. grouped by layer type) and storage coordinates sequentially. For example, the sequential association works like this FieldGroups | BucketStorage 0 ├── BAR Bucket 0 ──┤ │   └── bax <> Field 0 ──┤ | │ │ | └── FOO │ |

├── bar <> Field 1 ──┘          |
│                    Bucket 1 ──┘
├── foo <> Field 0 ──┘
|                               BucketStorage 1
│                    Bucket 0 ──┘
└── qux <> Field 0 ──┘

func WriteStorageDeployer

func WriteStorageDeployer[S BucketStorage](name string, storagePath string, stores []S, w io.Writer) error

WriteStorageDeployer writes a helper contract to deploy a set of BucketStorage contracts located at storagePath.

Types

type Bucket

type Bucket interface {
	Data() ([]byte, error)
	UncompressedSize() int
	NumFields() int
}

A Bucket aggregates and compresses a list of Fields, adding additional indexing metadata.

type BucketStorage

type BucketStorage interface {
	Name() string
	Buckets() []Bucket
	NumFields() int
	Size() (int, error)
}

A BucketStorage is a named list of Buckets that will mapped to a single contract file.

type FeatureGroup

type FeatureGroup interface {
	Name() string
	NumValues() uint8
}

FeatureGroup denotes a certain types of features. E.g. "Background" with values "Black" and "White"

type Field

type Field interface {
	Encode() ([]byte, error)
}

A Field represents arbitrary data that can be represented in a binary format.

type FieldsGroup

type FieldsGroup interface {
	Name() string
	NumFields() int
}

FieldsGroup is a generic grouping of fields (e.g. all layers with a certain layer type)

type LabelledBucket

type LabelledBucket interface {
	Bucket
	Labels() []uint16
}

LabelledBucket is a bucket that contains labelled fields

type LabelledField

type LabelledField interface {
	Field
	Label() uint16
}

LabelledField is a field with an additional label

Jump to

Keyboard shortcuts

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