Documentation ¶
Index ¶
- func DashBlockTransactions() func() float64
- func DashMempoolTransactions() func() float64
- func GenerateMerkleTree(transactions []*protobufs.Transaction, receiptsContract []*protobufs.Receipt) ([]byte, error)
- func OpenService(CurrentBlock uint64)
- type BeaconChain
- type Blockchain
- func (bc *Blockchain) AddMempoolTransaction(pb *protobufs.Transaction, transaction []byte) error
- func (bc *Blockchain) AddMissingBlock(key string, arrivalOrder float64, hightestBlock string)
- func (bc *Blockchain) GenerateBlock(miner string, shard uint32, validators *ValidatorsBook) (*protobufs.Block, error)
- func (bc *Blockchain) GetBlock(index uint64) ([]byte, error)
- func (bc *Blockchain) GetContractCode(address []byte) ([]byte, error)
- func (bc *Blockchain) GetNetworkIndex() int64
- func (bc *Blockchain) GetWalletState(wallet string) (protobufs.AccountState, error)
- func (bc *Blockchain) ModifyMissingBlock(key string, mb MissingBlockStruct, hashCurrentBlock string)
- func (bc *Blockchain) SetState(wallet string, newState *protobufs.AccountState) error
- func (bc *Blockchain) ValidateBlock(block *protobufs.Block) (bool, error)
- func (bc *Blockchain) ValidateTransaction(t *protobufs.Transaction) error
- type Contract
- type MissingBlockStruct
- type ReturnState
- type Validator
- type ValidatorsBook
- func (v *ValidatorsBook) AddValidator(wallet string, dynasty int64, pubSchnorrKey []byte, ...) bool
- func (v *ValidatorsBook) CheckDynasty(wallet string, currentBlock uint64) bool
- func (v *ValidatorsBook) CheckIsValidator(wallet string) bool
- func (v *ValidatorsBook) CheckWithdraw(wallet string, bc *Blockchain) bool
- func (v *ValidatorsBook) ChooseShard(seed int64, wallet string, bc *Blockchain) (uint32, error)
- func (v *ValidatorsBook) ChooseValidator(currentBlock int64, currentShard uint32, bc *Blockchain) (string, error)
- func (v *ValidatorsBook) GetSchnorrPublicKey(wallet string) (kyber.Point, error)
- func (v *ValidatorsBook) GetShard(wallet string) (uint32, error)
- func (v *ValidatorsBook) LenValidators(currentShard uint32) int
- func (v *ValidatorsBook) RemoveValidator(wallet string) error
- func (v *ValidatorsBook) SetShard(wallet string, shard uint32) error
- func (v *ValidatorsBook) WithdrawValidator(wallet string, currentBlock int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DashBlockTransactions ¶
func DashBlockTransactions() func() float64
func DashMempoolTransactions ¶
func DashMempoolTransactions() func() float64
func GenerateMerkleTree ¶
func GenerateMerkleTree(transactions []*protobufs.Transaction, receiptsContract []*protobufs.Receipt) ([]byte, error)
GenerateMerkleTree generate a merkletree and return its root
func OpenService ¶
func OpenService(CurrentBlock uint64)
OpenService open a service in 3142 port where you can find all the balance and nonce of everyone in the network
Types ¶
type BeaconChain ¶
type BeaconChain struct { MerkleRootsDb map[uint32]*leveldb.DB Validators *ValidatorsBook CurrentBlock map[uint32]uint64 }
BeaconChain is an internal representation of a beacon chain
func NewBeaconChain ¶
func NewBeaconChain(dbPath string) (*BeaconChain, error)
NewBeaconChain create a new beacon chain
func (*BeaconChain) GetBlockBeacon ¶
func (beaconChain *BeaconChain) GetBlockBeacon(index int64, shard uint32) ([]byte, error)
GetBlockBeacon returns the array of blocks at an index and at a specific shard
func (*BeaconChain) GetMerkleRoots ¶
func (beaconChain *BeaconChain) GetMerkleRoots(index uint64, shard uint32) ([]byte, error)
func (*BeaconChain) SaveMerkleRoots ¶
func (beaconChain *BeaconChain) SaveMerkleRoots(mr *protobufs.MerkleRootsSigned) error
type Blockchain ¶
type Blockchain struct { BlockDb *leveldb.DB ContractDb *leveldb.DB StateDb *leveldb.DB CasperVotesDb *leveldb.DB Mempool *mempool Schnorr map[string][]byte MTReceipt [][]byte RSchnorr [][]byte PSchnorr [][]byte MessagesReceipt [][]byte GenesisTimestamp uint64 CurrentBlock uint64 CurrentVote uint64 CurrentCheckpoint uint64 CurrentValidator map[uint64]string PriorityBlocks pq.PriorityQueue MissingBlock map[string]MissingBlockStruct HashBlocks map[string]uint64 // contains filtered or unexported fields }
Blockchain is an internal representation of a blockchain
func NewBlockchain ¶
func NewBlockchain(dbPath string, index uint64) (*Blockchain, error)
NewBlockchain creates a database db
func (*Blockchain) AddMempoolTransaction ¶
func (bc *Blockchain) AddMempoolTransaction(pb *protobufs.Transaction, transaction []byte) error
AddMempoolTransaction adds a transaction to the mempool
func (*Blockchain) AddMissingBlock ¶
func (bc *Blockchain) AddMissingBlock(key string, arrivalOrder float64, hightestBlock string)
func (*Blockchain) GenerateBlock ¶
func (bc *Blockchain) GenerateBlock(miner string, shard uint32, validators *ValidatorsBook) (*protobufs.Block, error)
GenerateBlock generates a valid unsigned block with transactions from the mempool
func (*Blockchain) GetBlock ¶
func (bc *Blockchain) GetBlock(index uint64) ([]byte, error)
GetBlock returns the array of blocks at an index
func (*Blockchain) GetContractCode ¶
func (bc *Blockchain) GetContractCode(address []byte) ([]byte, error)
GetContractCode returns the code of a contract at an address. Used as a wrapper so when we add diffed contracts in the future it's easier to change without breaking everything
func (*Blockchain) GetNetworkIndex ¶
func (bc *Blockchain) GetNetworkIndex() int64
GetNetworkIndex returns the current block index of the network
func (*Blockchain) GetWalletState ¶
func (bc *Blockchain) GetWalletState(wallet string) (protobufs.AccountState, error)
GetWalletState returns the state of a wallet in the current block
func (*Blockchain) ModifyMissingBlock ¶
func (bc *Blockchain) ModifyMissingBlock(key string, mb MissingBlockStruct, hashCurrentBlock string)
func (*Blockchain) SetState ¶
func (bc *Blockchain) SetState(wallet string, newState *protobufs.AccountState) error
func (*Blockchain) ValidateBlock ¶
func (bc *Blockchain) ValidateBlock(block *protobufs.Block) (bool, error)
ValidateBlock checks the validity of a block. It uses the current blockchain state so the passed block might become valid in the future.
func (*Blockchain) ValidateTransaction ¶
func (bc *Blockchain) ValidateTransaction(t *protobufs.Transaction) error
ValidateTransaction validates a transaction with the current state. Different from ValidateBlock because that has to verify for double spends inside the same block.
type Contract ¶
type Contract struct { ContractDb *leveldb.DB StateDb *leveldb.DB Code []byte Address []byte State *bp.ContractState Block *bp.Block Chain *Blockchain Transaction *bp.Transaction Return *ReturnState Sender string TempDB map[string][]byte TempBalance uint64 Module *wasm.Module VM *exec.VM }
Contract is the struct that saves the state of a contract
func GetContract ¶
func GetContract(address string, bc *Blockchain, tr *bp.Transaction, balance uint64) (*Contract, error)
GetContract loads the code and state from the DB and returns an error if there is no code. In case there is no state an empty one will be generated
func (*Contract) ExecuteContract ¶
func (c *Contract) ExecuteContract(exportName string, arguments []uint64) *ReturnState
ExecuteContract runs the function with the passed arguments
type MissingBlockStruct ¶
type MissingBlockStruct struct {
// contains filtered or unexported fields
}
func (MissingBlockStruct) GetMBArrivalOrder ¶
func (mb MissingBlockStruct) GetMBArrivalOrder() float64
func (MissingBlockStruct) GetMBHightestBlock ¶
func (mb MissingBlockStruct) GetMBHightestBlock() string
func (MissingBlockStruct) GetMBSequenceBlock ¶
func (mb MissingBlockStruct) GetMBSequenceBlock() uint64
func (MissingBlockStruct) GetMBbBlocksToRecalculate ¶
func (mb MissingBlockStruct) GetMBbBlocksToRecalculate() []string
type ReturnState ¶
ReturnState tells the block generator what the contract outputed
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator is a representation of a validator node
type ValidatorsBook ¶
type ValidatorsBook struct {
// contains filtered or unexported fields
}
ValidatorsBook is a structure that keeps record of every validator and its stake
func NewValidatorsBook ¶
func NewValidatorsBook() (v *ValidatorsBook)
NewValidatorsBook creates an empty ValidatorsBook object
func (*ValidatorsBook) AddValidator ¶
func (v *ValidatorsBook) AddValidator(wallet string, dynasty int64, pubSchnorrKey []byte, transaction *protobufs.Transaction, shard uint32) bool
AddValidator adds a new validator to the book. If the validator is already registered, overwrites its stake with the new one Return if the validator already exist or not
func (*ValidatorsBook) CheckDynasty ¶
func (v *ValidatorsBook) CheckDynasty(wallet string, currentBlock uint64) bool
CheckDynasty check if the dynasty of wallet are correct
func (*ValidatorsBook) CheckIsValidator ¶
func (v *ValidatorsBook) CheckIsValidator(wallet string) bool
CheckIsValidator check if wallet is inside the valsArray
func (*ValidatorsBook) CheckWithdraw ¶
func (v *ValidatorsBook) CheckWithdraw(wallet string, bc *Blockchain) bool
CheckWithdraw remove the validator and give it back him cash
func (*ValidatorsBook) ChooseShard ¶
func (v *ValidatorsBook) ChooseShard(seed int64, wallet string, bc *Blockchain) (uint32, error)
ChooseShard calulate the shard for every validators return the shard for a specific wallet
func (*ValidatorsBook) ChooseValidator ¶
func (v *ValidatorsBook) ChooseValidator(currentBlock int64, currentShard uint32, bc *Blockchain) (string, error)
ChooseValidator returns a validator's wallet, chosen randomly and proportionally to the stake
func (*ValidatorsBook) GetSchnorrPublicKey ¶
func (v *ValidatorsBook) GetSchnorrPublicKey(wallet string) (kyber.Point, error)
GetSchnorrPublicKey returns the schnorrPublicKey for a given wallet.
func (*ValidatorsBook) GetShard ¶
func (v *ValidatorsBook) GetShard(wallet string) (uint32, error)
GetShard is used to get the validator's shard
func (*ValidatorsBook) LenValidators ¶
func (v *ValidatorsBook) LenValidators(currentShard uint32) int
func (*ValidatorsBook) RemoveValidator ¶
func (v *ValidatorsBook) RemoveValidator(wallet string) error
RemoveValidator must be called in case a validator leaves its job
func (*ValidatorsBook) SetShard ¶
func (v *ValidatorsBook) SetShard(wallet string, shard uint32) error
SetShard is used to update the validator's shard when it changes.
func (*ValidatorsBook) WithdrawValidator ¶
func (v *ValidatorsBook) WithdrawValidator(wallet string, currentBlock int64) error
WithdrawValidator when a withdraw message arrive change the enddynasy of the wallet