types

package
v0.0.0-...-24e5678 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTagTxMsg       = EventType(0x00)
	EventTagReward      = EventType(0x01)
	EventTagCallHistory = EventType(0x02)
	EventTagTxFee       = EventType(0x03)
)
View Source
const (
	Go uint8 = iota
	Js
	Evm
)

Variables

View Source
var (
	ErrExistContractType            = errors.New("exist contract type")
	ErrNotExistContract             = errors.New("not exist contract")
	ErrInvalidClassID               = errors.New("invalid class id")
	ErrInvalidContractTransactionID = errors.New("invalid contract transaction id")
	ErrInvalidTransactionCount      = errors.New("invalid transaction count")
	ErrInvalidSignerCount           = errors.New("invalid signer count")
	ErrInvalidSigner                = errors.New("invalid signer")
	ErrDustAmount                   = errors.New("dust amount")
	ErrInvalidTransactionIDFormat   = errors.New("invalid transaction id format")
	ErrUsedTimeSlot                 = errors.New("used timeslot")
	ErrInvalidTransactionTimeSlot   = errors.New("invalid transaction timeslot")
	ErrAlreadyAdmin                 = errors.New("already admin")
	ErrInvalidAdmin                 = errors.New("invalid admin")
	ErrAlreadyGenerator             = errors.New("already generator")
	ErrInvalidGenerator             = errors.New("invalid generator")
	ErrDirtyContext                 = errors.New("dirty context")
	ErrInvalidContractMethod        = errors.New("invalid contract method")
	ErrInvalidArguments             = errors.New("invalid contract method arguments")
	ErrConstructorNotAllowd         = errors.New("constructor not allowd")
	ErrOnlyFormulatorAllowed        = errors.New("only formulator allowed")
)

transaction errors

View Source
var (
	String, _  = abi.NewType("string", "", nil)
	Uint8, _   = abi.NewType("uint8", "", nil)
	Uint256, _ = abi.NewType("uint256", "", nil)
	Address, _ = abi.NewType("address", "", nil)
	Bool, _    = abi.NewType("bool", "", nil)
)
View Source
var ExecLock sync.Mutex

Functions

func CheckABI

func CheckABI(b *Block, ctx *Context)

func ContractInputsConv

func ContractInputsConv(Args []interface{}, rMethod reflect.Value) ([]reflect.Value, error)

func ContractName

func ContractName(ClassID uint64) string

func ContractType

func ContractType(ClassID uint64) string

func EachAllAddressAmount

func EachAllAddressAmount(mp map[common.Address]*amount.Amount, fn func(key common.Address, value *amount.Amount) error) error

func EachAllAddressBool

func EachAllAddressBool(mp map[common.Address]bool, fn func(key common.Address, value bool) error) error

func EachAllAddressBytes

func EachAllAddressBytes(mp map[common.Address][]byte, fn func(key common.Address, value []byte) error) error

func EachAllAddressContractDefine

func EachAllAddressContractDefine(mp map[common.Address]*ContractDefine, fn func(key common.Address, cd *ContractDefine) error) error

func EachAllAddressUint32

func EachAllAddressUint32(mp map[common.Address]uint32, fn func(key common.Address, value uint32) error) error

func EachAllAddressUint64

func EachAllAddressUint64(mp map[common.Address]uint64, fn func(key common.Address, value uint64) error) error

func EachAllStringBool

func EachAllStringBool(mp map[string]bool, fn func(key string, value bool) error) error

func EachAllStringBytes

func EachAllStringBytes(mp map[string][]byte, fn func(key string, value []byte) error) error

func EachAllTimeSlotMap

func EachAllTimeSlotMap(mp map[uint32]map[string]bool, fn func(key uint32, value map[string]bool) error) error

func GetContractClassID

func GetContractClassID(cont Contract) (string, uint64)

func GetTxType

func GetTxType(ctx *Context, tx *Transaction) (tp uint8, method string)

func IsValidClassID

func IsValidClassID(ClassID uint64) bool

func MarshalAddressAmountMap

func MarshalAddressAmountMap(mp map[common.Address]*amount.Amount) ([]byte, error)

func MarshalAddressBytesMap

func MarshalAddressBytesMap(mp map[common.Address][]byte) ([]byte, error)

func MarshalID

func MarshalID(height uint32, index uint16, n uint16) uint64

MarshalID returns the packed id

func ParseTransactionID

func ParseTransactionID(TXID string) (uint32, uint16, error)

ParseTransactionID returns the id of the transaction

func ParseTransactionIDBytes

func ParseTransactionIDBytes(bs []byte) (uint32, uint16, error)

ParseTransactionID returns the id of the transaction

