vochain

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2023 License: AGPL-3.0 Imports: 47 Imported by: 4

Documentation

Overview

Package vochain provides all the functions for creating and managing a vocdoni voting blockchain

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAddress = fmt.Errorf("invalid address")
)
View Source
var (
	// ErrTransactionNotFound is returned when the transaction is not found in the blockstore.
	ErrTransactionNotFound = fmt.Errorf("transaction not found")
)
View Source
var PrefixDBCacheSize = 0

PrefixDBCacheSize is the size of the cache for the MutableTree IAVL databases

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

func AminoPubKey(pubkey []byte) ([]byte, error)

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 *genesis.ConsensusParams,
	validators []privval.FilePV, oracles, accounts []string, initAccountsBalance int,
	treasurer string, txCosts *genesis.TransactionCosts) ([]byte, error)

NewGenesis creates a new genesis and return its bytes

func NewNodeKey

func NewNodeKey(tmPrivKey, nodeKeyFilePath string) (*tmtypes.NodeKey, error)

NewNodeKey returns and saves to the disk storage a tendermint node key

func NewPrivateValidator

func NewPrivateValidator(tmPrivKey, keyFilePath, stateFilePath string) (*privval.FilePV, error)

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.

Types

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) BeginBlock

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

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

Commit saves the current vochain state and returns a commit hash

func (*BaseApplication) DeliverTx

DeliverTx unmarshals req.Tx and adds it to the State if it is valid

func (*BaseApplication) EndBlock

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

func (app *BaseApplication) GetTx(height uint32, txIndex int32) (*models.SignedTx, error)

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

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

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 (*BaseApplication) LoadSnapshotChunk

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 (*BaseApplication) Query

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 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 VotePackage added in v1.0.3

type VotePackage struct {
	Nonce string `json:"nonce,omitempty"`
	Votes []int  `json:"votes"`
}

VotePackage represents the payload of a vote (usually base64 encoded)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL