Documentation ¶
Index ¶
- Constants
- Variables
- func Clear(dbAddr string) error
- func Destroy(dbAddr string) error
- type PostgresStore
- func (s *PostgresStore) Close() error
- func (s *PostgresStore) Connect(dbAddr string) (interface{}, error)
- func (s *PostgresStore) CreateLedger(cocoonID, name string, chained, public bool) (*types.Ledger, error)
- func (s *PostgresStore) CreateLedgerThen(cocoonID, name string, chained, public bool, thenFunc func() error) (*types.Ledger, error)
- func (s *PostgresStore) Get(ledger, key string) (*types.Transaction, error)
- func (s *PostgresStore) GetImplementationName() string
- func (s *PostgresStore) GetLedger(name string) (*types.Ledger, error)
- func (s *PostgresStore) GetRange(ledger, startKey, endKey string, inclusive bool, limit, offset int) ([]*types.Transaction, error)
- func (s *PostgresStore) Init(systemPublicLedgerName, systemPrivateLedgerName string) error
- func (s *PostgresStore) Put(ledgerName string, txs []*types.Transaction) ([]*types.TxReceipt, error)
- func (s *PostgresStore) PutThen(ledgerName string, txs []*types.Transaction, ...) ([]*types.TxReceipt, error)
- func (s *PostgresStore) SetBlockchainImplementation(b types.Blockchain)
Constants ¶
const LedgerTableName = "ledgers"
LedgerTableName represents the name of the table where all known ledger info are stored.
const TransactionTableName = "transactions"
TransactionTableName represents the name of the table where all transactions are stored.
Variables ¶
var ErrChainExist = errors.New("chain already exists")
ErrChainExist represents an error about an existing chain
Functions ¶
Types ¶
type PostgresStore ¶
type PostgresStore struct {
// contains filtered or unexported fields
}
PostgresStore defines a store implementation on the postgres database. It implements the Store interface
func (*PostgresStore) Close ¶
func (s *PostgresStore) Close() error
Close releases any resource held
func (*PostgresStore) Connect ¶
func (s *PostgresStore) Connect(dbAddr string) (interface{}, error)
Connect connects to a postgres server and returns a client or error if connection failed.
func (*PostgresStore) CreateLedger ¶
func (s *PostgresStore) CreateLedger(cocoonID, name string, chained, public bool) (*types.Ledger, error)
CreateLedger creates a new ledger.
func (*PostgresStore) CreateLedgerThen ¶
func (s *PostgresStore) CreateLedgerThen(cocoonID, name string, chained, public bool, thenFunc func() error) (*types.Ledger, error)
CreateLedgerThen creates a new ledger and accepts an additional operation (via the thenFunc) to be executed before the ledger creation transaction is committed. If the thenFunc returns an error, the transaction is rolled back and error returned
func (*PostgresStore) Get ¶
func (s *PostgresStore) Get(ledger, key string) (*types.Transaction, error)
Get fetches a transaction by its ledger and key
func (*PostgresStore) GetImplementationName ¶
func (s *PostgresStore) GetImplementationName() string
GetImplementationName returns the name of this store implementation
func (*PostgresStore) GetLedger ¶
func (s *PostgresStore) GetLedger(name string) (*types.Ledger, error)
GetLedger fetches a ledger meta information
func (*PostgresStore) GetRange ¶
func (s *PostgresStore) GetRange(ledger, startKey, endKey string, inclusive bool, limit, offset int) ([]*types.Transaction, error)
GetRange fetches transactions with keys included in a specified range. No lock is acquired in this operation.
func (*PostgresStore) Init ¶
func (s *PostgresStore) Init(systemPublicLedgerName, systemPrivateLedgerName string) error
Init initializes the types. Creates the necessary tables such as the the tables and public and private system ledgers
func (*PostgresStore) Put ¶
func (s *PostgresStore) Put(ledgerName string, txs []*types.Transaction) ([]*types.TxReceipt, error)
Put creates one or more transactions associated to a ledger. Returns a list of transaction receipts and a general error.
func (*PostgresStore) PutThen ¶
func (s *PostgresStore) PutThen(ledgerName string, txs []*types.Transaction, thenFunc func(validTxss []*types.Transaction) error) ([]*types.TxReceipt, error)
PutThen adds transactions to the store and returns a list of transaction receipts. Any transaction that failed to be created will result in an error receipt being created and returned along with success receipts of they successfully added transactions. However, all transactions will be rolled back if the `thenFunc` returns error. Only the transaction that are successfully added will be passed to the thenFunc. Future work may allow the caller to determine the behaviour via an additional parameter.
func (*PostgresStore) SetBlockchainImplementation ¶
func (s *PostgresStore) SetBlockchainImplementation(b types.Blockchain)
SetBlockchainImplementation sets sets a reference of the blockchain implementation