func RegisterContractType

func RegisterContractType(cont Contract) (uint64, error)

IMPORTANT: RegisterContractType must be called only at initialization time and never have to called concurrently with CreateContract, IsValidClassID, ContractName functions

func SetLegacyCheckHeight

func SetLegacyCheckHeight(l uint32)

func ToTimeSlot

func ToTimeSlot(timestamp uint64) uint32

ToTimeSlot returns the timeslot of the timestamp

func TransactionID

func TransactionID(Height uint32, Index uint16) string

TransactionID returns the id of the transaction

func TransactionIDBytes

func TransactionIDBytes(Height uint32, Index uint16) []byte

TransactionIDBytes returns the id bytes of the transaction

func TxArg

func TxArg(ctx *Context, tx *Transaction) (to common.Address, method string, data []interface{}, err error)

func UnmarshalAddressAmountMap

func UnmarshalAddressAmountMap(bs []byte, mp map[common.Address]*amount.Amount) error

func UnmarshalAddressBytesMap

func UnmarshalAddressBytesMap(bs []byte, mp map[common.Address][]byte) error

func UnmarshalID

func UnmarshalID(id uint64) (uint32, uint16, uint16)

UnmarshalID returns the block height, the transaction index in the block, the output index in the transaction

Types

type Block

type Block struct {
	Header Header
	Body   Body
}

func (*Block) Clone

func (s *Block) Clone() *Block

func (*Block) ReadFrom

func (s *Block) ReadFrom(r io.Reader) (int64, error)

func (*Block) WriteTo

func (s *Block) WriteTo(w io.Writer) (int64, error)

type BlockSign

type BlockSign struct {
	HeaderHash         hash.Hash256
	GeneratorSignature common.Signature
}

BlockSign is the generator signature of the block

func (*BlockSign) ReadFrom

func (s *BlockSign) ReadFrom(r io.Reader) (int64, error)

func (*BlockSign) WriteTo

func (s *BlockSign) WriteTo(w io.Writer) (int64, error)

type Body

type Body struct {
	Transactions          []*Transaction
	Events                []*ctypes.Event
	TransactionSignatures []common.Signature
	BlockSignatures       []common.Signature
}

func (*Body) Clone

func (s *Body) Clone() Body

func (*Body) ReadFrom

func (s *Body) ReadFrom(r io.Reader) (int64, error)

func (*Body) WriteTo

func (s *Body) WriteTo(w io.Writer) (int64, error)

type ChargeFee

type ChargeFee interface {
	ChargeFee(cc *ContractContext, fee *amount.Amount) error
}

ChargeFee defines Chargeable Contract functions

type Context

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

Context is an intermediate in-memory state using the context data stack between blocks

func NewContext

func NewContext(loader internalLoader) *Context

NewContext returns a Context

func NewEmptyContext

func NewEmptyContext() *Context

NewEmptyContext returns a EmptyContext

func (*Context) AddAddrSeq

func (ctx *Context) AddAddrSeq(addr common.Address)

AddAddrSeq update the sequence of the target account

func (*Context) AddrSeq

func (ctx *Context) AddrSeq(addr common.Address) uint64

AddrSeq returns the sequence of the target account

func (*Context) BasicFee

func (ctx *Context) BasicFee() *amount.Amount

BasicFee returns the basic fee

func (*Context) ChainID

func (ctx *Context) ChainID() *big.Int

ChainID returns the id of the chain

func (*Context) Commit

func (ctx *Context) Commit(sn int)

Commit apply snapshots to the top after the snapshot number

func (*Context) Contract

func (ctx *Context) Contract(addr common.Address) (Contract, error)

Contract returns the contract data

func (*Context) ContractContext

func (ctx *Context) ContractContext(cont Contract, from common.Address) *ContractContext

ContractContext returns a ContractContext

func (*Context) ContractContextFromAddress

func (ctx *Context) ContractContextFromAddress(cont, from common.Address) *ContractContext

ContractContextFromAddress returns a ContractContext

func (*Context) ContractLoader

func (ctx *Context) ContractLoader(cont common.Address) ContractLoader

ContractLoader returns a ContractLoader

func (*Context) Data

func (ctx *Context) Data(cont common.Address, addr common.Address, name []byte) []byte

Data returns the data from the top snapshot

func (*Context) DeployContract

func (ctx *Context) DeployContract(owner common.Address, ClassID uint64, Args []byte) (Contract, error)

DeployContract deploy contract to the chain

func (*Context) DeployContractWithAddress

func (ctx *Context) DeployContractWithAddress(owner common.Address, ClassID uint64, addr common.Address, Args []byte) (Contract, error)

