types

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: LGPL-3.0 Imports: 19 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// BloomByteLength represents the number of bytes used in a Header log bloom.
	BloomByteLength = 256

	// BloomBitLength represents the number of bits used in a Header log bloom.
	BloomBitLength = 8 * BloomByteLength
)

Variables

View Source
var (
	ErrUnknownChangeLogType  = errors.New("unknown change log type")
	ErrWrongChangeLogVersion = errors.New("the version of change log and account is not match")
	ErrAlreadyRedo           = errors.New("the change log's version is lower than account's. maybe it has redid")
	// ErrWrongChangeLogVersion is returned by the ChangeLog Undo/Redo if account has an unexpected version
	ErrWrongChangeLogData = errors.New("change log data is incorrect")
)
View Source
var (
	// ErrKnownBlock is returned when a block to import is already known locally.
	ErrKnownBlock = errors.New("block already known")

	// ErrGasLimitReached is returned by the gas pool if the amount of gas required
	// by a transaction is higher than what's left in the block.
	ErrGasLimitReached = errors.New("block gas limit reached")

	// ErrBlacklistedHash is returned if a block to import is on the blacklist.
	ErrBlacklistedHash = errors.New("blacklisted hash")
)
View Source
var (
	TopicContractCreation = rlpHash("Contract creation")
	TopicRunFail          = rlpHash("Contract run fail")
)
View Source
var (
	DefaultTTTL   uint64 = 2 * 60 * 60 // Transaction Time To Live, 2hours
	ErrInvalidSig        = errors.New("invalid transaction v, r, s values")
	TxVersion     uint8  = 1 // current transaction version. should between 0 and 128
)
View Source
var (
	ErrPublicKey = errors.New("invalid public key")
)

Functions

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

func CombineV

func CombineV(txType uint8, version uint8, chainId uint16) *big.Int

CombineV combines type, version, chainId together to get V (without secp256k1.V)

func DeriveChangeLogsSha

func DeriveChangeLogsSha(logs []*ChangeLog) common.Hash

DeriveChangeLogsSha 计算changelog的根HASH

func DeriveDeputyRootSha

func DeriveDeputyRootSha(nodes deputynode.DeputyNodes) common.Hash

func DeriveEventsSha

func DeriveEventsSha(events []*Event) common.Hash

DeriveEventsSha 计算event的根HASH

func DeriveTxsSha

func DeriveTxsSha(txs []*Transaction) common.Hash

DeriveTxsSha 计算交易的根HASH

func ParseV

func ParseV(V *big.Int) (txType uint8, version uint8, secp256k1V uint8, chainId uint16)

ParseV split V to 4 parts

func RegisterChangeLog

func RegisterChangeLog(logType ChangeLogType, TypeName string, newValDecoder, extraDecoder changeLogDecoder, redo, undo changeLogDoFunc)

func SetSecp256k1V

func SetSecp256k1V(V *big.Int, secp256k1V byte) *big.Int

SetSecp256k1V merge secp256k1.V into the result of CombineV function

Types

type AccountAccessor

type AccountAccessor interface {
	GetAddress() common.Address
	GetBalance() *big.Int
	SetBalance(balance *big.Int)
	GetVersion(logType ChangeLogType) uint32
	SetVersion(logType ChangeLogType, version uint32)
	GetCodeHash() common.Hash
	SetCodeHash(codeHash common.Hash)
	GetCode() (Code, error)
	SetCode(code Code)
	GetStorageRoot() common.Hash
	SetStorageRoot(root common.Hash)
	GetStorageState(key common.Hash) ([]byte, error)
	SetStorageState(key common.Hash, value []byte) error
	GetBaseHeight() uint32
	GetTxHashList() []common.Hash
	IsEmpty() bool
	GetSuicide() bool
	SetSuicide(suicided bool)
	MarshalJSON() ([]byte, error)
}

type AccountData

