kv

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package kv defines structures to interact with 0g storage kv.

Index

Constants

This section is empty.

Variables

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

df2ff3bb0af36c6384e6206552a4ed807f6f6a26e7d0aa6bff772ddc9d4307aa

Functions

This section is empty.

Types

type Batcher

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

Batcher struct to cache and execute KV write and access control operations.

func NewBatcher added in v0.3.1

func NewBatcher(version uint64, clients []*node.ZgsClient, w3Client *web3go.Client, opts ...zg_common.LogOption) *Batcher

NewBatcher Initialize a new batcher. Version denotes the expected version of keys to read or write when the cached KV operations is settled on chain.

func (Batcher) Build added in v0.3.1

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

Build serialize all cached KV operations to StreamData.

func (*Batcher) Exec

func (b *Batcher) Exec(ctx context.Context, option ...transfer.UploadOption) (common.Hash, error)

Exec Serialize the cached KV operations in Batcher, then submit the serialized data to 0g storage network. The submission process is the same as uploading a normal file. The batcher should be dropped after execution. Note, this may be 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.

func (Batcher) GrantAdminRole added in v0.3.1

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

GrantAdminRole Cache a GrantAdminRole operation.

func (Batcher) GrantSpecialWriteRole added in v0.3.1

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

GrantSpecialWriteRole Cache a GrantSpecialWriteRole operation.

func (Batcher) GrantWriteRole added in v0.3.1

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

GrantWriteRole Cache a GrantWriteRole operation.

func (Batcher) RenounceAdminRole added in v0.3.1

func (builder Batcher) RenounceAdminRole(streamId common.Hash) *streamDataBuilder

RenounceAdminRole Cache a RenounceAdminRole operation.

func (Batcher) RenounceSpecialWriteRole added in v0.3.1

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

RenounceSpecialWriteRole Cache a RenounceSpecialWriteRole operation.

func (Batcher) RenounceWriteRole added in v0.3.1

func (builder Batcher) RenounceWriteRole(streamId common.Hash) *streamDataBuilder

RenounceWriteRole Cache a RenounceWriteRole operation.

func (Batcher) RevokeSpecialWriteRole added in v0.3.1

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

RevokeSpecialWriteRole Cache a RevokeSpecialWriteRole operation.

func (Batcher) RevokeWriteRole added in v0.3.1

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

RevokeWriteRole Cache a RevokeWriteRole operation.

func (Batcher) Set added in v0.3.1

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

Set Cache a write key operation.

func (Batcher) SetKeyToNormal added in v0.3.1

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

SetKeyToNormal Cache a SetKeyToNormal operation.

func (Batcher) SetKeyToSpecial added in v0.3.1

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

SetKeyToSpecial Cache a SetKeyToSpecial operation.

func (Batcher) SetVersion added in v0.3.1

func (builder Batcher) SetVersion(version uint64) *streamDataBuilder

SetVersion Set the expected version of keys.

func (Batcher) Watch added in v0.3.1

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

Watch Cache a read key operation.

type Client

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

Client client to query data from 0g kv node.

func NewClient

func NewClient(node *node.KvClient) *Client

NewClient creates a new client for kv queries.

func (*Client) Get

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

Get returns paginated value for the specified stream key.

func (*Client) GetFirst

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

GetFirst returns paginated key-value of the first key of the specified stream.

func (*Client) GetHoldingStreamIds

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

GetHoldingStreamIds query the stream ids monitered by the kv node.

func (*Client) GetLast

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

GetLast returns paginated key-value of the first key of the specified stream.

func (*Client) GetNext

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

GetNext returns paginated key-value of the next key of the specified stream key.

func (*Client) GetPrev

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

GetPrev returns paginated key-value of the prev key of the specified stream key.

func (*Client) GetTransactionResult

func (c *Client) GetTransactionResult(ctx context.Context, txSeq uint64) (result string, err error)

GetTransactionResult query the kv replay status of a given data by sequence id.

func (*Client) GetValue

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

GetValue Get value of a given key from kv node.

func (*Client) HasWritePermission

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

HasWritePermission check if the account is able to write the stream.

func (*Client) IsAdmin

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

IsAdmin check if the account is the admin of the stream.

func (*Client) IsSpecialKey

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

IsSpecialKey check if the key has unique access control.

func (*Client) IsWriterOfKey

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

IsWriterOfKey check if the account can write the special key.

func (*Client) IsWriterOfStream

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

IsWriterOfStream check if the account is the writer of the stream.

func (*Client) NewIterator

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

NewIterator creates an iterator.

type Iterator

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

Iterator to iterate over a kv stream

func (*Iterator) KeyValue

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

KeyValue return key-value at current position

func (*Iterator) Next

func (iter *Iterator) Next(ctx context.Context) error

Next move to the next position

func (*Iterator) Prev

func (iter *Iterator) Prev(ctx context.Context) error

Prev move to the prev position

func (*Iterator) SeekAfter

func (iter *Iterator) SeekAfter(ctx context.Context, key []byte) error

SeekAfter seek to the position after given key(inclusive)

func (*Iterator) SeekBefore

func (iter *Iterator) SeekBefore(ctx context.Context, key []byte) error

SeekBefore seek to the position before given key(inclusive)

func (*Iterator) SeekToFirst

func (iter *Iterator) SeekToFirst(ctx context.Context) error

SeekToFirst seek to the first position

func (*Iterator) SeekToLast

func (iter *Iterator) SeekToLast(ctx context.Context) error

SeekToLast seek to the last position

func (*Iterator) Valid

func (iter *Iterator) Valid() bool

Valid check if current position is exist

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.

Jump to

Keyboard shortcuts

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