types

package
v0.0.0-...-020e20f Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package types defines commonly used types for sql-chain.

Index

Constants

View Source
const (
	// Read defines the read user permission.
	Read UserPermissionRole = 1 << iota
	// Write defines the writer user permission.
	Write
	// Super defines the super user permission.
	Super
	// Invalid defines the invalid permission
	Invalid

	// ReadOnly defines the reader user permission.
	ReadOnly = Read
	// WriteOnly defines the writer user permission.
	WriteOnly = Write
	// ReadWrite defines the reader && writer user permission.
	ReadWrite = Read | Write
	// Admin defines the privilege to full control the database.
	Admin = Read | Write | Super

	// Void defines the initial permission.
	Void UserPermissionRole = 0
)
View Source
const (
	// ReplicateFromBeginning is the replication offset observes from genesis block.
	ReplicateFromBeginning = int32(0)
	// ReplicateFromNewest is the replication offset observes from block head of current node.
	ReplicateFromNewest = int32(-1)
)

Variables

View Source
var (
	// ErrMerkleRootVerification indicates a failed merkle root verificatin.
	ErrMerkleRootVerification = errors.New("merkle root verification failed")
	// ErrNodePublicKeyNotMatch indicates that the public key given with a node does not match the
	// one in the key store.
	ErrNodePublicKeyNotMatch = errors.New("node publick key doesn't match")
	// ErrSignVerification indicates a failed signature verification.
	ErrSignVerification = errors.New("signature verification failed")
	// ErrBillingNotMatch indicates that the billing request doesn't match the local result.
	ErrBillingNotMatch = errors.New("billing request doesn't match")
	// ErrHashVerification indicates a failed hash verification.
	ErrHashVerification = errors.New("hash verification failed")
	// ErrInvalidGenesis indicates a failed genesis block verification.
	ErrInvalidGenesis = errors.New("invalid genesis block")
)
View Source
var TokenList = map[TokenType]string{
	Particle: "Particle",
	Wave:     "Wave",
}

TokenList lists supporting token.

Functions

This section is empty.

Types

type Account

type Account struct {
	Address      proto.AccountAddress
	TokenBalance [SupportTokenNumber]uint64
	Rating       float64
	NextNonce    pi.AccountNonce
}

Account store its balance, and other mate data.

type Ack

type Ack struct {
	proto.Envelope
	Header SignedAckHeader `json:"h"`
}

Ack defines a whole client ack request entity.

func (*Ack) Sign

func (a *Ack) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*Ack) Verify

func (a *Ack) Verify() error

Verify checks hash and signature in ack.

type AckHeader

type AckHeader struct {
	Response     ResponseHeader `json:"r"`
	ResponseHash hash.Hash      `json:"rh"`
	NodeID       proto.NodeID   `json:"i"` // ack node id
	Timestamp    time.Time      `json:"t"` // time in UTC zone
}

AckHeader defines client ack entity.

func (*AckHeader) GetQueryKey

func (h *AckHeader) GetQueryKey() QueryKey

GetQueryKey returns the request query key.

func (*AckHeader) GetRequestHash

func (h *AckHeader) GetRequestHash() hash.Hash

GetRequestHash returns the request hash.

func (*AckHeader) GetRequestTimestamp

func (h *AckHeader) GetRequestTimestamp() time.Time

GetRequestTimestamp returns the request timestamp.

func (*AckHeader) GetResponseHash

func (h *AckHeader) GetResponseHash() hash.Hash

GetResponseHash returns the response hash.

func (*AckHeader) GetResponseTimestamp

func (h *AckHeader) GetResponseTimestamp() time.Time

GetResponseTimestamp returns the response timestamp.

type AckResponse

type AckResponse struct{}

AckResponse defines client ack response entity.

type AddTxReq

type AddTxReq struct {
	proto.Envelope

	TTL uint32 // defines the broadcast TTL on BP network.
	Tx  interfaces.Transaction
}

AddTxReq defines a request of the AddTx RPC method.

type AddTxResp

type AddTxResp struct {
	proto.Envelope
}

AddTxResp defines a response of the AddTx RPC method.

type AdviseNewBlockReq

type AdviseNewBlockReq struct {
	proto.Envelope
	Block *BPBlock
}

AdviseNewBlockReq defines a request of the AdviseNewBlock RPC method.

type AdviseNewBlockResp

type AdviseNewBlockResp struct {
	proto.Envelope
}

AdviseNewBlockResp defines a response of the AdviseNewBlock RPC method.

type BPBlock

type BPBlock struct {
	SignedHeader BPSignedHeader
	Transactions []pi.Transaction
}

BPBlock defines the main chain block.

func (*BPBlock) BlockHash

func (b *BPBlock) BlockHash() *hash.Hash

BlockHash returns the parent hash field of the block header.

func (*BPBlock) GetTxHashes

func (b *BPBlock) GetTxHashes() []*hash.Hash

GetTxHashes returns all hashes of tx in block.{Billings, ...}.

func (*BPBlock) PackAndSignBlock

func (b *BPBlock) PackAndSignBlock(signer *asymmetric.PrivateKey) error

PackAndSignBlock computes block's hash and sign it.

func (*BPBlock) ParentHash

func (b *BPBlock) ParentHash() *hash.Hash

ParentHash returns the parent hash field of the block header.

func (*BPBlock) Producer

func (b *BPBlock) Producer() proto.AccountAddress

Producer returns the producer of block.

