kv

package
v0.0.0-...-cd21dfb Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StreamDomain = common.Hash(sha256.Sum256([]byte("STREAM")))

df2ff3bb0af36c6384e6206552a4ed807f6f6a26e7d0aa6bff772ddc9d4307aa

Functions

func CreateTags

func CreateTags(streamIds ...common.Hash) []byte

Types

type AccessControl

type AccessControl struct {
	Type     AccessControlType
	StreamId common.Hash
	Account  *common.Address
	Key      *[]byte
}

type AccessControlBuilder

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

func (*AccessControlBuilder) AddStreamId

func (builder *AccessControlBuilder) AddStreamId(streamId common.Hash)

func (*AccessControlBuilder) Build

func (builder *AccessControlBuilder) Build() ([]AccessControl, error)

func (*AccessControlBuilder) BuildTags

func (builder *AccessControlBuilder) BuildTags(sorted ...bool) []byte

func (*AccessControlBuilder) GrantAdminRole

func (builder *AccessControlBuilder) GrantAdminRole(streamId common.Hash, account common.Address) *AccessControlBuilder

func (*AccessControlBuilder) GrantSpecialWriteRole

func (builder *AccessControlBuilder) GrantSpecialWriteRole(streamId common.Hash, key []byte, account common.Address) *AccessControlBuilder

func (*AccessControlBuilder) GrantWriteRole

func (builder *AccessControlBuilder) GrantWriteRole(streamId common.Hash, account common.Address) *AccessControlBuilder

func (*AccessControlBuilder) RenounceAdminRole

func (builder *AccessControlBuilder) RenounceAdminRole(streamId common.Hash) *AccessControlBuilder

func (*AccessControlBuilder) RenounceSpecialWriteRole

func (builder *AccessControlBuilder) RenounceSpecialWriteRole(streamId common.Hash, key []byte) *AccessControlBuilder

func (*AccessControlBuilder) RenounceWriteRole

func (builder *AccessControlBuilder) RenounceWriteRole(streamId common.Hash) *AccessControlBuilder

func (*AccessControlBuilder) RevokeSpecialWriteRole

func (builder *AccessControlBuilder) RevokeSpecialWriteRole(streamId common.Hash, key []byte, account common.Address) *AccessControlBuilder

func (*AccessControlBuilder) RevokeWriteRole

func (builder *AccessControlBuilder) RevokeWriteRole(streamId common.Hash, account common.Address) *AccessControlBuilder

func (*AccessControlBuilder) SetKeyToNormal

func (builder *AccessControlBuilder) SetKeyToNormal(streamId common.Hash, key []byte) *AccessControlBuilder

func (*AccessControlBuilder) SetKeyToSpecial

func (builder *AccessControlBuilder) SetKeyToSpecial(streamId common.Hash, key []byte) *AccessControlBuilder

type AccessControlType

type AccessControlType uint8
const (
	// Admin role
	AclTypeGrantAdminRole    AccessControlType = 0x00
	AclTypeRenounceAdminRole AccessControlType = 0x01

	// set/unset special key
	AclTypeSetKeyToSpecial AccessControlType = 0x10
	AclTypeSetKeyToNormal  AccessControlType = 0x11

	// Write role for all keys
	AclTypeGrantWriteRole    AccessControlType = 0x20
	AclTypeRevokeWriteRole   AccessControlType = 0x21
	AclTypeRenounceWriteRole AccessControlType = 0x22

	// Write role for special key
	AclTypeGrantSpecialWriteRole    AccessControlType = 0x30
	AclTypeRevokeSpecialWriteRole   AccessControlType = 0x31
	AclTypeRenounceSpecialWriteRole AccessControlType = 0x32
)

type Batcher

type Batcher struct {
	*StreamDataBuilder
	// contains filtered or unexported fields
}

func (Batcher) AddStreamId

func (builder Batcher) AddStreamId(streamId common.Hash)

func (Batcher) BuildTags

func (builder Batcher) BuildTags(sorted ...bool) []byte

func (*Batcher) Exec

func (b *Batcher) Exec() error

Exec submit the kv operations to Neurahive network in batch.

Note, this is a time consuming operation, e.g. several seconds or even longer. When it comes to a time sentitive context, it should be executed in a separate go-routine.

type Client

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

Client is used for users to communicate with server for kv operations.

func NewClient

func NewClient(node *node.Client, flow *contract.FlowContract) *Client

NewClient creates a new client for kv operations.

Generally, you could refer to the `upload` function in `cmd/upload.go` file for how to create storage node client and flow contract client.

func (*Client) Batcher

func (c *Client) Batcher() *Batcher

Batcher returns a Batcher instance for kv operations in batch.

