util

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TxGas uint64 = 21000 // Per transaction not creating a contract.

	ConfirmGas         uint64 = 200
	CommonQuotaRatio   uint8  = 10
	QuotaRatioDivision uint64 = 10
)

Variables

View Source
var (
	ErrInvalidMethodParam        = VMError{"invalid method param", false}
	ErrInvalidQuotaRatio         = VMError{"invalid quota ratio", false}
	ErrRewardIsNotDrained        = VMError{"reward is not drained", false}
	ErrInsufficientBalance       = VMError{"insufficient balance for transfer", false}
	ErrCalcPoWTwice              = VMError{"calc PoW twice referring to one snapshot block", false}
	ErrAbiMethodNotFound         = VMError{"abi: method not found", false}
	ErrInvalidConfirmTime        = VMError{"invalid confirm time", false}
	ErrAddressNotMatch           = VMError{"current address not match", false}
	ErrTransactionTypeNotSupport = VMError{"transaction type not supported", false}
	ErrVersionNotSupport         = VMError{"feature not supported in current snapshot height", false}
	ErrBlockTypeNotSupported     = VMError{"block type not supported", true}
	ErrDataNotExist              = VMError{"data not exist", false}
	ErrContractNotExists         = VMError{"contract not exists", false}
	ErrNoReliableStatus          = VMError{"no reliable status", false}

	ErrAddressCollision = VMError{"contract address collision", false}
	ErrIdCollision      = VMError{"id collision", false}
	ErrRewardNotDue     = VMError{"reward not due", false}

	ErrExecutionReverted = VMError{"execution reverted", false}
	ErrDepth             = VMError{"max call depth exceeded", false}

	ErrGasUintOverflow          = VMError{"gas uint64 overflow", true}
	ErrMemSizeOverflow          = VMError{"memory size uint64 overflow", true}
	ErrReturnDataOutOfBounds    = VMError{"vm: return data out of bounds", true}
	ErrBlockQuotaLimitReached   = VMError{"quota limit for block reached", true}
	ErrAccountQuotaLimitReached = VMError{"quota limit for account reached", true}
	ErrOutOfQuota               = VMError{"out of quota", true}
	ErrInvalidUnconfirmedQuota  = VMError{"calc quota failed, invalid unconfirmed quota", true}

	ErrStackLimitReached      = VMError{"stack limit reached", true}
	ErrStackUnderflow         = VMError{"stack underflow", true}
	ErrInvalidJumpDestination = VMError{"invalid jump destination", true}
	ErrInvalidOpCode          = VMError{"invalid opcode", true}

	ErrChainForked          = VMError{"chain forked", false}
	ErrContractCreationFail = VMError{"contract creation failed", false}
)
View Source
var (
	AttovPerVite = big.NewInt(1e18)
)
View Source
var (
	SolidityPPContractType = []byte{1}
)

Functions

func AddBalance

func AddBalance(db dbInterface, id *types.TokenTypeId, amount *big.Int)

func CalcQuotaUsed

func CalcQuotaUsed(useQuota bool, quotaTotal, quotaAddition, quotaLeft uint64, err error) (q uint64, qUsed uint64)

func DataGasCost

func DataGasCost(data []byte) (uint64, error)

func DealWithErr

func DealWithErr(v interface{})

func GetCodeFromCreateContractData added in v1.2.0

func GetCodeFromCreateContractData(data []byte) []byte

func GetConfirmTimeFromCreateContractData

func GetConfirmTimeFromCreateContractData(data []byte) uint8

func GetContractCode added in v1.2.0

func GetContractCode(db CommonDb, addr *types.Address, status GlobalStatus) ([]byte, []byte)

func GetContractTypeFromCreateContractData added in v1.2.0

func GetContractTypeFromCreateContractData(data []byte) []byte

func GetCreateContractData added in v1.2.0

func GetCreateContractData(bytecode []byte, contractType []byte, confirmTimes uint8, quotaRatio uint8, gid types.Gid) []byte

func GetGidFromCreateContractData added in v1.2.0

func GetGidFromCreateContractData(data []byte) types.Gid

func GetQuotaRatioFromCreateContractData

func GetQuotaRatioFromCreateContractData(data []byte) uint8

func GetValue

func GetValue(db dbInterface, key []byte) []byte

func IntrinsicGasCost

func IntrinsicGasCost(data []byte, isCreate bool, confirmTime uint8) (uint64, error)

func IsDelegateGid

func IsDelegateGid(gid types.Gid) bool

