Documentation ¶
Overview ¶
Package validator represents a collection of helper methods useful for validators in the SummerCash network. Methods in the validator package are specified in terms of a validator interface, that of which is also implemented in the validator package. NOTE: Ripped from another one of my projects; https://github.com/polaris-project/go-polaris/tree/master/validator
Package validator represents a collection of helper methods useful for validators in the SummerCash network. Methods in the validator package are specified in terms of a validator interface, that of which is also implemented in the validator package. NOTE: Ripped from another one of my projects; https://github.com/polaris-project/go-polaris/tree/master/validator
Index ¶
- Constants
- Variables
- type StandardValidator
- func (validator *StandardValidator) GetWorkingConfig() *config.ChainConfig
- func (validator *StandardValidator) PerformChainSafetyChecks(transaction *types.Transaction) error
- func (validator *StandardValidator) ValidateTransaction(transaction *types.Transaction) error
- func (validator *StandardValidator) ValidateTransactionHash(transaction *types.Transaction) bool
- func (validator *StandardValidator) ValidateTransactionIsNotDuplicate(transaction *types.Transaction) bool
- func (validator *StandardValidator) ValidateTransactionNonce(transaction *types.Transaction) bool
- func (validator *StandardValidator) ValidateTransactionSenderBalance(transaction *types.Transaction) bool
- func (validator *StandardValidator) ValidateTransactionSignature(transaction *types.Transaction) bool
- func (validator *StandardValidator) ValidateTransactionState(transaction *types.Transaction) bool
- func (validator *StandardValidator) ValidateTransactionTimestamp(transaction *types.Transaction) bool
- func (validator *StandardValidator) ValidationProtocol() string
- type Validator
Constants ¶
const StandardValidatorValidationProtocol = "standard_sig_ver"
StandardValidatorValidationProtocol represents the validation protocol of the standard validator.
Variables ¶
var ( // ErrInvalidTransactionHash is an error definition representing a transaction hash of invalid value. ErrInvalidTransactionHash = errors.New("transaction hash is invalid") // ErrInvalidTransactionState is an error definition representing a transaction state of invalid value. ErrInvalidTransactionState = errors.New("transaction state is invalid") // ErrInvalidTransactionTimestamp is an error definition representing a transaction timestamp of invalid value. ErrInvalidTransactionTimestamp = errors.New("invalid transaction timestamp") // ErrInvalidTransactionSignature is an error definition representing a transaction signature of invalid value. ErrInvalidTransactionSignature = errors.New("invalid transaction signature") // ErrInsufficientSenderBalance is an error definition representing a sender balance of insufficient value. ErrInsufficientSenderBalance = errors.New("insufficient sender balance") // ErrDuplicateTransaction is an error definition representing a transaction of duplicate value in the working chain. ErrDuplicateTransaction = errors.New("transaction already exists in the working chain (duplicate)") // ErrInvalidNonce is an error definition representing a transaction of invalid nonce value. ErrInvalidNonce = errors.New("invalid transaction nonce") )
Functions ¶
This section is empty.
Types ¶
type StandardValidator ¶
type StandardValidator struct {
Config *config.ChainConfig `json:"config"` // Chain configuration reference
}
StandardValidator represents a standard validator implementing the validator interface.
func NewStandardValidator ¶
func NewStandardValidator(config *config.ChainConfig) *StandardValidator
NewStandardValidator initializes a new beacon dag with a given config and working chain.
func (*StandardValidator) GetWorkingConfig ¶
func (validator *StandardValidator) GetWorkingConfig() *config.ChainConfig
GetWorkingConfig attempts to fetch the working config instance.
func (*StandardValidator) PerformChainSafetyChecks ¶
func (validator *StandardValidator) PerformChainSafetyChecks(transaction *types.Transaction) error
PerformChainSafetyChecks loads a given transaction's sender chain, requests it if it doesn't exist, and makes one if it cannot request it from its peers.
func (*StandardValidator) ValidateTransaction ¶
func (validator *StandardValidator) ValidateTransaction(transaction *types.Transaction) error
ValidateTransaction validates the given transaction via the standard validator. Each validation issue is returned as an error.
func (*StandardValidator) ValidateTransactionHash ¶
func (validator *StandardValidator) ValidateTransactionHash(transaction *types.Transaction) bool
ValidateTransactionHash checks that a given transaction's hash is equivalent to the calculated hash of that given transaction.
func (*StandardValidator) ValidateTransactionIsNotDuplicate ¶
func (validator *StandardValidator) ValidateTransactionIsNotDuplicate(transaction *types.Transaction) bool
ValidateTransactionIsNotDuplicate checks that a given transaction does not already exist in the working dag.
func (*StandardValidator) ValidateTransactionNonce ¶
func (validator *StandardValidator) ValidateTransactionNonce(transaction *types.Transaction) bool
ValidateTransactionNonce checks that a given transaction's nonce is equivalent to the sending account's last nonce + 1.
func (*StandardValidator) ValidateTransactionSenderBalance ¶
func (validator *StandardValidator) ValidateTransactionSenderBalance(transaction *types.Transaction) bool
ValidateTransactionSenderBalance checks that a given transaction's sender has a balance greater than or equal to the transaction's total value (including gas costs).
func (*StandardValidator) ValidateTransactionSignature ¶
func (validator *StandardValidator) ValidateTransactionSignature(transaction *types.Transaction) bool
ValidateTransactionSignature validates the given transaction's signature against the transaction sender's public key. If the transaction's signature is nil, false is returned.
func (*StandardValidator) ValidateTransactionState ¶ added in v0.6.1
func (validator *StandardValidator) ValidateTransactionState(transaction *types.Transaction) bool
ValidateTransactionState checks that a given transaction's working state is equivalent to that of the parent, with the given transition applied.
func (*StandardValidator) ValidateTransactionTimestamp ¶
func (validator *StandardValidator) ValidateTransactionTimestamp(transaction *types.Transaction) bool
ValidateTransactionTimestamp validates the given transaction's timestamp against that of its parents. If the timestamp of any one of the given transaction's parents is after the given transaction's timestamp, false is returned. If any one of the transaction's parent transactions cannot be found in the working dag, false is returned.
func (*StandardValidator) ValidationProtocol ¶
func (validator *StandardValidator) ValidationProtocol() string
ValidationProtocol fetches the current validator's validation protocol.
type Validator ¶
type Validator interface { ValidateTransaction(transaction *types.Transaction) error // Validate a given transaction ValidateTransactionHash(transaction *types.Transaction) bool // Validate a given transaction's hash ValidateTransactionState(transaction *types.Transaction) bool // Validate a given transaction's state ValidateTransactionTimestamp(transaction *types.Transaction) bool // Validate a given transaction's timestamp ValidateTransactionSignature(transaction *types.Transaction) bool // Validate a given transaction's signature ValidateTransactionSenderBalance(transaction *types.Transaction) bool // Validate a given transaction's sender has ValidateTransactionIsNotDuplicate(transaction *types.Transaction) bool // Validate that a given transaction does not already exist in the working chain ValidateTransactionNonce(transaction *types.Transaction) bool // Validate that a given transaction's nonce is equivalent to the current account index + 1 ValidationProtocol() string // Get the current validator's validation protocol GetWorkingConfig() *config.ChainConfig // Get current validator's working config }
Validator represents any generic validator.