host

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2018 License: LGPL-3.0 Imports: 11 Imported by: 13

Documentation

Index

Constants

View Source
const (
	DHCPTable      = "dhcp_table"
	DHCPRTable     = "dhcp_revert_table"
	DHCPOwnerTable = "dhcp_owner_table"
)

const table name

View Source
const (
	ContractAccountPrefix = "CA"
	ContractGasPrefix     = "CG"
)

const prefixs

Variables

View Source
var (
	PutCost  = contract.NewCost(100, 0, 12)
	GetCost  = contract.NewCost(100, 0, 8)
	DelCost  = contract.NewCost(0, 0, 8)
	KeysCost = contract.NewCost(100, 0, 12)

	CompileErrCost       = contract.NewCost(0, 0, 10)
	ContractNotFoundCost = contract.NewCost(0, 0, 10)
	ABINotFoundCost      = contract.NewCost(0, 0, 11)

	DelContractCost = contract.NewCost(0, 0, 10)

	BlockInfoCost = contract.NewCost(0, 0, 1)
	TxInfoCost    = contract.NewCost(0, 0, 1)

	TransferCost = contract.NewCost(300, 0, 3)

	RequireAuthCost = contract.NewCost(0, 0, 1)
)

var list cost

View Source
var (
	ErrBalanceNotEnough = errors.New("balance not enough")
	ErrTransferNegValue = errors.New("trasfer amount less than zero")
	ErrReenter          = errors.New("re-entering")
	ErrPermissionLost   = errors.New("transaction has no permission")

	ErrContractNotFound = errors.New("contract not exists")
	ErrUpdateRefused    = errors.New("update refused")
	ErrDestroyRefused   = errors.New("destroy refused")

	ErrCoinExists         = errors.New("coin exists")
	ErrCoinNotExists      = errors.New("coin not exists")
	ErrCoinIssueRefused   = errors.New("coin issue refused")
	ErrCoinSetRateRefused = errors.New("coin set rate refused")
)

var errors

Functions

func CodeSavageCost

func CodeSavageCost(size int) *contract.Cost

CodeSavageCost cost in deploy contract based on code size

func CommonErrorCost

func CommonErrorCost(layer int) *contract.Cost

CommonErrorCost returns cost increased by stack layer

func EventCost

func EventCost(size int) *contract.Cost

EventCost return cost based on event size

func Post

func Post(topic event.Event_Topic, data string) *contract.Cost

Post post the event

func ReceiptCost

func ReceiptCost(size int) *contract.Cost

ReceiptCost based on receipt size

Types

type APIDelegate

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

APIDelegate ...

func NewAPI

func NewAPI(h *Host) APIDelegate

NewAPI ...

func (*APIDelegate) Receipt

func (h *APIDelegate) Receipt(s string) *contract.Cost

Receipt ...

func (*APIDelegate) RequireAuth

func (h *APIDelegate) RequireAuth(pubkey string) (ok bool, cost *contract.Cost)

RequireAuth ...

type Context

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

Context thread unsafe context with global fields

func NewContext

func NewContext(base *Context) *Context

NewContext new context based on base

func (*Context) Base

func (c *Context) Base() *Context

Base get base of context

func (*Context) GSet

func (c *Context) GSet(key string, value interface{})

GSet set global value of key, thread unsafe

func (*Context) GValue

func (c *Context) GValue(key string) (value interface{})

GValue get global value of key

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set set value of k

func (*Context) Value

func (c *Context) Value(key string) (value interface{})

Value get value of key

type DBHandler

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