type AccountData struct {
	Address     common.Address `json:"address" gencodec:"required"`
	Balance     *big.Int       `json:"balance" gencodec:"required"`
	CodeHash    common.Hash    `json:"codeHash" gencodec:"required"`
	StorageRoot common.Hash    `json:"root" gencodec:"required"` // MPT root of the storage trie
	// It records the block height which contains any type of newest change log.
	NewestRecords map[ChangeLogType]VersionRecord `json:"records" gencodec:"required"`
	// related transactions include income and outcome
	TxHashList []common.Hash `json:"-"`
}

AccountData is the Lemochain consensus representation of accounts. These objects are stored in the store.

func (*AccountData) Copy

func (a *AccountData) Copy() *AccountData

func (*AccountData) DecodeRLP

func (a *AccountData) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*AccountData) EncodeRLP

func (a *AccountData) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (AccountData) MarshalJSON

func (a AccountData) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*AccountData) String

func (a *AccountData) String() string

func (*AccountData) UnmarshalJSON

func (a *AccountData) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type Block

type Block struct {
	Header      *Header                `json:"header"        gencodec:"required"`
	Txs         []*Transaction         `json:"transactions"  gencodec:"required"`
	ChangeLogs  []*ChangeLog           `json:"changeLogs"    gencodec:"required"`
	Events      []*Event               `json:"events"        gencodec:"required"`
	Confirms    []SignData             `json:"confirms"`
	DeputyNodes deputynode.DeputyNodes `json:"deputyNodes"`
}

Block

func NewBlock

func NewBlock(header *Header, txs []*Transaction, changeLog []*ChangeLog, events []*Event, confirms []SignData) *Block

func (*Block) Bloom

func (b *Block) Bloom() Bloom

func (*Block) EventRoot

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

func (*Block) Extra

func (b *Block) Extra() []byte

func (*Block) GasLimit

func (b *Block) GasLimit() uint64

func (*Block) GasUsed

func (b *Block) GasUsed() uint64

func (*Block) Hash

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

func (*Block) Height

func (b *Block) Height() uint32

func (*Block) LogsHash

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

func (Block) MarshalJSON

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

MarshalJSON marshals as JSON.

func (*Block) MinerAddress

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

func (*Block) ParentHash

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

func (*Block) SetChangeLogs

func (b *Block) SetChangeLogs(logs []*ChangeLog)

func (*Block) SetConfirms

func (b *Block) SetConfirms(confirms []SignData)

func (*Block) SetDeputyNodes

func (b *Block) SetDeputyNodes(deputyNodes deputynode.DeputyNodes)

func (*Block) SetEvents

func (b *Block) SetEvents(events []*Event)

func (*Block) SetHeader

func (b *Block) SetHeader(header *Header)

func (*Block) SetTxs

func (b *Block) SetTxs(txs []*Transaction)

func (*Block) SignData

func (b *Block) SignData() []byte

func (*Block) String

func (b *Block) String() string

func (*Block) Time

func (b *Block) Time() uint32

func (*Block) TxHash

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

func (*Block) UnmarshalJSON

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

UnmarshalJSON unmarshals from JSON.

func (*Block) VersionRoot

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

type Blocks

type Blocks []*Block

type Bloom

type Bloom [BloomByteLength]byte

Bloom represents a 2048 bit bloom filter.

func BytesToBloom

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func CreateBloom

func CreateBloom(events []*Event) Bloom

func (*Bloom) Add

func (b *Bloom) Add(d *big.Int)

Add adds d to the filter. Future calls of Test(d) will return true.

func (Bloom) Big

func (b Bloom) Big() *big.Int

Big converts b to a big integer.

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

func (Bloom) MarshalText

func (b Bloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (Bloom) Test

func (b Bloom) Test(test *big.Int) bool

func (Bloom) TestBytes

func (b Bloom) TestBytes(test []byte) bool

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

UnmarshalText b as a hex string with 0x prefix.

type ChangeLog

type ChangeLog struct {
	LogType ChangeLogType  `json:"type"       gencodec:"required"`
	Address common.Address `json:"address"    gencodec:"required"`
	// The No. of ChangeLog in an account
	Version uint32 `json:"version"    gencodec:"required"`

	// data pointer. Their content type depend on specific NewXXXLog function
	OldVal interface{} `json:"-"` // It's used for undo. So no need to save or send to others
	NewVal interface{} `json:"newValue"`
	Extra  interface{} `json:"extra"`
}

func (*ChangeLog) Copy

func (c *ChangeLog) Copy() *ChangeLog

func (*ChangeLog) DecodeRLP

func (c *ChangeLog) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder.

func (*ChangeLog) EncodeRLP

func (c *ChangeLog) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*ChangeLog) Hash

