host

package
v0.0.0-...-5fdeb2f Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DNSTable      = "dns_table"
	DNSRTable     = "dns_revert_table"
	DNSOwnerTable = "dns_owner_table"
)

const table name

Variables

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")
	ErrInvalidData      = errors.New("invalid data")
	ErrInvalidAmount    = errors.New("invalid amount")
	ErrOutOfGas         = errors.New("out of gas")

	ErrContractNotFound   = errors.New("contract not exists")
	ErrContractExists     = errors.New("contract exists")
	ErrAbiHasInternalFunc = errors.New("abi has internal function")
	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")

	ErrTokenExists               = errors.New("token exists")
	ErrTokenNotExists            = errors.New("token not exists")
	ErrAmountLimitTokenNotExists = errors.New("token not exists in amountLimit")
	ErrTokenNoTransfer           = errors.New("token can't transfer")
	ErrTokenIssueRefused         = errors.New("token issue refused")
	ErrMemoTooLarge              = errors.New("memo too large")

	ErrDelaytxNotFound   = errors.New("delaytx not exists")
	ErrCannotCancelDelay = errors.New("can not cancel delaytx")
)

var errors

View Source
var (
	Costs = map[string]contract.Cost{
		"JSCost":           contract.NewCost(0, 0, 30000),
		"PutCost":          contract.NewCost(0, 0, 300),
		"GetCost":          contract.NewCost(0, 0, 300),
		"DelCost":          contract.NewCost(0, 0, 300),
		"KeysCost":         contract.NewCost(0, 0, 300),
		"ContextCost":      contract.NewCost(0, 0, 10),
		"EventPrice":       contract.NewCost(0, 0, 1),
		"ReceiptPrice":     contract.NewCost(0, 1, 0),
		"CodePrice":        contract.NewCost(0, 0, 1),
		"SetCodeBasePrice": contract.NewCost(0, 0, 200000),
		"SetCodePrice":     contract.NewCost(0, 0, 70),
		"OpPrice":          contract.NewCost(0, 0, 1),
		"ErrPrice":         contract.NewCost(0, 0, 1),
	}
)

var costs

Functions

func Auth

func Auth(vi *database.Visitor, id, permission string, authMap, reenter map[string]int) (bool, contract.Cost)

Auth check auth

func AuthPublisher

func AuthPublisher(vi *database.Visitor, id, permission string, authMap, reenter map[string]int) (bool, contract.Cost)

AuthPublisher check publisher auth

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 CommonOpCost

func CommonOpCost(layer int) contract.Cost

CommonOpCost returns cost increased by stack layer

func DelDelayTxCost

func DelDelayTxCost(dataLen int, payer string) contract.Cost

DelDelayTxCost returns cost of a delay transaction.

func DelayTxCost

func DelayTxCost(dataLen int, payer string) contract.Cost

DelayTxCost returns cost of a delay transaction.

func EventCost

func EventCost(size int) contract.Cost

EventCost return cost based on event size

func IsValidKey

func IsValidKey(key string) error

IsValidKey return error if the key is invalid as state db key or field

func ReadAuth

func ReadAuth(vi *database.Visitor, id string) (*account.Account, contract.Cost)

ReadAuth read auth

func ReceiptCost

func ReceiptCost(size int) contract.Cost

ReceiptCost based on receipt size

func SetCodeCost

func SetCodeCost(size int) contract.Cost

SetCodeCost calculate set code cost based on code 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 ...

type Authority

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

Authority module of ...

func (*Authority) IsContract

func (h *Authority) IsContract(id string) bool

IsContract to judge the id is contract format

func (*Authority) RequireAuth

func (h *Authority) RequireAuth(id, p string) (bool, contract.Cost)

RequireAuth check auth

func (*Authority) RequirePublisherAuth

func (h *Authority) RequirePublisherAuth(id string) (bool, contract.Cost)

RequirePublisherAuth check publisher auth

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

func (c *Context) GClear()

GClear clear global values

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