func (*Client) Get

func (c *Client) Get(streamId common.Hash, key []byte, startIndex, length uint64, version ...uint64) (val *node.Value, err error)

Get returns paginated value for the specified stream key and offset.

func (*Client) GetFirst

func (c *Client) GetFirst(streamId common.Hash, startIndex, length uint64, version ...uint64) (val *node.KeyValue, err error)

func (*Client) GetHoldingStreamIds

func (c *Client) GetHoldingStreamIds() (streamIds []common.Hash, err error)

func (*Client) GetLast

func (c *Client) GetLast(streamId common.Hash, startIndex, length uint64, version ...uint64) (val *node.KeyValue, err error)

func (*Client) GetNext

func (c *Client) GetNext(streamId common.Hash, key []byte, startIndex, length uint64, inclusive bool, version ...uint64) (val *node.KeyValue, err error)

func (*Client) GetPrev

func (c *Client) GetPrev(streamId common.Hash, key []byte, startIndex, length uint64, inclusive bool, version ...uint64) (val *node.KeyValue, err error)

func (*Client) GetTransactionResult

func (c *Client) GetTransactionResult(txSeq uint64) (result string, err error)

func (*Client) GetValue

func (c *Client) GetValue(streamId common.Hash, key []byte, version ...uint64) (val *node.Value, err error)

func (*Client) HasWritePermission

func (c *Client) HasWritePermission(account common.Address, streamId common.Hash, key []byte, version ...uint64) (hasPermission bool, err error)

func (*Client) IsAdmin

func (c *Client) IsAdmin(account common.Address, streamId common.Hash, version ...uint64) (isAdmin bool, err error)

func (*Client) IsSpecialKey

func (c *Client) IsSpecialKey(streamId common.Hash, key []byte, version ...uint64) (isSpecialKey bool, err error)

func (*Client) IsWriterOfKey

func (c *Client) IsWriterOfKey(account common.Address, streamId common.Hash, key []byte, version ...uint64) (isWriter bool, err error)

func (*Client) IsWriterOfStream

func (c *Client) IsWriterOfStream(account common.Address, streamId common.Hash, version ...uint64) (isWriter bool, err error)

func (*Client) NewIterator

func (c *Client) NewIterator(streamId common.Hash, version ...uint64) *Iterator

type Iterator

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

func (*Iterator) KeyValue

func (iter *Iterator) KeyValue() *node.KeyValue

func (*Iterator) Next

func (iter *Iterator) Next() error

func (*Iterator) Prev

func (iter *Iterator) Prev() error

func (*Iterator) SeekAfter

func (iter *Iterator) SeekAfter(key []byte) error

func (*Iterator) SeekBefore

func (iter *Iterator) SeekBefore(key []byte) error

func (*Iterator) SeekToFirst

func (iter *Iterator) SeekToFirst() error

func (*Iterator) SeekToLast

func (iter *Iterator) SeekToLast() error

func (*Iterator) Valid

func (iter *Iterator) Valid() bool

type StreamData

type StreamData struct {
	Version  uint64
	Reads    []StreamRead
	Writes   []StreamWrite
	Controls []AccessControl
}

func (*StreamData) Encode

func (sd *StreamData) Encode() ([]byte, error)

func (*StreamData) Size

func (sd *StreamData) Size() int

Size returns the serialized data size in bytes.

type StreamDataBuilder

type StreamDataBuilder struct {
	AccessControlBuilder
	// contains filtered or unexported fields
}

func NewStreamDataBuilder

func NewStreamDataBuilder(version uint64) *StreamDataBuilder

func (*StreamDataBuilder) AddStreamId

func (builder *StreamDataBuilder) AddStreamId(streamId common.Hash)

func (*StreamDataBuilder) Build

func (builder *StreamDataBuilder) Build(sorted ...bool) (*StreamData, error)

func (*StreamDataBuilder) BuildTags

func (builder *StreamDataBuilder) BuildTags(sorted ...bool) []byte

func (*StreamDataBuilder) Set

func (builder *StreamDataBuilder) Set(streamId common.Hash, key []byte, data []byte) *StreamDataBuilder

func (*StreamDataBuilder) SetVersion

func (builder *StreamDataBuilder) SetVersion(version uint64) *StreamDataBuilder

func (*StreamDataBuilder) Watch

func (builder *StreamDataBuilder) Watch(streamId common.Hash, key []byte) *StreamDataBuilder

type StreamRead

type StreamRead struct {
	StreamId common.Hash
	Key      []byte
}

type StreamWrite

type StreamWrite struct {
	StreamId common.Hash
	Key      []byte
	Data     []byte
}

Jump to

Keyboard shortcuts

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