func (c *ChangeLog) Hash() (h common.Hash)

Hash returns the keccak256 hash of its RLP encoding.

func (ChangeLog) MarshalJSON

func (c ChangeLog) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*ChangeLog) Redo

func (c *ChangeLog) Redo(processor ChangeLogProcessor) error

Redo reply the change for light client. Its behavior depends on ChangeLog.ChangeLogType

func (*ChangeLog) String

func (c *ChangeLog) String() string

func (*ChangeLog) Undo

func (c *ChangeLog) Undo(processor ChangeLogProcessor) error

Undo reverts the change. Its behavior depends on ChangeLog.ChangeLogType

func (*ChangeLog) UnmarshalJSON

func (c *ChangeLog) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type ChangeLogProcessor

type ChangeLogProcessor interface {
	GetAccount(addr common.Address) AccountAccessor
	PushEvent(event *Event)
	PopEvent() error
}

ChangeLogProcessor is used to access account, and the intermediate data generated by transactions. It is implemented by account.Manager

type ChangeLogSlice

type ChangeLogSlice []*ChangeLog

func (ChangeLogSlice) FindByType

func (c ChangeLogSlice) FindByType(target *ChangeLog) *ChangeLog

FindByType find the first same type change log.

func (ChangeLogSlice) Len

func (c ChangeLogSlice) Len() int

func (ChangeLogSlice) Less

func (c ChangeLogSlice) Less(i, j int) bool

func (ChangeLogSlice) Search

func (c ChangeLogSlice) Search(version uint32) int

func (ChangeLogSlice) Swap

func (c ChangeLogSlice) Swap(i, j int)

type ChangeLogType

type ChangeLogType uint32

func (ChangeLogType) String

func (t ChangeLogType) String() string

type Code

type Code []byte

func (Code) String

func (c Code) String() string

type DefaultSigner

type DefaultSigner struct {
}

DefaultSigner implements Signer.

func (DefaultSigner) GetSender

func (s DefaultSigner) GetSender(tx *Transaction) (common.Address, error)

func (DefaultSigner) Hash

func (s DefaultSigner) Hash(tx *Transaction) common.Hash

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (DefaultSigner) ParseSignature

func (s DefaultSigner) ParseSignature(tx *Transaction, sig []byte) (R, S, V *big.Int, err error)

ParseSignature returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type Event

type Event struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address common.Address `json:"address" gencodec:"required"`
	// list of topics provided by the contract.
	Topics []common.Hash `json:"topics" gencodec:"required"`
	// supplied by the contract, usually ABI-encoded
	Data []byte `json:"data" gencodec:"required"`

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	BlockHeight uint32 `json:"blockHeight"`
	// hash of the transaction
	TxHash common.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex" gencodec:"required"`
	// hash of the block in which the transaction was included
	BlockHash common.Hash `json:"blockHash"`
	// index of the event in the receipt
	Index uint `json:"eventIndex" gencodec:"required"`

	// The Removed field is true if this event was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive Events through a filter query.
	Removed bool `json:"removed"`
}

Event represents a contract event event. These Events are generated by the LOG opcode and stored/indexed by the node.

func (*Event) DecodeRLP

func (l *Event) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Event) EncodeRLP

func (l *Event) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*Event) Hash

func (l *Event) Hash() (h common.Hash)

Hash returns the keccak256 hash of its RLP encoding.

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Event) String

func (l *Event) String() string

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type EventForStorage

type EventForStorage Event

EventForStorage is a wrapper around a Event that flattens and parses the entire content of a event including non-consensus fields.

func (*EventForStorage) DecodeRLP

func (l *EventForStorage) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*EventForStorage) EncodeRLP

func (l *EventForStorage) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