func (*BPBlock) SetHash

func (b *BPBlock) SetHash() error

SetHash sets the block header hash, including the merkle root of the packed transactions.

func (*BPBlock) Timestamp

func (b *BPBlock) Timestamp() time.Time

Timestamp returns timestamp of block.

func (*BPBlock) Verify

func (b *BPBlock) Verify() error

Verify verifies whether the block is valid.

func (*BPBlock) VerifyHash

func (b *BPBlock) VerifyHash() error

VerifyHash verifies the block header hash, including the merkle root of the packed transactions.

type BPHeader

type BPHeader struct {
	Version    int32
	Producer   proto.AccountAddress
	MerkleRoot hash.Hash
	ParentHash hash.Hash
	Timestamp  time.Time
}

BPHeader defines the main chain block header.

type BPSignedHeader

type BPSignedHeader struct {
	BPHeader
	verifier.DefaultHashSignVerifierImpl
}

BPSignedHeader defines the main chain header with the signature.

type BaseAccount

type BaseAccount struct {
	Account
	pi.TransactionTypeMixin
}

BaseAccount defines the base account type header.

func NewBaseAccount

func NewBaseAccount(account *Account) *BaseAccount

NewBaseAccount returns new instance.

func (*BaseAccount) GetAccountAddress

func (b *BaseAccount) GetAccountAddress() proto.AccountAddress

GetAccountAddress implements interfaces/Transaction.GetAccountAddress.

func (*BaseAccount) GetAccountNonce

func (b *BaseAccount) GetAccountNonce() pi.AccountNonce

GetAccountNonce implements interfaces/Transaction.GetAccountNonce.

func (*BaseAccount) Hash

func (b *BaseAccount) Hash() (h hash.Hash)

Hash implements interfaces/Transaction.Hash.

func (*BaseAccount) Sign

func (b *BaseAccount) Sign(signer *asymmetric.PrivateKey) (err error)

Sign implements interfaces/Transaction.Sign.

func (*BaseAccount) Verify

func (b *BaseAccount) Verify() (err error)

Verify implements interfaces/Transaction.Verify.

type Block

type Block struct {
	SignedHeader SignedHeader
	FailedReqs   []*Request
	QueryTxs     []*QueryAsTx
	Acks         []*SignedAckHeader
}

Block is a node of blockchain.

func CreateRandomBlock

func CreateRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error)

CreateRandomBlock create a new random block

func (*Block) BlockHash

func (b *Block) BlockHash() *hash.Hash

BlockHash returns the parent hash field of the block header.

func (*Block) CalcNextID

func (b *Block) CalcNextID() (id uint64, ok bool)

CalcNextID calculates the next query id by examinating every query in block, and adds write query number to the last offset.

TODO(leventeliu): too tricky. Consider simply adding next id to each block header.

func (*Block) GenesisHash

func (b *Block) GenesisHash() *hash.Hash

GenesisHash returns the parent hash field of the block header.

func (*Block) PackAndSignBlock

func (b *Block) PackAndSignBlock(signer *ca.PrivateKey) (err error)

PackAndSignBlock generates the signature for the Block from the given PrivateKey.

func (*Block) PackAsGenesis

func (b *Block) PackAsGenesis() (err error)

PackAsGenesis generates the hash of the genesis block.

func (*Block) ParentHash

func (b *Block) ParentHash() *hash.Hash

ParentHash returns the parent hash field of the block header.

func (*Block) Producer

func (b *Block) Producer() proto.NodeID

Producer returns the producer field of the block header.

func (*Block) Signee

func (b *Block) Signee() *ca.PublicKey

Signee returns the signee field of the block signed header.

func (*Block) Timestamp

func (b *Block) Timestamp() time.Time

Timestamp returns the timestamp field of the block header.

func (*Block) Verify

func (b *Block) Verify() (err error)

Verify verifies the merkle root and header signature of the block.

func (*Block) VerifyAsGenesis

func (b *Block) VerifyAsGenesis() (err error)

VerifyAsGenesis verifies the block as a genesis block.

type Blocks

type Blocks []*Block

Blocks is Block (reference) array.

type CreateDatabase

CreateDatabase defines the database creation transaction.

func NewCreateDatabase

func NewCreateDatabase(header *CreateDatabaseHeader) *CreateDatabase

NewCreateDatabase returns new instance.

func (*CreateDatabase) GetAccountAddress

func (cd *CreateDatabase) GetAccountAddress() proto.AccountAddress

GetAccountAddress implements interfaces/Transaction.GetAccountAddress.

func (*CreateDatabase) Sign

func (cd *CreateDatabase) Sign(signer *asymmetric.PrivateKey) (err error)

Sign implements interfaces/Transaction.Sign.

func (*CreateDatabase) Verify

func (cd *CreateDatabase) Verify() error

Verify implements interfaces/Transaction.Verify.

type CreateDatabaseHeader

type CreateDatabaseHeader struct {
	Owner          proto.AccountAddress
	ResourceMeta   ResourceMeta
	GasPrice       uint64
	AdvancePayment uint64
	TokenType      TokenType
	Nonce          pi.AccountNonce
}

CreateDatabaseHeader defines the database creation transaction header.

func (*CreateDatabaseHeader) GetAccountNonce

func (h *CreateDatabaseHeader) GetAccountNonce() pi.AccountNonce

GetAccountNonce implements interfaces/Transaction.GetAccountNonce.

type CreateDatabaseRequest

