native

package
v0.34.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Permissions = New().MustContract("Permissions",
	`* Interface 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 _result is 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 _result is 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 is 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 _result is the permission flag that was set as uint64
			`,
		PermFlag: permission.SetGlobal,
		F:        setGlobal,
	},
)
View Source
var Precompiles = New().
	MustFunction(`Recover public key/address of account that signed the data`,
		leftPadAddress(1),
		permission.None,
		ecrecover).
	MustFunction(`Compute the sha256 hash of input`,
		leftPadAddress(2),
		permission.None,
		sha256).
	MustFunction(`Compute the ripemd160 hash of input`,
		leftPadAddress(3),
		permission.None,
		ripemd160Func).
	MustFunction(`Return an output identical to the input`,
		leftPadAddress(4),
		permission.None,
		identity).
	MustFunction(`Compute the operation base**exp % mod where the values are big ints`,
		leftPadAddress(5),
		permission.None,
		expMod).
	MustFunction(`Compute the keccak256 hash of input`,
		leftPadAddress(20),
		permission.None,
		keccak256Func)

Functions

This section is empty.

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

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

We define the address of an native contact as the last 20 bytes of the sha3 hash of its name

func (*Contract) Call

func (c *Contract) Call(state engine.State, params engine.CallParams) (output []byte, err error)

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) FullName

func (c *Contract) FullName() string

func (*Contract) FunctionByID

func (c *Contract) FunctionByID(id abi.FunctionID) (*Function, errors.CodedError)

Get function by calling identifier FunctionSelector

func (*Contract) FunctionByName

func (c *Contract) FunctionByName(name string) *Function

Get function by name

func (*Contract) Functions

func (c *Contract) Functions() []*Function

Get functions in order of declaration

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
	// Whether this function writes to state
	Pure bool
	// 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) Address

func (f *Function) Address() crypto.Address

func (*Function) Call

func (f *Function) Call(state engine.State, params engine.CallParams) ([]byte, error)

func (*Function) ContractMeta

func (f *Function) ContractMeta() []*acm.ContractMeta

func (*Function) FullName

func (f *Function) FullName() string

func (*Function) NArgs

func (f *Function) NArgs() int

NArgs returns the number of function arguments

func (*Function) Name

func (f *Function) Name() string

For templates

func (*Function) SetExternals

func (f *Function) SetExternals(externals engine.Dispatcher)

func (*Function) Signature

func (f *Function) Signature() string

Signature returns the function signature as would be used for ABI hashing

func (*Function) String

func (f *Function) String() string

type Natives

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

func DefaultNatives

func DefaultNatives() (*Natives, error)

func Merge

func Merge(nss ...*Natives) (*Natives, error)

func MustDefaultNatives

func MustDefaultNatives() *Natives

func New

func New() *Natives

func (*Natives) Callables

func (ns *Natives) Callables() []engine.Callable

func (*Natives) Contract

func (ns *Natives) Contract(name, comment string, functions ...Function) (*Natives, error)

func (*Natives) Dispatch

func (ns *Natives) Dispatch(acc *acm.Account) engine.Callable

func (*Natives) Function

func (ns *Natives) Function(comment string, address crypto.Address, permFlag permission.PermFlag, f interface{}) (*Natives, error)

func (*Natives) GetByAddress

func (ns *Natives) GetByAddress(address crypto.Address) engine.Native

func (*Natives) GetByName

func (ns *Natives) GetByName(name string) engine.Native

func (*Natives) GetContract

func (ns *Natives) GetContract(name string) *Contract

func (*Natives) GetFunction

func (ns *Natives) GetFunction(name string) *Function

func (*Natives) IsRegistered

func (ns *Natives) IsRegistered(address crypto.Address) bool

func (*Natives) MustContract

func (ns *Natives) MustContract(name, comment string, functions ...Function) *Natives

func (*Natives) MustFunction

func (ns *Natives) MustFunction(comment string, address crypto.Address, permFlag permission.PermFlag, f interface{}) *Natives

func (*Natives) SetExternals

func (ns *Natives) SetExternals(externals engine.Dispatcher)

func (*Natives) WithLogger

func (ns *Natives) WithLogger(logger *logging.Logger) *Natives

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 engine.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

func (*State) GetAccount

func (s *State) GetAccount(address crypto.Address) (*acm.Account, error)

func (*State) GetStorage

func (s *State) GetStorage(address crypto.Address, key binary.Word256) ([]byte, error)

func (*State) RemoveAccount

func (s *State) RemoveAccount(address crypto.Address) error

func (*State) SetStorage

func (s *State) SetStorage(address crypto.Address, key binary.Word256, value []byte) error

func (*State) UpdateAccount

func (s *State) UpdateAccount(updatedAccount *acm.Account) error

Jump to

Keyboard shortcuts

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