record

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package record contains code and types for storage records manipulation.

Index

Constants

View Source
const (
	// HashSize is a record hash size. We use 224-bit SHA-3 hash (28 bytes).
	HashSize = 28
	// PulseNumSize - 4 bytes is a PulseNum size (uint32)
	PulseNumSize = 4
	// IDSize is the size in bytes of ID binary representation.
	IDSize = PulseNumSize + HashSize
	// RefIDSize is the size in bytes of Reference binary representation.
	RefIDSize = IDSize * 2
)

Variables

This section is empty.

Functions

func Encode added in v0.0.2

func Encode(rec Record) ([]byte, error)

Encode serializes record to CBOR.

func EncodePulseNum added in v0.0.3

func EncodePulseNum(pulse PulseNum) []byte

EncodePulseNum serializes pulse number.

func EncodeRaw added in v0.0.2

func EncodeRaw(raw *Raw) ([]byte, error)

EncodeRaw encodes Raw to CBOR.

func ID2Bytes added in v0.0.2

func ID2Bytes(id ID) []byte

ID2Bytes converts ID struct to it's byte representation.

func MustEncode added in v0.0.2

func MustEncode(rec Record) []byte

MustEncode wraps Encode, panics on encoding errors.

func MustEncodeRaw added in v0.0.2

func MustEncodeRaw(raw *Raw) []byte

MustEncodeRaw wraps EncodeRaw, panics on encode errors.

func SHA3Hash224 added in v0.0.2

func SHA3Hash224(rec Record) []byte

SHA3Hash224 hashes Record by it's CBOR representation and type identifier.

Types

type ActivationRecord

type ActivationRecord struct {
	StatefulResult

	GoverningDomain Reference
}

ActivationRecord is an activation record.

type AmendRecord

type AmendRecord struct {
	StatefulResult

	HeadRecord    Reference
	AmendedRecord Reference
}

AmendRecord is produced when we modify another record in ledger.

type CallRequest

type CallRequest struct {
	RequestRecord

	CallInterface       Reference
	CallMethodSignature uint32
	ParamMemory         Memory
}

CallRequest is a contract execution request. Implements io.ReadWriter interface.

func (*CallRequest) CallMethod

func (r *CallRequest) CallMethod() uint32

CallMethod is a contract method number to call.

func (*CallRequest) Read

func (r *CallRequest) Read(p []byte) (n int, err error)

Read allows to read Request's paramMemory.

func (*CallRequest) Write

func (r *CallRequest) Write(p []byte) (n int, err error)

Write allows to write to Request's paramMemory.

type ClassActivateRecord

type ClassActivateRecord struct {
	ActivationRecord

	CodeRecord    Reference
	DefaultMemory Memory
}

ClassActivateRecord is produced when we "activate" new contract class.

type ClassAmendRecord

type ClassAmendRecord struct {
	AmendRecord

	NewCode    Reference   // CodeRecord
	Migrations []Reference // CodeRecord
}

ClassAmendRecord is an amendment record for classes.

type CodeRecord

type CodeRecord struct {
	StorageRecord

	TargetedCode map[core.MachineType][]byte
	SourceCode   string
	Types        []Reference
}

CodeRecord is a code storage record.

func (*CodeRecord) GetCode added in v0.0.2

func (r *CodeRecord) GetCode(archPref []core.MachineType) ([]byte, error)

GetCode returns class code according to provided architecture preferences. If preferences are not provided or the record does not contain code for any of provided architectures an error will be returned.

type DeactivationRecord

type DeactivationRecord struct {
	AmendRecord
}

DeactivationRecord marks targeted object as disabled.

type EnforcedObjectAmendRecord

type EnforcedObjectAmendRecord struct {
	ObjectAmendRecord
}

EnforcedObjectAmendRecord is an enforced amendment record for objects.

type ID added in v0.0.2

type ID struct {
	Pulse PulseNum
	Hash  []byte
}

ID is a composite identifier for records.

Hash is a bytes slice here to avoid copy of Hash array.

func Bytes2ID added in v0.0.2

func Bytes2ID(b []byte) ID

