model

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: LGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyTxRoot    = DeriveSha(Transactions{})
	EmptyVerfRoot  = DeriveSha(Verifications{})
	EmptyInterRoot = DeriveSha(InterLink{})
)
View Source
var (
	DefaultBlockBloomConfig = iblt.NewBloomConfig(8, 4)
	DefaultInvBloomConfig   = iblt.NewInvBloomConfig(1<<12, 4)
	DefaultTxs              = 100
)
View Source
var (
	DefaultPriorityCalculator = getCalculator()

	StakeValMin = float64(100)
)
View Source
var (
	AddressIsNotVerifierBootNode = errors.New("the Address isn't verifier boot node")
	VoteRecoverAddrError         = errors.New("the aliveVerifierVote recover Address is invalid")
	AddressIsNotCurrentVerifier  = errors.New("the recover Address isn't current verifier")
	WrongVoteType                = errors.New("wrong vote type")
)
View Source
var (

	// 4096 blocks in a cycle , if the cycle is too short,
	// will lead to occasional large deviations which will affect the whole too much.
	BlockCountOfPeriod uint64
)
View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
View Source
var IgnoreDifficultyValidation = false

Whether the tag skips the difficulty value validation in the case of unit testing is not skipped by default. Validation must be performed under non-test conditions. The variable needs to be changed to true in the test to skip validation

Functions

func CalNonce

func CalNonce(block *Block)

calculate block nonce

func CalPriority

func CalPriority(hash common.Hash, reputation uint64) (uint64, error)

func CalReputation

func CalReputation(nonce uint64, stake *big.Int, performance uint64) (uint64, error)

func CheckAddressIsCurrentVerifier

func CheckAddressIsCurrentVerifier(address common.Address, verifiers []common.Address) bool

func CheckAddressIsVerifierBootNode

func CheckAddressIsVerifierBootNode(address common.Address) bool

func CreateKey

func CreateKey() (*ecdsa.PrivateKey, *ecdsa.PrivateKey)

func DeriveSha

func DeriveSha(list DerivableList) common.Hash

func Elem

func Elem(x float64, epsilon1 float64, epsilon2 float64, epsilon3 float64) (float64, error)

func HashLevel

func HashLevel(hash common.Hash, maxHash common.Hash) int

func IsIgnoreDifficultyValidation

func IsIgnoreDifficultyValidation() bool

func LastPeriodBlockNum

func LastPeriodBlockNum(curBlockNum uint64) uint64

Getting the latest cycle's block num, Return the same num in the same cycle to ensure that caching is available new block num - 1 = cur block num

func NewCalNewWorkDiff

func NewCalNewWorkDiff(preSpanBlock, lastNormalBlock AbstractBlock, currentBlockNumber uint64) common.Difficulty

there are empty blocks in a Recent block, so we need to consider empty blocks and use a new method.

func RunWorkMap

func RunWorkMap(task iblt.Operation, txs []*Transaction) error

Input TXs-list and Algorithms for Goroutine

func SetBlockJsonHandler

func SetBlockJsonHandler(h BlockJsonHandler)

func SetBlockRlpHandler

func SetBlockRlpHandler(h BlockRlpHandler)

maybe set handler outside

Types

type AbsTransactions

type AbsTransactions []AbstractTransaction

merkle root for AbstractTransaction

func (AbsTransactions) GetKey

func (verf AbsTransactions) GetKey(i int) []byte

func (AbsTransactions) GetRlp