type CreateDatabaseRequest struct {
	proto.Envelope
	Header SignedCreateDatabaseRequestHeader
}

CreateDatabaseRequest defines client create database rpc request entity.

func (*CreateDatabaseRequest) Sign

func (r *CreateDatabaseRequest) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*CreateDatabaseRequest) Verify

func (r *CreateDatabaseRequest) Verify() error

Verify checks hash and signature in request header.

type CreateDatabaseRequestHeader

type CreateDatabaseRequestHeader struct {
	ResourceMeta ResourceMeta
}

CreateDatabaseRequestHeader defines client create database rpc header.

type CreateDatabaseResponse

type CreateDatabaseResponse struct {
	proto.Envelope
	Header SignedCreateDatabaseResponseHeader
}

CreateDatabaseResponse defines client create database rpc response entity.

func (*CreateDatabaseResponse) Sign

func (r *CreateDatabaseResponse) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the response.

func (*CreateDatabaseResponse) Verify

func (r *CreateDatabaseResponse) Verify() error

Verify checks hash and signature in response header.

type CreateDatabaseResponseHeader

type CreateDatabaseResponseHeader struct {
	InstanceMeta ServiceInstance
}

CreateDatabaseResponseHeader defines client create database rpc response header.

type DropDatabaseRequest

type DropDatabaseRequest struct {
	proto.Envelope
	Header SignedDropDatabaseRequestHeader
}

DropDatabaseRequest defines client drop database rpc request entity.

func (*DropDatabaseRequest) Sign

Sign the request.

func (*DropDatabaseRequest) Verify

func (r *DropDatabaseRequest) Verify() error

Verify checks hash and signature in request header.

type DropDatabaseRequestHeader

type DropDatabaseRequestHeader struct {
	DatabaseID proto.DatabaseID
}

DropDatabaseRequestHeader defines client drop database rpc request header.

type DropDatabaseResponse

type DropDatabaseResponse struct{}

DropDatabaseResponse defines client drop database rpc response entity.

type FetchBlockByCountReq

type FetchBlockByCountReq struct {
	proto.Envelope
	Count uint32
}

FetchBlockByCountReq define a request of the FetchBlockByCount RPC method.

type FetchBlockReq

type FetchBlockReq struct {
	proto.Envelope
	Height uint32
}

FetchBlockReq defines a request of the FetchBlock RPC method.

type FetchBlockResp

type FetchBlockResp struct {
	proto.Envelope
	Height uint32
	Count  uint32
	Block  *BPBlock
}

FetchBlockResp defines a response of the FetchBlock RPC method.

type FetchLastIrreversibleBlockReq

type FetchLastIrreversibleBlockReq struct {
	proto.Envelope
	Address proto.AccountAddress
}

FetchLastIrreversibleBlockReq defines a request of the FetchLastIrreversibleBlock RPC method.

type FetchLastIrreversibleBlockResp

type FetchLastIrreversibleBlockResp struct {
	proto.Envelope
	Count     uint32
	Height    uint32
	Block     *BPBlock
	SQLChains []*SQLChainProfile
}

FetchLastIrreversibleBlockResp defines a response of the FetchLastIrreversibleBlock RPC method.

type FetchTxBillingReq

type FetchTxBillingReq struct {
	proto.Envelope
}

FetchTxBillingReq defines a request of the FetchTxBilling RPC method.

type FetchTxBillingResp

type FetchTxBillingResp struct {
	proto.Envelope
}

FetchTxBillingResp defines a response of the FetchTxBilling RPC method.

type GetDatabaseRequest

type GetDatabaseRequest struct {
	proto.Envelope
	Header SignedGetDatabaseRequestHeader
}

GetDatabaseRequest defines client get database rpc request entity.

func (*GetDatabaseRequest) Sign

func (r *GetDatabaseRequest) Sign(signer *asymmetric.PrivateKey) error

Sign the request.

func (*GetDatabaseRequest) Verify

func (r *GetDatabaseRequest) Verify() error

Verify checks hash and signature in request header.

type GetDatabaseRequestHeader

type GetDatabaseRequestHeader struct {
	DatabaseID proto.DatabaseID
}

GetDatabaseRequestHeader defines client get database rpc request header entity.

type GetDatabaseResponse

type GetDatabaseResponse struct {
	proto.Envelope
	Header SignedGetDatabaseResponseHeader
}

GetDatabaseResponse defines client get database rpc response entity.

func (*GetDatabaseResponse) Sign

func (r *GetDatabaseResponse) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*GetDatabaseResponse) Verify

func (r *GetDatabaseResponse) Verify() (err error)

Verify checks hash and signature in response header.

type GetDatabaseResponseHeader

type GetDatabaseResponseHeader struct {
	InstanceMeta ServiceInstance
}

GetDatabaseResponseHeader defines client get database rpc response header entity.

type Header struct {
	Version     int32
	Producer    proto.NodeID
	GenesisHash hash.Hash
	ParentHash  hash.Hash
	MerkleRoot  hash.Hash
	Timestamp   time.Time
}

Header is a block header.

type InitService

type InitService struct {
	proto.Envelope
}

InitService defines worker service init request.

type InitServiceResponse

type InitServiceResponse struct {
	Header SignedInitServiceResponseHeader
}

InitServiceResponse defines worker service init response.

func (*InitServiceResponse) Sign

func (rs *InitServiceResponse) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*InitServiceResponse) Verify

func (rs *InitServiceResponse) Verify() error

