Documentation ¶
Overview ¶
Package kv defines structures to interact with 0g storage kv.
Index ¶
- Variables
- type Batcher
- func (builder Batcher) Build(sorted ...bool) (*StreamData, error)
- func (b *Batcher) Exec(ctx context.Context, option ...transfer.UploadOption) (common.Hash, error)
- func (builder Batcher) GrantAdminRole(streamId common.Hash, account common.Address) *streamDataBuilder
- func (builder Batcher) GrantSpecialWriteRole(streamId common.Hash, key []byte, account common.Address) *streamDataBuilder
- func (builder Batcher) GrantWriteRole(streamId common.Hash, account common.Address) *streamDataBuilder
- func (builder Batcher) RenounceAdminRole(streamId common.Hash) *streamDataBuilder
- func (builder Batcher) RenounceSpecialWriteRole(streamId common.Hash, key []byte) *streamDataBuilder
- func (builder Batcher) RenounceWriteRole(streamId common.Hash) *streamDataBuilder
- func (builder Batcher) RevokeSpecialWriteRole(streamId common.Hash, key []byte, account common.Address) *streamDataBuilder
- func (builder Batcher) RevokeWriteRole(streamId common.Hash, account common.Address) *streamDataBuilder
- func (builder Batcher) Set(streamId common.Hash, key []byte, data []byte) *streamDataBuilder
- func (builder Batcher) SetKeyToNormal(streamId common.Hash, key []byte) *streamDataBuilder
- func (builder Batcher) SetKeyToSpecial(streamId common.Hash, key []byte) *streamDataBuilder
- func (builder Batcher) SetVersion(version uint64) *streamDataBuilder
- func (builder Batcher) Watch(streamId common.Hash, key []byte) *streamDataBuilder
- type Client
- func (c *Client) Get(ctx context.Context, streamId common.Hash, key []byte, ...) (val *node.Value, err error)
- func (c *Client) GetFirst(ctx context.Context, streamId common.Hash, startIndex, length uint64, ...) (val *node.KeyValue, err error)
- func (c *Client) GetHoldingStreamIds(ctx context.Context) (streamIds []common.Hash, err error)
- func (c *Client) GetLast(ctx context.Context, streamId common.Hash, startIndex, length uint64, ...) (val *node.KeyValue, err error)
- func (c *Client) GetNext(ctx context.Context, streamId common.Hash, key []byte, ...) (val *node.KeyValue, err error)
- func (c *Client) GetPrev(ctx context.Context, streamId common.Hash, key []byte, ...) (val *node.KeyValue, err error)
- func (c *Client) GetTransactionResult(ctx context.Context, txSeq uint64) (result string, err error)
- func (c *Client) GetValue(ctx context.Context, streamId common.Hash, key []byte, version ...uint64) (val *node.Value, err error)
- func (c *Client) HasWritePermission(ctx context.Context, account common.Address, streamId common.Hash, key []byte, ...) (hasPermission bool, err error)
- func (c *Client) IsAdmin(ctx context.Context, account common.Address, streamId common.Hash, ...) (isAdmin bool, err error)
- func (c *Client) IsSpecialKey(ctx context.Context, streamId common.Hash, key []byte, version ...uint64) (isSpecialKey bool, err error)
- func (c *Client) IsWriterOfKey(ctx context.Context, account common.Address, streamId common.Hash, key []byte, ...) (isWriter bool, err error)
- func (c *Client) IsWriterOfStream(ctx context.Context, account common.Address, streamId common.Hash, ...) (isWriter bool, err error)
- func (c *Client) NewIterator(streamId common.Hash, version ...uint64) *Iterator
- type Iterator
- func (iter *Iterator) KeyValue() *node.KeyValue
- func (iter *Iterator) Next(ctx context.Context) error
- func (iter *Iterator) Prev(ctx context.Context) error
- func (iter *Iterator) SeekAfter(ctx context.Context, key []byte) error
- func (iter *Iterator) SeekBefore(ctx context.Context, key []byte) error
- func (iter *Iterator) SeekToFirst(ctx context.Context) error
- func (iter *Iterator) SeekToLast(ctx context.Context) error
- func (iter *Iterator) Valid() bool
- type StreamData
Constants ¶
This section is empty.
Variables ¶
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 ¶
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
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
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) SetKeyToNormal ¶ added in v0.3.1
SetKeyToNormal Cache a SetKeyToNormal operation.
func (Batcher) SetKeyToSpecial ¶ added in v0.3.1
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.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client client to query data from 0g kv node.
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 ¶
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 ¶
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.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator to iterate over a kv stream
func (*Iterator) SeekBefore ¶
SeekBefore seek to the position before given key(inclusive)
func (*Iterator) SeekToFirst ¶
SeekToFirst seek to the first position
func (*Iterator) SeekToLast ¶
SeekToLast seek to the last position
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.