burrow: github.com/hyperledger/burrow/execution/native Index | Files

package native

import "github.com/hyperledger/burrow/execution/native"

Index

Package Files

account.go call.go contract.go function.go gas.go native.go natives.go permissions.go precompiles.go state.go

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",
    "" /* 158 byte string literal not displayed */,

    Function{
        Comment: "" /* 154 byte string literal not displayed */,

        PermFlag: permission.AddRole,
        F:        addRole,
    },
    Function{
        Comment: "" /* 161 byte string literal not displayed */,

        PermFlag: permission.RemoveRole,
        F:        removeRole,
    },
    Function{
        Comment: "" /* 170 byte string literal not displayed */,

        PermFlag: permission.HasRole,
        F:        hasRole,
    },
    Function{
        Comment: "" /* 362 byte string literal not displayed */,

        PermFlag: permission.SetBase,
        F:        setBase,
    },
    Function{
        Comment: "" /* 324 byte string literal not displayed */,

        PermFlag: permission.UnsetBase,
        F:        unsetBase,
    },
    Function{
        Comment: "" /* 313 byte string literal not displayed */,

        PermFlag: permission.HasBase,
        F:        hasBase,
    },
    Function{Comment: "" /* 269 byte string literal not displayed */,

        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)

func AddressFromName Uses

func AddressFromName(name string) (address crypto.Address)

func Call Uses

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 Uses

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

func FireCallEvent Uses

func FireCallEvent(callFrame *engine.CallFrame, callErr error, eventSink exec.EventSink, output []byte,
    params engine.CallParams) error

func HasPermission Uses

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 Uses

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

func InitEVMCode Uses

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

func InitWASMCode Uses

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

func RemoveAccount Uses

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

func Transfer Uses

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

func UpdateAccount Uses

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

func UpdateContractMeta Uses

func UpdateContractMeta(st acmstate.ReaderWriter, metaSt acmstate.MetadataWriter, address crypto.Address, payloadMeta []*payload.ContractMeta) error

type Context Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (c *Contract) ContractMeta() []*acm.ContractMeta

func (*Contract) FullName Uses

func (c *Contract) FullName() string

func (*Contract) FunctionByID Uses

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

Get function by calling identifier FunctionSelector

func (*Contract) FunctionByName Uses

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

Get function by name

func (*Contract) Functions Uses

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

Get functions in order of declaration

func (*Contract) SetExternals Uses

func (c *Contract) SetExternals(externals engine.Dispatcher)

type Function Uses

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 Uses

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 Uses

func (f *Function) Abi() *abi.FunctionSpec

Abi returns the FunctionSpec for this function

func (*Function) Address Uses

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

func (*Function) Call Uses

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

func (*Function) ContractMeta Uses

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

func (*Function) FullName Uses

func (f *Function) FullName() string

func (*Function) NArgs Uses

func (f *Function) NArgs() int

NArgs returns the number of function arguments

func (*Function) Name Uses

func (f *Function) Name() string

For templates

func (*Function) SetExternals Uses

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

func (*Function) Signature Uses

func (f *Function) Signature() string

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

func (*Function) String Uses

func (f *Function) String() string

type Native Uses

type Native interface {
    engine.Callable
    SetExternals(externals engine.Dispatcher)
    ContractMeta() []*acm.ContractMeta
    FullName() string
    Address() crypto.Address
}

type Natives Uses

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

func DefaultNatives Uses

func DefaultNatives() (*Natives, error)

func Merge Uses

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

func MustDefaultNatives Uses

func MustDefaultNatives() *Natives

func New Uses

func New() *Natives

func (*Natives) Callables Uses

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

func (*Natives) Contract Uses

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

func (*Natives) Dispatch Uses

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

func (*Natives) Function Uses

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

func (*Natives) GetByAddress Uses

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

func (*Natives) GetByName Uses

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

func (*Natives) GetContract Uses

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

func (*Natives) GetFunction Uses

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

func (*Natives) IsRegistered Uses

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

func (*Natives) MustContract Uses

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

func (*Natives) MustFunction Uses

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

func (*Natives) SetExternals Uses

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

func (*Natives) WithLogger Uses

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

type State Uses

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 Uses

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 Uses

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

func (*State) GetStorage Uses

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

func (*State) RemoveAccount Uses

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

func (*State) SetStorage Uses

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

func (*State) UpdateAccount Uses

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

Package native imports 21 packages (graph) and is imported by 13 packages. Updated 2020-05-03. Refresh now. Tools for package owners.