func IsExistContractType added in v1.2.0

func IsExistContractType(contractType []byte) bool

func IsPoW

func IsPoW(block *ledger.AccountBlock) bool

func IsSnapshotGid

func IsSnapshotGid(gid types.Gid) bool

func IsUserAccount added in v1.2.0

func IsUserAccount(addr types.Address) bool

func IsValidQuotaRatio

func IsValidQuotaRatio(quotaRatio uint8) bool

func IsViteToken

func IsViteToken(tokenId types.TokenTypeId) bool

func MakeSendBlock

func MakeSendBlock(fromAddress types.Address, toAddress types.Address, blockType byte, amount *big.Int, tokenId types.TokenTypeId, data []byte) *ledger.AccountBlock

func MultipleCost

func MultipleCost(cost uint64, quotaRatio uint8) (uint64, error)

func NewContractAddress added in v1.2.0

func NewContractAddress(accountAddress types.Address, accountBlockHeight uint64, prevBlockHash types.Hash) types.Address

func NewLog added in v1.3.0

func NewLog(c abi.ABIContract, name string, params ...interface{}) *ledger.VmLog

func PackContractCode added in v1.2.0

func PackContractCode(contractType, code []byte) []byte

func PrintMap added in v1.2.0

func PrintMap(m map[string][]byte) string

func SetValue

func SetValue(db dbInterface, key []byte, value []byte)

func SubBalance

func SubBalance(db dbInterface, id *types.TokenTypeId, amount *big.Int)

func UseQuota

func UseQuota(quotaLeft, cost uint64) (uint64, error)

func UseQuotaWithFlag

func UseQuotaWithFlag(quotaLeft, cost uint64, flag bool) (uint64, error)

Types

type CommonDb added in v1.2.0

type CommonDb interface {
	Address() *types.Address
	IsContractAccount() (bool, error)
	GetContractCode() ([]byte, error)
	GetContractCodeBySnapshotBlock(addr *types.Address, snapshotBlock *ledger.SnapshotBlock) ([]byte, error)
}

type ConsensusReader

type ConsensusReader interface {
	GetIndexByStartTime(t int64, genesisTime int64) (startIndex uint64, startTime int64, drained bool)
	GetIndexByEndTime(t int64, genesisTime int64) (endIndex uint64, endTime int64, withinADay bool)
	GetIndexByTime(t int64, genesisTime int64) uint64
	GetEndTimeByIndex(index uint64) int64
	GetConsensusDetailByDay(startIndex, endIndex uint64) ([]*core.DayStats, error)
}

type GlobalStatus

type GlobalStatus interface {
	Seed() (uint64, error)
	SnapshotBlock() *ledger.SnapshotBlock
}

type SBPStatReader

type SBPStatReader interface {
	DayStats(startIndex uint64, endIndex uint64) ([]*core.DayStats, error)
	GetDayTimeIndex() core.TimeIndex
}

type VMConsensusReader

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

func NewVmConsensusReader

func NewVmConsensusReader(sr SBPStatReader) *VMConsensusReader

func (*VMConsensusReader) GetConsensusDetailByDay

func (r *VMConsensusReader) GetConsensusDetailByDay(startIndex, endIndex uint64) ([]*core.DayStats, error)

func (*VMConsensusReader) GetEndTimeByIndex

func (r *VMConsensusReader) GetEndTimeByIndex(index uint64) int64

func (*VMConsensusReader) GetIndexByEndTime

func (r *VMConsensusReader) GetIndexByEndTime(t int64, genesisTime int64) (uint64, int64, bool)

get first index before t and index start time if t <= genesis time + 24h, return index 0, within one day if t ∈ (genesis time + 24h, genesis time + 48h], return index 0

func (*VMConsensusReader) GetIndexByStartTime

func (r *VMConsensusReader) GetIndexByStartTime(t int64, genesisTime int64) (uint64, int64, bool)

index 0 : (genesis time, genesis time + 24h] index 1: (genesis time + 24h, genesis time + 48h] get first index after t and index start time if t == -1, reward drained if t == 0, return index 0 if t ∈ (genesis time, genesis time + 24h], return index 1

func (*VMConsensusReader) GetIndexByTime

func (r *VMConsensusReader) GetIndexByTime(t int64, genesisTime int64) uint64

type VMError

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

func (VMError) CostAllGas

func (e VMError) CostAllGas() bool

func (VMError) Error

func (e VMError) Error() string

Jump to

Keyboard shortcuts

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