func (verf AbsTransactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (AbsTransactions) Len

func (verf AbsTransactions) Len() int

Len returns the length of s.

type AbstractBlock

type AbstractBlock interface {
	Version() uint64
	Number() uint64
	IsSpecial() bool
	Difficulty() common.Difficulty
	PreHash() common.Hash
	Seed() common.Hash
	RefreshHashCache() common.Hash
	Hash() common.Hash
	EncodeRlpToBytes() ([]byte, error)
	TxIterator(cb func(int, AbstractTransaction) error) error
	TxRoot() common.Hash
	Timestamp() *big.Int
	Nonce() common.BlockNonce
	StateRoot() common.Hash
	SetStateRoot(root common.Hash)
	GetRegisterRoot() common.Hash
	SetRegisterRoot(root common.Hash)
	FormatForRpc() interface{}
	SetNonce(nonce common.BlockNonce)
	CoinBaseAddress() common.Address
	GetTransactionFees() *big.Int
	CoinBase() *big.Int
	GetTransactions() []*Transaction
	GetInterlinks() InterLink
	SetInterLinkRoot(root common.Hash)
	GetInterLinkRoot() (root common.Hash)
	SetInterLinks(inter InterLink)
	GetAbsTransactions() []AbstractTransaction
	GetBloom() iblt.Bloom
	Header() AbstractHeader
	Body() AbstractBody
	TxCount() int
	GetEiBloomBlockData(reqEstimator *iblt.HybridEstimator) *BloomBlockData
	GetBlockTxsBloom() *iblt.Bloom
	VerificationRoot() common.Hash
	SetVerifications(vs []AbstractVerification)
	VersIterator(func(int, AbstractVerification, AbstractBlock) error) error
	GetVerifications() []AbstractVerification
}

type AbstractBody

type AbstractBody interface {
	GetTxsSize() int
	GetTxByIndex(i int) AbstractTransaction
	EncodeRlpToBytes() ([]byte, error)
	GetInterLinks() InterLink
}

type AbstractHeader

type AbstractHeader interface {
	GetNumber() uint64
	Hash() common.Hash
	GetPreHash() common.Hash
	EncodeRlpToBytes() ([]byte, error)
	GetStateRoot() common.Hash
	CoinBaseAddress() common.Address
	DuplicateHeader() AbstractHeader
	IsEqual(header AbstractHeader) bool
	SetVerificationRoot(newRoot common.Hash)
	GetSeed() common.Hash
	GetProof() []byte
	GetMinerPubKey() *ecdsa.PublicKey
	GetInterLinkRoot() common.Hash
	GetDifficulty() common.Difficulty
	GetRegisterRoot() common.Hash
	SetRegisterRoot(root common.Hash)
}

type AbstractTransaction

type AbstractTransaction interface {
	Size() common.StorageSize
	Amount() *big.Int
	CalTxId() common.Hash
	Fee() *big.Int
	Nonce() uint64
	To() *common.Address
	Sender(singer Signer) (common.Address, error)
	SenderPublicKey(signer Signer) (*ecdsa.PublicKey, error)
	EncodeRlpToBytes() ([]byte, error)
	GetSigner() Signer
	GetType() common.TxType
	ExtraData() []byte
	Cost() *big.Int
	EstimateFee() *big.Int
}

func TxDifference

func TxDifference(a, b []AbstractTransaction) []AbstractTransaction

TxDifference returns a new set which is the difference between a and b.

type AbstractVerification

type AbstractVerification interface {
	GetHeight() uint64
	GetRound() uint64
	GetViewID() uint64
	GetType() VoteMsgType
	GetBlockId() common.Hash
	GetAddress() common.Address
	GetBlockHash() string
	Valid() error
	HaltedVoteValid(verifiers []common.Address) error
}

type BftBlockBody

type BftBlockBody struct {
	Txs    []*Transaction `json:"transactions"`
	Vers   []*VoteMsg     `json:"commit_msg"`
	Inters InterLink      `json:"interlinks"`
}

Check whether the signature is correct and match the corresponding address to exclude the case that one person votes twice

type Block

type Block struct {
	// contains filtered or unexported fields
}

func CreateBlock

func CreateBlock(num uint64, preHash common.Hash, txsNum int) *Block

func NewBlock

func NewBlock(header *Header, txs []*Transaction, msgs []AbstractVerification) *Block
func NewBlockWithLink(header *Header, txs []*Transaction, msgs []AbstractVerification, preLink InterLink) *Block

func (*Block) Body

func (b *Block) Body() AbstractBody

func (*Block) CoinBase

func (b *Block) CoinBase() *big.Int

func (*Block) CoinBaseAddress

func (b *Block) CoinBaseAddress() common.Address

func (*Block) DecodeRLP

func (b *Block) DecodeRLP(s *rlp.Stream) error

func (*Block) Difficulty

func (b *Block) Difficulty() common.Difficulty

func (*Block) EncodeRLP

func (b *Block) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP block format.

func (*Block) EncodeRlpToBytes

func (b *Block) EncodeRlpToBytes() ([]byte, error)

func (*Block) EncodeToIBLT

func (b *Block) EncodeToIBLT() *iblt.Graphene

EncodeToIBLT returns an Invertible Bloom LookUp Table from the block's all transactions

func (*Block) FormatForRpc

func (b *Block) FormatForRpc() interface{}

func (*Block) GetAbsTransactions

func (b *Block) GetAbsTransactions() []AbstractTransaction

func (*Block) GetBlockTxsBloom

func (b *Block) GetBlockTxsBloom() *iblt.Bloom

Get block txs bloom

func (*Block) GetBloom

func (b *Block) GetBloom() iblt.Bloom

func (Block) GetCoinbase

func (b Block) GetCoinbase() *big.Int

func (*Block) GetEiBloomBlockData

func (b *Block) GetEiBloomBlockData(reqEstimator *iblt.HybridEstimator) *BloomBlockData

func (*Block) GetHeader

func (b *Block) GetHeader() AbstractHeader

func (*Block) GetInterLinkRoot

func (b *Block) GetInterLinkRoot() (root common.Hash)
func (b *Block) GetInterlinks() InterLink

func (*Block) GetRegisterRoot

func (b *Block) GetRegisterRoot() common.Hash

func (Block) GetTransactionFees

func (b Block) GetTransactionFees() *big.Int

func (*Block) GetTransactions

func (b *Block) GetTransactions() []*Transaction

func (*Block) GetVerifications

func (b *Block) GetVerifications() (result []AbstractVerification)

func (*Block) Hash

func (b *Block) Hash() common.Hash

func (*Block) Header

func (b *Block) Header() AbstractHeader

func (*Block) IsSpecial

func (b *Block) IsSpecial() bool

func (Block) MarshalJSON

func (b Block) MarshalJSON() ([]byte, error)

func (*Block) Nonce

func (b *Block) Nonce() common.BlockNonce

func (*Block) Number

func (b *Block) Number() uint64

func (*Block) PreHash

func (b *Block) PreHash() common.Hash

func (*Block) RefreshHashCache

func (b *Block) RefreshHashCache() common.Hash

func (*Block) Seed

func (b *Block) Seed() common.Hash

func (*Block) SetDifficulty

func (b *Block) SetDifficulty(diff common.Difficulty)

func (*Block) SetInterLinkRoot

func (b *Block) SetInterLinkRoot(root common.Hash)
func (b *Block) SetInterLinks(inter InterLink)

func (*Block) SetNonce

func (b *Block) SetNonce(nonce common.BlockNonce)

func (*Block) SetRegisterRoot

func (b *Block) SetRegisterRoot(root common.Hash)

func (*Block) SetStateRoot

func (b *Block) SetStateRoot(root common.Hash)

func (*Block) SetTimeStamp

func (b *Block) SetTimeStamp(timeStamp *big.Int)

func (*Block) SetVerifications

func (b *Block) SetVerifications(vs []AbstractVerification)

func (*Block) StateRoot

func (b *Block) StateRoot() common.Hash

func (*Block) String

func (b *Block) String() string

func (*Block) Timestamp

func (b *Block) Timestamp() *big.Int

func (*Block) Transaction

func (b *Block) Transaction(hash common.Hash) *Transaction

func (*Block) TxCount

func (b *Block) TxCount() int

func (Block) TxIterator

func (b Block) TxIterator(cb func(int, AbstractTransaction) error) error

func (*Block) TxRoot

func (b *Block) TxRoot() common.Hash

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(input []byte) error

func (*Block) VerificationRoot

func (b *Block) VerificationRoot() common.Hash

func (*Block) Verifications

func (b *Block) Verifications() []AbstractVerification

func (Block) VersIterator

func (b Block) VersIterator(cb func(int, AbstractVerification, AbstractBlock) error) error

func (*Block) Version

func (b *Block) Version() uint64

type BlockBy

type BlockBy func(b1, b2 *Block) bool

func (BlockBy) Sort

func (self BlockBy) Sort(blocks Blocks)

type BlockDecoder

type BlockDecoder interface {
	DecodeRlpHeaderFromBytes(data []byte) (AbstractHeader, error)
	DecodeRlpBodyFromBytes(data []byte) (AbstractBody, error)
	DecodeRlpBlockFromHeaderAndBodyBytes(headerB []byte, bodyB []byte) (AbstractBlock, error)
	DecodeRlpBlockFromBytes(data []byte) (AbstractBlock, error)
	DecodeRlpTransactionFromBytes(data []byte) (AbstractTransaction, error)
}

func MakeDefaultBlockDecoder

func MakeDefaultBlockDecoder() BlockDecoder

type BlockJsonHandler

type BlockJsonHandler interface {
	DecodeBody(to *Body, input []byte) error
}

only have interface use diff rlp handler

type BlockRlpHandler

type BlockRlpHandler interface {
	DecodeBody(to *Body, s *rlp.Stream) error
}

only have interface use diff rlp handler

type Blocks

type Blocks []*Block

type BloomBlockData

type BloomBlockData struct {
	Header   *Header
	BloomRLP []byte
	// pre height vs
	PreVerification []AbstractVerification
	// cur height vs
	CurVerification []AbstractVerification
	//interlins
	Interlinks InterLink
}

func (*BloomBlockData) EiRecoverToBlock

func (data *BloomBlockData) EiRecoverToBlock(txPoolMap map[common.Hash]AbstractTransaction) (block *Block, err error)

type Body

type Body struct {
	Txs    []*Transaction         `json:"transactions"`
	Vers   []AbstractVerification `json:"commit_msg"`
	Inters InterLink              `json:"interlinks"`
}

swagger:response Body

func (*Body) DecodeRLP

func (b *Body) DecodeRLP(s *rlp.Stream) error

func (*Body) EncodeRlpToBytes

func (b *Body) EncodeRlpToBytes() ([]byte, error)
func (b *Body) GetInterLinks() InterLink

func (*Body) GetTxByIndex

func (b *Body) GetTxByIndex(i int) AbstractTransaction

func (*Body) GetTxsSize

func (b *Body) GetTxsSize() int

func (*Body) UnmarshalJSON

func (b *Body) UnmarshalJSON(input []byte) error

type DerivableList

type DerivableList interface {
	Len() int
	GetKey(i int) []byte
	GetRlp(i int) []byte
}

type DeriveShaInterface

type DeriveShaInterface interface {
	DeriveSha(list DerivableList) common.Hash
}
type Header struct {
	// version of this block generated
	Version uint64 `json:"version"  gencodec:"required"`
	// the height of the block
	Number uint64 `json:"number"  gencodec:"required"`
	// used for VRF
	Seed common.Hash `json:"seed"  gencodec:"required"`
	// seed proof
	Proof []byte `json:"proof"  gencodec:"required"`
	// miner public key
	MinerPubKey []byte `json:"miner_pub_key"  gencodec:"required"`
	//Previous block hash
	PreHash common.Hash `json:"pre_hash"  gencodec:"required"`
	// difficulty for this block
	Diff common.Difficulty `json:"diff"  gencodec:"required"`
	// timestamp for this block
	TimeStamp *big.Int `json:"timestamp"  gencodec:"required"`
	// the address of the miner who mined this block
	CoinBase common.Address `json:"coinbase"  gencodec:"required"`
	// nonce needed to be mined by the miner
	Nonce common.BlockNonce `json:"nonce"  gencodec:"required"`
	//todo add bloom filter for logs or txs
	Bloom *iblt.Bloom `json:"Bloom"        gencodec:"required"`
	// MPT trie root for transaction
	TransactionRoot common.Hash `json:"txs_root"   gencodec:"required"`
	// MPT trie root for accounts state
	//todo if we want to put normal accounts and contract accounts into different tree we can generate two MPT trie for them
	StateRoot common.Hash `json:"state_root" gencodec:"required"`
	// MPT trie root for committed message
	VerificationRoot common.Hash `json:"verification_root"  gencodec:"required"`
	// MPT trie root for interlink message
	InterlinkRoot common.Hash `json:"interlink_root"  gencodec:"required"`
	// MPT trie root for register
	RegisterRoot common.Hash `json:"register_root"  gencodec:"required"`
}

func CopyHeader

func CopyHeader(h *Header) *Header

CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.

func NewHeader

func NewHeader(version uint64, num uint64, prehash common.Hash, seed common.Hash, diff common.Difficulty, time *big.Int, coinbase common.Address, nonce common.BlockNonce) *Header

func (*Header) CoinBaseAddress

func (h *Header) CoinBaseAddress() common.Address

func (*Header) DuplicateHeader

func (h *Header) DuplicateHeader() AbstractHeader

func (*Header) EncodeRlpToBytes

func (h *Header) EncodeRlpToBytes() ([]byte, error)

func (*Header) GetDifficulty

func (bh *Header) GetDifficulty() common.Difficulty

func (*Header) GetInterLinkRoot

func (h *Header) GetInterLinkRoot() common.Hash

func (*Header) GetMinerPubKey

func (h *Header) GetMinerPubKey() *ecdsa.PublicKey

func (*Header) GetNumber

func (h *Header) GetNumber() uint64

func (*Header) GetPreHash

func (h *Header) GetPreHash() common.Hash

func (*Header) GetProof

func (h *Header) GetProof() []byte

func (*Header) GetRegisterRoot

func (h *Header) GetRegisterRoot() common.Hash

func (*Header) GetSeed

func (h *Header) GetSeed() common.Hash

func (*Header) GetStateRoot

func (h *Header) GetStateRoot() common.Hash

func (*Header) Hash

func (h *Header) Hash() common.Hash

compute Hash of the header

func (*Header) HashWithoutNonce

func (h *Header) HashWithoutNonce() common.Hash

the nonce is not comprised to calculate the hash value

func (*Header) IsEqual

func (h *Header) IsEqual(header AbstractHeader) bool

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

func (Header) RlpBlockWithoutNonce

func (h Header) RlpBlockWithoutNonce() (rb []byte)

func (*Header) SetRegisterRoot

func (h *Header) SetRegisterRoot(root common.Hash)

func (*Header) SetVerificationRoot

func (h *Header) SetVerificationRoot(newRoot common.Hash)

func (*Header) Size

func (h *Header) Size() common.StorageSize

todo for download

func (*Header) String

func (h *Header) String() string

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(input []byte) error
type InterLink []common.Hash
func NewInterLink(preBlockLinks InterLink, curBlock AbstractBlock) InterLink

assuming genesis blocks level is 0,other level,relative to the paper description, move one layer as a whole.

func (InterLink) GetKey

func (l InterLink) GetKey(i int) []byte

func (InterLink) GetRlp

func (l InterLink) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (InterLink) Len

func (l InterLink) Len() int

Len returns the length of s.

type MapWorkHybridEstimator

type MapWorkHybridEstimator struct {
	// contains filtered or unexported fields
}

func (MapWorkHybridEstimator) DoTask

func (estimator MapWorkHybridEstimator) DoTask(i interface{}) interface{}

type MapWorkInvBloom

type MapWorkInvBloom struct {
	// contains filtered or unexported fields
}

func (MapWorkInvBloom) DoTask

func (bloom MapWorkInvBloom) DoTask(i interface{}) interface{}

type MercurySigner

type MercurySigner struct {
	// contains filtered or unexported fields
}

func NewMercurySigner

func NewMercurySigner(chainId *big.Int) MercurySigner

func (MercurySigner) Equal

func (fs MercurySigner) Equal(s2 Signer) bool

func (MercurySigner) GetSender

func (fs MercurySigner) GetSender(tx *Transaction) (common.Address, error)

func (MercurySigner) GetSenderPublicKey

func (fs MercurySigner) GetSenderPublicKey(tx *Transaction) (*ecdsa.PublicKey, error)

func (MercurySigner) GetSignHash

func (fs MercurySigner) GetSignHash(rtx *Transaction) (common.Hash, error)

GetSignHash will return the VRFHash of the transaction with have the raw transaction data and chainId

func (MercurySigner) SignatureValues

func (fs MercurySigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type PBFTBlockJsonHandler

type PBFTBlockJsonHandler struct{}

func (*PBFTBlockJsonHandler) DecodeBody

func (h *PBFTBlockJsonHandler) DecodeBody(to *Body, input []byte) error

type PBFTBlockRlpHandler

type PBFTBlockRlpHandler struct{}

func (*PBFTBlockRlpHandler) DecodeBody

func (h *PBFTBlockRlpHandler) DecodeBody(to *Body, s *rlp.Stream) error

type PBFTBody

type PBFTBody struct {
	Txs    []*Transaction `json:"transactions"`
	Vers   []*VoteMsg     `json:"commit_msg"`
	Inters InterLink      `json:"interlinks"`
}

type PriofityCalculator

type PriofityCalculator interface {
	GetElectPriority(common.Hash, uint64, *big.Int, uint64) (uint64, error)
	GetReputation(uint64, *big.Int, uint64) (uint64, error)
}

type Proofs

type Proofs struct {
	VoteA    *VoteMsg
	VoteB    *VoteMsg
	VRFHash  common.Hash
	Proof    []byte
	Priority uint64
}

type RpcTransaction

type RpcTransaction struct {
	To             common.Address
	Value          *big.Int
	TransactionFee *big.Int
	Data           []byte
	Nonce          uint64
}

type SignHashFunc

type SignHashFunc func(hash []byte) ([]byte, error)

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	GetSender(tx *Transaction) (common.Address, error)
	//Get Sender Public Key
	GetSenderPublicKey(tx *Transaction) (*ecdsa.PublicKey, error)
	// SignatureValues returns the raw R, S, V values corresponding to the
	// given signature.
	SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)
	// Hash returns the VRFHash to be signed.
	GetSignHash(rtx *Transaction) (common.Hash, error)
	// Equal returns true if the given signer is the same as the receiver.
	Equal(Signer) bool
}