Verify checks hash and signature in init service response header.

type InitServiceResponseHeader

type InitServiceResponseHeader struct {
	Instances []ServiceInstance
}

InitServiceResponseHeader defines worker service init response header.

type IssueKeys

IssueKeys defines the database creation transaction.

func NewIssueKeys

func NewIssueKeys(header *IssueKeysHeader) *IssueKeys

NewIssueKeys returns new instance.

func (*IssueKeys) GetAccountAddress

func (ik *IssueKeys) GetAccountAddress() proto.AccountAddress

GetAccountAddress implements interfaces/Transaction.GetAccountAddress.

func (*IssueKeys) Sign

func (ik *IssueKeys) Sign(signer *asymmetric.PrivateKey) (err error)

Sign implements interfaces/Transaction.Sign.

func (*IssueKeys) Verify

func (ik *IssueKeys) Verify() error

Verify implements interfaces/Transaction.Verify.

type IssueKeysHeader

type IssueKeysHeader struct {
	TargetSQLChain proto.AccountAddress
	MinerKeys      []MinerKey
	Nonce          interfaces.AccountNonce
}

IssueKeysHeader defines an encryption key header.

func (*IssueKeysHeader) GetAccountNonce

func (h *IssueKeysHeader) GetAccountNonce() interfaces.AccountNonce

GetAccountNonce implements interfaces/Transaction.GetAccountNonce.

type MinerIncome

type MinerIncome struct {
	Miner  proto.AccountAddress
	Income uint64
}

MinerIncome defines the income of miner.

type MinerInfo

type MinerInfo struct {
	Address        proto.AccountAddress
	NodeID         proto.NodeID
	Name           string
	PendingIncome  uint64
	ReceivedIncome uint64
	UserArrears    []*UserArrears
	Deposit        uint64
	Status         Status
	EncryptionKey  string
}

MinerInfo defines a miner.

type MinerKey

type MinerKey struct {
	Miner         proto.AccountAddress
	EncryptionKey string
}

MinerKey defines an encryption key associated with miner address.

type NamedArg

type NamedArg struct {
	Name  string
	Value interface{}
}

NamedArg defines the named argument structure for database.

type NextAccountNonceReq

type NextAccountNonceReq struct {
	proto.Envelope
	Addr proto.AccountAddress
}

NextAccountNonceReq defines a request of the NextAccountNonce RPC method.

type NextAccountNonceResp

type NextAccountNonceResp struct {
	proto.Envelope
	Addr  proto.AccountAddress
	Nonce interfaces.AccountNonce
}

NextAccountNonceResp defines a response of the NextAccountNonce RPC method.

type OrderMakerReq

type OrderMakerReq struct {
	proto.Envelope
}

OrderMakerReq defines a request of the order maker in database market.

type OrderTakerReq

type OrderTakerReq struct {
	proto.Envelope
	DBMeta ResourceMeta
}

OrderTakerReq defines a request of the order taker in database market.

type OrderTakerResp

type OrderTakerResp struct {
	proto.Envelope
	// contains filtered or unexported fields
}

OrderTakerResp defines a response of the order taker in database market.

type PermStat

type PermStat struct {
	Permission *UserPermission
	Status     Status
}

PermStat defines the permissions status structure.

type ProvideService

ProvideService define the miner providing service transaction.

func NewProvideService

func NewProvideService(h *ProvideServiceHeader) *ProvideService

NewProvideService returns new instance.

func (*ProvideService) GetAccountAddress

func (ps *ProvideService) GetAccountAddress() proto.AccountAddress

GetAccountAddress implements interfaces/Transaction.GetAccountAddress.

func (*ProvideService) Sign

func (ps *ProvideService) Sign(signer *asymmetric.PrivateKey) (err error)

Sign implements interfaces/Transaction.Sign.

func (*ProvideService) Verify

func (ps *ProvideService) Verify() error

Verify implements interfaces/Transaction.Verify.

type ProvideServiceHeader

type ProvideServiceHeader struct {
	Space         uint64  // reserved storage space in bytes
	Memory        uint64  // reserved memory in bytes
	LoadAvgPerCPU float64 // max loadAvg15 per CPU
	TargetUser    []proto.AccountAddress
	GasPrice      uint64
	TokenType     TokenType
	NodeID        proto.NodeID
	Nonce         interfaces.AccountNonce
}

ProvideServiceHeader define the miner providing service transaction header.

func (*ProvideServiceHeader) GetAccountNonce

func (h *ProvideServiceHeader) GetAccountNonce() interfaces.AccountNonce

GetAccountNonce implements interfaces/Transaction.GetAccountNonce.

type ProviderProfile

type ProviderProfile struct {
	Provider      proto.AccountAddress
	Space         uint64  // reserved storage space in bytes
	Memory        uint64  // reserved memory in bytes
	LoadAvgPerCPU float64 // max loadAvg15 per CPU
	TargetUser    []proto.AccountAddress
	Deposit       uint64 // default 10 Particle
	GasPrice      uint64
	TokenType     TokenType // default Particle
	NodeID        proto.NodeID
}

ProviderProfile defines a provider list.

type Query

type Query struct {
	Pattern string
	Args    []NamedArg
}

Query defines single query.

type QueryAccountSQLChainProfilesReq

type QueryAccountSQLChainProfilesReq struct {
	proto.Envelope
	Addr proto.AccountAddress
}

QueryAccountSQLChainProfilesReq defines a request of QueryAccountSQLChainProfiles RPC method.