type GasPool

type GasPool uint64

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount uint64) *GasPool

func (*GasPool) Gas

func (gp *GasPool) Gas() uint64

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount uint64) error
type Header struct {
	ParentHash   common.Hash    `json:"parentHash"       gencodec:"required"`
	MinerAddress common.Address `json:"miner"            gencodec:"required"`
	VersionRoot  common.Hash    `json:"versionRoot"      gencodec:"required"`
	TxRoot       common.Hash    `json:"transactionRoot"  gencodec:"required"`
	LogRoot      common.Hash    `json:"changeLogRoot"    gencodec:"required"`
	EventRoot    common.Hash    `json:"eventRoot"        gencodec:"required"`
	Bloom        Bloom          `json:"eventBloom"       gencodec:"required"`
	Height       uint32         `json:"height"           gencodec:"required"`
	GasLimit     uint64         `json:"gasLimit"         gencodec:"required"`
	GasUsed      uint64         `json:"gasUsed"          gencodec:"required"`
	Time         uint32         `json:"timestamp"        gencodec:"required"`
	SignData     []byte         `json:"signData"         gencodec:"required"`
	DeputyRoot   []byte         `json:"deputyRoot"`
	Extra        []byte         `json:"extraData"` // max length is 256 bytes
}

func (*Header) Copy

func (h *Header) Copy() *Header

Copy 拷贝一份头

func (*Header) Hash

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

Hash 块hash 排除 SignData字段

func (Header) MarshalJSON

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

MarshalJSON marshals as JSON.

func (*Header) String

func (h *Header) String() string

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type SignData

type SignData [65]byte

签名信息

func (SignData) MarshalText

func (sd SignData) MarshalText() ([]byte, error)

func (SignData) String

func (sd SignData) String() string

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	GetSender(tx *Transaction) (common.Address, error)
	// ParseSignature returns the raw R, S, V values corresponding to the
	// given signature.
	ParseSignature(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)
	// Hash returns the hash to be signed.
	Hash(tx *Transaction) common.Hash
}

Signer encapsulates transaction signature handling.

func MakeSigner

func MakeSigner() Signer

MakeSigner returns a Signer based on the given version and chainId.

type Transaction

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

func NewContractCreation

func NewContractCreation(amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, chainId uint16, expiration uint64, toName string, message string) *Transaction

func NewTransaction

func NewTransaction(to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, chainId uint16, expiration uint64, toName string, message string) *Transaction

func SignTx

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

SignTx signs the transaction using the given signer and private key

func (*Transaction) Amount

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

func (*Transaction) ChainId

func (tx *Transaction) ChainId() uint16

func (*Transaction) Cost

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

Cost returns amount + gasprice * gaslimit.

func (*Transaction) Data

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

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

func (tx *Transaction) Expiration() uint64

func (*Transaction) From

func (tx *Transaction) From() (common.Address, error)

func (*Transaction) GasLimit

func (tx *Transaction) GasLimit() uint64

func (*Transaction) GasPrice

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

func (*Transaction) Hash

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

func (*Transaction) MarshalJSON

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

MarshalJSON encodes the lemoClient RPC transaction format.

func (*Transaction) Message

func (tx *Transaction) Message() string

func (*Transaction) Raw

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

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) To

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

func (*Transaction) ToName

func (tx *Transaction) ToName() string

func (*Transaction) Type

func (tx *Transaction) Type() uint8

func (*Transaction) UnmarshalJSON

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

UnmarshalJSON decodes the lemoClient RPC transaction format.

func (*Transaction) Version

func (tx *Transaction) Version() uint8

func (*Transaction) WithSignature

func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, error)

WithSignature returns a new transaction with the given signature.

type Transactions

type Transactions []*Transaction

type VersionRecord

type VersionRecord struct {
	Version uint32 `json:"version" gencodec:"required"`
	Height  uint32 `json:"height" gencodec:"required"`
}

func (VersionRecord) MarshalJSON

func (v VersionRecord) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*VersionRecord) UnmarshalJSON

func (v *VersionRecord) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

Jump to

Keyboard shortcuts

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