contract

package
v0.0.0-...-a293c92 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountRef

type AccountRef string

AccountRef 账户对象引用 (实现了合约对象引用ContractRef接口) 因为在合约调用过程中,调用者有可能是外部账户,也有可能是合约账户,所以两者的结构是互通的

func (AccountRef) Address

func (ar AccountRef) Address() string

Address 将账户引用转换为普通地址对象

type Contract

type Contract struct {
	// 调用者地址,应该为外部账户的地址
	// 如果是通过合约再调用合约时,会从上级合约中获取调用者地址进行赋值
	CallerAddress string

	// 合约代码和代码哈希
	Code     []byte
	CodeHash common.Hash

	// 合约地址以及输入参数
	CodeAddr string
	Input    []byte

	// 委托调用时,此属性会被设置为true
	DelegateCall bool
	// contains filtered or unexported fields
}

Contract 合约对象,它在内存中表示一个合约账户的代码即地址信息实体 每次合约调用都会创建一个新的合约对象

func NewContract

func NewContract(caller Ref, object Ref, value uint64) *Contract

NewContract 创建一个新的合约调用对象 不管合约是否存在,每次调用时都会新创建一个合约对象交给解释器执行,对象持有合约代码和合约地址

func (*Contract) Address

func (c *Contract) Address() string

Address 返回上下文中合约自身的地址 注意,当合约通过CallCode调用时,这个地址并不是当前合约代码对应的地址,而是调用者的地址

func (*Contract) AsDelegate

func (c *Contract) AsDelegate() *Contract

AsDelegate 设置当前的合约对象为被委托调用 返回当前合约对象的指针,以便在多层调用链模式下使用

func (*Contract) Caller

func (c *Contract) Caller() string

Caller 返回合约的调用者 如果当前合约为委托调用,则调用它的不是外部账户,而是合约账户,所以此时的caller为调用此合约的合约的caller 这个关系可以一直递归向上,直到定位到caller为外部账户地址

func (*Contract) GetByte

func (c *Contract) GetByte(n uint64) byte

GetByte 获取合约代码中制定位置的字节值

func (*Contract) SetCallCode

func (c *Contract) SetCallCode(addr string, hash common.Hash, code []byte)

SetCallCode 设置合约代码和代码哈希

func (*Contract) SetCode

func (c *Contract) SetCode(hash common.Hash, code []byte)

SetCode 设置合约代码内容

func (*Contract) Value

func (c *Contract) Value() uint64

Value 合约包含转账逻辑时,转账的金额

type Ref

type Ref interface {
	Address() string
}

Ref 合约对象引用

Jump to

Keyboard shortcuts

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