signer define different kind of method handling signature

func MakeSigner

func MakeSigner(config *chain_config.ChainConfig, blockNumber uint64) Signer

todo set signer config

type TestCalculator

type TestCalculator struct {
}

func (TestCalculator) GetElectPriority

func (tc TestCalculator) GetElectPriority(hash common.Hash, nonce uint64, stake *big.Int, performance uint64) (uint64, error)

hash means luck which calculate by block seed and address

func (TestCalculator) GetReputation

func (tc TestCalculator) GetReputation(nonce uint64, stake *big.Int, performance uint64) (uint64, error)

acquire reputation value

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

func CreateRawClaimTx

func CreateRawClaimTx(nonce uint64, key []byte, amount *big.Int, fee *big.Int, alice common.Address, bob common.Address) *Transaction

func CreateRawLockTx

func CreateRawLockTx(nonce uint64, lock common.Hash, time *big.Int, amount *big.Int, fee *big.Int, alice common.Address, bob common.Address) *Transaction

func CreateRawRefundTx

func CreateRawRefundTx(nonce uint64, amount *big.Int, fee *big.Int, alice common.Address, bob common.Address) *Transaction

func CreateSignedTx

func CreateSignedTx(nonce uint64, amount *big.Int) *Transaction

func CreateSignedTxList