func (c *Context) String() string

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 is an application layer abstraction of our base basic_handler and map_handler. it offers interface which has an interface{} type value and ramPayer semantic it also handles the Marshal and Unmarshal work and determine the cost of each operation

func NewDBHandler

func NewDBHandler(h *Host) DBHandler

NewDBHandler ...

func (*DBHandler) Del

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

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

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

GlobalHas if another contract's db has key

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

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

GlobalMapHas if another contract's map has field

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, error)

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{}, ramPayer ...string) (contract.Cost, error)

MapPut put kfv to db

func (*DBHandler) Put

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

Put put kv to db

type DNS

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

DNS dns server handler

func NewDNS

func NewDNS(h *Host) DNS

NewDNS make a dns

func (*DNS) ContractID

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

ContractID find cid from url

func (*DNS) IsDomain

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

IsDomain determine if s is a domain

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

RemoveLink remove a url

func (*DNS) URL

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

URL get url of cid

func (*DNS) URLOwner

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

URLOwner find owner of url

func (*DNS) URLTransfer

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

URLTransfer give url to another id

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

WriteLink add url and url owner to contract

type EventPoster

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

EventPoster the event handler in host

func NewEventPoster

func NewEventPoster(h *Host) EventPoster

NewEventPoster returns a new EventPoster instance.

func (*EventPoster) PostEvent

func (p *EventPoster) PostEvent(data string) contract.Cost

PostEvent post the event

type GasManager

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

GasManager handle the logic of gas. It should be called in a contract

func NewGasManager

func NewGasManager(h *Host) GasManager

NewGasManager new gas manager

func (*GasManager) ChangeTGas

func (g *GasManager) ChangeTGas(name string, delta *common.Fixed, changeQuota bool) contract.Cost

ChangeTGas ...

func (*GasManager) ChangeTGasQuota

func (g *GasManager) ChangeTGasQuota(name string, delta *common.Fixed) contract.Cost

ChangeTGasQuota ...

func (*GasManager) CostGas

func (g *GasManager) CostGas(name string, gasCost *common.Fixed) error

CostGas subtract gas of a user. It is not called in a contract. Need a better design here

func (*GasManager) DelGasPledge

func (g *GasManager) DelGasPledge(name string, pledger string) contract.Cost

DelGasPledge ...

func (*GasManager) GasLimit

func (g *GasManager) GasLimit(name string) (*common.Fixed, contract.Cost)

GasLimit ...

func (*GasManager) GasPledge

func (g *GasManager) GasPledge(name string, pledger string) (*common.Fixed, contract.Cost)

GasPledge ...

func (*GasManager) GasPledgeTotal

func (g *GasManager) GasPledgeTotal(name string) (*common.Fixed, contract.Cost)

GasPledgeTotal ...

func (*GasManager) GasStock

func (g *GasManager) GasStock(name string) (*common.Fixed, contract.Cost)

GasStock `gasStock` means the gas amount at last update time.

func (*GasManager) GasUpdateTime

func (g *GasManager) GasUpdateTime(name string) (int64, contract.Cost)

GasUpdateTime ...

func (*GasManager) PGas

func (g *GasManager) PGas(name string) *common.Fixed

PGas returns the current total gas of a user. It is dynamically calculated

func (*GasManager) RefreshPGas

func (g *GasManager) RefreshPGas(name string) (contract.Cost, error)

RefreshPGas update the gas status

func (*GasManager) SetGasLimit

func (g *GasManager) SetGasLimit(name string, l *common.Fixed) contract.Cost

SetGasLimit ...

func (*GasManager) SetGasPledge

func (g *GasManager) SetGasPledge(name string, pledger string, p *common.Fixed) contract.Cost

SetGasPledge ...

func (*GasManager) SetGasPledgeTotal

func (g *GasManager) SetGasPledgeTotal(name string, r *common.Fixed) contract.Cost

SetGasPledgeTotal ...

func (*GasManager) SetGasStock

func (g *GasManager) SetGasStock(name string, gas *common.Fixed) contract.Cost

SetGasStock ...

func (*GasManager) SetGasUpdateTime