DBHandler struct {

func NewDBHandler

func NewDBHandler(h *Host) DBHandler

NewDBHandler ...

func (*DBHandler) Del

func (h *DBHandler) Del(key string) *contract.Cost

Del delete key

func (*DBHandler) Get

func (h *DBHandler) Get(key string) (value interface{}, cost *contract.Cost)

Get get value of key from db

func (*DBHandler) GlobalGet

func (h *DBHandler) GlobalGet(con, key string) (value interface{}, cost *contract.Cost)

GlobalGet get another contract's data

func (*DBHandler) GlobalMapGet

func (h *DBHandler) GlobalMapGet(con, key, field string) (value interface{}, cost *contract.Cost)

GlobalMapGet get another contract's map data

func (*DBHandler) GlobalMapKeys

func (h *DBHandler) GlobalMapKeys(con, key string) (keys []string, cost *contract.Cost)

GlobalMapKeys get another contract's map keys

func (*DBHandler) GlobalMapLen

func (h *DBHandler) GlobalMapLen(con, key string) (length int, cost *contract.Cost)

GlobalMapLen get another contract's map length

func (*DBHandler) Has

func (h *DBHandler) Has(key string) (bool, *contract.Cost)

Has if db has key

func (*DBHandler) MapDel

func (h *DBHandler) MapDel(key, field string) *contract.Cost

MapDel delete field

func (*DBHandler) MapGet

func (h *DBHandler) MapGet(key, field string) (value interface{}, cost *contract.Cost)

MapGet get value by kf from db

func (*DBHandler) MapHas

func (h *DBHandler) MapHas(key, field string) (bool, *contract.Cost)

MapHas if has field

func (*DBHandler) MapKeys

func (h *DBHandler) MapKeys(key string) (fields []string, cost *contract.Cost)

MapKeys list keys

func (*DBHandler) MapLen

func (h *DBHandler) MapLen(key string) (int, *contract.Cost)

MapLen get length of map

func (*DBHandler) MapPut

func (h *DBHandler) MapPut(key, field string, value interface{}) *contract.Cost

MapPut put kfv to db

func (*DBHandler) Put

func (h *DBHandler) Put(key string, value interface{}) *contract.Cost

Put put kv to db

type DHCP

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

DHCP dhcp server handler

func NewDHCP

func NewDHCP(h *Host) DHCP

NewDHCP make a dhcp

func (*DHCP) ContractID

func (d *DHCP) ContractID(url string) string

ContractID find cid from url

func (*DHCP) IsDomain

func (d *DHCP) IsDomain(s string) bool

IsDomain determine if s is a domain

func (d *DHCP) RemoveLink(url, cid string)

RemoveLink remove a url

func (*DHCP) URL

func (d *DHCP) URL(cid string) string

URL git url of cid

func (*DHCP) URLOwner

func (d *DHCP) URLOwner(url string) string

URLOwner find owner of url

func (*DHCP) URLTransfer

func (d *DHCP) URLTransfer(url, to string)

URLTransfer give url to another id

func (d *DHCP) WriteLink(url, cid, owner string)

WriteLink add url and url owner to contract

type EventPoster

type EventPoster struct {
}

EventPoster the event handler in host

type Host

type Host struct {
	DBHandler
	Info
	Teller
	APIDelegate
	EventPoster
	DHCP
	// contains filtered or unexported fields
}

Host host struct, used as isolate of vm

func NewHost

func NewHost(ctx *Context, db *database.Visitor, monitor Monitor, logger *ilog.Logger) *Host

NewHost get a new host

func (*Host) Call

func (h *Host) Call(contract, api, jarg string) ([]interface{}, *contract.Cost, error)

Call call a new contract in this context

func (*Host) CallWithReceipt

func (h *Host) CallWithReceipt(contractName, api, jarg string) ([]interface{}, *contract.Cost, error)

CallWithReceipt call and generate receipt

func (*Host) Context

func (h *Host) Context() *Context

Context get context in host

func (*Host) DB

func (h *Host) DB() *database.Visitor

DB get current version mvccdb

func (*Host) Deadline

func (h *Host) Deadline() time.Time

Deadline return this host's deadline

func (*Host) DestroyCode

func (h *Host) DestroyCode(contractName string) (*contract.Cost, error)

DestroyCode delete code

func (*Host) Logger

func (h *Host) Logger() *ilog.Logger

Logger get a log in host

func (*Host) PopCtx

func (h *Host) PopCtx()

PopCtx pop current context

func (*Host) PushCtx

func (h *Host) PushCtx()

PushCtx make a new context based on current one

func (*Host) SetCode

func (h *Host) SetCode(c *contract.Contract) (*contract.Cost, error)

SetCode set code to storage

func (*Host) SetContext

func (h *Host) SetContext(ctx *Context)

SetContext set a new context to host

func (*Host) SetDeadline

func (h *Host) SetDeadline(t time.Time)

SetDeadline set this host's deadline

func (*Host) UpdateCode

func (h *Host) UpdateCode(c *contract.Contract, id database.SerializedJSON) (*contract.Cost, error)

UpdateCode update code

type Info

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

Info current info handler of this isolate

func NewInfo

func NewInfo(h *Host) Info

NewInfo new info

func (*Info) ABIConfig

func (h *Info) ABIConfig(key, value string)

ABIConfig set this abi config

func (*Info) BlockInfo

func (h *Info) BlockInfo() (info database.SerializedJSON, cost *contract.Cost)

BlockInfo get block info, in json

func (*Info) GasLimit

func (h *Info) GasLimit() int64

GasLimit get gas limit

func (*Info) TxInfo

func (h *Info) TxInfo() (info database.SerializedJSON, cost *contract.Cost)

TxInfo get tx info

type Monitor

type Monitor interface {
	Call(host *Host, contractName, api string, jarg string) (rtn []interface{}, cost *contract.Cost, err error)
	Compile(con *contract.Contract) (string, error)
}

Monitor monitor interface

type Teller

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

Teller handler of iost

func NewTeller

func NewTeller(h *Host) Teller

NewTeller new teller

func (*Teller) ConsumeCoin

func (h *Teller) ConsumeCoin(coinName, from string, amount int64) (cost *contract.Cost, err error)

ConsumeCoin consume coin from

func (*Teller) ConsumeServi

func (h *Teller) ConsumeServi(from string, amount int64) (cost *contract.Cost, err error)

ConsumeServi ...

func (*Teller) Countermand

func (h *Teller) Countermand(c, to string, amount int64) (*contract.Cost, error)

Countermand ...

func (*Teller) Deposit

func (h *Teller) Deposit(from string, amount int64) (*contract.Cost, error)

Deposit ...

func (*Teller) DoPay

func (h *Teller) DoPay(witness string, gasPrice int64) error

DoPay ...

func (*Teller) GetBalance

func (h *Teller) GetBalance(from string) (int64, *contract.Cost, error)

GetBalance return balance of an id

func (*Teller) GrantCoin

func (h *Teller) GrantCoin(coinName, to string, amount int64) (*contract.Cost, error)

GrantCoin issue coin

func (*Teller) GrantServi

func (h *Teller) GrantServi(to string, amount int64) (*contract.Cost, error)

GrantServi ...

func (*Teller) PayCost

func (h *Teller) PayCost(c *contract.Cost, who string)

PayCost ...

func (*Teller) Privilege

func (h *Teller) Privilege(id string) int

Privilege ...

func (*Teller) TopUp

func (h *Teller) TopUp(c, from string, amount int64) (*contract.Cost, error)

TopUp ...

func (*Teller) TotalServi

func (h *Teller) TotalServi() (ts int64, cost *contract.Cost)

TotalServi ...

func (*Teller) Transfer

func (h *Teller) Transfer(from, to string, amount int64) (*contract.Cost, error)

Transfer ...

func (*Teller) Withdraw

func (h *Teller) Withdraw(to string, amount int64) (*contract.Cost, error)

Withdraw ...

Jump to

Keyboard shortcuts

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