func CreateSignedTxList(n int) []*Transaction

func NewCancelTransaction

func NewCancelTransaction(nonce uint64, fee *big.Int) *Transaction

func NewContractCreation

func NewContractCreation(nonce uint64, amount *big.Int, fee *big.Int, data []byte) *Transaction

func NewEvidenceTransaction

func NewEvidenceTransaction(nonce uint64, fee *big.Int, target *common.Address, voteA *VoteMsg, voteB *VoteMsg) *Transaction

func NewRegisterTransaction

func NewRegisterTransaction(nonce uint64, amount *big.Int, fee *big.Int) *Transaction

Name CalledBy Parameters Return

func NewTransaction

func NewTransaction(nonce uint64, to common.Address, amount *big.Int, fee *big.Int, data []byte) *Transaction

func NewUnNormalTransaction

func NewUnNormalTransaction(nonce uint64, amount *big.Int, fee *big.Int) *Transaction

func NewUnStakeTransaction

func NewUnStakeTransaction(nonce uint64, fee *big.Int) *Transaction

func (*Transaction) Amount

func (tx *Transaction) Amount() *big.Int

func (*Transaction) CalTxId

func (tx *Transaction) CalTxId() common.Hash

get the transaction ID

func (Transaction) ChainId

func (tx Transaction) ChainId() *big.Int

