Documentation ¶
Overview ¶
Package vochain provides all the functions for creating and managing a vocdoni voting blockchain
Index ¶
- Variables
- func AminoKeys(key crypto256k1.PrivKey) (private, public []byte, err error)
- func AminoPubKey(pubkey []byte) ([]byte, error)
- func GenerateFaucetPackage(from *ethereum.SignKeys, to ethcommon.Address, amount uint64) (*models.FaucetPackage, error)
- func NewGenesis(cfg *config.VochainCfg, chainID string, consensusParams *ConsensusParams, ...) ([]byte, error)
- func NewNodeKey(tmPrivKey, nodeKeyFilePath string) (*tmtypes.NodeKey, error)
- func NewPrivateValidator(tmPrivKey, keyFilePath, stateFilePath string) (*privval.FilePV, error)
- func NewTemplateGenesisFile(dir string, validators int) (*tmtypes.GenesisDoc, error)
- func TxCostNameToTxType(key string) models.TxType
- func TxTypeToCostName(txType models.TxType) string
- type AppStateValidators
- type BaseApplication
- func (app *BaseApplication) AdvanceTestBlock()
- func (app *BaseApplication) ApplySnapshotChunk(req abcitypes.RequestApplySnapshotChunk) abcitypes.ResponseApplySnapshotChunk
- func (app *BaseApplication) BeginBlock(req abcitypes.RequestBeginBlock) abcitypes.ResponseBeginBlock
- func (app *BaseApplication) ChainID() string
- func (app *BaseApplication) CheckTx(req abcitypes.RequestCheckTx) abcitypes.ResponseCheckTx
- func (app *BaseApplication) CircuitConfigurationTag() string
- func (app *BaseApplication) Commit() abcitypes.ResponseCommit
- func (app *BaseApplication) DeliverTx(req abcitypes.RequestDeliverTx) abcitypes.ResponseDeliverTx
- func (app *BaseApplication) EndBlock(req abcitypes.RequestEndBlock) abcitypes.ResponseEndBlock
- func (app *BaseApplication) Genesis() *tmtypes.GenesisDoc
- func (app *BaseApplication) GetBlockByHash(hash []byte) *tmtypes.Block
- func (app *BaseApplication) GetBlockByHeight(height int64) *tmtypes.Block
- func (app *BaseApplication) GetTx(height uint32, txIndex int32) (*models.SignedTx, error)
- func (app *BaseApplication) GetTxHash(height uint32, txIndex int32) (*models.SignedTx, []byte, error)
- func (app *BaseApplication) Height() uint32
- func (app *BaseApplication) Info(req abcitypes.RequestInfo) abcitypes.ResponseInfo
- func (app *BaseApplication) InitChain(req abcitypes.RequestInitChain) abcitypes.ResponseInitChain
- func (app *BaseApplication) ListSnapshots(req abcitypes.RequestListSnapshots) abcitypes.ResponseListSnapshots
- func (app *BaseApplication) LoadSnapshotChunk(req abcitypes.RequestLoadSnapshotChunk) abcitypes.ResponseLoadSnapshotChunk
- func (app *BaseApplication) MempoolSize() int
- func (app *BaseApplication) OfferSnapshot(req abcitypes.RequestOfferSnapshot) abcitypes.ResponseOfferSnapshot
- func (app *BaseApplication) Query(req abcitypes.RequestQuery) abcitypes.ResponseQuery
- func (app *BaseApplication) SendTx(tx []byte) (*ctypes.ResultBroadcastTx, error)
- func (app *BaseApplication) SetChainID(chainId string)
- func (app *BaseApplication) SetCircuitConfigTag(tag string) error
- func (app *BaseApplication) SetDefaultMethods()
- func (app *BaseApplication) SetFnBeginBlock(fn func(req abcitypes.RequestBeginBlock) abcitypes.ResponseBeginBlock)
- func (app *BaseApplication) SetFnEndBlock(fn func(req abcitypes.RequestEndBlock) abcitypes.ResponseEndBlock)
- func (app *BaseApplication) SetFnGetBlockByHash(fn func(hash []byte) *tmtypes.Block)
- func (app *BaseApplication) SetFnGetBlockByHeight(fn func(height int64) *tmtypes.Block)
- func (app *BaseApplication) SetFnGetTx(fn func(height uint32, txIndex int32) (*models.SignedTx, error))
- func (app *BaseApplication) SetFnGetTxHash(fn func(height uint32, txIndex int32) (*models.SignedTx, []byte, error))
- func (app *BaseApplication) SetFnMempoolSize(fn func() int)
- func (app *BaseApplication) SetFnSendTx(fn func(tx []byte) (*ctypes.ResultBroadcastTx, error))
- func (app *BaseApplication) SetNode(vochaincfg *config.VochainCfg, genesis []byte) error
- func (app *BaseApplication) SetTestingMethods()
- func (app *BaseApplication) Timestamp() int64
- func (app *BaseApplication) TimestampFromBlock(height int64) *time.Time
- func (app *BaseApplication) TimestampStartBlock() int64
- type BlockParams
- type ConsensusParams
- type EvidenceParams
- type GenesisAccount
- type GenesisAppState
- type GenesisDoc
- type GenesisValidator
- type QueryData
- type TenderLogger
- func (l *TenderLogger) Debug(msg string, keyvals ...interface{})
- func (l *TenderLogger) Error(msg string, keyvals ...interface{})
- func (l *TenderLogger) Info(msg string, keyvals ...interface{})
- func (l *TenderLogger) SetLogLevel(logLevel string)
- func (l *TenderLogger) With(keyvals ...interface{}) tmlog.Logger
- type TendermintPubKey
- type TransactionCosts
- type ValidatorParams
- type VersionParams
- type VotePackage
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidAddress = fmt.Errorf("invalid address")
)
var ( // ErrTransactionNotFound is returned when the transaction is not found in the blockstore. ErrTransactionNotFound = fmt.Errorf("transaction not found") )
var PrefixDBCacheSize = 0
PrefixDBCacheSize is the size of the cache for the MutableTree IAVL databases
var TxCostNameToTxTypeMap = map[string]models.TxType{ "SetProcessStatus": models.TxType_SET_PROCESS_STATUS, "SetProcessCensus": models.TxType_SET_PROCESS_CENSUS, "SetProcessResults": models.TxType_SET_PROCESS_RESULTS, "SetProcessQuestionIndex": models.TxType_SET_PROCESS_QUESTION_INDEX, "SendTokens": models.TxType_SEND_TOKENS, "SetAccountInfoURI": models.TxType_SET_ACCOUNT_INFO_URI, "CreateAccount": models.TxType_CREATE_ACCOUNT, "RegisterKey": models.TxType_REGISTER_VOTER_KEY, "NewProcess": models.TxType_NEW_PROCESS, "AddDelegateForAccount": models.TxType_ADD_DELEGATE_FOR_ACCOUNT, "DelDelegateForAccount": models.TxType_DEL_DELEGATE_FOR_ACCOUNT, "CollectFaucet": models.TxType_COLLECT_FAUCET, }
TxCostNameToTxTypeMap maps a valid string to a txType
var TxTypeToCostNameMap = map[models.TxType]string{ models.TxType_SET_PROCESS_STATUS: "SetProcessStatus", models.TxType_SET_PROCESS_CENSUS: "SetProcessCensus", models.TxType_SET_PROCESS_RESULTS: "SetProcessResults", models.TxType_SET_PROCESS_QUESTION_INDEX: "SetProcessQuestionIndex", models.TxType_SEND_TOKENS: "SendTokens", models.TxType_SET_ACCOUNT_INFO_URI: "SetAccountInfoURI", models.TxType_CREATE_ACCOUNT: "CreateAccount", models.TxType_REGISTER_VOTER_KEY: "RegisterKey", models.TxType_NEW_PROCESS: "NewProcess", models.TxType_ADD_DELEGATE_FOR_ACCOUNT: "AddDelegateForAccount", models.TxType_DEL_DELEGATE_FOR_ACCOUNT: "DelDelegateForAccount", models.TxType_COLLECT_FAUCET: "CollectFaucet", }
TxTypeToCostNameMap maps a valid txType to a string
Functions ¶
func AminoKeys ¶
func AminoKeys(key crypto256k1.PrivKey) (private, public []byte, err error)
AminoKeys is a helper function that transforms a standard EDDSA key into Tendermint like amino format useful for creating genesis files.
func AminoPubKey ¶ added in v1.3.0
AminoPubKey is a helper function that transforms a standard EDDSA pubkey into Tendermint like amino format useful for creating genesis files.
func GenerateFaucetPackage ¶ added in v1.3.0
func GenerateFaucetPackage(from *ethereum.SignKeys, to ethcommon.Address, amount uint64) (*models.FaucetPackage, error)
GenerateFaucetPackage generates a faucet package. The package is signed by the given `from` key (holder of the funds) and sent to the `to` address. The `amount` is the amount of tokens to be sent.
func NewGenesis ¶
func NewGenesis(cfg *config.VochainCfg, chainID string, consensusParams *ConsensusParams, validators []privval.FilePV, oracles, accounts []string, initAccountsBalance int, treasurer string, txCosts *TransactionCosts) ([]byte, error)
NewGenesis creates a new genesis and return its bytes
func NewNodeKey ¶
NewNodeKey returns and saves to the disk storage a tendermint node key
func NewPrivateValidator ¶
NewPrivateValidator returns a tendermint file private validator (key and state) if tmPrivKey not specified, uses the existing one or generates a new one
func NewTemplateGenesisFile ¶ added in v1.4.0
func NewTemplateGenesisFile(dir string, validators int) (*tmtypes.GenesisDoc, error)
NewTemplateGenesisFile creates a genesis file with the given number of validators and its private keys. Also includes an oracle, treasurer and faucet account. The genesis document is returned.
func TxCostNameToTxType ¶ added in v1.3.0
TxCostNameToTxType converts a valid string to a txType
func TxTypeToCostName ¶ added in v1.3.0
TxTypeToCostName converts a valid txType to a string
Types ¶
type AppStateValidators ¶ added in v1.4.0
type BaseApplication ¶
type BaseApplication struct { State *vstate.State Service service.Service Node *tmcli.Local TransactionHandler *transaction.TransactionHandler IsSynchronizing func() bool // contains filtered or unexported fields }
BaseApplication reflects the ABCI application implementation.
func NewBaseApplication ¶
func NewBaseApplication(dbType, dbpath string) (*BaseApplication, error)
NewBaseApplication creates a new BaseApplication given a name and a DB backend. Node still needs to be initialized with SetNode. Callback functions still need to be initialized.
func NewVochain ¶
func NewVochain(vochaincfg *config.VochainCfg, genesis []byte) *BaseApplication
NewVochain starts a node with an ABCI application
func TestBaseApplication ¶ added in v1.3.0
func TestBaseApplication(tb testing.TB) *BaseApplication
TestBaseApplication creates a new BaseApplication for testing purposes. It initializes the State, TransactionHandler and all the callback functions. Once the application is create, it is the caller's responsibility to call app.AdvanceTestBlock() to advance the block height and commit the state.
func (*BaseApplication) AdvanceTestBlock ¶ added in v1.3.0
func (app *BaseApplication) AdvanceTestBlock()
AdvanceTestBlock commits the current state, ends the current block and starts a new one. Advances the block height and timestamp.
func (*BaseApplication) ApplySnapshotChunk ¶
func (app *BaseApplication) ApplySnapshotChunk( req abcitypes.RequestApplySnapshotChunk) abcitypes.ResponseApplySnapshotChunk
func (*BaseApplication) BeginBlock ¶
func (app *BaseApplication) BeginBlock(req abcitypes.RequestBeginBlock) abcitypes.ResponseBeginBlock
BeginBlock is called at the beginning of every block.
func (*BaseApplication) ChainID ¶ added in v1.0.3
func (app *BaseApplication) ChainID() string
ChainID returns the Node ChainID
func (*BaseApplication) CheckTx ¶
func (app *BaseApplication) CheckTx(req abcitypes.RequestCheckTx) abcitypes.ResponseCheckTx
CheckTx unmarshals req.Tx and checks its validity
func (*BaseApplication) CircuitConfigurationTag ¶ added in v1.4.0
func (app *BaseApplication) CircuitConfigurationTag() string
CircuitConfigurationTag returns the Node CircuitConfigurationTag
func (*BaseApplication) Commit ¶
func (app *BaseApplication) Commit() abcitypes.ResponseCommit
Commit saves the current vochain state and returns a commit hash
func (*BaseApplication) DeliverTx ¶
func (app *BaseApplication) DeliverTx(req abcitypes.RequestDeliverTx) abcitypes.ResponseDeliverTx
DeliverTx unmarshals req.Tx and adds it to the State if it is valid
func (*BaseApplication) EndBlock ¶
func (app *BaseApplication) EndBlock(req abcitypes.RequestEndBlock) abcitypes.ResponseEndBlock
EndBlock is called at the end of every block.
func (*BaseApplication) Genesis ¶ added in v1.4.0
func (app *BaseApplication) Genesis() *tmtypes.GenesisDoc
Genesis returns the tendermint genesis information
func (*BaseApplication) GetBlockByHash ¶ added in v1.0.3
func (app *BaseApplication) GetBlockByHash(hash []byte) *tmtypes.Block
GetBlockByHash retreies a full Tendermint block indexed by its Hash
func (*BaseApplication) GetBlockByHeight ¶ added in v1.0.3
func (app *BaseApplication) GetBlockByHeight(height int64) *tmtypes.Block
GetBlockByHeight retrieves a full Tendermint block indexed by its height. This method uses an LRU cache for the blocks so in general it is more convinient for high load operations than GetBlockByHash(), which does not use cache.
func (*BaseApplication) GetTx ¶ added in v1.0.3
GetTx retrieves a vochain transaction from the blockstore
func (*BaseApplication) GetTxHash ¶ added in v1.0.3
func (app *BaseApplication) GetTxHash(height uint32, txIndex int32) (*models.SignedTx, []byte, error)
GetTxHash retrieves a vochain transaction, with its hash, from the blockstore
func (*BaseApplication) Height ¶ added in v1.0.3
func (app *BaseApplication) Height() uint32
Height returns the current blockchain height
func (*BaseApplication) Info ¶
func (app *BaseApplication) Info(req abcitypes.RequestInfo) abcitypes.ResponseInfo
Info Return information about the application state. Used to sync Tendermint with the application during a handshake that happens on startup. The returned AppVersion will be included in the Header of every block. Tendermint expects LastBlockAppHash and LastBlockHeight to be updated during Commit, ensuring that Commit is never called twice for the same block height.
func (*BaseApplication) InitChain ¶
func (app *BaseApplication) InitChain(req abcitypes.RequestInitChain) abcitypes.ResponseInitChain
InitChain called once upon genesis ResponseInitChain can return a list of validators. If the list is empty, Tendermint will use the validators loaded in the genesis file.
func (*BaseApplication) ListSnapshots ¶
func (app *BaseApplication) ListSnapshots( req abcitypes.RequestListSnapshots) abcitypes.ResponseListSnapshots
func (*BaseApplication) LoadSnapshotChunk ¶
func (app *BaseApplication) LoadSnapshotChunk( req abcitypes.RequestLoadSnapshotChunk) abcitypes.ResponseLoadSnapshotChunk
func (*BaseApplication) MempoolSize ¶ added in v1.3.0
func (app *BaseApplication) MempoolSize() int
MempoolSize returns the size of the transaction mempool
func (*BaseApplication) OfferSnapshot ¶
func (app *BaseApplication) OfferSnapshot( req abcitypes.RequestOfferSnapshot) abcitypes.ResponseOfferSnapshot
func (*BaseApplication) Query ¶
func (app *BaseApplication) Query(req abcitypes.RequestQuery) abcitypes.ResponseQuery
Query does nothing
func (*BaseApplication) SendTx ¶ added in v1.0.3
func (app *BaseApplication) SendTx(tx []byte) (*ctypes.ResultBroadcastTx, error)
SendTx sends a transaction to the mempool (sync)
func (*BaseApplication) SetChainID ¶ added in v1.3.0
func (app *BaseApplication) SetChainID(chainId string)
SetChainID sets the app and state chainID
func (*BaseApplication) SetCircuitConfigTag ¶ added in v1.4.0
func (app *BaseApplication) SetCircuitConfigTag(tag string) error
SetCircuitConfigTag sets the current BaseApplication circuit config tag attribute to the provided one and loads the circuit configuration based on it. The available circuit config tags are defined in /crypto/zk/circuit/config.go
func (*BaseApplication) SetDefaultMethods ¶ added in v1.0.3
func (app *BaseApplication) SetDefaultMethods()
SetDefaultMethods assigns fnGetBlockByHash, fnGetBlockByHeight, fnSendTx to use the BlockStore from app.Node to load blocks. Assumes app.Node has been set.
func (*BaseApplication) SetFnBeginBlock ¶ added in v1.4.0
func (app *BaseApplication) SetFnBeginBlock(fn func(req abcitypes.RequestBeginBlock) abcitypes.ResponseBeginBlock)
func (*BaseApplication) SetFnEndBlock ¶ added in v1.4.0
func (app *BaseApplication) SetFnEndBlock(fn func(req abcitypes.RequestEndBlock) abcitypes.ResponseEndBlock)
func (*BaseApplication) SetFnGetBlockByHash ¶ added in v1.0.3
func (app *BaseApplication) SetFnGetBlockByHash(fn func(hash []byte) *tmtypes.Block)
SetFnGetBlockByHash sets the getter for blocks by hash
func (*BaseApplication) SetFnGetBlockByHeight ¶ added in v1.0.3
func (app *BaseApplication) SetFnGetBlockByHeight(fn func(height int64) *tmtypes.Block)
SetFnGetBlockByHeight sets the getter for blocks by height
func (*BaseApplication) SetFnGetTx ¶ added in v1.3.0
func (app *BaseApplication) SetFnGetTx(fn func(height uint32, txIndex int32) (*models.SignedTx, error))
SetFnGetTx sets the getTx method
func (*BaseApplication) SetFnGetTxHash ¶ added in v1.3.0
func (app *BaseApplication) SetFnGetTxHash(fn func(height uint32, txIndex int32) (*models.SignedTx, []byte, error))
SetFnGetTxHash sets the getTxHash method
func (*BaseApplication) SetFnMempoolSize ¶ added in v1.3.0
func (app *BaseApplication) SetFnMempoolSize(fn func() int)
SetFnMempoolSize sets the mempool size method method
func (*BaseApplication) SetFnSendTx ¶ added in v1.0.3
func (app *BaseApplication) SetFnSendTx(fn func(tx []byte) (*ctypes.ResultBroadcastTx, error))
SetFnSendTx sets the sendTx method
func (*BaseApplication) SetNode ¶ added in v1.0.3
func (app *BaseApplication) SetNode(vochaincfg *config.VochainCfg, genesis []byte) error
func (*BaseApplication) SetTestingMethods ¶ added in v1.0.3
func (app *BaseApplication) SetTestingMethods()
SetTestingMethods assigns fnGetBlockByHash, fnGetBlockByHeight, fnSendTx to use mockBlockStore
func (*BaseApplication) Timestamp ¶ added in v1.0.3
func (app *BaseApplication) Timestamp() int64
Timestamp returns the last block end timestamp
func (*BaseApplication) TimestampFromBlock ¶ added in v1.3.0
func (app *BaseApplication) TimestampFromBlock(height int64) *time.Time
TimestampFromBlock returns the timestamp for a specific block height. If the block is not found, it returns nil. If the block is the current block, it returns the current block start timestamp.
func (*BaseApplication) TimestampStartBlock ¶ added in v1.3.0
func (app *BaseApplication) TimestampStartBlock() int64
TimestampStartBlock returns the current block start timestamp
type BlockParams ¶ added in v1.0.3
BlockParams define limits on the block size and gas plus minimum time between blocks.
type ConsensusParams ¶ added in v1.0.3
type ConsensusParams struct { Block BlockParams `json:"block"` Evidence EvidenceParams `json:"evidence"` Validator ValidatorParams `json:"validator"` Version VersionParams `json:"version"` }
type EvidenceParams ¶ added in v1.0.3
type GenesisAccount ¶ added in v1.4.0
type GenesisAccount struct { Address types.HexBytes `json:"address"` Balance uint64 `json:"balance"` }
GenesisAccount represents an account in the genesis app state
type GenesisAppState ¶ added in v1.0.3
type GenesisAppState struct { Validators []AppStateValidators `json:"validators"` Oracles []types.HexBytes `json:"oracles"` Accounts []GenesisAccount `json:"accounts"` Treasurer types.HexBytes `json:"treasurer"` TxCost TransactionCosts `json:"tx_cost"` }
GenesisAppState application state in genesis
type GenesisDoc ¶ added in v1.0.3
type GenesisDoc struct { GenesisTime time.Time `json:"genesis_time"` ChainID string `json:"chain_id"` ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"` Validators []GenesisValidator `json:"validators,omitempty"` AppHash types.HexBytes `json:"app_hash"` AppState GenesisAppState `json:"app_state,omitempty"` }
type GenesisValidator ¶ added in v1.0.3
type GenesisValidator struct { Address types.HexBytes `json:"address"` PubKey TendermintPubKey `json:"pub_key"` Power string `json:"power"` Name string `json:"name"` }
type QueryData ¶ added in v1.0.3
type QueryData struct { Method string `json:"method"` ProcessID string `json:"processId,omitempty"` Nullifier string `json:"nullifier,omitempty"` From int64 `json:"from,omitempty"` ListSize int64 `json:"listSize,omitempty"` Timestamp int64 `json:"timestamp,omitempty"` ProcessType string `json:"type,omitempty"` }
QueryData is an abstraction of any kind of data a query request could have
type TenderLogger ¶
type TenderLogger struct { Artifact string // contains filtered or unexported fields }
TenderLogger implements tendermint's Logger interface, with a couple of modifications.
First, it routes the logs to go-dvote's logger, so that we don't end up with two loggers writing directly to stdout or stderr.
Second, because we generally don't care about tendermint errors such as failures to connect to peers, we route all log levels to our debug level. They will only surface if dvote's log level is "debug".
func NewTenderLogger ¶
func NewTenderLogger(artifact string, logLevel string) *TenderLogger
NewTenderLogger creates a Tendermint compatible logger for specified artifact
func (*TenderLogger) Debug ¶
func (l *TenderLogger) Debug(msg string, keyvals ...interface{})
func (*TenderLogger) Error ¶
func (l *TenderLogger) Error(msg string, keyvals ...interface{})
func (*TenderLogger) Info ¶
func (l *TenderLogger) Info(msg string, keyvals ...interface{})
func (*TenderLogger) SetLogLevel ¶ added in v1.4.0
func (l *TenderLogger) SetLogLevel(logLevel string)
func (*TenderLogger) With ¶
func (l *TenderLogger) With(keyvals ...interface{}) tmlog.Logger
type TendermintPubKey ¶ added in v1.0.3
type TransactionCosts ¶ added in v1.3.0
type TransactionCosts struct { SetProcessStatus uint32 `json:"Tx_SetProcessStatus"` SetProcessCensus uint32 `json:"Tx_SetProcessCensus"` SetProcessResults uint32 `json:"Tx_SetProcessResults"` SetProcessQuestionIndex uint32 `json:"Tx_SetProcessQuestionIndex"` RegisterKey uint32 `json:"Tx_RegisterKey"` NewProcess uint32 `json:"Tx_NewProcess"` SendTokens uint32 `json:"Tx_SendTokens"` SetAccountInfoURI uint32 `json:"Tx_SetAccountInfoURI"` CreateAccount uint32 `json:"Tx_CreateAccount"` AddDelegateForAccount uint32 `json:"Tx_AddDelegateForAccount"` DelDelegateForAccount uint32 `json:"Tx_DelDelegateForAccount"` CollectFaucet uint32 `json:"Tx_CollectFaucet"` }
________________________ TRANSACTION COSTS __________________________ TransactionCosts describes how much each operation should cost
func (*TransactionCosts) AsMap ¶ added in v1.3.0
func (t *TransactionCosts) AsMap() map[models.TxType]uint64
AsMap returns the contents of TransactionCosts as a map. Its purpose is to keep knowledge of TransactionCosts' fields within itself, so the function using it only needs to iterate over the key-values.
type ValidatorParams ¶ added in v1.0.3
type ValidatorParams struct {
PubKeyTypes []string `json:"pub_key_types"`
}
type VersionParams ¶ added in v1.3.0
type VersionParams struct {
AppVersion uint64 `json:"app_version"`
}
type VotePackage ¶ added in v1.0.3
VotePackage represents the payload of a vote (usually base64 encoded)