Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToBig(b []byte) *big.Int
- type AdminInput
- type AdminOutput
- type AdminRule
- type AllAdminsOutput
- type AllColsAllowedOutput
- type AllRowWritersOutput
- type AllWritersOutput
- type Block
- type BlockChange
- type BlockChangeCursor
- type BlockSignatureInvalidError
- type BlockState
- type Blockchain
- func (bc *Blockchain) AddTransaction(tx *Transaction) error
- func (bc *Blockchain) BuildBlock(txs []*Transaction) (*Block, error)
- func (bc *Blockchain) BuildGenesis() (*Block, error)
- func (bc *Blockchain) BuildVote(blockId, prevBlockId Hash, value bool) (*Vote, error)
- func (bc *Blockchain) DeleteTransactions(txs []*Transaction) error
- func (bc *Blockchain) GetBlockChangefeed() (*BlockChangeCursor, error)
- func (bc *Blockchain) GetBlocks(blockIds []Hash) ([]*Block, error)
- func (bc *Blockchain) GetMyTransactionChangefeed() (*TransactionChangeCursor, error)
- func (bc *Blockchain) GetMyTransactions() ([]*Transaction, error)
- func (bc *Blockchain) GetOldestBlocks(after int64, limit int) ([]*Block, error)
- func (bc *Blockchain) GetRecentVotes() ([]*Vote, error)
- func (bc *Blockchain) GetStaleTransactions(staleAge int64) ([]*Transaction, error)
- func (bc *Blockchain) GetVoteChangefeed() (*VoteChangeCursor, error)
- func (bc *Blockchain) ValidateBlock(b *Block) error
- func (bc *Blockchain) ValidateTransaction(tx *Transaction) error
- func (bc *Blockchain) WriteBlock(b *Block) error
- func (bc *Blockchain) WriteVote(v *Vote) error
- type Cell
- type ColAllowedOutput
- type ColRules
- type ColsAllowedRule
- type HasTableExistsRule
- type Hash
- type Input
- type InputLink
- type InputType
- type MissingOutputsError
- type Node
- type Output
- type OutputRequirement
- type OutputType
- type RowRule
- type RowRuleType
- type RowRules
- type RowWriterInput
- type RowWriterOutput
- type Rule
- type RuleErrors
- type TableExistsOutput
- type TableExistsOutputMixin
- type TableExistsRule
- type TableMetadata
- type TableMetadataFlag
- type TableMissingRule
- type TableNameMixin
- type Transaction
- type TransactionChange
- type TransactionChangeCursor
- type TransactionErrors
- type TransactionType
- type UndecidedOutputsError
- type ValidOutputTypesRule
- type Vote
- type VoteChange
- type VoteChangeCursor
- type WriterInput
- type WriterOutput
- type WriterRule
Constants ¶
const GENESIS_MESSAGE = `` /* 285-byte string literal not displayed */
Message from Iphone X reveal on Sept 12, 2017
const HashLength = 32
const TABLE_METADATA_TABLE = "table_metadata"
Name of table metadata table
Variables ¶
var TABLE_METADATA_MAP = map[TableMetadataFlag]string{ TABLE_METADATA_ADMINS: "admins", TABLE_METADATA_WRITERS: "writers", TABLE_METADATA_ROW_RULES: "row_rules", TABLE_METADATA_COL_RULES: "col_rules", }
Map from TableMetadataFlag to the column name
Functions ¶
func BytesToBig ¶
Types ¶
type AdminInput ¶
func (*AdminInput) Data ¶
func (in *AdminInput) Data() []byte
func (*AdminInput) FromData ¶
func (in *AdminInput) FromData(data []byte) error
func (*AdminInput) Type ¶
func (in *AdminInput) Type() InputType
type AdminOutput ¶
type AdminOutput struct { *TableNameMixin PubKey []byte }
func (*AdminOutput) Data ¶
func (o *AdminOutput) Data() []byte
func (*AdminOutput) FromData ¶
func (o *AdminOutput) FromData(data []byte) error
func (*AdminOutput) Type ¶
func (o *AdminOutput) Type() OutputType
type AdminRule ¶
type AdminRule struct{}
func (*AdminRule) RequestedOutputIds ¶
func (rule *AdminRule) RequestedOutputIds(tx *Transaction) map[string]OutputRequirement
type AllAdminsOutput ¶
type AllAdminsOutput struct {
*TableNameMixin
}
func (*AllAdminsOutput) Data ¶
func (o *AllAdminsOutput) Data() []byte
func (*AllAdminsOutput) FromData ¶
func (o *AllAdminsOutput) FromData(data []byte) error
func (*AllAdminsOutput) Type ¶
func (o *AllAdminsOutput) Type() OutputType
type AllColsAllowedOutput ¶
type AllColsAllowedOutput struct {
*TableNameMixin
}
func (*AllColsAllowedOutput) Data ¶
func (o *AllColsAllowedOutput) Data() []byte
func (*AllColsAllowedOutput) FromData ¶
func (o *AllColsAllowedOutput) FromData(data []byte) error
func (*AllColsAllowedOutput) Type ¶
func (o *AllColsAllowedOutput) Type() OutputType
type AllRowWritersOutput ¶
type AllRowWritersOutput struct { *TableNameMixin RowId []byte }
func (*AllRowWritersOutput) Data ¶
func (o *AllRowWritersOutput) Data() []byte
func (*AllRowWritersOutput) FromData ¶
func (o *AllRowWritersOutput) FromData(data []byte) error
func (*AllRowWritersOutput) Requirement ¶
func (o *AllRowWritersOutput) Requirement() OutputRequirement
func (*AllRowWritersOutput) Type ¶
func (o *AllRowWritersOutput) Type() OutputType
type AllWritersOutput ¶
type AllWritersOutput struct {
*TableNameMixin
}
func (*AllWritersOutput) Data ¶
func (o *AllWritersOutput) Data() []byte
func (*AllWritersOutput) FromData ¶
func (o *AllWritersOutput) FromData(data []byte) error
func (*AllWritersOutput) Requirement ¶
func (o *AllWritersOutput) Requirement() OutputRequirement
func (*AllWritersOutput) Type ¶
func (o *AllWritersOutput) Type() OutputType
type Block ¶
type Block struct { Transactions []*Transaction // Contains hashes of all contained transactions CreatedAt *big.Int // Time at which block was created, will be used to determine order Creator []byte Sig []byte Voters [][]byte State BlockState }
type BlockChange ¶
type BlockChangeCursor ¶
type BlockChangeCursor struct {
// contains filtered or unexported fields
}
Wrapper around a meddb block that maps meddb blocks to core blocks.
func (*BlockChangeCursor) Next ¶
func (cursor *BlockChangeCursor) Next(change *BlockChange) bool
type BlockSignatureInvalidError ¶
type BlockSignatureInvalidError struct {
BlockId Hash
}
func (*BlockSignatureInvalidError) Error ¶
func (e *BlockSignatureInvalidError) Error() string
type BlockState ¶
type BlockState int
const ( BLOCK_STATE_UNDECIDED BlockState = iota // UNDECIDED = 0 BLOCK_STATE_ACCEPTED // ACCEPTED = 1 BLOCK_STATE_REJECTED // REJECTED = 2 )
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
func InitBlockchain ¶
func InitBlockchain(me *Node) (*Blockchain, error)
Temp method, has hardcoded stuff
func NewBlockchain ¶
func NewBlockchain(db meddb.BlockchainDB, bt meddb.Bigtable, me *Node, federation []*Node) *Blockchain
func (*Blockchain) AddTransaction ¶
func (bc *Blockchain) AddTransaction(tx *Transaction) error
Adds transaction to blockchain backlog.
func (*Blockchain) BuildBlock ¶
func (bc *Blockchain) BuildBlock(txs []*Transaction) (*Block, error)
Builds block from given transactions. DOES NOT VALIDATE TRANSACTIONS. That must be done before.
func (*Blockchain) BuildGenesis ¶
func (bc *Blockchain) BuildGenesis() (*Block, error)
Creates the genesis block which contains one transaction with the message in GENESIS_MESSAGE. Generally this message should be some string that could not have been created before the date of blockchain genesis.
func (*Blockchain) BuildVote ¶
func (bc *Blockchain) BuildVote(blockId, prevBlockId Hash, value bool) (*Vote, error)
Builds and signs vote for particular block, given previous block.
func (*Blockchain) DeleteTransactions ¶
func (bc *Blockchain) DeleteTransactions(txs []*Transaction) error
Proxy to db to delete transactions from backlog.
func (*Blockchain) GetBlockChangefeed ¶
func (bc *Blockchain) GetBlockChangefeed() (*BlockChangeCursor, error)
func (*Blockchain) GetBlocks ¶
func (bc *Blockchain) GetBlocks(blockIds []Hash) ([]*Block, error)
Returns blocks from blocks table for the given blockIds
func (*Blockchain) GetMyTransactionChangefeed ¶
func (bc *Blockchain) GetMyTransactionChangefeed() (*TransactionChangeCursor, error)
Returns meddb changefeed cursor for transactions assigned to this node.
func (*Blockchain) GetMyTransactions ¶
func (bc *Blockchain) GetMyTransactions() ([]*Transaction, error)
Returns list of transactions currently assigned to this node in the backlog.
func (*Blockchain) GetOldestBlocks ¶
func (bc *Blockchain) GetOldestBlocks(after int64, limit int) ([]*Block, error)
Returns `limit` blocks from blocks table starting at given timestamp, sorted by increasing CreatedAt.
func (*Blockchain) GetRecentVotes ¶
func (bc *Blockchain) GetRecentVotes() ([]*Vote, error)
Returns all of the votes with the timestamp of the most recent vote for this node.
func (*Blockchain) GetStaleTransactions ¶
func (bc *Blockchain) GetStaleTransactions(staleAge int64) ([]*Transaction, error)
Returns list of transactions that are at least staleAge old from backlog.
func (*Blockchain) GetVoteChangefeed ¶
func (bc *Blockchain) GetVoteChangefeed() (*VoteChangeCursor, error)
func (*Blockchain) ValidateBlock ¶
func (bc *Blockchain) ValidateBlock(b *Block) error
Validates block. Checks whether the signature of the block is valid. Checks whether the transactions within the block are valid.
func (*Blockchain) ValidateTransaction ¶
func (bc *Blockchain) ValidateTransaction(tx *Transaction) error
Validates transaction. Returns nil when validation is successful, returns error with reason otherwise.
func (*Blockchain) WriteBlock ¶
func (bc *Blockchain) WriteBlock(b *Block) error
Writes block to block table. Assumes that block and all of its transactions have been verified. Also, assumes that the block has been signed by this node.
func (*Blockchain) WriteVote ¶
func (bc *Blockchain) WriteVote(v *Vote) error
Writes vote to vote table. Assumes vote is already signed.
type ColAllowedOutput ¶
type ColAllowedOutput struct { *TableNameMixin ColName []byte }
func (*ColAllowedOutput) Data ¶
func (o *ColAllowedOutput) Data() []byte
func (*ColAllowedOutput) FromData ¶
func (o *ColAllowedOutput) FromData(data []byte) error
func (*ColAllowedOutput) Type ¶
func (o *ColAllowedOutput) Type() OutputType
type ColRules ¶
type ColRules struct {
AllowedColIds [][]byte // List of col ids that are allows to exist in this table
}
type ColsAllowedRule ¶
type ColsAllowedRule struct{}
func (*ColsAllowedRule) RequestedOutputIds ¶
func (rule *ColsAllowedRule) RequestedOutputIds(tx *Transaction) map[string]OutputRequirement
func (*ColsAllowedRule) Validate ¶
func (rule *ColsAllowedRule) Validate(tx *Transaction, linkedOutputs map[string]Output, spentInputs map[string][]Input) error
type HasTableExistsRule ¶
type HasTableExistsRule struct{}
func (*HasTableExistsRule) RequestedOutputIds ¶
func (rule *HasTableExistsRule) RequestedOutputIds(tx *Transaction) map[string]OutputRequirement
func (*HasTableExistsRule) Validate ¶
func (rule *HasTableExistsRule) Validate(tx *Transaction, linkedOutputs map[string]Output, spentInputs map[string][]Input) error
type Hash ¶
type Hash [HashLength]byte
func BytesToHash ¶
func HashOutput ¶
Hashes rlp encoded outputHashObject with fields filled in.
func StringToHash ¶
type Input ¶
type Input interface { OutputHash() Hash Type() InputType // TODO: Make explicit that this is a signature. For now there are no use cases of this being // anything else and there will probably not be. Data() []byte // TODO: Make explicit that this is a signature. For now there are no use cases of this being // anything else and there will probably not be. FromData([]byte) error }
type InputLink ¶
type InputLink struct {
LinksTo Hash // The hash of the output that this input links to.
}
Forms a link from an input to an output
func (*InputLink) OutputHash ¶
type MissingOutputsError ¶
type MissingOutputsError struct {
OutputIds [][]byte
}
func (*MissingOutputsError) Error ¶
func (e *MissingOutputsError) Error() string
type Node ¶
type Node struct { PubKey []byte PrivKey *ecdsa.PrivateKey }
func NewNode ¶
func NewNode(priv *ecdsa.PrivateKey) *Node
func NewNodeFromFile ¶
type Output ¶
type Output interface { Type() OutputType Data() []byte FromData([]byte) error TableName() []byte SetTableName([]byte) }
func NewOutput ¶
func NewOutput(outputType OutputType, data []byte) (Output, error)
Factory method for creating outputs
func NewOutputFromMap ¶
func NewOutputFromMap(outputType OutputType, data map[string][]byte) (Output, error)
type OutputRequirement ¶
type OutputRequirement int
Defines OutputRequirement "enum" Essentially specifies how strict we are about whether we could find the output when validating a transaction. Rules returns some set of outputs, and not all of them are required. In fact, sometimes we are looking for the lack of an output.
const ( // If the output is missing, we ignore it. OUTPUT_REQUIREMENT_NONE OutputRequirement = iota // NONE = 0 // NONE + if the output is undecided, we place it back in the backlog OUTPUT_REQUIREMENT_DECIDED // DECIDED = 1 // DECIDED + if the output is missing or rejected, transaction is invalid OUTPUT_REQUIREMENT_REQUIRED // REQUIRED = 2 )
type OutputType ¶
type OutputType int
const ( OUTPUT_TYPE_TABLE_EXISTS OutputType = iota // TABLE_EXISTS = 0 OUTPUT_TYPE_COL_ALLOWED // COL_ALLOWED = 1 OUTPUT_TYPE_ALL_COLS_ALLOWED // ALL_COLS_ALLOWED = 2 OUTPUT_TYPE_ALL_ADMINS // ALL_ADMINS = 3 OUTPUT_TYPE_ADMIN // ADMIN = 4 OUTPUT_TYPE_ALL_WRITERS // ALL_WRITERS = 5 OUTPUT_TYPE_WRITER // WRITER = 6 OUTPUT_TYPE_ALL_ROW_WRITERS // ALL_ROW_WRITERS = 7 OUTPUT_TYPE_ROW_WRITER // ROW_WRITER = 8 )
Defines OutputType "enum"
type RowRule ¶
type RowRule struct{}
func (*RowRule) RequestedOutputIds ¶
func (rule *RowRule) RequestedOutputIds(tx *Transaction) map[string]OutputRequirement
type RowRuleType ¶
type RowRuleType int
Enum for row rule types
const ( ROW_RULE_ALL RowRuleType = iota // ALL = 1 - anyone ROW_RULE_OWNER // OWNER = 2 - only the first writer )
type RowWriterInput ¶
func (*RowWriterInput) Data ¶
func (in *RowWriterInput) Data() []byte
func (*RowWriterInput) FromData ¶
func (in *RowWriterInput) FromData(data []byte) error
func (*RowWriterInput) Type ¶
func (in *RowWriterInput) Type() InputType
type RowWriterOutput ¶
type RowWriterOutput struct { *TableNameMixin RowId []byte PubKey []byte }
func (*RowWriterOutput) Data ¶
func (o *RowWriterOutput) Data() []byte
func (*RowWriterOutput) FromData ¶
func (o *RowWriterOutput) FromData(data []byte) error
func (*RowWriterOutput) Requirement ¶
func (o *RowWriterOutput) Requirement() OutputRequirement
func (*RowWriterOutput) Type ¶
func (o *RowWriterOutput) Type() OutputType
type Rule ¶
type Rule interface { RequestedOutputIds(*Transaction) map[string]OutputRequirement Validate(*Transaction, map[string]Output, map[string][]Input) error }
type RuleErrors ¶
type RuleErrors struct {
Errors []error
}
func (*RuleErrors) Error ¶
func (e *RuleErrors) Error() string
type TableExistsOutput ¶
type TableExistsOutput struct {
*TableNameMixin
}
func (*TableExistsOutput) Data ¶
func (o *TableExistsOutput) Data() []byte
func (*TableExistsOutput) FromData ¶
func (o *TableExistsOutput) FromData(data []byte) error
func (*TableExistsOutput) Type ¶
func (o *TableExistsOutput) Type() OutputType
type TableExistsOutputMixin ¶
type TableExistsOutputMixin struct{}
func (*TableExistsOutputMixin) RequestedOutputIds ¶
func (mixin *TableExistsOutputMixin) RequestedOutputIds( tx *Transaction) map[string]OutputRequirement
type TableExistsRule ¶
type TableExistsRule struct {
TableExistsOutputMixin
}
func (*TableExistsRule) Validate ¶
func (rule *TableExistsRule) Validate(tx *Transaction, linkedOutputs map[string]Output, spentInputs map[string][]Input) error
type TableMetadata ¶
type TableMetadata struct { TableName []byte // Name of the table this metadata is for Admins [][]byte // List of public keys of admins of this table Writers [][]byte // List of public keys that can write to this table RowRules *RowRules // Row level rules ColRules *ColRules // Col level rules }
func (*TableMetadata) Read ¶
func (tm *TableMetadata) Read(bt meddb.Bigtable, flag TableMetadataFlag) error
Reads non-null fields (specified by flag) of TableMetadata from bigtable Flag == 0 means to read all fields
func (*TableMetadata) Write ¶
func (tm *TableMetadata) Write(bt meddb.Bigtable, flag TableMetadataFlag) error
Writes non-null fields (specified by flag) of TableMetadata to bigtable Flag == 0 means to write all fields
type TableMetadataFlag ¶
type TableMetadataFlag int
Enum for specifying which columns to read/write from/to table metadata table
const ( TABLE_METADATA_ADMINS TableMetadataFlag = 1 << iota TABLE_METADATA_WRITERS TABLE_METADATA_ROW_RULES TABLE_METADATA_COL_RULES TABLE_METADATA_ALL TableMetadataFlag = 0 )
type TableMissingRule ¶
type TableMissingRule struct {
TableExistsOutputMixin
}
func (*TableMissingRule) Validate ¶
func (rule *TableMissingRule) Validate(tx *Transaction, linkedOutputs map[string]Output, spentInputs map[string][]Input) error
type TableNameMixin ¶
type TableNameMixin struct {
Table []byte
}
func (*TableNameMixin) SetTableName ¶
func (mixin *TableNameMixin) SetTableName(tableName []byte)
func (*TableNameMixin) TableName ¶
func (mixin *TableNameMixin) TableName() []byte
type Transaction ¶
type Transaction struct { AssignedTo []byte // TODO: Make more strict type for public keys AssignedAt *big.Int Type TransactionType TableName []byte RowId []byte Cols map[string]*Cell Outputs []Output Inputs []Input }
func (*Transaction) GetRuleset ¶
func (tx *Transaction) GetRuleset() ([]Rule, error)
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() Hash
type TransactionChange ¶
type TransactionChange struct { NewTransaction *Transaction OldTransaction *Transaction }
type TransactionChangeCursor ¶
type TransactionChangeCursor struct {
// contains filtered or unexported fields
}
Wrapper around a meddb transaction that maps meddb transactions to core transactions.
func (*TransactionChangeCursor) Next ¶
func (cursor *TransactionChangeCursor) Next(change *TransactionChange) bool
type TransactionErrors ¶
func (*TransactionErrors) Error ¶
func (e *TransactionErrors) Error() string
type TransactionType ¶
type TransactionType int
const ( TRANSACTION_TYPE_CREATE_TABLE TransactionType = iota // CREATE_TABLE = 0 TRANSACTION_TYPE_UPDATE_TABLE // UPDATE_TABLE = 1 TRANSACTION_TYPE_PUT_CELLS // PUT_CELLS = 2 )
type UndecidedOutputsError ¶
type UndecidedOutputsError struct {
OutputIds [][]byte
}
func (*UndecidedOutputsError) Error ¶
func (e *UndecidedOutputsError) Error() string
type ValidOutputTypesRule ¶
type ValidOutputTypesRule struct {
// contains filtered or unexported fields
}
func (*ValidOutputTypesRule) RequestedOutputIds ¶
func (rule *ValidOutputTypesRule) RequestedOutputIds(tx *Transaction) map[string]OutputRequirement
func (*ValidOutputTypesRule) Validate ¶
func (rule *ValidOutputTypesRule) Validate(tx *Transaction, linkedOutputs map[string]Output, spentInputs map[string][]Input) error
type Vote ¶
type VoteChange ¶
type VoteChangeCursor ¶
type VoteChangeCursor struct {
// contains filtered or unexported fields
}
Wrapper around a meddb vote that maps votes to core votes
func (*VoteChangeCursor) Next ¶
func (cursor *VoteChangeCursor) Next(change *VoteChange) bool
type WriterInput ¶
func (*WriterInput) Data ¶
func (in *WriterInput) Data() []byte
func (*WriterInput) FromData ¶
func (in *WriterInput) FromData(data []byte) error
func (*WriterInput) Type ¶
func (in *WriterInput) Type() InputType
type WriterOutput ¶
type WriterOutput struct { *TableNameMixin PubKey []byte }
func (*WriterOutput) Data ¶
func (o *WriterOutput) Data() []byte
func (*WriterOutput) FromData ¶
func (o *WriterOutput) FromData(data []byte) error
func (*WriterOutput) Requirement ¶
func (o *WriterOutput) Requirement() OutputRequirement
func (*WriterOutput) Type ¶
func (o *WriterOutput) Type() OutputType
type WriterRule ¶
type WriterRule struct{}
func (*WriterRule) RequestedOutputIds ¶
func (rule *WriterRule) RequestedOutputIds(tx *Transaction) map[string]OutputRequirement
func (*WriterRule) Validate ¶
func (rule *WriterRule) Validate(tx *Transaction, linkedOutputs map[string]Output, spentInputs map[string][]Input) error