func (*Transaction) Cost

func (tx *Transaction) Cost() *big.Int

Cost returns amount + fee

func (*Transaction) DecodeRLP

func (tx *Transaction) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*Transaction) EncodeRLP

func (tx *Transaction) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*Transaction) EncodeRlpToBytes

func (tx *Transaction) EncodeRlpToBytes() ([]byte, error)

func (*Transaction) EstimateFee

func (tx *Transaction) EstimateFee() *big.Int

func (*Transaction) ExtraData

func (tx *Transaction) ExtraData() []byte

func (*Transaction) Fee

func (tx *Transaction) Fee() *big.Int

func (Transaction) GetSigner

func (tx Transaction) GetSigner() Signer

todo: currently use default signer ,later need get a way to determine the signer from the tx itself.

func (Transaction) GetType

func (tx Transaction) GetType() common.TxType

func (*Transaction) HashKey

func (tx *Transaction) HashKey() []byte

func (*Transaction) HashLock

func (tx *Transaction) HashLock() *common.Hash

func (tx *Transaction) Version() uint64 { return tx.data.Version }

func (Transaction) IsEqual

func (tx Transaction) IsEqual(tempTx Transaction) bool

func (Transaction) MarshalJSON

func (tx Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

func (*Transaction) RawSignatureValues

func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int)