DeployContract deploy contract to the chain with address

func (*Context) Dump

func (ctx *Context) Dump() string

Dump prints the top context data of the context

func (*Context) GetPCSize

func (ctx *Context) GetPCSize() uint64

GetSize returns context data size

func (*Context) Hash

func (ctx *Context) Hash() hash.Hash256

Hash returns the hash value of it

func (*Context) IsAdmin

func (ctx *Context) IsAdmin(addr common.Address) bool

IsAdmin returns the account is Admin or not

func (*Context) IsContract

func (ctx *Context) IsContract(addr common.Address) bool

Contract returns the contract data

func (*Context) IsGenerator

func (ctx *Context) IsGenerator(addr common.Address) bool

IsGenerator returns the account is generator or not

func (*Context) IsProcessReward

func (ctx *Context) IsProcessReward() bool

IsProcessReward reeturns the reward is processed or not

func (*Context) IsUsedTimeSlot

func (ctx *Context) IsUsedTimeSlot(slot uint32, key string) bool

IsUsedTimeSlot returns timeslot is used or not

func (*Context) LastTimestamp

func (ctx *Context) LastTimestamp() uint64

LastTimestamp returns the prev timestamp of the chain

func (*Context) MainToken

func (ctx *Context) MainToken() *common.Address

func (*Context) NextContext

func (ctx *Context) NextContext(LastHash hash.Hash256, Timestamp uint64) *Context

NextContext returns the next Context of the Context

func (*Context) PrevHash

func (ctx *Context) PrevHash() hash.Hash256

PrevHash returns the recorded prev hash when context generation

func (*Context) ProcessReward

func (ctx *Context) ProcessReward(inctx *Context, b *Block) (map[common.Address][]byte, error)

ProcessReward returns processing the reward

func (*Context) Revert

func (ctx *Context) Revert(sn int)

Revert removes snapshots after the snapshot number

func (*Context) SetAdmin

func (ctx *Context) SetAdmin(addr common.Address, is bool) error

SetAdmin adds the account as a Admin or not

func (*Context) SetBasicFee

func (ctx *Context) SetBasicFee(fee *amount.Amount)

SetBasicFee update the basic fee

func (*Context) SetData

func (ctx *Context) SetData(cont common.Address, addr common.Address, name []byte, value []byte)

SetData inserts the data to the top snapshot

func (*Context) SetGenerator

func (ctx *Context) SetGenerator(addr common.Address, is bool) error

SetGenerator adds the account as a generator or not

func (*Context) SetMainToken

func (ctx *Context) SetMainToken(addr common.Address)

func (*Context) SetNonce

func (ctx *Context) SetNonce(addr common.Address, nonce uint64)

func (*Context) Snapshot

func (ctx *Context) Snapshot() int

Snapshot push a snapshot and returns the snapshot number of it

func (*Context) StackSize

func (ctx *Context) StackSize() int

StackSize returns the size of the context data stack

func (*Context) TargetHeight

func (ctx *Context) TargetHeight() uint32

TargetHeight returns the recorded target height when context generation

func (*Context) Top

func (ctx *Context) Top() *ContextData

Top returns the top snapshot

func (*Context) UseTimeSlot

func (ctx *Context) UseTimeSlot(slot uint32, key string) error

UseTimeSlot consumes timeslot

func (*Context) Version

func (ctx *Context) Version(h uint32) uint16

Version returns the version of the chain

func (*Context) WriteDump

func (ctx *Context) WriteDump() string

Dump prints the top context data of the context

type ContextData

type ContextData struct {
	Parent *ContextData

	AdminMap            map[common.Address]bool
	DeletedAdminMap     map[common.Address]bool
	AddrSeqMap          map[common.Address]uint64
	GeneratorMap        map[common.Address]bool
	DeletedGeneratorMap map[common.Address]bool
	ContractDefineMap   map[common.Address]*ContractDefine
	DataMap             map[string][]byte
	DeletedDataMap      map[string]bool
	TimeSlotMap         map[uint32]map[string]bool
	// contains filtered or unexported fields
}

ContextData is a state data of the context

func NewContextData

func NewContextData(cache *contextCache, Parent *ContextData) *ContextData

NewContextData returns a ContextData

func (*ContextData) AddAddrSeq

func (ctd *ContextData) AddAddrSeq(addr common.Address)

AddSeq update the sequence of the target address

func (*ContextData) AddrSeq

func (ctd *ContextData) AddrSeq(addr common.Address) uint64

Seq returns the number of txs using the UseSeq flag of the address.

func (*ContextData) BasicFee

func (ctd *ContextData) BasicFee() *amount.Amount