type QueryAccountSQLChainProfilesResp

type QueryAccountSQLChainProfilesResp struct {
	proto.Envelope
	Addr     proto.AccountAddress
	Profiles []*SQLChainProfile
}

QueryAccountSQLChainProfilesResp defines a response of QueryAccountSQLChainProfiles RPC method.

type QueryAccountTokenBalanceReq

type QueryAccountTokenBalanceReq struct {
	proto.Envelope
	Addr      proto.AccountAddress
	TokenType TokenType
}

QueryAccountTokenBalanceReq defines a request of the QueryAccountTokenBalance RPC method.

type QueryAccountTokenBalanceResp

type QueryAccountTokenBalanceResp struct {
	proto.Envelope
	Addr    proto.AccountAddress
	OK      bool
	Balance uint64
}

QueryAccountTokenBalanceResp defines a request of the QueryAccountTokenBalance RPC method.

type QueryAsTx

type QueryAsTx struct {
	Request  *Request
	Response *SignedResponseHeader
}

QueryAsTx defines a tx struct which is combined with request and signed response header for block.

type QueryKey

type QueryKey struct {
	NodeID       proto.NodeID `json:"id"`
	ConnectionID uint64       `json:"cid"`
	SeqNo        uint64       `json:"seq"`
}

QueryKey defines an unique query key of a request.

func (QueryKey) String

func (k QueryKey) String() string

String implements fmt.Stringer for logging purpose.

type QuerySQLChainProfileReq

type QuerySQLChainProfileReq struct {
	proto.Envelope
	DBID proto.DatabaseID
}

QuerySQLChainProfileReq defines a request of the QuerySQLChainProfile RPC method.

type QuerySQLChainProfileResp

type QuerySQLChainProfileResp struct {
	proto.Envelope
	Profile SQLChainProfile
}

QuerySQLChainProfileResp defines a response of the QuerySQLChainProfile RPC method.

type QueryTxStateReq

type QueryTxStateReq struct {
	proto.Envelope
	Hash hash.Hash
}

QueryTxStateReq defines a request of the QueryTxState RPC method.

type QueryTxStateResp

type QueryTxStateResp struct {
	proto.Envelope
	Hash  hash.Hash
	State pi.TransactionState
}

QueryTxStateResp defines a response of the QueryTxState RPC method.

type QueryType

type QueryType int32

QueryType enumerates available query type, currently read/write.

const (
	// ReadQuery defines a read query type.
	ReadQuery QueryType = iota
	// WriteQuery defines a write query type.
	WriteQuery
	// NumberOfQueryType defines the number of query type.
	NumberOfQueryType
)

func (QueryType) String

func (t QueryType) String() string

String implements fmt.Stringer for logging purpose.

type Range

type Range struct {
	From, To uint32
}

Range defines a height range (from, to].

type Request

type Request struct {
	proto.Envelope
	Header  SignedRequestHeader `json:"h"`
	Payload RequestPayload      `json:"p"`
	// contains filtered or unexported fields
}

Request defines a complete query request.

func (*Request) GetMarshalCache

func (r *Request) GetMarshalCache() (buf []byte)

GetMarshalCache gets _marshalCache.

func (*Request) SetMarshalCache

func (r *Request) SetMarshalCache(buf []byte)

SetMarshalCache sets _marshalCache.

func (*Request) Sign

func (r *Request) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*Request) Verify

func (r *Request) Verify() (err error)

Verify checks hash and signature in whole request.

type RequestHeader

type RequestHeader struct {
	QueryType    QueryType        `json:"qt"`
	NodeID       proto.NodeID     `json:"id"`   // request node id
	DatabaseID   proto.DatabaseID `json:"dbid"` // request database id
	ConnectionID uint64           `json:"cid"`
	SeqNo        uint64           `json:"seq"`
	Timestamp    time.Time        `json:"t"`  // time in UTC zone
	BatchCount   uint64           `json:"bc"` // query count in this request
	QueriesHash  hash.Hash        `json:"qh"` // hash of query payload
}

RequestHeader defines a query request header.

func (*RequestHeader) GetQueryKey

func (h *RequestHeader) GetQueryKey() QueryKey

GetQueryKey returns a unique query key of this request.

type RequestPayload

type RequestPayload struct {
	Queries []Query `json:"qs"`
}

RequestPayload defines a queries payload.

type ResourceMeta

type ResourceMeta struct {
	TargetMiners           []proto.AccountAddress // designated miners
	Node                   uint16                 // reserved node count
	Space                  uint64                 // reserved storage space in bytes
	Memory                 uint64                 // reserved memory in bytes
	LoadAvgPerCPU          float64                // max loadAvg15 per CPU
	EncryptionKey          string                 // encryption key for database instance
	UseEventualConsistency bool                   // use eventual consistency replication if enabled
	ConsistencyLevel       float64                // customized strong consistency level
	IsolationLevel         int                    // customized isolation level
}

ResourceMeta defines single database resource meta.

type Response

type Response struct {
	Header  SignedResponseHeader `json:"h"`
	Payload ResponsePayload      `json:"p"`
}

Response defines a complete query response.

func (*Response) BuildHash

func (r *Response) BuildHash() (err error)

BuildHash computes the hash of the response.

func (*Response) Hash

func (r *Response) Hash() hash.Hash

Hash returns the response header hash.

func (*Response) VerifyHash

func (r *Response) VerifyHash() (err error)