func (*Transaction) Sender

func (tx *Transaction) Sender(signer Signer) (common.Address, error)

func (*Transaction) SenderPublicKey

func (tx *Transaction) SenderPublicKey(signer Signer) (*ecdsa.PublicKey, error)

func (*Transaction) SignTx

func (tx *Transaction) SignTx(priKey *ecdsa.PrivateKey, s Signer) (*Transaction, error)

func (*Transaction) Size

func (tx *Transaction) Size() common.StorageSize

func (Transaction) String

func (tx Transaction) String() string

func (*Transaction) TimeLock

func (tx *Transaction) TimeLock() *big.Int

func (*Transaction) To

func (tx *Transaction) To() *common.Address

func (*Transaction) UnmarshalJSON

func (tx *Transaction) UnmarshalJSON(input []byte) error

type TransactionBuilder

type TransactionBuilder struct {
	// contains filtered or unexported fields
}

func (*TransactionBuilder) NewNormalTransaction

func (builder *TransactionBuilder) NewNormalTransaction(from common.Address, to common.Address, amount *big.Int, fee *big.Int, data []byte) AbstractTransaction

type TransactionBy

type TransactionBy func(b1, b2 *Block) bool

func (TransactionBy) Sort

func (self TransactionBy) Sort(blocks Blocks)