BasicFee returns the basic fee

func (*ContextData) Contract

func (ctd *ContextData) Contract(addr common.Address) (Contract, error)

Contract returns the contract

func (*ContextData) Data

func (ctd *ContextData) Data(cont common.Address, addr common.Address, name []byte) []byte

Data returns the data

func (*ContextData) DeployContract

func (ctd *ContextData) DeployContract(sender common.Address, ClassID uint64, Args []byte) (Contract, error)

DeployContract deploy contract to the chain

func (*ContextData) DeployContractWithAddress

func (ctd *ContextData) DeployContractWithAddress(sender common.Address, ClassID uint64, addr common.Address, Args []byte) (Contract, error)

DeployContract deploy contract to the chain with address

func (*ContextData) Dump

func (ctd *ContextData) Dump() string

Dump prints the context data

func (*ContextData) GetPCSize

func (ctd *ContextData) GetPCSize() uint64

func (*ContextData) Hash

func (ctd *ContextData) Hash() hash.Hash256

Hash returns the hash value of it

func (*ContextData) IsAdmin

func (ctd *ContextData) IsAdmin(addr common.Address) bool

IsAdmin returns the account is admin or not

func (*ContextData) IsContract

func (ctd *ContextData) IsContract(addr common.Address) bool

IsContract returns is the contract

func (*ContextData) IsGenerator

func (ctd *ContextData) IsGenerator(addr common.Address) bool

IsGenerator returns the account is generator or not

func (*ContextData) IsUsedTimeSlot

func (ctd *ContextData) IsUsedTimeSlot(slot uint32, key string) bool

IsUsedTimeSlot returns timeslot is used or not

func (*ContextData) MainToken

func (ctd *ContextData) MainToken() *common.Address

MainToken returns the MainToken

func (*ContextData) NextSeq

func (ctd *ContextData) NextSeq() uint32

NextSeq returns the next squence number

func (*ContextData) SetAdmin

func (ctd *ContextData) SetAdmin(addr common.Address, is bool) error

SetAdmin adds the account as a admin or not

func (*ContextData) SetBasicFee

func (ctd *ContextData) SetBasicFee(fee *amount.Amount)

SetBasicFee update the basic fee

func (*ContextData) SetData

func (ctd *ContextData) SetData(cont common.Address, addr common.Address, name []byte, value []byte)

SetData inserts the data

func (*ContextData) SetGenerator

func (ctd *ContextData) SetGenerator(addr common.Address, is bool) error

SetGenerator adds the account as a generator or not

func (*ContextData) SetMainToken

func (ctd *ContextData) SetMainToken(addr common.Address)

SetMainToken is set the maintoken

func (*ContextData) SetNonce

func (ctd *ContextData) SetNonce(addr common.Address, nonce uint64)

SetNonce update the sequence(nonce) of the target address

func (*ContextData) UnsafeBasicFee

func (ctd *ContextData) UnsafeBasicFee() *amount.Amount

UnsafeBasicFee returns the basic fee

func (*ContextData) UnsafeGetMainToken

func (ctd *ContextData) UnsafeGetMainToken() *common.Address

UnsafeGetMainToken returns the MainToken or nil

func (*ContextData) UseTimeSlot

func (ctd *ContextData) UseTimeSlot(slot uint32, key string) error

UseTimeSlot consumes timeslot

func (*ContextData) WriteDump

func (ctd *ContextData) WriteDump() string

Dump prints the context data

type Contract

type Contract interface {
	Address() common.Address
	Master() common.Address
	Init(addr common.Address, master common.Address)
	OnCreate(cc *ContractContext, Args []byte) error
	OnReward(cc *ContractContext, b *Block, CountMap map[common.Address]uint32) (map[common.Address]*amount.Amount, error)
	Front() interface{}
}

Contract defines chain Contract functions

func CreateContract

func CreateContract(cd *ContractDefine) (Contract, error)

type ContractContext

type ContractContext struct {
	Exec ExecFunc
	// contains filtered or unexported fields
}

ContractContext is an context for the contract

func (*ContractContext) AccountData

func (cc *ContractContext) AccountData(addr common.Address, name []byte) []byte

AccountData returns the account data from the top snapshot

func (*ContractContext) AddAddrSeq

func (cc *ContractContext) AddAddrSeq(addr common.Address)

AddSeq update the sequence of the target account

func (*ContractContext) AddrSeq

func (cc *ContractContext) AddrSeq(addr common.Address) uint64

Seq returns the sequence of the target account

func (*ContractContext) ChainID

func (cc *ContractContext) ChainID() *big.Int

ChainID returns the id of the chain

func (*ContractContext) ContractData

