contract

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2019 License: Apache-2.0 Imports: 13 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrArgIdxNotFound = errors.New("argument idx not found")
View Source
var (
	ErrContractNotFound = errors.New("contract not found")
)

Functions

func CallContract

func CallContract(ps Process, addr, entry Reader, argb Reader) int

func ECRecover

func ECRecover(ps Process, h, v, r, s Reader, ret Writer) int

func ECRecoverAddress

func ECRecoverAddress(ps Process, h, v, r, s Reader, ret Writer) int

func EmitEvent added in v0.2.0

func EmitEvent(ps Process, name, value Reader) int

func GetArg

func GetArg(ps Process, idx, offset int, buf Writer) int

func GetContractAddress added in v0.4.1

func GetContractAddress(ps Process, w Writer) int

func GetSender

func GetSender(ps Process, w Writer) int

func Keccak256 added in v0.2.0

func Keccak256(ps Process, msg Reader, ret Writer) int

func Log

func Log(ps Process, msg Reader) int

func Read

func Read(ps Process, id, offset int, buf Writer) int

func ReadState

func ReadState(ps Process, key Reader, offset int, buf Writer) int

func SetResponse

func SetResponse(ps Process, val Reader) int

func Sha256 added in v0.2.0

func Sha256(ps Process, msg Reader, ret Writer) int

func WriteBuf added in v0.2.1

func WriteBuf(ps Process, buf Writer, offset int, v []byte) int

func WriteState

func WriteState(ps Process, key, val Reader) int

Types

type Args

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

func DeserializeArgs

func DeserializeArgs(b []byte) (Args, error)

DeserializeArgs returns args bytes format is <elem_num: 4byte>|<elem1_size: 4byte>|<elem1_data>|<elem2_size: 4byte>|<elem2_data>|...

func NewArgs

func NewArgs(bs [][]byte) Args

func NewArgsFromStrings

func NewArgsFromStrings(ss []string) Args

func (Args) Get

func (a Args) Get(idx int) ([]byte, bool)

func (*Args) Len

func (a *Args) Len() int

func (*Args) PushBytes

func (a *Args) PushBytes(b []byte)

func (*Args) PushString

func (a *Args) PushString(s string)

type Contract

type Contract struct {
	Owner common.Address
	Code  []byte
}

func TxToContract

func TxToContract(tx *transaction.ContractDeployTx) *Contract

func (*Contract) Address

func (c *Contract) Address() common.Address

func (*Contract) Bytes

func (c *Contract) Bytes() []byte

func (*Contract) Decode

func (c *Contract) Decode(b []byte) error

func (*Contract) Encode

func (c *Contract) Encode() ([]byte, error)

type ContractManager

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

func NewContractManager

func NewContractManager(mp ContractMapper) *ContractManager

func (*ContractManager) DeployContract

func (cm *ContractManager) DeployContract(ctx types.Context, tx *transaction.ContractDeployTx) (common.Address, error)

func (*ContractManager) GetContract

func (cm *ContractManager) GetContract(ctx types.Context, addr common.Address) (*Contract, error)

func (*ContractManager) SaveContract

func (cm *ContractManager) SaveContract(ctx types.Context, addr common.Address, c *Contract) error

type ContractMapper

type ContractMapper interface {
	Put(ctx types.Context, addr common.Address, c *Contract)
	Get(ctx types.Context, addr common.Address) (*Contract, error)
}

func NewContractMapper

func NewContractMapper(storeKey types.StoreKey) ContractMapper

type Env

type Env struct {
	Context sdk.Context
	Logger  logger.Logger
	Sender  common.Address
	Args    Args

	EnvManager *EnvManager
	Contract   *Contract
	VMProvider VMProvider

	DB *db.VersionedDB
	// contains filtered or unexported fields
}

func (*Env) Exec

func (env *Env) Exec(ctx sdk.Context, entry string) (*Result, error)

func (*Env) GetReponse

func (env *Env) GetReponse() []byte

func (*Env) SetResponse

func (env *Env) SetResponse(v []byte)

type EnvManager

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

func NewEnvManager

func NewEnvManager(key sdk.StoreKey, cm ContractMapper) *EnvManager

func (*EnvManager) Get

func (em *EnvManager) Get(ctx sdk.Context, sender, addr common.Address, args Args) (*Env, error)

type Process

type Process interface {
	Logger() logger.Logger
	Sender() common.Address
	ContractAddress() common.Address
	Args() Args
	GetArg(idx int) ([]byte, error)
	State() db.StateDB
	SetResponse([]byte)
	Call(addr common.Address, entry []byte, args Args) (int, error)
	Read(id int) ([]byte, error)
	ValueTable() ValueTable
	EmitEvent(ev *event.Entry)
}

func NewProcess

func NewProcess(env *Env, logger logger.Logger, vt ValueTable) Process

NewProcess create a new process

type Reader

type Reader interface {
	Len() int
	Read() []byte
}

func NewReader

func NewReader(mem []byte, pos, len int64) Reader

type Resolver

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

func NewResolver

func NewResolver(env *Env) *Resolver

func (*Resolver) ResolveFunc

func (r *Resolver) ResolveFunc(module, field string) exec.FunctionImport

ResolveFunc defines a set of import functions that may be called within a WebAssembly module.

func (*Resolver) ResolveGlobal

func (r *Resolver) ResolveGlobal(module, field string) int64

ResolveGlobal defines a set of global variables for use within a WebAssembly module.

type Result

type Result struct {
	Code     int32
	Response []byte
	State    State
}

type State added in v0.4.4

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

func (*State) AddEvents added in v0.4.4

func (s *State) AddEvents(evs ...*event.Event)

func (*State) AddRWSets added in v0.4.4

func (s *State) AddRWSets(ss ...*db.RWSet)

func (State) Events added in v0.4.4

func (s State) Events() []*event.Event

func (State) RWSets added in v0.4.4

func (s State) RWSets() db.RWSets

func (*State) Update added in v0.4.4

func (s *State) Update(other State)

type VM

type VM struct {
	*exec.VirtualMachine
}

func DefaultVMProvider

func DefaultVMProvider(env *Env) (*VM, error)

type VMProvider

type VMProvider func(*Env) (*VM, error)

type ValueTable

type ValueTable interface {
	Get(id int) ([]byte, error)
	Put(v []byte) (int, error)
}

ValueTable manages values that external contract returns.

type Writer

type Writer interface {
	Len() int
	Write([]byte) int
}

func NewWriter

func NewWriter(mem []byte, pos, len int64) Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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