VerifyHash verify the hash of the response.

type ResponseHeader

type ResponseHeader struct {
	Request         RequestHeader        `json:"r"`
	RequestHash     hash.Hash            `json:"rh"`
	NodeID          proto.NodeID         `json:"id"` // response node id
	Timestamp       time.Time            `json:"t"`  // time in UTC zone
	RowCount        uint64               `json:"c"`  // response row count of payload
	LogOffset       uint64               `json:"o"`  // request log offset
	LastInsertID    int64                `json:"l"`  // insert insert id
	AffectedRows    int64                `json:"a"`  // affected rows
	PayloadHash     hash.Hash            `json:"dh"` // hash of query response payload
	ResponseAccount proto.AccountAddress `json:"aa"` // response account
}

ResponseHeader defines a query response header.

func (*ResponseHeader) GetRequestHash

func (h *ResponseHeader) GetRequestHash() hash.Hash

GetRequestHash returns the request hash.

func (*ResponseHeader) GetRequestTimestamp

func (h *ResponseHeader) GetRequestTimestamp() time.Time

GetRequestTimestamp returns the request timestamp.

type ResponsePayload

type ResponsePayload struct {
	Columns   []string      `json:"c"`
	DeclTypes []string      `json:"t"`
	Rows      []ResponseRow `json:"r"`
}

ResponsePayload defines column names and rows of query response.

type ResponseRow

type ResponseRow struct {
	Values []interface{}
}

ResponseRow defines single row of query response.

type SQLChainProfile

type SQLChainProfile struct {
	ID                proto.DatabaseID
	Address           proto.AccountAddress
	Period            uint64
	GasPrice          uint64
	LastUpdatedHeight uint32

	TokenType TokenType

	Owner proto.AccountAddress
	// first miner in the list is leader
	Miners []*MinerInfo

	Users []*SQLChainUser

	EncodedGenesis []byte

	Meta ResourceMeta // dumped from db creation tx
}

SQLChainProfile defines a SQLChainProfile related to an account.

type SQLChainRole

type SQLChainRole byte

SQLChainRole defines roles of account in a SQLChain.

const (
	// Miner defines the miner role as a SQLChain user.
	Miner SQLChainRole = iota
	// Customer defines the customer role as a SQLChain user.
	Customer
	// NumberOfRoles defines the SQLChain roles number.
	NumberOfRoles
)

type SQLChainUser

type SQLChainUser struct {
	Address        proto.AccountAddress
	Permission     *UserPermission
	AdvancePayment uint64
	Arrears        uint64
	Deposit        uint64
	Status         Status
}

SQLChainUser defines a SQLChain user.

type ServiceInstance

type ServiceInstance struct {
	DatabaseID   proto.DatabaseID
	Peers        *proto.Peers
	ResourceMeta ResourceMeta
	GenesisBlock *Block
}

ServiceInstance defines single instance to be initialized.

type SignedAckHeader

type SignedAckHeader struct {
	AckHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedAckHeader defines client signed ack entity.

func (*SignedAckHeader) Sign

func (sh *SignedAckHeader) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*SignedAckHeader) Verify

func (sh *SignedAckHeader) Verify() (err error)

Verify checks hash and signature in ack header.

type SignedCreateDatabaseRequestHeader

