Documentation ¶
Index ¶
- Constants
- type BlockMakerInterface
- type ConsensusConfig
- func (cc ConsensusConfig) Export(defaultaddresses string, appname string, thisnodeaddr string) (jsondata []byte, err error)
- func (cc ConsensusConfig) ExportToFile(filepath string, defaultaddresses string, appname string, thisnodeaddr string) error
- func (cc *ConsensusConfig) ExtendRulesApplyStartHeigh(setHeigh int)
- func (cc ConsensusConfig) GetInfoForTransactions() structures.ConsensusInfo
- func (cc ConsensusConfig) GetPaidTransactionsWallet() string
- func (cc ConsensusConfig) GetPaidTransactionsWalletPubKeyHash() []byte
- func (cc ConsensusConfig) GetRandomInitialAddress() *net.NodeAddr
- func (cc ConsensusConfig) IsDefault() bool
- func (cc *ConsensusConfig) SetConfigFilePath(fp string)
- func (cc *ConsensusConfig) UpdateConfig(jsondoc []byte) error
- type ConsensusConfigApplication
- type ConsensusConfigCost
- type ConsensusConfigTable
- type NodeBlockMaker
- func (n *NodeBlockMaker) AddTransactionToPool(tx *structures.Transaction, flags int) error
- func (n *NodeBlockMaker) CompleteBlock() (*structures.Block, error)
- func (n *NodeBlockMaker) GetPreparedBlockTransactionsIDs() ([][]byte, error)
- func (n *NodeBlockMaker) IsBlockPrepared() bool
- func (n *NodeBlockMaker) PrepareNewBlock() (int, error)
- func (n *NodeBlockMaker) SetDBManager(DB database.DBManager)
- func (n *NodeBlockMaker) SetLogManager(Logger *utils.LoggerMan)
- func (n *NodeBlockMaker) SetMinterAddress(minter string)
- func (n *NodeBlockMaker) SetPreparedBlock(block *structures.Block) error
- func (n *NodeBlockMaker) VerifyBlock(block *structures.Block, flags int) error
- func (n NodeBlockMaker) VerifyTransaction(tx *structures.Transaction, prevTXs []structures.Transaction, ...) error
- type ProofOfWork
- type ProofOfWorkSettings
- type QueryFromProxyResult
- type SQLTransactionsInterface
Constants ¶
const ( BlockPrepare_Error = 0 BlockPrepare_Done = 1 BlockPrepare_NoTransactions = 2 BlockPrepare_NotGoodTime = 3 SQLProcessingResultError = 0 // error SQLProcessingResultExecuted = 1 // Query doesn't need signature . It was executed . SQLProcessingResultPubKeyRequired = 2 // Query needs signature and all other info. Data to sign is not yet preared (pubkey was not provided) SQLProcessingResultSignatureRequired = 3 // Query needs signature. TX was prepared and data to sign is retuned SQLProcessingResultTranactionComplete = 4 // Query needs signature. TX was created with provied signature SQLProcessingResultTranactionCompleteInternally = 5 // Query needs signature. TX was created with internal keys and completed SQLProcessingResultCanBeExecuted = 6 // Query doesn't need signature . It was NOT executed. A proxy can pass it to a server )
const (
KindConseususPoW = "proofofwork"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockMakerInterface ¶
type BlockMakerInterface interface { SetDBManager(DB database.DBManager) SetLogManager(Logger *utils.LoggerMan) SetMinterAddress(minter string) PrepareNewBlock() (int, error) SetPreparedBlock(block *structures.Block) error IsBlockPrepared() bool GetPreparedBlockTransactionsIDs() ([][]byte, error) // returns list of transactions in prepared block CompleteBlock() (*structures.Block, error) VerifyBlock(block *structures.Block, flags int) error AddTransactionToPool(tx *structures.Transaction, flags int) error }
func NewBlockMakerManager ¶
func NewBlockMakerManager(config *ConsensusConfig, minter string, DB database.DBManager, Logger *utils.LoggerMan) BlockMakerInterface
type ConsensusConfig ¶
type ConsensusConfig struct { Application ConsensusConfigApplication Kind string CoinsForBlockMade float64 Settings map[string]interface{} ApplyRulesAfterBlock int AllowTableCreate bool AllowTableDrop bool AllowRowDelete bool TransactionCost ConsensusConfigCost UnmanagedTables []string TableRules []ConsensusConfigTable InitNodesAddreses []string PaidTransactionsWallet string // contains filtered or unexported fields }
func NewConfigDefault ¶
func NewConfigDefault() (*ConsensusConfig, error)
func NewConfigFromFile ¶
func NewConfigFromFile(filepath string) (*ConsensusConfig, error)
Load config from config file. Some config options an be missed missed options must be replaced with default values correctly
func (ConsensusConfig) Export ¶
func (cc ConsensusConfig) Export(defaultaddresses string, appname string, thisnodeaddr string) (jsondata []byte, err error)
Exports config to JSON string
func (ConsensusConfig) ExportToFile ¶
func (cc ConsensusConfig) ExportToFile(filepath string, defaultaddresses string, appname string, thisnodeaddr string) error
Exports config to file
func (*ConsensusConfig) ExtendRulesApplyStartHeigh ¶
func (cc *ConsensusConfig) ExtendRulesApplyStartHeigh(setHeigh int)
Increase rule start block heigh for all rules It is used for initial DB import and create BC on existent data
func (ConsensusConfig) GetInfoForTransactions ¶
func (cc ConsensusConfig) GetInfoForTransactions() structures.ConsensusInfo
Return info about transaction settings
func (ConsensusConfig) GetPaidTransactionsWallet ¶
func (cc ConsensusConfig) GetPaidTransactionsWallet() string
Returns wallet where to send money spent on paid transactions
func (ConsensusConfig) GetPaidTransactionsWalletPubKeyHash ¶
func (cc ConsensusConfig) GetPaidTransactionsWalletPubKeyHash() []byte
Returns wallet where to send money spent on paid transactions
func (ConsensusConfig) GetRandomInitialAddress ¶
func (cc ConsensusConfig) GetRandomInitialAddress() *net.NodeAddr
Returns one of addresses listed in initial addresses
func (ConsensusConfig) IsDefault ¶
func (cc ConsensusConfig) IsDefault() bool
Checks if a config structure was loaded from file or not
func (*ConsensusConfig) SetConfigFilePath ¶
func (cc *ConsensusConfig) SetConfigFilePath(fp string)
Set config file path. this defines a path where a config file should be, even if it is not yet here
func (*ConsensusConfig) UpdateConfig ¶
func (cc *ConsensusConfig) UpdateConfig(jsondoc []byte) error
type ConsensusConfigCost ¶
type ConsensusConfigTable ¶
type NodeBlockMaker ¶
type NodeBlockMaker struct { DB database.DBManager Logger *utils.LoggerMan MinterAddress string // this is the wallet that will receive for mining PreparedBlock *structures.Block // contains filtered or unexported fields }
func (*NodeBlockMaker) AddTransactionToPool ¶
func (n *NodeBlockMaker) AddTransactionToPool(tx *structures.Transaction, flags int) error
Add transaction to a pool. This will call verification and if all is ok it adds to a poool of transactions
func (*NodeBlockMaker) CompleteBlock ¶
func (n *NodeBlockMaker) CompleteBlock() (*structures.Block, error)
finalise a block. in this place we do MIMING Block was prepared. Now do final work for this block. In our case it is PoW process
func (*NodeBlockMaker) GetPreparedBlockTransactionsIDs ¶
func (n *NodeBlockMaker) GetPreparedBlockTransactionsIDs() ([][]byte, error)
Returns IDs of transactions selected to do a next block
func (*NodeBlockMaker) IsBlockPrepared ¶
func (n *NodeBlockMaker) IsBlockPrepared() bool
check if a block was prepared already
func (*NodeBlockMaker) PrepareNewBlock ¶
func (n *NodeBlockMaker) PrepareNewBlock() (int, error)
func (*NodeBlockMaker) SetDBManager ¶
func (n *NodeBlockMaker) SetDBManager(DB database.DBManager)
func (*NodeBlockMaker) SetLogManager ¶
func (n *NodeBlockMaker) SetLogManager(Logger *utils.LoggerMan)
func (*NodeBlockMaker) SetMinterAddress ¶
func (n *NodeBlockMaker) SetMinterAddress(minter string)
func (*NodeBlockMaker) SetPreparedBlock ¶
func (n *NodeBlockMaker) SetPreparedBlock(block *structures.Block) error
func (*NodeBlockMaker) VerifyBlock ¶
func (n *NodeBlockMaker) VerifyBlock(block *structures.Block, flags int) error
Verify the block. We check if it is correct agains previous block Verify a block against blockchain RULES
- Verification is done agains blockchain branch starting from prevblock, not current top branch
- There can be only 1 transaction make reward per block
- number of transactions must be in correct ranges (reward transaction is not calculated)
- transactions can have as input other transaction from this block and it must be listed BEFORE (output must be before input in same block)
- all inputs must be in blockchain (correct unspent inputs)
- Additionally verify each transaction agains signatures, total amount, balance etc
- Verify hash is correc agains rules
func (NodeBlockMaker) VerifyTransaction ¶
func (n NodeBlockMaker) VerifyTransaction(tx *structures.Transaction, prevTXs []structures.Transaction, prevBlockHash []byte, prevBlockHeight int, flags int) error
Verify transaction against all rules
type ProofOfWork ¶
type ProofOfWork struct {
// contains filtered or unexported fields
}
ProofOfWork represents a proof-of-work
func NewProofOfWork ¶
func NewProofOfWork(b *structures.Block, settings map[string]interface{}) *ProofOfWork
NewProofOfWork builds and returns a ProofOfWork object The object can be used to find a hash for the block
func (*ProofOfWork) GetTransactionLimitsPerBlock ¶
func (pow *ProofOfWork) GetTransactionLimitsPerBlock(h int) (min int, max int)
func (*ProofOfWork) Run ¶
func (pow *ProofOfWork) Run() (int, []byte, error)
Run performs a proof-of-work
func (*ProofOfWork) Validate ¶
func (pow *ProofOfWork) Validate() (bool, error)
Validate validates block's PoW It calculates hash from same data and check if it is equal to block hash
type ProofOfWorkSettings ¶
type QueryFromProxyResult ¶
type QueryFromProxyResult struct { Status uint8 TX *structures.Transaction TXData []byte StringToSign []byte ReplaceQuery string ErrorCode uint16 Error error }
The structure to return information on new query request from proxy This includes a status , data to sign (if needed), new transaction (if was created) The structure can include error, so no need to have error response separately
type SQLTransactionsInterface ¶
type SQLTransactionsInterface interface { NewQuery(sql string, pubKey []byte) (uint, []byte, []byte, *structures.Transaction, error) NewQuerySigned(txEncoded []byte, signature []byte) (*structures.Transaction, error) NewQueryByNode(sql string, pubKey []byte, privKey ecdsa.PrivateKey) (uint, *structures.Transaction, error) NewQueryByNodeInit(sql string, pubKey []byte, privKey ecdsa.PrivateKey) (tx *structures.Transaction, err error) NewQueryFromProxy(sql string) QueryFromProxyResult RepeatTransactionsFromCanceledBlocks(txList []structures.Transaction) error }
func NewSQLQueryManager ¶
func NewSQLQueryManager(config *ConsensusConfig, DB database.DBManager, Logger *utils.LoggerMan, pubKey []byte, privKey ecdsa.PrivateKey) (SQLTransactionsInterface, error)