Documentation ¶
Index ¶
- Constants
- Variables
- func AddressFromName(name string) (address crypto.Address)
- func Call(state engine.State, params engine.CallParams, ...) ([]byte, error)
- func CreateAccount(st acmstate.ReaderWriter, address crypto.Address) error
- func FireCallEvent(callFrame *engine.CallFrame, callErr error, eventSink exec.EventSink, ...) error
- func HasPermission(st acmstate.Reader, address crypto.Address, perm permission.PermFlag) (bool, error)
- func InitChildCode(st acmstate.ReaderWriter, address crypto.Address, parent crypto.Address, ...) error
- func InitEVMCode(st acmstate.ReaderWriter, address crypto.Address, code []byte) error
- func InitWASMCode(st acmstate.ReaderWriter, address crypto.Address, code []byte) error
- func RemoveAccount(st acmstate.ReaderWriter, address crypto.Address) error
- func Transfer(st acmstate.ReaderWriter, from, to crypto.Address, amount uint64) error
- func UpdateAccount(st acmstate.ReaderWriter, address crypto.Address, ...) error
- func UpdateContractMeta(st acmstate.ReaderWriter, metaSt acmstate.MetadataWriter, ...) error
- type Context
- type Contract
- func (c *Contract) Address() crypto.Address
- func (c *Contract) Call(state engine.State, params engine.CallParams) (output []byte, err error)
- func (c *Contract) ContractMeta() []*acm.ContractMeta
- func (c *Contract) FullName() string
- func (c *Contract) FunctionByID(id abi.FunctionID) (*Function, errors.CodedError)
- func (c *Contract) FunctionByName(name string) *Function
- func (c *Contract) Functions() []*Function
- func (c *Contract) SetExternals(externals engine.Dispatcher)
- type Function
- func (f *Function) Abi() *abi.FunctionSpec
- func (f *Function) Address() crypto.Address
- func (f *Function) Call(state engine.State, params engine.CallParams) ([]byte, error)
- func (f *Function) ContractMeta() []*acm.ContractMeta
- func (f *Function) FullName() string
- func (f *Function) NArgs() int
- func (f *Function) Name() string
- func (f *Function) SetExternals(externals engine.Dispatcher)
- func (f *Function) Signature() string
- func (f *Function) String() string
- type Native
- type Natives
- func (ns *Natives) Callables() []engine.Callable
- func (ns *Natives) Contract(name, comment string, functions ...Function) (*Natives, error)
- func (ns *Natives) Dispatch(acc *acm.Account) engine.Callable
- func (ns *Natives) Function(comment string, address crypto.Address, permFlag permission.PermFlag, ...) (*Natives, error)
- func (ns *Natives) GetByAddress(address crypto.Address) Native
- func (ns *Natives) GetByName(name string) Native
- func (ns *Natives) GetContract(name string) *Contract
- func (ns *Natives) GetFunction(name string) *Function
- func (ns *Natives) IsRegistered(address crypto.Address) bool
- func (ns *Natives) MustContract(name, comment string, functions ...Function) *Natives
- func (ns *Natives) MustFunction(comment string, address crypto.Address, permFlag permission.PermFlag, ...) *Natives
- func (ns *Natives) SetExternals(externals engine.Dispatcher)
- func (ns *Natives) WithLogger(logger *logging.Logger) *Natives
- type State
- func (s *State) GetAccount(address crypto.Address) (*acm.Account, error)
- func (s *State) GetStorage(address crypto.Address, key binary.Word256) ([]byte, error)
- func (s *State) RemoveAccount(address crypto.Address) error
- func (s *State) SetStorage(address crypto.Address, key binary.Word256, value []byte) error
- func (s *State) UpdateAccount(updatedAccount *acm.Account) error
Constants ¶
const ( GasSha3 uint64 = 1 GasGetAccount uint64 = 1 GasStorageUpdate uint64 = 1 GasCreateAccount uint64 = 1 GasBaseOp uint64 = 0 // TODO: make this 1 GasStackOp uint64 = 1 GasEcRecover uint64 = 1 GasSha256Word uint64 = 1 GasSha256Base uint64 = 1 GasRipemd160Word uint64 = 1 GasRipemd160Base uint64 = 1 GasExpModWord uint64 = 1 GasExpModBase uint64 = 1 GasIdentityWord uint64 = 1 GasIdentityBase uint64 = 1 )
Variables ¶
var Permissions = New().MustContract("Permissions", `* acmstate.ReaderWriter for managing Secure Native authorizations. * @dev This interface describes the functions exposed by the native permissions layer in burrow. `, Function{ Comment: ` * @notice Adds a role to an account * @param Account account address * @param Role role name * @return result whether role was added `, PermFlag: permission.AddRole, F: addRole, }, Function{ Comment: ` * @notice Removes a role from an account * @param Account account address * @param Role role name * @return result whether role was removed `, PermFlag: permission.RemoveRole, F: removeRole, }, Function{ Comment: ` * @notice Indicates whether an account has a role * @param Account account address * @param Role role name * @return result whether account has role `, PermFlag: permission.HasRole, F: hasRole, }, Function{ Comment: ` * @notice Sets the permission flags for an account. Makes them explicitly set (on or off). * @param Account account address * @param Permission the base permissions flags to set for the account * @param Set whether to set or unset the permissions flags at the account level * @return The permission flag that was set as uint64 `, PermFlag: permission.SetBase, F: setBase, }, Function{ Comment: ` * @notice Unsets the permissions flags for an account. Causes permissions being unset to fall through to global permissions. * @param Account account address * @param Permission the permissions flags to unset for the account * @return The permission flag that was unset as uint64 `, PermFlag: permission.UnsetBase, F: unsetBase, }, Function{ Comment: ` * @notice Indicates whether an account has a subset of permissions set * @param Account account address * @param Permission the permissions flags (mask) to check whether enabled against base permissions for the account * @return result whether account has the passed permissions flags set `, PermFlag: permission.HasBase, F: hasBase, }, Function{Comment: ` * @notice Sets the global (default) permissions flags for the entire chain * @param Permission the permissions flags to set * @param Set whether to set (or unset) the permissions flags * @return The permission flag that was set as uint64 `, PermFlag: permission.SetGlobal, F: setGlobal, }, )
var Precompiles = New(). MustFunction(`Compute the sha256 hash of input`, leftPadAddress(2), permission.None, sha256Func). MustFunction(`Compute the ripemd160 hash of input`, leftPadAddress(3), permission.None, ripemd160Func). MustFunction(`Return an output identical to the input`, leftPadAddress(4), permission.None, identityFunc). MustFunction(`Compute the operation base**exp % mod where the values are big ints`, leftPadAddress(5), permission.None, expModFunc)
Functions ¶
func AddressFromName ¶
func Call ¶
func Call(state engine.State, params engine.CallParams, execute func(engine.State, engine.CallParams) ([]byte, error)) ([]byte, error)
Call provides a standard wrapper for implementing Callable.Call with appropriate error handling and event firing.
func CreateAccount ¶
func CreateAccount(st acmstate.ReaderWriter, address crypto.Address) error
func FireCallEvent ¶
func HasPermission ¶
func HasPermission(st acmstate.Reader, address crypto.Address, perm permission.PermFlag) (bool, error)
CONTRACT: it is the duty of the contract writer to call known permissions we do not convey if a permission is not set (unlike in state/execution, where we guarantee HasPermission is called on known permissions and panics else) If the perm is not defined in the acc nor set by default in GlobalPermissions, this function returns false.
func InitChildCode ¶
func InitEVMCode ¶ added in v0.30.4
func InitWASMCode ¶
func RemoveAccount ¶
func RemoveAccount(st acmstate.ReaderWriter, address crypto.Address) error
func UpdateAccount ¶
func UpdateContractMeta ¶
func UpdateContractMeta(st acmstate.ReaderWriter, metaSt acmstate.MetadataWriter, address crypto.Address, payloadMeta []*payload.ContractMeta) error
Types ¶
type Context ¶
type Context struct { State engine.State engine.CallParams Logger *logging.Logger // contains filtered or unexported fields }
Context is the first argument to any native function. This struct carries all the context an native needs to access e.g. state in burrow.
type Contract ¶
type Contract struct { // Comment describing purpose of native contract and reason for assembling // the particular functions Comment string // Name of the native contract Name string // contains filtered or unexported fields }
Contract is metadata for native contract. Acts as a call target from the EVM. Can be used to generate bindings in a smart contract languages.
func NewContract ¶
func NewContract(name string, comment string, logger *logging.Logger, fs ...Function) (*Contract, error)
Create a new native contract description object by passing a comment, name and a list of member functions descriptions
func (*Contract) Address ¶
We define the address of an native contact as the last 20 bytes of the sha3 hash of its name
func (*Contract) Call ¶
Dispatch is designed to be called from the EVM once a native contract has been selected.
func (*Contract) ContractMeta ¶
func (c *Contract) ContractMeta() []*acm.ContractMeta
func (*Contract) FunctionByID ¶
func (c *Contract) FunctionByID(id abi.FunctionID) (*Function, errors.CodedError)
Get function by calling identifier FunctionSelector
func (*Contract) FunctionByName ¶
Get function by name
func (*Contract) SetExternals ¶
func (c *Contract) SetExternals(externals engine.Dispatcher)
type Function ¶
type Function struct { // Comment describing function's purpose, parameters, and return value Comment string // Permissions required to call function PermFlag permission.PermFlag // Native function to which calls will be dispatched when a containing F interface{} // contains filtered or unexported fields }
Function is metadata for native functions. Act as call targets for the EVM when collected into an Contract. Can be used to generate bindings in a smart contract languages.
func NewFunction ¶
func NewFunction(comment string, address crypto.Address, permFlag permission.PermFlag, f interface{}) (*Function, error)
Created a new function mounted directly at address (i.e. no Solidity contract or function selection)
func (*Function) Abi ¶
func (f *Function) Abi() *abi.FunctionSpec
Abi returns the FunctionSpec for this function
func (*Function) ContractMeta ¶
func (f *Function) ContractMeta() []*acm.ContractMeta
func (*Function) SetExternals ¶
func (f *Function) SetExternals(externals engine.Dispatcher)
type Native ¶
type Native interface { engine.Callable SetExternals(externals engine.Dispatcher) ContractMeta() []*acm.ContractMeta FullName() string Address() crypto.Address }
type Natives ¶
type Natives struct {
// contains filtered or unexported fields
}
func DefaultNatives ¶
func MustDefaultNatives ¶
func MustDefaultNatives() *Natives
func (*Natives) GetContract ¶
func (*Natives) GetFunction ¶
func (*Natives) MustContract ¶
func (*Natives) MustFunction ¶
func (*Natives) SetExternals ¶
func (ns *Natives) SetExternals(externals engine.Dispatcher)
type State ¶
type State struct {
// contains filtered or unexported fields
}
This wrapper provides a state that behaves 'as if' the natives were stored directly in state. TODO: we may want to actually store native account sentinel values (and their metadata) in on-disk state down the line
func NewState ¶
func NewState(natives *Natives, backend acmstate.ReaderWriter) *State
Get a new state that wraps the backend but intercepts any calls to natives returning appropriate errors message or an Account sentinel for the particular native