Documentation ¶
Index ¶
- Constants
- Variables
- type DataStore
- type Database
- type Namespace
- type Redis
- func (rd *Redis) Close() error
- func (rd *Redis) DeleteData(key string, field string) error
- func (rd *Redis) LoadFieldsForKey(key string) (map[string][]byte, error)
- func (rd *Redis) Ping() error
- func (rd *Redis) StoreData(key string, field string, data []byte) error
- func (rd *Redis) Subscribe(seChan chan<- *SubEvent)
- func (rd *Redis) Unsubscribe() error
- type SubAction
- type SubEvent
Constants ¶
const NamespaceBytes = 4
NamespaceBytes is the byte length of a namespace
Variables ¶
var ErrInvalidNamespaceLength = errors.New("Namespace identifier does not have the right length")
ErrInvalidNamespaceLength indicates that a namespace identifier is used which does not have the correct length according to the NamespaceBytes
Functions ¶
This section is empty.
Types ¶
type DataStore ¶
type DataStore struct {
// contains filtered or unexported fields
}
DataStore pulls arbitrary data, stored in transactions, from the blockchain, and saves it in a connected database
func New ¶
func New(cs modules.ConsensusSet, db Database, persistDir string, bcInfo types.BlockchainInfo, chainCts types.ChainConstants) (*DataStore, error)
New creates a new DataStore from a consensus set and a Database. If the connection opts specify an unknown driver, initialization fails and an error is returned. Currently only `redis` is supported
type Database ¶
type Database interface { // Ping tests the database connection Ping() error // StoreData stores the specified data, linked to a key and a field in that key // Multiple section of data must be storeable for the same key. The field is unique // for the key, but other keys might have the same fields for different data StoreData(string, string, []byte) error // DeleteData removes the data specified by the key and field. DeleteData(string, string) error // LoadFieldsForKey loads a mapping of all fields and the associated data for a given key LoadFieldsForKey(string) (map[string][]byte, error) // Subscribe continuously manages a channel for messages // Subscribe(SubEventCallback) Subscribe(chan<- *SubEvent) // Unsubscribe ends the subscription to the message channel and closes the // event channel provided by the subscribe function Unsubscribe() error // Close gracefully closes the database connection Close() error }
Database is the common interface which must be implemented to be compatible with the datastore
type Namespace ¶
type Namespace [NamespaceBytes]byte
Namespace is an identifier used to group data written on the blockchain when it is replicated to external storage
func (*Namespace) LoadString ¶
LoadString tries to convert a string representation of a namespace into the corresponding bytes
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis wraps a redis connection
func NewRedis ¶
func NewRedis(addr, password string, db int, persistDir string, bcInfo types.BlockchainInfo) (*Redis, error)
NewRedis creates a new redis struct which attempts to connect to the specified DB/instance The connection always used tcp
func (*Redis) DeleteData ¶
DeleteData removes data from an HSET
func (*Redis) LoadFieldsForKey ¶
LoadFieldsForKey returns all field-value mappings in an HSET defined by key
func (*Redis) Subscribe ¶
Subscribe starts a subscription to the replication channel. Once the subscribtion ends after a call to Unsubscribe, the channel is also closed
func (*Redis) Unsubscribe ¶
Unsubscribe stops the subsciption on the replication channel
type SubAction ¶
type SubAction string
SubAction is the action which must be done for a subscription
const ( // SubStart indicates that a new subscribtion must begin, with an optional // starttime indicating the earliest block which must be tracked SubStart SubAction = "start" // SubEnd indicates that a subscription ends immediatly SubEnd SubAction = "end" )
The actions which can be passed through a channel