func (cc *ContractContext) ContractData(name []byte) []byte

ContractData returns the contract data from the top snapshot

func (*ContractContext) DeployContractWithAddress

func (cc *ContractContext) DeployContractWithAddress(owner common.Address, ClassID uint64, addr common.Address, Args []byte) (Contract, error)

DeployContract deploy contract to the chain

func (*ContractContext) EvmCall

func (cc *ContractContext) EvmCall(caller vm.ContractRef, to common.Address, input []byte) ([]byte, uint64, error)

EvmCall execute evm.Call function and returns result, usedGas, error

func (*ContractContext) From

func (cc *ContractContext) From() common.Address

From returns current signer address

func (*ContractContext) Hash

func (cc *ContractContext) Hash() hash.Hash256

Hash returns the hash value of it

func (*ContractContext) IsContract

func (cc *ContractContext) IsContract(addr common.Address) bool

IsContract returns is the contract

func (*ContractContext) IsGenerator

func (cc *ContractContext) IsGenerator(addr common.Address) bool

IsGenerator returns the account is generator or not

func (*ContractContext) IsUsedTimeSlot

func (cc *ContractContext) IsUsedTimeSlot(slot uint32, key string) bool

IsUsedTimeSlot returns timeslot is used or not

func (*ContractContext) LastTimestamp

func (cc *ContractContext) LastTimestamp() uint64

LastTimestamp returns the recorded prev timestamp when ContractContext generation

func (*ContractContext) MainToken

func (cc *ContractContext) MainToken() *common.Address

MainToken returns the MainToken

func (*ContractContext) NextSeq

func (cc *ContractContext) NextSeq() uint32

NextSeq returns the next squence number

func (*ContractContext) PrevHash

func (cc *ContractContext) PrevHash() hash.Hash256

PrevHash returns the recorded prev hash when ContractContext generation

func (*ContractContext) SetAccountData

func (cc *ContractContext) SetAccountData(addr common.Address, name []byte, value []byte)

SetAccountData inserts the account data to the top snapshot

func (*ContractContext) SetContractData

func (cc *ContractContext) SetContractData(name []byte, value []byte)

SetContractData inserts the contract data to the top snapshot

func (*ContractContext) SetGenerator

func (cc *ContractContext) SetGenerator(addr common.Address, is bool) error

SetGenerator adds the account as a generator or not only formulator contract can call

func (*ContractContext) TargetHeight

func (cc *ContractContext) TargetHeight() uint32

TargetHeight returns the recorded target height when ContractContext generation

func (*ContractContext) Version

func (cc *ContractContext) Version(h uint32) uint16

Version returns the version of the chain

type ContractDefine

type ContractDefine struct {
	Address common.Address
	Owner   common.Address
	ClassID uint64
}

ContractDefine defines chain Contract functions

func (*ContractDefine) Clone

func (s *ContractDefine) Clone() *ContractDefine

func (*ContractDefine) ReadFrom

func (s *ContractDefine) ReadFrom(r io.Reader) (int64, error)

func (*ContractDefine) WriteTo

func (s *ContractDefine) WriteTo(w io.Writer) (int64, error)

type ContractLoader

type ContractLoader interface {
	Loader
	ContractData(name []byte) []byte
	AccountData(addr common.Address, name []byte) []byte
}

ContractLoader defines functions that loads state data from the target chain

type Event

type Event struct {
	Index  uint16
	Type   EventType
	Result []byte
}

func NewEvent

func NewEvent(Index uint16, Type EventType, result []byte) *Event

func (*Event) ReadFrom

func (s *Event) ReadFrom(r io.Reader) (int64, error)

func (*Event) WriteTo

func (s *Event) WriteTo(w io.Writer) (int64, error)

type EventType

type EventType uint8

func (EventType) String

func (e EventType) String() string

type ExecFunc

type ExecFunc = func(Cc *ContractContext, Addr common.Address, MethodName string, Args []interface{}) ([]interface{}, error)
type Header struct {
	ChainID       *big.Int       // ~=8byte
	Version       uint16         // 2byte
	Height        uint32         // 4byte
	PrevHash      hash.Hash256   // 32byte
	LevelRootHash hash.Hash256   // 32byte
	ContextHash   hash.Hash256   // 32byte
	TimeoutCount  uint32         // 4byte
	Timestamp     uint64         // 8byte
	Generator     common.Address // 20byte
	Gas           uint16         // 2byte
	ReceiptHash   hash.Hash256   // 32byte
}

func (*Header) Clone

func (s *Header) Clone() Header

func (*Header) ReadFrom

func (s *Header) ReadFrom(r io.Reader) (int64, error)