Bytes2ID converts ID from byte representation to struct.

func (ID) IsEqual added in v0.0.2

func (id ID) IsEqual(id2 ID) bool

IsEqual checks equality of IDs.

func (ID) WriteHash added in v0.0.2

func (id ID) WriteHash(w io.Writer)

WriteHash implements hash.Writer interface.

type LockUnlockRequest

type LockUnlockRequest struct {
	RequestRecord

	Transaction          Reference
	ExpectedLockDuration time.Duration
}

LockUnlockRequest is a request to temporary lock (or unlock) another record.

type LockUnlockResult

type LockUnlockResult struct {
	SpecialResult
}

LockUnlockResult is a result of lock/unlock attempts.

type Memory

type Memory []byte

Memory is actual contracts' state, variables etc.

type ObjectActivateRecord

type ObjectActivateRecord struct {
	ActivationRecord

	ClassActivateRecord Reference
	Memory              Memory
}

ObjectActivateRecord is produced when we instantiate new object from an available class.

type ObjectAmendRecord

type ObjectAmendRecord struct {
	AmendRecord

	NewMemory Memory
}

ObjectAmendRecord is an amendment record for objects.

type ObjectAppendRecord

type ObjectAppendRecord struct {
	AmendRecord

	AppendMemory Memory
}

ObjectAppendRecord is an "append state" record for objects. It does not contain full actual state.

type ProjectionType

type ProjectionType uint32

ProjectionType is a "view filter" for record. E.g. we can read whole object or just it's hash.

type PulseNum added in v0.0.2

type PulseNum uint32

PulseNum is a sequential number of Pulse. Upper 2 bits are reserved for use in references (scope), must be zero otherwise. Valid Absolute PulseNum must be >65536. If PulseNum <65536 it is a relative PulseNum

const SpecialPulseNumber PulseNum = 65536

SpecialPulseNumber - special value of PulseNum, it means a Drop-relative Pulse Number. It is only allowed for Storage.

func DecodePulseNum added in v0.0.3

func DecodePulseNum(buff []byte) PulseNum

DecodePulseNum deserializes pulse number.

func (PulseNum) Bytes added in v0.0.2

func (pn PulseNum) Bytes(rec Record) []byte

Bytes evaluates bytes representation of PulseNum and Record pair.

func (PulseNum) ID added in v0.0.2

func (pn PulseNum) ID(rec Record) ID

ID evaluates record ID on PulseNum for Record.

func (PulseNum) MustWrite added in v0.0.4

func (pn PulseNum) MustWrite(w io.Writer)

MustWrite writes binary representation of PulseNum to io.Writer.

Prefix 'Must' means it panics on write error.

type Raw added in v0.0.2

type Raw struct {
	Type TypeID
	Data []byte
}

Raw struct contains raw serialized record. We need raw blob to not have dependency on record structure changes in future, and have ability of consistent hash checking on old records.

func DecodeToRaw added in v0.0.2

func DecodeToRaw(b []byte) (*Raw, error)

DecodeToRaw decodes bytes to Raw struct from CBOR.

func EncodeToRaw added in v0.0.2

func EncodeToRaw(rec Record) (*Raw, error)

EncodeToRaw converts record to Raw record.

func (*Raw) Hash added in v0.0.2

func (raw *Raw) Hash() []byte

Hash generates hash for Raw record.

func (*Raw) ToRecord added in v0.0.2

func (raw *Raw) ToRecord() Record

ToRecord decodes Raw to Record.

type ReadObject

type ReadObject struct {
	ReadRequest

	ProjectionType ProjectionType
}

ReadObject is a request type

type ReadObjectComposite

type ReadObjectComposite struct {
	ReadObject

	CompositeType Reference
}

ReadObjectComposite is a request to read object including it's "injected" fields.

type ReadObjectResult

type ReadObjectResult struct {
	StatelessResult

	State            int32
	MemoryProjection Memory
}

ReadObjectResult contains necessary object's memory.

type ReadRecordRequest

type ReadRecordRequest struct {
	ReadRequest

	ExpectedRecordType TypeID
}

ReadRecordRequest is a request type to read another record.

