Skip to content

3 Query Service

Senthilnathan Natarajan edited this page May 27, 2020 · 3 revisions

Query Service

// queryService implements the QueryService RPC
type queryService struct {
     membershipManager MembershipManager
     stateDB           StateDBQuerier
     provenanceDB      ProvenanceDBQuerier
     blockStore        BlockStoreQuerier
}

// QueryService is generated from service interface. This would be
// present in the proto generated file
type QueryService interface {
     Get(query *pb.DataQuery) (*pb.Value, error)
     GetHistory(query *pb.HistoryQuery) (*pb.HistoryDataSet, error)
     GetProof(query *pb.ProofQuery) (*pb.Proof, error)
     GetMerkleRoot() *pb.Digest
     GetTx(txID *pb.TxID) returns (Envelope)
     GetBlock(blkNum *pb.BlockNumber) *pb.Block
     GetUsers(query *pb.UserQuery) *pb.Users
     GetBlockHeight() *pb.BlockNumber
}

StateDB Query APIs

type stateDB sturct {
     db *leveldb
     mu sync.RWMutex
}

type StateDBQueries interface {
     Get(key string) ([]byte, error)
}

ProvenanceDB Query APIs

type provenanceDB sturct {
     db *leveldb
     mu sync.RWMutex
}

type ProvenanceDBQuerier interface {
     GetHistory(key string, option pb.HistoryQuery) ([]byte, error)
     GetProof(query *pb.ProofQuery) (*pb.Proof, error)
     GetMerkleRoot() *pb.Digest
}

Block Store Query APIs

type blockStore sturct {
     fileBasedStore FileStore
     mu sync.RWMutex
}

type BlockStoreQuerier interface {
     GetBlock(blockNumber uint64) (*pb.Block, error)
     GetTx(txID string) (*pb.Envelope, error)
     GetBlockHeight() (*pb.BlockNumber, error)
}