storage

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0, Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const CrossVmCallMethodKey = "CrossVmCallMethod"

const CrossVmOutParamsEndKey = "CrossVMOutParamsEnd" const CrossVmInParamsBeginKey = "CrossVMInParamsBegin" const CrossVmInParamsEndKey = "CrossVMInParamsEnd"

View Source
const CrossVmOutParamsBeginKey = "CrossVMCall"
View Source
const HashLen = 32

Variables

This section is empty.

Functions

func IntAddr2HexStr added in v3.0.1

func IntAddr2HexStr(addr *evmutils.Int, version uint32) string

func MergeResultCache

func MergeResultCache(src *ResultCache, to *ResultCache)

func MergeResultCache2211

func MergeResultCache2211(src *ResultCache, to *ResultCache)

func TruncateNullTail

func TruncateNullTail(val []byte) []byte

Types

type BalanceCache

type BalanceCache map[string]*balance

type Cache

type Cache map[string]*evmutils.Int

type CacheUnderAddress

type CacheUnderAddress map[string]Cache

func (CacheUnderAddress) Get

func (c CacheUnderAddress) Get(address string, key string) *evmutils.Int

func (CacheUnderAddress) Set

func (c CacheUnderAddress) Set(address string, key string, v *evmutils.Int)

type CodeCache

type CodeCache map[string][]byte

type ContractStorage