type ReadRecordResult

type ReadRecordResult struct {
	StatelessResult

	RecordBody []byte
}

ReadRecordResult just contains necessary record from storage.

type ReadRequest

type ReadRequest struct {
	RequestRecord
}

ReadRequest is a request type to read data.

type ReasonCode

type ReasonCode uint32

ReasonCode is an error reason code.

type Record

type Record interface {
	Domain() *Reference
}

Record is base interface for all records.

type Reference

type Reference struct {
	Domain ID
	Record ID
}

Reference allows to address any record across the whole network.

func Core2Reference added in v0.0.5

func Core2Reference(cRef core.RecordRef) Reference

Core2Reference converts commonly used reference to Ledger-specific.

func (*Reference) CoreRef added in v0.0.5

func (ref *Reference) CoreRef() *core.RecordRef

CoreRef generates Reference byte representation (key without prefix).

func (Reference) IsEqual added in v0.0.2

func (ref Reference) IsEqual(ref2 Reference) bool

IsEqual checks equality of References.

func (Reference) IsNotEqual added in v0.0.2

func (ref Reference) IsNotEqual(ref2 Reference) bool

IsNotEqual checks non equality of References.

type RejectionResult

type RejectionResult struct {
	SpecialResult
}

RejectionResult is a result type for failed attempts.

type RequestRecord

type RequestRecord struct {
	Requester Reference
	Target    Reference
}

RequestRecord is common type for all requests.

func (*RequestRecord) Domain added in v0.0.2

func (rec *RequestRecord) Domain() *Reference

Domain implements Record interface

type ResultRecord

type ResultRecord struct {
	DomainRecord  Reference
	RequestRecord Reference
}

ResultRecord is a common type for all results.

func (*ResultRecord) Domain added in v0.0.2

func (rec *ResultRecord) Domain() *Reference

Domain implements Record interface

type SpecialResult

type SpecialResult struct {
	ResultRecord

	ReasonCode ReasonCode
}

SpecialResult is a result type for special situations.

type StatefulCallResult

type StatefulCallResult struct {
	ObjectAmendRecord

	ResultMemory Memory
}

StatefulCallResult is a contract call result that produces new state.

type StatefulExceptionResult

type StatefulExceptionResult struct {
	StatefulCallResult

	ExceptionType Reference
}

StatefulExceptionResult is an exception result that needs to be stored.

type StatefulResult

type StatefulResult struct {
	ResultRecord
}

StatefulResult is a result type which contents need to be persistently stored.

type StatelessCallResult

type StatelessCallResult struct {
	StatelessResult

	ResultMemory Memory
}

StatelessCallResult is a contract call result that didn't produce new state.

func (*StatelessCallResult) Read

func (r *StatelessCallResult) Read(p []byte) (n int, err error)

Read allows to read Result's resultMemory.

func (*StatelessCallResult) Write

func (r *StatelessCallResult) Write(p []byte) (n int, err error)

Write allows to write to Request's paramMemory.

type StatelessExceptionResult

type StatelessExceptionResult struct {
	StatelessCallResult

	ExceptionType Reference
}

StatelessExceptionResult is an exception result that does not need to be stored.

type StatelessResult

type StatelessResult struct {
	ResultRecord
}

StatelessResult is a result type that does not need to be stored.

type StorageRecord

type StorageRecord struct {
	StatefulResult
}

StorageRecord is produced when we store something in ledger. Code, data etc.

type TypeID added in v0.0.2

type TypeID uint32

TypeID encodes a record object type.

func (TypeID) WriteHash added in v0.0.2

func (id TypeID) WriteHash(w io.Writer)

WriteHash implements hash.Writer interface.

type TypeRecord added in v0.0.5

type TypeRecord struct {
	StorageRecord

	TypeDeclaration []byte
}

TypeRecord is a code interface declaration.

type WipeOutRecord

type WipeOutRecord struct {
	ResultRecord

	Replacement Reference
	WipedHash   [HashSize]byte
}

WipeOutRecord is a special record that takes place of another record when we need to completely wipe out some information from storage (think GDPR).

Jump to

Keyboard shortcuts

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