type TransactionJSON

type TransactionJSON struct {
	TxData txData
	Wit    witness
}

type TransactionRLP

type TransactionRLP struct {
	Txdata txData
	Wit    witness
}

type Transactions

type Transactions []*Transaction

Transactions is a Transaction slice type for basic sorting.

func (Transactions) GetKey

func (ss Transactions) GetKey(i int) []byte

func (Transactions) GetRlp

func (ss Transactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (Transactions) Len

func (ss Transactions) Len() int

Len returns the length of s.

func (Transactions) Less

func (ss Transactions) Less(i, j int) bool

func (Transactions) String

func (ss Transactions) String() string

func (Transactions) Swap

func (ss Transactions) Swap(i, j int)

Swap swaps the i'th and the j'th element in s.

type TransactionsByFeeAndNonce

type TransactionsByFeeAndNonce struct {
	// contains filtered or unexported fields
}

TransactionsByPriceAndNonce represents a set of transactions that can return transactions in a profit-maximizing sorted order, while supporting removing entire batches of transactions for non-executable accounts.

func NewTransactionsByFeeAndNonce

func NewTransactionsByFeeAndNonce(signer Signer, txs map[common.Address][]AbstractTransaction) *TransactionsByFeeAndNonce

NewTransactionsByPriceAndNonce creates a transaction set that can retrieve price sorted transactions in a nonce-honouring way.

Note, the input map is reowned so the caller should not interact any more with if after providing it to the constructor. TODO errors will occur if all transactions are deleted

func (*TransactionsByFeeAndNonce) Peek

Peek returns the next transaction by price.

func (*TransactionsByFeeAndNonce) Pop

func (t *TransactionsByFeeAndNonce) Pop()

Pop removes the best transaction, *not* replacing it with the next one from the same account. This should be used when a transaction cannot be executed and hence all subsequent ones should be discarded from the same account.

func (*TransactionsByFeeAndNonce) Shift

func (t *TransactionsByFeeAndNonce) Shift()

Shift replaces the current best head with the next one from the same account.

type TxByFee

type TxByFee []AbstractTransaction

TxByPrice implements both the sort and the heap interface, making it useful for all at once sorting as well as individually adding and removing elements.

func (TxByFee) Len

func (s TxByFee) Len() int

func (TxByFee) Less

func (s TxByFee) Less(i, j int) bool

func (*TxByFee) Pop

func (s *TxByFee) Pop() interface{}

func (*TxByFee) Push

func (s *TxByFee) Push(x interface{})

func (TxByFee) Swap

func (s TxByFee) Swap(i, j int)

type TxCacher

type TxCacher struct {
	// contains filtered or unexported fields
}

txCacher is a helper structure to concurrently recover transaction id from digital signatures on background threads.

func NewTxCacher

func NewTxCacher(threads int) *TxCacher

NewTxCacher creates a new transaction id background cacher and starts as many processing goroutines as allowed by the GOMAXPROCS on construction.

func (*TxCacher) StopTxCacher

func (cacher *TxCacher) StopTxCacher()

func (*TxCacher) TxRecover

func (cacher *TxCacher) TxRecover(txs []AbstractTransaction)

TxRecover recovers the id from a batch of transactions and caches them back into the same data structures. There is no validation being done, nor any reaction to invalid signatures. That is up to calling code later.

type TxCacherRequest

type TxCacherRequest struct {
	// contains filtered or unexported fields
}

type Verifications

type Verifications []AbstractVerification

merkle root for AbstractVerification

func (Verifications) GetKey

func (verf Verifications) GetKey(i int) []byte

func (Verifications) GetRlp

func (verf Verifications) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (Verifications) Len

func (verf Verifications) Len() int

Len returns the length of s.

type VoteMsg

type VoteMsg struct {
	Height    uint64
	Round     uint64
	BlockID   common.Hash
	VoteType  VoteMsgType
	Timestamp time.Time
	Witness   *WitMsg
}

func CreateSignedVote

func CreateSignedVote(height, round uint64, blockId common.Hash, voteType VoteMsgType) *VoteMsg

func NewVoteMsg

func NewVoteMsg(height, round uint64, blockID common.Hash, voteType VoteMsgType) *VoteMsg

func NewVoteMsgWithSign

func NewVoteMsgWithSign(height, round uint64, blockID common.Hash, voteType VoteMsgType, signFunc SignHashFunc, signAddress common.Address) (*VoteMsg, error)

Create a new signature VoteMsg

func (VoteMsg) GetAddress

func (v VoteMsg) GetAddress() common.Address

func (VoteMsg) GetBlockHash

func (v VoteMsg) GetBlockHash() string

func (VoteMsg) GetBlockId

func (v VoteMsg) GetBlockId() common.Hash

func (VoteMsg) GetHeight

func (v VoteMsg) GetHeight() uint64

func (VoteMsg) GetRound

func (v VoteMsg) GetRound() uint64

func (VoteMsg) GetType

func (v VoteMsg) GetType() VoteMsgType

func (VoteMsg) GetViewID

func (v VoteMsg) GetViewID() uint64

func (VoteMsg) HaltedVoteValid

func (v VoteMsg) HaltedVoteValid(verifiers []common.Address) error

func (VoteMsg) Hash

func (v VoteMsg) Hash() common.Hash

func (VoteMsg) String

func (v VoteMsg) String() string

func (VoteMsg) Valid

func (v VoteMsg) Valid() error

type VoteMsgType

type VoteMsgType byte
const (
	PreVoteMessage           VoteMsgType = 0
	VoteMessage              VoteMsgType = 1
	VerBootNodeVoteMessage   VoteMsgType = 2
	AliveVerifierVoteMessage VoteMsgType = 3
)

func (VoteMsgType) String

func (i VoteMsgType) String() string

type WitMsg

type WitMsg struct {
	Address common.Address `json:"address"`
	Sign    []byte         `json:"sign"`
}

func (*WitMsg) Valid

func (witMsg *WitMsg) Valid(dataHash []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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