func (g *GasManager) SetGasUpdateTime(name string, t int64) contract.Cost

SetGasUpdateTime ...

func (*GasManager) TGas

func (g *GasManager) TGas(name string) (*common.Fixed, contract.Cost)

TGas ...

func (*GasManager) TGasQuota

func (g *GasManager) TGasQuota(name string) (*common.Fixed, contract.Cost)

TGasQuota Since TGas can only be transferred once, 'TGasQuota' means 'how much TGas one account can transfer out'

func (*GasManager) TotalGas

func (g *GasManager) TotalGas(name string) *common.Fixed

TotalGas ...

type Host

type Host struct {
	DBHandler
	Info
	Teller
	APIDelegate
	EventPoster
	DNS
	Authority
	GasManager
	*version.Rules
	// contains filtered or unexported fields
}

Host host struct, used as isolate of vm

func NewHost

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

NewHost get a new host

func (*Host) Call

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

Call call a new contract in this context

func (*Host) CallWithAuth

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

CallWithAuth call a new contract with permission of current contract

func (*Host) CancelDelaytx

func (h *Host) CancelDelaytx(txHash string) (contract.Cost, error)

CancelDelaytx deletes delaytx hash.

The given argument txHash is from user's input. So we should Base58Decode it first.

func (*Host) CheckAmountLimit

func (h *Host) CheckAmountLimit(amountLimit []*contract.Amount) error

CheckAmountLimit check amountLimit of tx valid

func (*Host) CheckPublisher

func (h *Host) CheckPublisher(t *tx.Tx) error

CheckPublisher check publisher of tx

func (*Host) CheckSigners

func (h *Host) CheckSigners(t *tx.Tx) error

CheckSigners check signers of tx

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

func (h *Host) IsValidAccount(name string) bool

IsValidAccount check whether account exists

func (*Host) IsValidAddress

func (h *Host) IsValidAddress(address string) bool

IsValidAddress check address

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

func (h *Host) ReadSettings()

ReadSettings read settings from db

func (*Host) SetCode

func (h *Host) SetCode(c *contract.Contract, owner string) (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) BlockTime

func (h *Info) BlockTime() (ntime int64, cost contract.Cost)

BlockTime get block time, in int64

func (*Info) ContextInfo

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

ContextInfo get context info

func (*Info) ContractName

func (h *Info) ContractName() (name string, cost contract.Cost)

ContractName get block time, in int64

func (*Info) GasLimitValue

func (h *Info) GasLimitValue() int64

GasLimitValue 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)
	Validate(con *contract.Contract) error
	Compile(con *contract.Contract) (string, error)
}

Monitor monitor interface

type Setting

type Setting struct {
	Costs map[string]contract.Cost `json:"costs"`
}

Setting in state db

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

func (t *Teller) AddCacheCost(c contract.Cost)

AddCacheCost ...

func (*Teller) CacheCost

func (t *Teller) CacheCost() contract.Cost

CacheCost ...

func (*Teller) ClearCacheCost

func (t *Teller) ClearCacheCost()

ClearCacheCost ...

func (*Teller) ClearCosts

func (t *Teller) ClearCosts()

ClearCosts ...

func (*Teller) ClearRAMCosts

func (t *Teller) ClearRAMCosts()

ClearRAMCosts ...

func (*Teller) Costs

func (t *Teller) Costs() map[string]contract.Cost

Costs ...

func (*Teller) DoPay

func (t *Teller) DoPay(witness string, gasRatio int64) (paidGas *common.Fixed, err error)

DoPay ...

func (*Teller) FlushCacheCost

func (t *Teller) FlushCacheCost()

FlushCacheCost ...

func (*Teller) GasPaid

func (t *Teller) GasPaid(publishers ...string) int64

GasPaid ...

func (*Teller) IsProducer

func (t *Teller) IsProducer(acc string) bool

IsProducer check account is producer

func (*Teller) PayCost

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

PayCost ...

func (*Teller) Privilege

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

Privilege ...

Jump to

Keyboard shortcuts

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