Documentation
¶
Index ¶
- Constants
- Variables
- func CreateKeyValuesProof(ctx context.Context, cli apiPB.APIServiceClient, trieID, proofID string, ...) (er error)
- func CreateTrie(ctx context.Context, cli apiPB.APIServiceClient, ...) (id, root string, er error)
- func CreateTrieProof(ctx context.Context, cli apiPB.APIServiceClient, id, root string, ...) (tp *apiPB.TrieProof, er error)
- func DeleteTrie(ctx context.Context, cli apiPB.APIServiceClient, id string) error
- func DeleteTrieProof(ctx context.Context, cli apiPB.APIServiceClient, id, proofID string) (tp *apiPB.TrieProof, er error)
- func ExportTrie(ctx context.Context, cli apiPB.APIServiceClient, id, outputPath string) error
- func GetEthTrieFromKeyValuesProof(path string) (et *proof.EthTrie, er error)
- func GetFilePathKeyMetadataKeyValues(key, fp string, de *godirwalk.Dirent) (kvs []*apiPB.KeyValue, er error)
- func GetFilePathKeyValueStream(ctx context.Context, path string, concurrency uint32, ordered bool, ...) (kvCH <-chan *apiPB.KeyValue, errCH <-chan error)
- func GetTrie(ctx context.Context, cli apiPB.APIServiceClient, id string) (tr *apiPB.Trie, er error)
- func GetTrieKeyValue(ctx context.Context, cli apiPB.APIServiceClient, id, root string, ...) (kv *apiPB.KeyValue, er error)
- func GetTrieKeyValues(ctx context.Context, cli apiPB.APIServiceClient, id, root string) (kvCH <-chan *apiPB.KeyValue, errCH <-chan error)
- func GetTrieProof(ctx context.Context, cli apiPB.APIServiceClient, ...) (tp *apiPB.TrieProof, er error)
- func GetTrieProofs(ctx context.Context, cli apiPB.APIServiceClient, id string, ...) (tpCH <-chan *apiPB.TrieProof, errCH <-chan error)
- func GetTrieRoots(ctx context.Context, cli apiPB.APIServiceClient, id string, ...) (trCH <-chan *apiPB.TrieRoot, errCH <-chan error)
- func GetTries(ctx context.Context, cli apiPB.APIServiceClient) (trCH <-chan *apiPB.Trie, errCH <-chan error)
- func ImportTrie(ctx context.Context, cli apiPB.APIServiceClient, id string, path string, ...) (newID, root string, er error)
- func InterceptKeyValueStream(ctx context.Context, input <-chan *apiPB.KeyValue, ...) (output <-chan *apiPB.KeyValue)
- func MarshalToKeyValues(keyPrefix string, v interface{}) (kvs []*apiPB.KeyValue, er error)
- func NewAPIClient(hostPort string, creds credentials.PerRPCCredentials) (con *grpc.ClientConn, cli apiPB.APIServiceClient, er error)
- func NormalizeKey(key []byte) []byte
- func SetTrieKeyValues(ctx context.Context, cli apiPB.APIServiceClient, id, root string, ...) (nextRoot string, er error)
- func SetTrieRoot(ctx context.Context, cli apiPB.APIServiceClient, id, root string) (er error)
- func SetTrieStorageType(ctx context.Context, cli apiPB.APIServiceClient, id string, ...) (er error)
- func StripCompoundKeyAnchorTriePart(kv *apiPB.KeyValue) *apiPB.KeyValue
- func SubscribeTrieProof(ctx context.Context, cli apiPB.APIServiceClient, trieID, proofID string) (tpCH <-chan *apiPB.TrieProof, errCH <-chan error)
- func UnmarshalFromKeyValues(keyPrefix string, getKeyValue func() (*apiPB.KeyValue, error), v interface{}) (er error)
- func VerifyKeyValuesProof(ctx context.Context, cli apiPB.APIServiceClient, path string, ...) (kvCH <-chan *apiPB.KeyValue, rpCH <-chan *apiPB.VerifyProofReply, ...)
- func VerifyTrieProof(ctx context.Context, cli apiPB.APIServiceClient, id, proofID string, ...) (kvCH <-chan *apiPB.KeyValue, rpCH <-chan *apiPB.VerifyProofReply, ...)
- func WithAPIClient(hostPort string, creds credentials.PerRPCCredentials, ...) error
- func WithImportedTrie(ctx context.Context, cli apiPB.APIServiceClient, id string, path string, ...) (er error)
- func WithTrie(ctx context.Context, cli apiPB.APIServiceClient, ...) (er error)
- type FilePathKeyMetadata
- type OnFilePathKeyFunc
Examples ¶
Constants ¶
const ( // MetadataPrefix is the prefix for a metadata key MetadataPrefix = metadataPrefixHeader + metadataPrefixBody // MetadataSep is the separator for a metadata key MetadataSep = "/" )
const ( // AnchorKeySepLen is the length of the key separator for the top anchor trie. For normal // Proof_ETH_TRIE format, it should be 1; for signed Proof_ETH_TRIE_SIGNED, it should be 2 AnchorKeySepLen = 1 )
Variables ¶
var ( // DefaultGetFilePathKeyValueStreamConcurrency is the default concurrency for // GetFilePathKeyValueStream DefaultGetFilePathKeyValueStreamConcurrency uint32 = 4 // FileExtensionTrie is the file extension for a trie FileExtensionTrie = ".proofable" // FileExtensionKeyValuesProof is the file extension for a key-values proof FileExtensionKeyValuesProof = ".subproofable" // FileExtensionDotGraph is the file extension for a Graphviz Dot Graph FileExtensionDotGraph = ".dot" // ErrFileSkipped is the error returned when a file is skipped ErrFileSkipped = errors.New("file skipped") )
Functions ¶
func CreateKeyValuesProof ¶
func CreateKeyValuesProof( ctx context.Context, cli apiPB.APIServiceClient, trieID, proofID string, filter *apiPB.KeyValuesFilter, outputPath string, ) (er error)
CreateKeyValuesProof creates a key-values proof for the provided key-values out of the given trie proof. When ProofID is zero, a new trie proof will be created on-the-fly
func CreateTrie ¶
func CreateTrie( ctx context.Context, cli apiPB.APIServiceClient, storageType apiPB.Trie_StorageType, ) (id, root string, er error)
CreateTrie creates a new empty trie
func CreateTrieProof ¶
func CreateTrieProof( ctx context.Context, cli apiPB.APIServiceClient, id, root string, anchorType anchorPB.Anchor_Type, ) (tp *apiPB.TrieProof, er error)
CreateTrieProof creates a trie proof for the given trie root. When root is zero (""), the current root hash of the trie will be used, and the request will be blocked until all ongoing updates are finished
func DeleteTrie ¶
DeleteTrie deletes the given trie
func DeleteTrieProof ¶
func DeleteTrieProof( ctx context.Context, cli apiPB.APIServiceClient, id, proofID string, ) (tp *apiPB.TrieProof, er error)
DeleteTrieProof deletes a proof for a trie root
func ExportTrie ¶
ExportTrie exports the given trie
func GetEthTrieFromKeyValuesProof ¶
GetEthTrieFromKeyValuesProof returns the EthTrie from the given key-values proof
func GetFilePathKeyMetadataKeyValues ¶
func GetFilePathKeyMetadataKeyValues(key, fp string, de *godirwalk.Dirent) ( kvs []*apiPB.KeyValue, er error)
GetFilePathKeyMetadataKeyValues gets the metadata key-values for a file path key
func GetFilePathKeyValueStream ¶
func GetFilePathKeyValueStream( ctx context.Context, path string, concurrency uint32, ordered bool, onFilePathKey OnFilePathKeyFunc, ) (kvCH <-chan *apiPB.KeyValue, errCH <-chan error)
GetFilePathKeyValueStream returns a key value stream of the file path. When concurrency is 1 or ordered is true, the key-value stream is guaranteed to be sorted lexically by key; when concurrency is 0, DefaultGetFilePathKeyValueStreamConcurrency is used. In summary, the three working modes of the stream generator are:
- parallel unordered processing: concurrency > 1, fastest speed
- parallel ordered processing: concurrency > 1, normal speed
- serial processing: ordered, concurrency == 1, slowest speed
Example ¶
kvCH, errCH := GetFilePathKeyValueStream( context.Background(), "../../cmd/playground/", 1, true, func(key, fp string, de *godirwalk.Dirent) (kvs []*apiPB.KeyValue, er error) { // use this callback to define the metadata embedding logic and ignored files kvs = []*apiPB.KeyValue{ {Key: []byte(key + "/!metadata/2"), Value: []byte("value2")}, {Key: []byte(key + "/!metadata/1"), Value: []byte("value1")}, } return }) for kv := range kvCH { fmt.Printf("%s -> %x\n", kv.GetKey(), kv.GetValue()) } err := <-errCH if err != nil { log.Fatal(err) }
Output: ./!metadata/1 -> 76616c756531 ./!metadata/2 -> 76616c756532 playground.go -> 87768d49ee2a77adc0cc99f751cf7c9a2bcd15e547bbd78c3791ce1f46345b5f playground.go/!metadata/1 -> 76616c756531 playground.go/!metadata/2 -> 76616c756532
func GetTrie ¶
func GetTrie( ctx context.Context, cli apiPB.APIServiceClient, id string, ) (tr *apiPB.Trie, er error)
GetTrie gets a trie
func GetTrieKeyValue ¶
func GetTrieKeyValue( ctx context.Context, cli apiPB.APIServiceClient, id, root string, key *apiPB.Key, ) (kv *apiPB.KeyValue, er error)
GetTrieKeyValue get a key-value of the trie at the given root. When root is zero (""), the current root hash of the trie will be used, and the request will be blocked until all ongoing updates are finished
func GetTrieKeyValues ¶
func GetTrieKeyValues( ctx context.Context, cli apiPB.APIServiceClient, id, root string, ) (kvCH <-chan *apiPB.KeyValue, errCH <-chan error)
GetTrieKeyValues gets the key-values of the trie at the given root. When root is zero (""), the current root hash of the trie will be used, and the request will be blocked until all ongoing updates are finished
func GetTrieProof ¶
func GetTrieProof( ctx context.Context, cli apiPB.APIServiceClient, trieID, proofID, trieRoot string, ) (tp *apiPB.TrieProof, er error)
GetTrieProof gets a trie proof by either proof ID or root. If by root, the latest proof of that root will be returned
func GetTrieProofs ¶
func GetTrieProofs( ctx context.Context, cli apiPB.APIServiceClient, id string, filter *apiPB.RootFilter, ) (tpCH <-chan *apiPB.TrieProof, errCH <-chan error)
GetTrieProofs gets proofs of a trie
func GetTrieRoots ¶
func GetTrieRoots( ctx context.Context, cli apiPB.APIServiceClient, id string, filter *apiPB.RootFilter, ) (trCH <-chan *apiPB.TrieRoot, errCH <-chan error)
GetTrieRoots gets roots of a trie. This is a series of roots showing the modification history of a trie
func GetTries ¶
func GetTries( ctx context.Context, cli apiPB.APIServiceClient, ) (trCH <-chan *apiPB.Trie, errCH <-chan error)
GetTries gets all tries. Admin privilege is required
func ImportTrie ¶
func ImportTrie( ctx context.Context, cli apiPB.APIServiceClient, id string, path string, storageType apiPB.Trie_StorageType, ) (newID, root string, er error)
ImportTrie imports the trie data and creates a new trie. If ID is zero, a new trie ID will be generated, which is recommended when importing
func InterceptKeyValueStream ¶
func InterceptKeyValueStream( ctx context.Context, input <-chan *apiPB.KeyValue, fn func(kv *apiPB.KeyValue) *apiPB.KeyValue, ) (output <-chan *apiPB.KeyValue)
InterceptKeyValueStream intercepts the key-value stream with the given callback function
func MarshalToKeyValues ¶
MarshalToKeyValues marshals the given value to key-values while respecting the JSON tags
func NewAPIClient ¶
func NewAPIClient(hostPort string, creds credentials.PerRPCCredentials) ( con *grpc.ClientConn, cli apiPB.APIServiceClient, er error)
NewAPIClient creates a new API client
func NormalizeKey ¶
NormalizeKey normalizes the given key to make sure that the metadata prefix if presented has the `metadataPrefixHeader`
func SetTrieKeyValues ¶
func SetTrieKeyValues( ctx context.Context, cli apiPB.APIServiceClient, id, root string, rangeable interface{}, ) (nextRoot string, er error)
SetTrieKeyValues sets the key-values to the trie. When root is zero (""), the current root hash of the trie will be used, and the request will be blocked until all ongoing updates are finished
func SetTrieRoot ¶
SetTrieRoot sets the root of a trie to the given one. This will add an entry in the root history
func SetTrieStorageType ¶ added in v0.3.0
func SetTrieStorageType( ctx context.Context, cli apiPB.APIServiceClient, id string, storageType apiPB.Trie_StorageType, ) (er error)
SetTrieStorageType sets the storage type of a trie
func StripCompoundKeyAnchorTriePart ¶
StripCompoundKeyAnchorTriePart strips away the anchor trie part from the compound key. The anchor trie part of a key is added by Anchor Service after a successful anchoring
func SubscribeTrieProof ¶
func SubscribeTrieProof( ctx context.Context, cli apiPB.APIServiceClient, trieID, proofID string, ) (tpCH <-chan *apiPB.TrieProof, errCH <-chan error)
SubscribeTrieProof subscribes to the given trie proof
func UnmarshalFromKeyValues ¶
func UnmarshalFromKeyValues( keyPrefix string, getKeyValue func() (*apiPB.KeyValue, error), v interface{}, ) (er error)
UnmarshalFromKeyValues unmarshals the given value from the key-values while respecting the JSON tags
func VerifyKeyValuesProof ¶
func VerifyKeyValuesProof( ctx context.Context, cli apiPB.APIServiceClient, path string, outputKeyValues bool, dotGraphOutputPath string, ) (kvCH <-chan *apiPB.KeyValue, rpCH <-chan *apiPB.VerifyProofReply, errCH <-chan error)
VerifyKeyValuesProof verifies the given key-values proof. When dotGraphOutputPath is non-zero, a Graphviz Dot Graph will be output
func VerifyTrieProof ¶
func VerifyTrieProof( ctx context.Context, cli apiPB.APIServiceClient, id, proofID string, outputKeyValues bool, dotGraphOutputPath string, ) (kvCH <-chan *apiPB.KeyValue, rpCH <-chan *apiPB.VerifyProofReply, errCH <-chan error)
VerifyTrieProof verifies the given trie proof. When dotGraphOutputPath is non-zero, a Graphviz Dot Graph will be output
func WithAPIClient ¶
func WithAPIClient(hostPort string, creds credentials.PerRPCCredentials, fn func(cli apiPB.APIServiceClient) error) error
WithAPIClient provides an API client to a closure that is automatically destroyed when done
func WithImportedTrie ¶
func WithImportedTrie( ctx context.Context, cli apiPB.APIServiceClient, id string, path string, storageType apiPB.Trie_StorageType, fn func(id, root string) error) (er error)
WithImportedTrie provides a new imported trie to the closure that is automatically destroyed when done. If ID is zero, a new trie ID will be generated, which is recommended when importing
Types ¶
type FilePathKeyMetadata ¶
type FilePathKeyMetadata struct { Size int64 `json:"size"` Mode os.FileMode `json:"mode"` ModTime int64 `json:"modTime"` ChangeTime int64 `json:"changeTime,omitempty"` BirthTime int64 `json:"birthTime,omitempty"` }
FilePathKeyMetadata represents a file path key metadata
func GetFilePathMetadata ¶
func GetFilePathMetadata(fp string) ( md *FilePathKeyMetadata, er error)
GetFilePathMetadata gets the metadata for a file path key
type OnFilePathKeyFunc ¶
OnFilePathKeyFunc represents the function called when a file path key is about to be generated. The returned key-values will be added to the result stream, which can be used to generate metadata key-values. Those key-values should be prefixed by the key to indicate their parent hierarchy. Return an ErrFileSkipped to skip current file and the walk will continue on the rest