func (*Header) WriteTo

func (s *Header) WriteTo(w io.Writer) (int64, error)

type IEngin

type IEngin interface {
	ContractInvoke(_cc interface{}, method string, params []interface{}) (interface{}, error)
	InitContract(_cc interface{}, contract []byte, InitArgs []interface{}) error
	UpdateContract(_cc interface{}, contract []byte) error
}

type IInteractor

type IInteractor interface {
	Distroy()
	Exec(Cc *ContractContext, Addr common.Address, MethodName string, Args []interface{}) ([]interface{}, error)
	EventList() []*ctypes.Event
	GasHistory() []uint64
	AddEvent(*ctypes.Event)
}

func NewInteractor

func NewInteractor(ctx *Context, cont Contract, cc *ContractContext, TXID string, saveEvent bool) IInteractor

func NewInteractor2

func NewInteractor2(ctx *Context, cc *ContractContext, TXID string, saveEvent bool) IInteractor

type InvokeableContract

type InvokeableContract interface {
	ContractInvoke(cc *ContractContext, method string, params []interface{}) (interface{}, error)
}

type Loader

type Loader interface {
	ChainID() *big.Int
	Version(uint32) uint16
	TargetHeight() uint32
	PrevHash() hash.Hash256
	LastTimestamp() uint64
}

Loader defines functions that loads state data from the target chain

type MethodCallEvent

type MethodCallEvent struct {
	From   common.Address
	To     common.Address
	Method string
	Args   []interface{}
	Result []interface{}
	Error  string
}

func (*MethodCallEvent) ReadFrom

func (s *MethodCallEvent) ReadFrom(r io.Reader) (int64, error)

func (*MethodCallEvent) WriteTo

func (s *MethodCallEvent) WriteTo(w io.Writer) (int64, error)

type Process

type Process interface {
	ID() uint8
	Version() string
	Name() string
}

Process defines process functions

type Provider

type Provider interface {
	ChainID() *big.Int
	Version(uint32) uint16
	Height() uint32
	InitHeight() uint32
	LastHash() hash.Hash256
	LastTimestamp() uint64
	Hash(uint32) (hash.Hash256, error)
	Header(uint32) (*Header, error)
	Block(uint32) (*Block, error)
	Receipts(uint32) (Receipts, error)
	AddrSeq(common.Address) uint64
	Contract(addr common.Address) (Contract, error)
}

Provider defines functions that loads chain data from the chain

type Receipts

type Receipts []*etypes.Receipt

Receipts implements DerivableList for receipts.

func (*Receipts) DeriveReceiptFields

func (rs *Receipts) DeriveReceiptFields(bHash common.Hash, number uint64, idx uint16, tx *etypes.Transaction, signer etypes.Signer) error

Receipt와 Log 데이터 중 일부를 block과 transaction 로부터 유추

func (*Receipts) Len

func (rs *Receipts) Len() int

Len returns the number of receipts in this list.

func (*Receipts) ReadFrom

func (rs *Receipts) ReadFrom(r io.Reader) (int64, error)

chain.(*Store).Block

func (*Receipts) WriteTo

func (rs *Receipts) WriteTo(w io.Writer) (int64, error)

chain.(*Store).StoreBlock

type Service

type Service interface {
	Name() string
	OnLoadChain(loader Loader) error
	OnBlockConnected(b *Block, loader Loader)
	OnTransactionInPoolExpired(txs []*Transaction)
	OnTransactionFail(height uint32, txs []*Transaction, err []error)
}

Service defines service functions

type ServiceBase

type ServiceBase struct{}

ServiceBase is a base handler of the chain service

func (*ServiceBase) OnBlockConnected

func (s *ServiceBase) OnBlockConnected(b *Block, loader Loader)

OnBlockConnected called when a block is connected to the chain

func (*ServiceBase) OnLoadChain

func (s *ServiceBase) OnLoadChain(loader Loader) error

OnLoadChain called when the chain loaded

func (*ServiceBase) OnTransactionFail

func (s *ServiceBase) OnTransactionFail(height uint32, txs []*Transaction, err []error)

OnTransactionFail called when a transaction in pool is expired

func (*ServiceBase) OnTransactionInPoolExpired

func (s *ServiceBase) OnTransactionInPoolExpired(txs []*Transaction)

OnTransactionInPoolExpired called when a transaction in pool is expired

type StateDB

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

func NewStateDB

func NewStateDB(ctx *Context) *StateDB

func (*StateDB) AddAddressToAccessList

func (s *StateDB) AddAddressToAccessList(addr common.Address)

AddAddressToAccessList adds the given address to the access list

func (*StateDB) AddBalance

