Documentation

Index

Constants

View Source
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

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(`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 AddressFromName(name string) (address crypto.Address)

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 FireCallEvent(callFrame *engine.CallFrame, callErr error, eventSink exec.EventSink, output []byte,
    	params engine.CallParams) error

    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 InitChildCode(st acmstate.ReaderWriter, address crypto.Address, parent crypto.Address, code []byte) error

      func InitEVMCode

      func InitEVMCode(st acmstate.ReaderWriter, address crypto.Address, code []byte) error

      func InitWASMCode

      func InitWASMCode(st acmstate.ReaderWriter, address crypto.Address, code []byte) error

      func RemoveAccount

      func RemoveAccount(st acmstate.ReaderWriter, address crypto.Address) error

      func Transfer

      func Transfer(st acmstate.ReaderWriter, from, to crypto.Address, amount uint64) error

      func UpdateAccount

      func UpdateAccount(st acmstate.ReaderWriter, address crypto.Address, updater func(acc *acm.Account) error) error

      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

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

                                  func (*Natives) GetByName

                                  func (ns *Natives) GetByName(name string) 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 *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