type SignedCreateDatabaseRequestHeader struct {
	CreateDatabaseRequestHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedCreateDatabaseRequestHeader defines signed client create database request header.

func (*SignedCreateDatabaseRequestHeader) Sign

Sign the request.

func (*SignedCreateDatabaseRequestHeader) Verify

func (sh *SignedCreateDatabaseRequestHeader) Verify() (err error)

Verify checks hash and signature in create database request header.

type SignedCreateDatabaseResponseHeader

type SignedCreateDatabaseResponseHeader struct {
	CreateDatabaseResponseHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedCreateDatabaseResponseHeader defines signed client create database response header.

func (*SignedCreateDatabaseResponseHeader) Sign

Sign the response.

func (*SignedCreateDatabaseResponseHeader) Verify

func (sh *SignedCreateDatabaseResponseHeader) Verify() (err error)

Verify checks hash and signature in create database response header.

type SignedDropDatabaseRequestHeader

type SignedDropDatabaseRequestHeader struct {
	DropDatabaseRequestHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedDropDatabaseRequestHeader defines signed client drop database rpc request header.

func (*SignedDropDatabaseRequestHeader) Sign

Sign the request.

func (*SignedDropDatabaseRequestHeader) Verify

func (sh *SignedDropDatabaseRequestHeader) Verify() (err error)

Verify checks hash and signature in request header.

type SignedGetDatabaseRequestHeader

type SignedGetDatabaseRequestHeader struct {
	GetDatabaseRequestHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedGetDatabaseRequestHeader defines signed client get database rpc request header entity.

func (*SignedGetDatabaseRequestHeader) Sign

Sign the request.

func (*SignedGetDatabaseRequestHeader) Verify

func (sh *SignedGetDatabaseRequestHeader) Verify() (err error)

Verify checks hash and signature in request header.

type SignedGetDatabaseResponseHeader

type SignedGetDatabaseResponseHeader struct {
	GetDatabaseResponseHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedGetDatabaseResponseHeader defines client get database rpc response header entity.

func (*SignedGetDatabaseResponseHeader) Sign

Sign the request.

func (*SignedGetDatabaseResponseHeader) Verify

func (sh *SignedGetDatabaseResponseHeader) Verify() (err error)

Verify checks hash and signature in response header.

type SignedHeader

type SignedHeader struct {
	Header
	HSV verifier.DefaultHashSignVerifierImpl
}

SignedHeader is block header along with its producer signature.

func (*SignedHeader) ComputeHash

func (s *SignedHeader) ComputeHash() error

ComputeHash computes the hash of the signed header.

func (*SignedHeader) Sign

func (s *SignedHeader) Sign(signer *ca.PrivateKey) error

Sign calls DefaultHashSignVerifierImpl to calculate header hash and sign it with signer.

func (*SignedHeader) Verify

func (s *SignedHeader) Verify() error

Verify verifies the signature of the signed header.

func (*SignedHeader) VerifyHash

func (s *SignedHeader) VerifyHash() error

VerifyHash verifies the hash of the signed header.

type SignedInitServiceResponseHeader

type SignedInitServiceResponseHeader struct {
	InitServiceResponseHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedInitServiceResponseHeader defines signed worker service init response header.

func (*SignedInitServiceResponseHeader) Sign

Sign the request.

func (*SignedInitServiceResponseHeader) Verify

func (sh *SignedInitServiceResponseHeader) Verify() (err error)

Verify checks hash and signature in init service response header.

type SignedRequestHeader

type SignedRequestHeader struct {
	RequestHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedRequestHeader defines a signed query request header.

func (*SignedRequestHeader) Sign

func (sh *SignedRequestHeader) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*SignedRequestHeader) Verify

func (sh *SignedRequestHeader) Verify() (err error)

Verify checks hash and signature in request header.

type SignedResponseHeader

type SignedResponseHeader struct {
	ResponseHeader
	ResponseHash hash.Hash
}

SignedResponseHeader defines a signed query response header.

func (*SignedResponseHeader) BuildHash

func (sh *SignedResponseHeader) BuildHash() (err error)

BuildHash computes the hash of the response header.

func (*SignedResponseHeader) Hash

func (sh *SignedResponseHeader) Hash() hash.Hash

Hash returns the response header hash.

func (*SignedResponseHeader) VerifyHash

func (sh *SignedResponseHeader) VerifyHash() (err error)

VerifyHash verify the hash of the response.

type SignedUpdateServiceHeader

type SignedUpdateServiceHeader struct {
	UpdateServiceHeader
	verifier.DefaultHashSignVerifierImpl
}

SignedUpdateServiceHeader defines signed service update header.

func (*SignedUpdateServiceHeader) Sign

func (sh *SignedUpdateServiceHeader) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*SignedUpdateServiceHeader) Verify

func (sh *SignedUpdateServiceHeader) Verify() (err error)

Verify checks hash and signature in update service header.

type Status

type Status int32

Status defines status of a SQLChain user/miner.

const (
	// UnknownStatus defines initial status.
	UnknownStatus Status = iota
	// Normal defines no bad thing happens.
	Normal
	// Reminder defines the user needs to increase advance payment.
	Reminder
	// Arrears defines the user is in arrears.
	Arrears
	// Arbitration defines the user/miner is in an arbitration.
	Arbitration
	// NumberOfStatus defines the number of status.
	NumberOfStatus
)

func (*Status) EnableQuery

func (s *Status) EnableQuery() bool

EnableQuery indicates whether the account is permitted to query.

type SubReq

type SubReq struct {
	proto.Envelope
	Topic    string
	Callback string
}

SubReq defines a request of the Sub RPC method.

type SubResp

type SubResp struct {
	proto.Envelope
	Result string
}

SubResp defines a response of the Sub RPC method.

type TokenType

type TokenType int32

TokenType defines token's type.

const (
	// Particle defines cqlprotocol's token
	Particle TokenType = iota
	// Wave defines cqlprotocol's token
	Wave
	// SupportTokenNumber defines the number of token cqlprotocol supports
	SupportTokenNumber
)

func FromString

func FromString(t string) TokenType

FromString returns token's number.

func (*TokenType) Listed

func (t *TokenType) Listed() bool

Listed returns if the token is listed in list.

func (TokenType) String

func (t TokenType) String() string

String returns token's symbol.

type Transfer

Transfer defines the transfer transaction.

func NewTransfer

func NewTransfer(header *TransferHeader) *Transfer

NewTransfer returns new instance.

func (*Transfer) GetAccountAddress

func (t *Transfer) GetAccountAddress() proto.AccountAddress

GetAccountAddress implements interfaces/Transaction.GetAccountAddress.

func (*Transfer) GetAccountNonce

func (t *Transfer) GetAccountNonce() pi.AccountNonce

GetAccountNonce implements interfaces/Transaction.GetAccountNonce.

func (*Transfer) Sign

func (t *Transfer) Sign(signer *asymmetric.PrivateKey) (err error)

Sign implements interfaces/Transaction.Sign.

func (*Transfer) Verify

func (t *Transfer) Verify() (err error)

Verify implements interfaces/Transaction.Verify.

type TransferHeader

type TransferHeader struct {
	Sender, Receiver proto.AccountAddress
	Nonce            pi.AccountNonce
	Amount           uint64
	TokenType        TokenType
}

TransferHeader defines the transfer transaction header.

type UpdateBilling

UpdateBilling defines the UpdateBilling transaction.

func NewUpdateBilling

func NewUpdateBilling(header *UpdateBillingHeader) *UpdateBilling

NewUpdateBilling returns new instance.

func (*UpdateBilling) GetAccountAddress

func (ub *UpdateBilling) GetAccountAddress() proto.AccountAddress

GetAccountAddress implements interfaces/Transaction.GetAccountAddress.

func (*UpdateBilling) GetAccountNonce

func (ub *UpdateBilling) GetAccountNonce() pi.AccountNonce

GetAccountNonce implements interfaces/Transaction.GetAccountNonce.

func (*UpdateBilling) Sign

func (ub *UpdateBilling) Sign(signer *asymmetric.PrivateKey) (err error)

Sign implements interfaces/Transaction.Sign.

func (*UpdateBilling) Verify

func (ub *UpdateBilling) Verify() (err error)

Verify implements interfaces/Transaction.Verify.

type UpdateBillingHeader

type UpdateBillingHeader struct {
	Receiver proto.AccountAddress
	Nonce    pi.AccountNonce
	Users    []*UserCost
	Range    Range
	Version  int32 `hsp:"v,version"`
}

UpdateBillingHeader defines the UpdateBilling transaction header.

type UpdatePermission

UpdatePermission defines the updating sqlchain permission transaction.

func NewUpdatePermission

func NewUpdatePermission(header *UpdatePermissionHeader) *UpdatePermission

NewUpdatePermission returns new instance.

func (*UpdatePermission) GetAccountAddress

func (up *UpdatePermission) GetAccountAddress() proto.AccountAddress

GetAccountAddress implements interfaces/Transaction.GetAccountAddress.

func (*UpdatePermission) Sign

func (up *UpdatePermission) Sign(signer *asymmetric.PrivateKey) (err error)

Sign implements interfaces/Transaction.Sign.

func (*UpdatePermission) Verify

func (up *UpdatePermission) Verify() error

Verify implements interfaces/Transaction.Verify.

type UpdatePermissionHeader

type UpdatePermissionHeader struct {
	TargetSQLChain proto.AccountAddress
	TargetUser     proto.AccountAddress
	Permission     *UserPermission
	Nonce          interfaces.AccountNonce
}

UpdatePermissionHeader defines the updating sqlchain permission transaction header.

func (*UpdatePermissionHeader) GetAccountNonce

func (u *UpdatePermissionHeader) GetAccountNonce() interfaces.AccountNonce

GetAccountNonce implements interfaces/Transaction.GetAccountNonce.

type UpdateService

type UpdateService struct {
	proto.Envelope
	Header SignedUpdateServiceHeader
}

UpdateService defines service update type.

func (*UpdateService) Sign

func (s *UpdateService) Sign(signer *asymmetric.PrivateKey) (err error)

Sign the request.

func (*UpdateService) Verify

func (s *UpdateService) Verify() error

Verify checks hash and signature in update service.

type UpdateServiceHeader

type UpdateServiceHeader struct {
	Op       UpdateType
	Instance ServiceInstance
}

UpdateServiceHeader defines service update header.

type UpdateServiceResponse

type UpdateServiceResponse struct{}

UpdateServiceResponse defines empty response entity.

type UpdateType

type UpdateType int32

UpdateType defines service update type.

const (
	// CreateDB indicates create database operation.
	CreateDB UpdateType = iota
	// UpdateDB indicates database peers update operation.
	UpdateDB
	// DropDB indicates drop database operation.
	DropDB
)

type UserArrears

type UserArrears struct {
	User    proto.AccountAddress
	Arrears uint64
}

UserArrears defines user's arrears.

type UserCost

type UserCost struct {
	User   proto.AccountAddress
	Cost   uint64
	Miners []*MinerIncome
}

UserCost defines the cost of user.

type UserPermission

type UserPermission struct {
	// User role to access database.
	Role UserPermissionRole
	// SQL pattern regulations for user queries
	// only a fully matched (case-sensitive) sql query is permitted to execute.
	Patterns []string
	// contains filtered or unexported fields
}

UserPermission defines permissions of a SQLChain user.

func UserPermissionFromRole

func UserPermissionFromRole(role UserPermissionRole) *UserPermission

UserPermissionFromRole construct a new user permission instance from primitive user permission role enum.

func (*UserPermission) HasDisallowedQueryPatterns

func (up *UserPermission) HasDisallowedQueryPatterns(queries []Query) (query string, status bool)

HasDisallowedQueryPatterns returns whether the queries are permitted.

func (*UserPermission) HasReadPermission

func (up *UserPermission) HasReadPermission() bool

HasReadPermission returns true if user owns read permission.

func (*UserPermission) HasSuperPermission

func (up *UserPermission) HasSuperPermission() bool

HasSuperPermission returns true if user owns super permission.

func (*UserPermission) HasWritePermission

func (up *UserPermission) HasWritePermission() bool

HasWritePermission returns true if user owns write permission.

func (*UserPermission) IsValid

func (up *UserPermission) IsValid() bool

IsValid returns whether the permission object is valid or not.

type UserPermissionRole

type UserPermissionRole int32

UserPermissionRole defines role of user permission including admin/write/read.

func (*UserPermissionRole) FromString

func (r *UserPermissionRole) FromString(perm string)

FromString converts string to UserPermissionRole.

func (UserPermissionRole) MarshalJSON

func (r UserPermissionRole) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (UserPermissionRole) String

func (r UserPermissionRole) String() string

String implements the fmt.Stringer interface.

func (*UserPermissionRole) UnmarshalJSON

func (r *UserPermissionRole) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshler interface.

Jump to

Keyboard shortcuts

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