Documentation ¶
Index ¶
- Variables
- func MakeGenesisBlockHash(chainName string) string
- func MakeTxsHash(txs []*types.Transaction) string
- func VerifyTxs(txs []*types.Transaction) (*types.Transaction, bool)
- type PostgresBlockchain
- func (b *PostgresBlockchain) Close() error
- func (b *PostgresBlockchain) Connect(dbAddr string) (interface{}, error)
- func (b *PostgresBlockchain) CreateBlock(id, chainName string, transactions []*types.Transaction) (*types.Block, error)
- func (b *PostgresBlockchain) CreateChain(name string, public bool) (*types.Chain, error)
- func (b *PostgresBlockchain) GetBlock(chainName, id string) (*types.Block, error)
- func (b *PostgresBlockchain) GetChain(name string) (*types.Chain, error)
- func (b *PostgresBlockchain) GetImplementationName() string
- func (b *PostgresBlockchain) Init() error
- func (b *PostgresBlockchain) MakeChainName(namespace, name string) string
Constants ¶
This section is empty.
Variables ¶
var BlockTableName = "blocks"
BlockTableName is the name of the transaction block table
var ChainTableName = "chains"
ChainTableName is the name of the table holding all chain information
Functions ¶
func MakeGenesisBlockHash ¶
MakeGenesisBlockHash creates the standard hash for the first block of a chain which is a sha256 hash of a concatenated chain name and 64 chars of `0`.
func MakeTxsHash ¶
func MakeTxsHash(txs []*types.Transaction) string
MakeTxsHash takes a slice of transactions and returns a SHA256 hash of the transactions
func VerifyTxs ¶
func VerifyTxs(txs []*types.Transaction) (*types.Transaction, bool)
VerifyTxs checks whether the hash of a transactions are valid hashes based on the hash algorithm defined by Transaction.MakeHash.
Types ¶
type PostgresBlockchain ¶
type PostgresBlockchain struct {
// contains filtered or unexported fields
}
PostgresBlockchain implements the Blockchain interface
func (*PostgresBlockchain) Connect ¶
func (b *PostgresBlockchain) Connect(dbAddr string) (interface{}, error)
Connect connects to a postgres server and returns a client or error if connection failed.
func (*PostgresBlockchain) CreateBlock ¶
func (b *PostgresBlockchain) CreateBlock(id, chainName string, transactions []*types.Transaction) (*types.Block, error)
CreateBlock creates a new block. It creates a chained structure by setting the new block's previous hash value to the hash of the last block of the chain specified. The new block's hash is calculated from the hash of all the contained transaction hashes.
func (*PostgresBlockchain) CreateChain ¶
CreateChain creates a new chain
func (*PostgresBlockchain) GetBlock ¶
func (b *PostgresBlockchain) GetBlock(chainName, id string) (*types.Block, error)
GetBlock fetches a block by its chain name and id
func (*PostgresBlockchain) GetChain ¶
func (b *PostgresBlockchain) GetChain(name string) (*types.Chain, error)
GetChain gets a chain
func (*PostgresBlockchain) GetImplementationName ¶
func (b *PostgresBlockchain) GetImplementationName() string
GetImplementationName returns th
func (*PostgresBlockchain) Init ¶
func (b *PostgresBlockchain) Init() error
Init creates the chain and block tables
func (*PostgresBlockchain) MakeChainName ¶
func (b *PostgresBlockchain) MakeChainName(namespace, name string) string
MakeChainName returns a new chain name prefixed with a namespace