func (s *StateDB) AddBalance(addr common.Address, amt *big.Int)

AddBalance adds amount to the account associated with addr.

func (*StateDB) AddLog

func (s *StateDB) AddLog(log *etypes.Log)

func (*StateDB) AddPreimage

func (s *StateDB) AddPreimage(hash common.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*StateDB) AddRefund

func (s *StateDB) AddRefund(gas uint64)

AddRefund adds gas to the refund counter

func (*StateDB) AddSlotToAccessList

func (s *StateDB) AddSlotToAccessList(addr common.Address, slot common.Hash)

AddSlotToAccessList adds the given (address, slot)-tuple to the access list

func (*StateDB) AddressInAccessList

func (s *StateDB) AddressInAccessList(addr common.Address) bool

AddressInAccessList returns true if the given address is in the access list.

func (*StateDB) BasicFee

func (s *StateDB) BasicFee() *big.Int

BasicFee returns the basic Fee

func (*StateDB) ChainID

func (s *StateDB) ChainID() *big.Int

ChainID returns the id of the chain

func (*StateDB) Copy

func (s *StateDB) Copy() *StateDB

Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.

func (*StateDB) CreateAccount

func (s *StateDB) CreateAccount(addr common.Address)

CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.

CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:

  1. sends funds to sha(account ++ (nonce + 1))
  2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1)

Carrying over the balance ensures that Ether doesn't disappear.

func (*StateDB) Empty

func (s *StateDB) Empty(addr common.Address) bool

Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)

func (*StateDB) Error

func (s *StateDB) Error() error

func (*StateDB) Exec

func (s *StateDB) Exec(user common.Address, contAddr common.Address, input []byte, gas uint64) ([]byte, uint64, []*ctypes.Event, error)

Exec executes the method of compiled contract in evm

func (*StateDB) Exist

func (s *StateDB) Exist(addr common.Address) bool

Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.

func (*StateDB) Finalise

func (s *StateDB) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the s destructed objects and clears the journal as well as the refunds. Finalise, however, will not push any updates into the tries just yet. Only IntermediateRoot or Commit will do that.

func (*StateDB) ForEachStorage

func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) error

func (*StateDB) GetBalance

func (s *StateDB) GetBalance(addr common.Address) *big.Int

GetBalance retrieves the balance from the given address or 0 if object not found

func (*StateDB) GetCode

func (s *StateDB) GetCode(addr common.Address) []byte

func (*StateDB) GetCodeHash

func (s *StateDB) GetCodeHash(addr common.Address) common.Hash

func (*StateDB) GetCodeSize

func (s *StateDB) GetCodeSize(addr common.Address) int

func (*StateDB) GetCommittedState

func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) common.Hash

GetCommittedState retrieves a value from the given account's committed storage trie.

func (*StateDB) GetLogs

func (s *StateDB) GetLogs(hash common.Hash, blockHash common.Hash) []*etypes.Log

func (*StateDB) GetNonce

func (s *StateDB) GetNonce(addr common.Address) uint64

func (*StateDB) GetProof

func (s *StateDB) GetProof(addr common.Address) ([][]byte, error)

GetProof returns the Merkle proof for a given account.

func (*StateDB) GetProofByHash

func (s *StateDB) GetProofByHash(addrHash common.Hash) ([][]byte, error)

GetProofByHash returns the Merkle proof for a given account.

func (*StateDB) GetRefund