type ContractStorage struct {
	OutParams *CrossVmParams
	//InParams        *CrossVmParams
	ResultCache ResultCache

	Ctx       protocol.TxSimContext
	BlockHash *evmutils.Int
	Contract  *common.Contract // contract info
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(extStorage IExternalStorage) *ContractStorage

func (ContractStorage) CallContract

func (c ContractStorage) CallContract(name string, rtType int32, method string, byteCode []byte,
	parameters map[string][]byte, gasUsed uint64, isCreate bool) (res *common.ContractResult, stat common.TxStatusCode)

CallContract 调用合约 @param name @param rtType @param method @param byteCode @param parameters @param gasUsed @param isCreate @return res @return stat

func (*ContractStorage) CanTransfer

func (c *ContractStorage) CanTransfer(from, to, val *evmutils.Int) bool

func (*ContractStorage) CreateFixedAddress

func (c *ContractStorage) CreateFixedAddress(caller *evmutils.Int, salt *evmutils.Int, tx environment.Transaction, addrType int32) *evmutils.Int

Only versions < 2300 are called

func (*ContractStorage) GetBalance

func (c *ContractStorage) GetBalance(address *evmutils.Int) (*evmutils.Int, error)

GetBalance 获取当前EVM合约的ETH余额 @param address @return *evmutils.Int @return error

func (*ContractStorage) GetBlockHash

func (c *ContractStorage) GetBlockHash(block *evmutils.Int) (*evmutils.Int, error)

func (*ContractStorage) GetCode

func (c *ContractStorage) GetCode(address *evmutils.Int) (code []byte, err error)

func (*ContractStorage) GetCodeHash

func (c *ContractStorage) GetCodeHash(address *evmutils.Int) (codeHase *evmutils.Int, err error)

func (*ContractStorage) GetCodeSize

func (c *ContractStorage) GetCodeSize(address *evmutils.Int) (size *evmutils.Int, err error)

func (*ContractStorage) GetCurrentBlockVersion

func (c *ContractStorage) GetCurrentBlockVersion() uint32

func (*ContractStorage) GetTx added in v3.0.1

func (c *ContractStorage) GetTx() *common.Transaction

func (ContractStorage) IsCrossVmMode

func (c ContractStorage) IsCrossVmMode() bool

func (*ContractStorage) Load

func (c *ContractStorage) Load(n string, k string) (*evmutils.Int, error)

func (*ContractStorage) SetCrossVmOutParams

func (c *ContractStorage) SetCrossVmOutParams(index *evmutils.Int, element *evmutils.Int)

func (ContractStorage) Store

func (c ContractStorage) Store(address string, key string, val []byte)

type CrossVmParams

type CrossVmParams struct {
	ParamsCache  Params
	IsCrossVm    bool
	ParamsBegin  int64
	LongStrLen   int64
	LastParamKey string
}

func NewParamsCache

func NewParamsCache() *CrossVmParams

func (*CrossVmParams) GetParam

func (p *CrossVmParams) GetParam(key string) []byte

func (*CrossVmParams) GetParamsCnt

func (p *CrossVmParams) GetParamsCnt() int

func (*CrossVmParams) Reset

func (p *CrossVmParams) Reset()

func (*CrossVmParams) ResetLongStrParamStatus

func (p *CrossVmParams) ResetLongStrParamStatus()

func (*CrossVmParams) SetParam

func (p *CrossVmParams) SetParam(key string, value []byte)

type Hash added in v3.0.1

type Hash [HashLen]byte

type IExternalStorage

type IExternalStorage interface {
	GetBalance(address *evmutils.Int) (*evmutils.Int, error)
	GetCode(address *evmutils.Int) ([]byte, error)
	GetCodeSize(address *evmutils.Int) (*evmutils.Int, error)
	GetCodeHash(address *evmutils.Int) (*evmutils.Int, error)
	GetBlockHash(block *evmutils.Int) (*evmutils.Int, error)
	GetCurrentBlockVersion() uint32
	GetTx() *common.Transaction
	//CreateAddress(name *evmutils.Int, addrType int32) *evmutils.Int
	CreateFixedAddress(caller *evmutils.Int, salt *evmutils.Int, tx environment.Transaction, addrType int32) *evmutils.Int

	CanTransfer(from *evmutils.Int, to *evmutils.Int, amount *evmutils.Int) bool

	Load(n string, k string) (*evmutils.Int, error)
	Store(address string, key string, val []byte)
	SetCrossVmOutParams(index *evmutils.Int, param *evmutils.Int)
	IsCrossVmMode() bool
	//GetCrossVmInParam(key string) []byte
	CallContract(name string, rtType int32, method string, byteCode []byte, parameters map[string][]byte,
		gasUsed uint64, isCreate bool) (res *common.ContractResult, stat common.TxStatusCode)
}

Teh External Storage,provding a Storage for touching out of current evm

type Log

type Log struct {
	Topics  [][]byte
	Data    []byte
	Context environment.Context
}

type LogCache

type LogCache map[string][]Log

type Params

type Params map[string][]byte

type ResultCache

type ResultCache struct {
	//OriginalData CacheUnderAddress
	ReadCache     CacheUnderAddress
	WriteCache    CacheUnderAddress //when version<=232, include read cache; when version>232, only include write
	Balance       BalanceCache
	Logs          LogCache
	Destructs     Cache
	ContractEvent []*commonPb.ContractEvent
}

type Storage

type Storage struct {
	ResultCache     ResultCache
	UpperStorage    *Storage
	ExternalStorage IExternalStorage

	TransientCache TStorage
	// contains filtered or unexported fields
}

func New

func New(upperStorage *Storage, extStorage IExternalStorage) *Storage

func (*Storage) Balance

func (s *Storage) Balance(address *evmutils.Int) (*evmutils.Int, error)

func (*Storage) BalanceModify

func (s *Storage) BalanceModify(address *evmutils.Int, value *evmutils.Int, neg bool)

func (*Storage) CreateFixedAddress

func (s *Storage) CreateFixedAddress(caller, current, salt *evmutils.Int, tx environment.Transaction,
	addrType int32, codeHash []byte) *evmutils.Int

func (*Storage) Destruct

func (s *Storage) Destruct(address *evmutils.Int)

func (*Storage) GetBlockHash

func (s *Storage) GetBlockHash(block *evmutils.Int) (*evmutils.Int, error)

func (*Storage) GetCode

func (s *Storage) GetCode(address *evmutils.Int) ([]byte, error)

func (*Storage) GetCodeHash

func (s *Storage) GetCodeHash(address *evmutils.Int) (*evmutils.Int, error)

func (*Storage) GetCodeSize

func (s *Storage) GetCodeSize(address *evmutils.Int) (*evmutils.Int, error)

func (*Storage) GetCurrentBlockVersion

func (s *Storage) GetCurrentBlockVersion() uint32

func (*Storage) IntAddr2HexStr added in v3.0.1

func (s *Storage) IntAddr2HexStr(addr *evmutils.Int) string

func (*Storage) Log

func (s *Storage) Log(address *evmutils.Int, topics [][]byte, data []byte, context environment.Context)

func (*Storage) SLoad

func (s *Storage) SLoad(contractAddr *evmutils.Int, k *evmutils.Int) (*evmutils.Int, error)

SLoad load data from storage, sequence: ResultCache, UpperStorage and ExternalStorage(just for the original evm)

func (*Storage) SLoad2217 added in v3.0.1

func (s *Storage) SLoad2217(n *evmutils.Int, k *evmutils.Int) (*evmutils.Int, error)

func (*Storage) SStore

func (s *Storage) SStore(n *evmutils.Int, k *evmutils.Int, v *evmutils.Int)

func (*Storage) SetCode

func (s *Storage) SetCode(address *evmutils.Int, code []byte)

func (*Storage) SetCodeHash

func (s *Storage) SetCodeHash(address *evmutils.Int, codeHash *evmutils.Int)

func (*Storage) SetCodeSize

func (s *Storage) SetCodeSize(address *evmutils.Int, size *evmutils.Int)

type TEntry added in v3.0.1

type TEntry map[Hash]Hash

type TStorage added in v3.0.1

type TStorage map[*evmutils.Int]TEntry

transient storage

func NewTStorage added in v3.0.1

func NewTStorage() TStorage

NewTStorage creates a new instance of a TStorage.

func (TStorage) Get added in v3.0.1

func (t TStorage) Get(addr *evmutils.Int, key Hash) Hash

Get gets the transient storage for `key` at the given `addr`.

func (TStorage) Set added in v3.0.1

func (t TStorage) Set(addr *evmutils.Int, key, value Hash)

Set sets the transient storage `value` for `key` at the given `addr`.

Jump to

Keyboard shortcuts

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