types

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: 14 Imported by: 3

Documentation

Overview

Package types defines frequently used data primitives for the solidify toolchain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeMerkleTree

func ComputeMerkleTree(tokens []Token) (*merkletree.MerkleTree, error)

ComputeMerkleTree computes the merkle tree for a list of tokens. This routine uses keccak256 for hashing and sorts leafs by size before doing so to be compatible with OpenZeppelin's merkle proof validator in Solidity.

func DecodeImage

func DecodeImage(r interface {
	io.Reader
	io.ReaderAt
}) (image.Image, error)

DecodeImage decodes image data. Currently supported types (BMP, PNG)

func LoadImage

func LoadImage(path string) (image.Image, error)

LoadImage loads an image from a given path. Currently supported types (BMP, PNG)

Types

type FeatureGroup

type FeatureGroup struct {
	Type          string
	NonZeroValues []string
	// contains filtered or unexported fields
}

FeatureGroup is an implementation of storage.FeatureGroup treating the zero- and non-zero values separately.

func (FeatureGroup) Name

func (g FeatureGroup) Name() string

Name returns the name (i.e. type) of the FeatureGroup. E.g. "Background"

func (FeatureGroup) NumValues

func (g FeatureGroup) NumValues() uint8

NumValues returns the number of values in this group. E.g. 3 for Backgrounds being either "None", "White" or "Black".

func (*FeatureGroup) SetZeroValue

func (g *FeatureGroup) SetZeroValue(zero string)

SetZeroValue sets the zero value of this feature. Defaults to "None"

func (FeatureGroup) Values

func (g FeatureGroup) Values() []string

Values returns the values in that the feature of given type can take. The zero value is always at first position.

func (FeatureGroup) ZeroValue

func (g FeatureGroup) ZeroValue() string

ZeroValue returns te current zero value

type Image

type Image struct {
	image.Image
	// contains filtered or unexported fields
}

Image wraps around the standard go image library and provides an encoding function that it can be used to build buckets.

func (Image) Encode

func (i Image) Encode() ([]byte, error)

Encode encodes the image as a data blob compatible with the raw BMP row and channel ordering + additional alpha and frame rectangle metadata.

| hasAlpha (byte) | frameRectangle (4 bytes) | blob [(A)BGR (4 or 3 bytes) | ...] |

The blob contains only data for the subframe of the original image with non-zero alpha values to save storage space. Further, it does not have an alpha channel if all alpha values are 255 anyway. Depending on the Image.CleanSpuriousAlpha flag, we map all alpha values of 254->255 before encoding if alpha=254 is the lowest value in the image.

func (*Image) IgnoreSpuriousAlpha

func (i *Image) IgnoreSpuriousAlpha(threshold uint8)

IgnoreSpuriousAlpha sets the threshold for the alpha cleaning during the serialisation. This means that if the image only contains `alpha >= threshold`, all alpha values will be set to 255.

type StringField

type StringField string

StringField is a string implementing the storage.Field interface.

func (StringField) Encode

func (v StringField) Encode() ([]byte, error)

Encode encodes a string as UTF-8 bytes

type Token

type Token struct {
	TokenID  uint16
	Features []uint8
}

Token fully defines an collection token by specifying its tokenID and features.

func (Token) CalculateHash

func (f Token) CalculateHash() ([]byte, error)

CalculateHash calculates the hash of a token. Needed in the computation of merkle trees.

func (Token) Encode

func (f Token) Encode() ([]byte, error)

Encode encodes the token as field by serialising the features

func (Token) Equals

func (f Token) Equals(other merkletree.Content) (bool, error)

Equals checks if two tokens are equal. Needed in the computation of merkle trees.

func (Token) Label

func (f Token) Label() uint16

Label labels each token with its tokenID. Needed for the use with labelled buckets.

Jump to

Keyboard shortcuts

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