func (s *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetState

func (s *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash

GetState retrieves a value from the given account's storage trie.

func (*StateDB) GetStorageProof

func (s *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error)

GetStorageProof returns the Merkle proof for given storage slot.

func (*StateDB) HasSuicided

func (s *StateDB) HasSuicided(addr common.Address) bool

func (*StateDB) Hash

func (s *StateDB) Hash() common.Hash

func (*StateDB) Height

func (s *StateDB) Height() uint32

func (*StateDB) IntermediateRoot

func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash

IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.

func (*StateDB) IsEvmContract

func (s *StateDB) IsEvmContract(addr common.Address) bool

func (*StateDB) IsExtContract

func (s *StateDB) IsExtContract(addr common.Address) bool

IsContract checks if the given address is contract one.

func (*StateDB) LastTimestamp

func (s *StateDB) LastTimestamp() uint64

LastTimestamp returns the prev timestamp of the chain

func (*StateDB) Logs

func (s *StateDB) Logs() []*etypes.Log

func (*StateDB) Preimages

func (s *StateDB) Preimages() map[common.Hash][]byte

Preimages returns a list of SHA3 preimages that have been submitted.

func (*StateDB) Prepare

func (s *StateDB) Prepare(thash common.Hash, ti int)

Prepare sets the current transaction hash and index which are used when the EVM emits new state logs.

func (*StateDB) PrepareAccessList

func (s *StateDB) PrepareAccessList(sender common.Address, dst *common.Address, precompiles []common.Address, list etypes.AccessList)

PrepareAccessList handles the preparatory steps for executing a state transition with regards to both EIP-2929 and EIP-2930:

- Add sender to access list (2929) - Add destination to access list (2929) - Add precompiles to access list (2929) - Add the contents of the optional tx access list (2930)

This method should only be called if Berlin/2929+2930 is applicable at the current number.

func (*StateDB) Revert

func (s *StateDB) Revert(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*StateDB) RevertToSnapshot

func (s *StateDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*StateDB) SetBalance

func (s *StateDB) SetBalance(addr common.Address, amt *big.Int)

SetBalance set amount of the account associated with addr.

func (*StateDB) SetCode

func (s *StateDB) SetCode(addr common.Address, code []byte)

SetCode save codeHash, size, code of the account(contract) associated with addr

func (*StateDB) SetNonce

func (s *StateDB) SetNonce(addr common.Address, nonce uint64)

SetBalance set nonce of the account associated with addr.

func (*StateDB) SetState

func (s *StateDB) SetState(addr common.Address, key, value common.Hash)

SetState save data of the account(contract) associated with addr

func (*StateDB) SetStorage

func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common.Hash)

SetStorage replaces the entire storage for the specified account with given storage. This function should only be used for debugging.

func (*StateDB) SlotInAccessList

func (s *StateDB) SlotInAccessList(addr common.Address, slot common.Hash) (addressPresent bool, slotPresent bool)

SlotInAccessList returns true if the given (address, slot)-tuple is in the access list.

func (*StateDB) Snapshot

func (s *StateDB) Snapshot() int

Snapshot returns an identifier for the current revision of the state.

func (*StateDB) StartPrefetcher

func (s *StateDB) StartPrefetcher(namespace string)

StartPrefetcher initializes a new trie prefetcher to pull in nodes from the state trie concurrently while the state is mutated so that when we reach the commit phase, most of the needed data is already hot.

func (*StateDB) StopPrefetcher

func (s *StateDB) StopPrefetcher()

StopPrefetcher terminates a running prefetcher and reports any leftover stats from the gathered metrics.

func (*StateDB) SubBalance

func (s *StateDB) SubBalance(addr common.Address, amt *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*StateDB) SubRefund

func (s *StateDB) SubRefund(gas uint64)

SubRefund removes gas from the refund counter. This method will panic if the refund counter goes below zero

func (*StateDB) Suicide

func (s *StateDB) Suicide(addr common.Address) bool

Suicide marks the given account as suicided. This clears the account balance.

The account's state object is still available until the state is committed, getStateObject will return a non-nil account after Suicide.

func (*StateDB) TargetHeight

func (s *StateDB) TargetHeight() uint32

func (*StateDB) TxIndex

func (s *StateDB) TxIndex() int

TxIndex returns the current transaction index set by Prepare.

type StateDBContext

type StateDBContext interface {
	ChainID() *big.Int
	TargetHeight() uint32
	Hash() common.Hash
	AddrSeq(addr common.Address) uint64
	SetNonce(addr common.Address, nonce uint64)
	Data(cont, addr common.Address, name []byte) []byte
	SetData(cont, addr common.Address, name, value []byte)
	IsContract(addr common.Address) bool
	Contract(addr common.Address) (Contract, error)
	ContractContext(cont Contract, from common.Address) *ContractContext
	Snapshot() int
	Revert(sn int)
	Commit(sn int)
}

StateContext defines functions that Evm use as Database

type Transaction

type Transaction struct {
	//Input data
	ChainID     *big.Int
	Version     uint16
	Timestamp   uint64
	Seq         uint64
	To          common.Address
	Method      string
	Args        []byte
	GasPrice    *big.Int
	UseSeq      bool
	IsEtherType bool

	//After exec tx data
	From common.Address

	VmType uint8
}

func NewTransaction

func NewTransaction(ctx *Context, _timeStamp string, _to common.Address, _method string, _args []byte) (*Transaction, error)

func (*Transaction) Hash

func (s *Transaction) Hash(height uint32) (h hash.Hash256)

func (*Transaction) HashSig

func (s *Transaction) HashSig() (h hash.Hash256)

func (*Transaction) Message

func (s *Transaction) Message() (h hash.Hash256)

func (*Transaction) ReadFrom

func (s *Transaction) ReadFrom(r io.Reader) (int64, error)

func (*Transaction) WriteTo

func (s *Transaction) WriteTo(w io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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