smart

package
v0.0.0-...-b8f9f05 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CallInit is a flag for calling init function of the contract
	CallInit = 0x01
	// CallCondition is a flag for calling condition function of the contract
	CallCondition = 0x02
	// CallAction is a flag for calling action function of the contract
	CallAction = 0x04
	// CallRollback is a flag for calling rollback function of the contract
	CallRollback = 0x08
)

Variables

View Source
var (
	ErrCurrentBalance = errors.New(`current balance is not enough`)
	ErrDiffKeys       = errors.New(`Contract and user public keys are different`)
	ErrEmptyPublicKey = errors.New(`empty public key`)
	ErrFounderAccount = errors.New(`Unknown founder account`)
	ErrFuelRate       = errors.New(`Fuel rate must be greater than 0`)
	ErrIncorrectSign  = errors.New(`incorrect sign`)
	ErrInvalidValue   = errors.New(`Invalid value`)
	ErrUnknownNodeID  = errors.New(`Unknown node id`)
	ErrWrongPriceFunc = errors.New(`Wrong type of price function`)
)

Functions

func Activate

func Activate(sc *SmartContract, tblid int64, state int64) error

Activate sets Active status of the contract in smartVM

func ActivateContract

func ActivateContract(tblid, state int64, active bool)

ActivateContract sets Active status of the contract in smartVM

func AddressToID

func AddressToID(input string) (addr int64)

AddressToID converts the string representation of the wallet number to a numeric

func CheckSignature

func CheckSignature(i *map[string]interface{}, name string) error

CheckSignature checks the additional signatures for the contract

func ColumnCondition

func ColumnCondition(sc *SmartContract, tableName, name, coltype, permissions string) error

ColumnCondition is contract func

func Compile

func Compile(src string, owner *script.OwnerInfo) error

Compile compiles contract source code in smartVM

func CompileBlock

func CompileBlock(src string, owner *script.OwnerInfo) (*script.Block, error)

CompileBlock calls CompileBlock for smartVM

func CompileContract

func CompileContract(sc *SmartContract, code string, state, id, token int64) (interface{}, error)

CompileContract is compiling contract

func CompileEval

func CompileEval(src string, prefix uint32) error

CompileEval calls CompileEval for smartVM

func ContractAccess

func ContractAccess(sc *SmartContract, names ...interface{}) bool

ContractAccess checks whether the name of the executable contract matches one of the names listed in the parameters.

func ContractConditions

func ContractConditions(sc *SmartContract, names ...interface{}) (bool, error)

ContractConditions calls the 'conditions' function for each of the contracts specified in the parameters

func CreateColumn

func CreateColumn(sc *SmartContract, tableName, name, coltype, permissions string) error

CreateColumn is creating column

func CreateEcosystem

func CreateEcosystem(sc *SmartContract, wallet int64, name string) (int64, error)

CreateEcosystem creates a new ecosystem

func CreateTable

func CreateTable(sc *SmartContract, name string, columns, permissions string) error

CreateTable is creating smart contract table

func DBInsert

func DBInsert(sc *SmartContract, tblname string, params string, val ...interface{}) (qcost int64, ret int64, err error)

DBInsert inserts a record into the specified database table

func DBSelect

func DBSelect(sc *SmartContract, tblname string, columns string, id int64, order string, offset, limit, ecosystem int64,
	where string, params []interface{}) (int64, []interface{}, error)

DBSelect returns an array of values of the specified columns when there is selection of data 'offset', 'limit', 'where'

func DBUpdate

func DBUpdate(sc *SmartContract, tblname string, id int64, params string, val ...interface{}) (qcost int64, err error)

DBUpdate updates the item with the specified id in the table

func DBUpdateExt

func DBUpdateExt(sc *SmartContract, tblname string, column string, value interface{},
	params string, val ...interface{}) (qcost int64, err error)

DBUpdateExt updates the record in the specified table. You can specify 'where' query in params and then the values for this query

func Date

func Date(time_format string, timestamp int64) string

Formats timestamp to specified date format

func Deactivate

func Deactivate(sc *SmartContract, tblid int64, state int64) error

DeactivateContract sets Active status of the contract in smartVM

func EcosysParam

func EcosysParam(sc *SmartContract, name string) string

EcosysParam returns the value of the specified parameter for the ecosystem

func EmbedFuncs

func EmbedFuncs(vm *script.VM, vt script.VMType)

EmbedFuncs is extending vm with embedded functions

func Eval

func Eval(sc *SmartContract, condition string) error

Eval evaluates the condition

func EvalCondition

func EvalCondition(sc *SmartContract, table, name, condfield string) error

EvalCondition gets the condition and check it

func EvalIf

func EvalIf(src string, state uint32, extend *map[string]interface{}) (bool, error)

EvalIf calls EvalIf for smartVM

func Extend

func Extend(ext *script.ExtendData)

Extend set extended variable and functions in smartVM

func ExtendCost

func ExtendCost(ext func(string) int64)

ExtendCost sets the cost of calling extended obj in smartVM

func ExternOff

func ExternOff()

ExternOff switches off the extern compiling mode in smartVM

func Float

func Float(v interface{}) (ret float64)

Float converts the value to float64

func FlushBlock

func FlushBlock(root *script.Block)

FlushBlock calls FlushBlock for smartVM

func FlushContract

func FlushContract(sc *SmartContract, iroot interface{}, id int64, active bool) error

FlushContract is flushing contract

func FuncCallsDB

func FuncCallsDB(funcCallsDB map[string]struct{})

func GetBytea

func GetBytea(db *model.DbTransaction, table string) map[string]bool

func GetMapKeys

func GetMapKeys(in map[string]interface{}) []interface{}

Returns the array of keys of the map

func GetTableName

func GetTableName(sc *SmartContract, tblname string, ecosystem int64) string

func GetTestValue

func GetTestValue(name string) string

GetTestValue returns the test value of the specified key

func GetUsedContracts

func GetUsedContracts(name string, state uint32, full bool) []string

GetUsedContracts returns the list of contracts which are called from the specified contract

func GetVM

func GetVM(vde bool, ecosystemID int64) *script.VM

GetVM is returning smart vm

func HMac

func HMac(key, data string, raw_output bool) (ret string, err error)

func HTTPPostJSON

func HTTPPostJSON(requrl string, headers map[string]interface{}, json_str string) (string, error)

HTTPPostJSON sends post http request with json

func HTTPRequest

func HTTPRequest(requrl, method string, headers map[string]interface{},
	params map[string]interface{}) (string, error)

HTTPRequest sends http request

func HexToBytes

func HexToBytes(hexdata string) ([]byte, error)

HexToBytes converts the hexadecimal representation to []byte

func IDToAddress

func IDToAddress(id int64) (out string)

IDToAddress converts the identifier of account to a string of the form XXXX -...- XXXX

func Int

func Int(val string) int64

Int converts a string to a number

func IsObject

func IsObject(sc *SmartContract, name string, state int64) bool

IsObject returns true if there is the specified contract

func JSONToMap

func JSONToMap(input string) (map[string]interface{}, error)

JSONToMap is converting json to map

func Join

func Join(input []interface{}, sep string) string

Join is joining input with separator

func LangRes

func LangRes(sc *SmartContract, idRes, lang string) string

LangRes returns the language resource

func Len

func Len(in []interface{}) int64

Len returns the length of the slice

func LoadContract

func LoadContract(transaction *model.DbTransaction, prefix string) (err error)

LoadContract reads and compiles contract of new state

func LoadContracts

func LoadContracts(transaction *model.DbTransaction) (err error)

LoadContracts reads and compiles contracts from smart_contracts tables

func LoadVDEContracts

func LoadVDEContracts(transaction *model.DbTransaction, prefix string) (err error)

func Money

func Money(v interface{}) (ret decimal.Decimal)

Money converts the value into a numeric type for money

func PermColumn

func PermColumn(sc *SmartContract, tableName, name, permissions string) error

PermColumn is contract func

func PermTable

func PermTable(sc *SmartContract, name, permissions string) error

PermTable is changing permission of table

func PrefixName

func PrefixName(table string) (prefix, name string)

func PubToID

func PubToID(hexkey string) int64

PubToID returns a numeric identifier for the public key specified in the hexadecimal form.

func Random

func Random(min int64, max int64) (int64, error)

func Replace

func Replace(s, old, new string) string

Replace replaces old substrings to new substrings

func RollbackColumn

func RollbackColumn(sc *SmartContract, tableName, name string) error

RollbackColumn is rolling back column

func RollbackEcosystem

func RollbackEcosystem(sc *SmartContract) error

RollbackEcosystem is rolling back ecosystem

func RollbackTable

func RollbackTable(sc *SmartContract, name string) error

RollbackTable is rolling back table

func RowConditions

func RowConditions(sc *SmartContract, tblname string, id int64) error

RowConditions checks conditions for table row by id

func Run

func Run(block *script.Block, params []interface{}, extend *map[string]interface{}) (ret []interface{}, err error)

Run executes Block in smartVM

func Sha256

func Sha256(text string) string

Sha256 returns SHA256 hash value

func Size

func Size(s string) int64

Size returns the length of the string

func SortedKeys

func SortedKeys(m map[string]interface{}) []interface{}

Returns the sorted array of keys of the map

func Split

func Split(input, sep string) []interface{}

Split splits the input string to array

func StackCont

func StackCont(sc interface{}, name string)

StackCont adds an element to the stack of contract call or removes the top element when name is empty

func Str

func Str(v interface{}) (ret string)

Str converts the value to a string

func Substr

func Substr(s string, off int64, slen int64) string

Substr returns the substring of the string

func SysFuel

func SysFuel(state int64) string

SysFuel returns the fuel rate

func SysParamInt

func SysParamInt(name string) int64

SysParamInt returns the value of the system parameter

func SysParamString

func SysParamString(name string) string

SysParamString returns the value of the system parameter

func TableConditions

func TableConditions(sc *SmartContract, name, columns, permissions string) (err error)

TableConditions is contract func

func UpdateCron

func UpdateCron(sc *SmartContract, id int64) error

func UpdateLang

func UpdateLang(sc *SmartContract, name, trans string)

UpdateLang updates language resource

func UpdateSysParam

func UpdateSysParam(sc *SmartContract, name, value, conditions string) (int64, error)

UpdateSysParam updates the system parameter

func VMCompileBlock

func VMCompileBlock(vm *script.VM, src string, owner *script.OwnerInfo) (*script.Block, error)

VMCompileBlock is compiling block

func VMCompileEval

func VMCompileEval(vm *script.VM, src string, prefix uint32) error

func VMEvalIf

func VMEvalIf(vm *script.VM, src string, state uint32, extend *map[string]interface{}) (bool, error)

func VMFlushBlock

func VMFlushBlock(vm *script.VM, root *script.Block)

func VMObjectExists

func VMObjectExists(vm *script.VM, name string, state uint32) bool

func VMRun

func VMRun(vm *script.VM, block *script.Block, params []interface{}, extend *map[string]interface{}) (ret []interface{}, err error)

func ValidateCondition

func ValidateCondition(sc *SmartContract, condition string, state int64) error

ValidateCondition checks if the condition can be compiled

func ValidateCron

func ValidateCron(cronSpec string) error

Types

type Contract

type Contract struct {
	Name          string
	Called        uint32
	FreeRequest   bool
	TxPrice       int64   // custom price for citizens
	TxGovAccount  int64   // state wallet
	EGSRate       float64 // money/EGS rate
	TableAccounts string
	StackCont     []string // Stack of called contracts
	Extend        *map[string]interface{}
	Block         *script.Block
}

Contract contains the information about the contract.

func GetContract

func GetContract(name string, state uint32) *Contract

GetContract returns true if the contract exists in smartVM

func GetContractByID

func GetContractByID(id int32) *Contract

GetContractByID returns true if the contract exists

func VMGetContract

func VMGetContract(vm *script.VM, name string, state uint32) *Contract

func VMGetContractByID

func VMGetContractByID(vm *script.VM, id int32) *Contract

func (*Contract) GetFunc

func (contract *Contract) GetFunc(name string) *script.Block

GetFunc returns the block of the specified function in the contract

type SignRes

type SignRes struct {
	Param string `json:"name"`
	Text  string `json:"text"`
}

SignRes contains the data of the signature

type SmartContract

type SmartContract struct {
	VDE           bool
	Rollback      bool
	SysUpdate     bool
	VM            *script.VM
	TxSmart       tx.SmartContract
	TxData        map[string]interface{}
	TxContract    *Contract
	TxCost        int64           // Maximum cost of executing contract
	TxUsedCost    decimal.Decimal // Used cost of CPU resources
	BlockData     *utils.BlockData
	TxHash        []byte
	PublicKeys    [][]byte
	DbTransaction *model.DbTransaction
}

SmartContract is storing smart contract data

func (*SmartContract) AccessColumns

func (sc *SmartContract) AccessColumns(table string, columns *[]string, update bool) error

AccessColumns checks access rights to the columns

func (*SmartContract) AccessRights

func (sc *SmartContract) AccessRights(condition string, iscondition bool) error

AccessRights checks the access right by executing the condition value

func (*SmartContract) AccessTable

func (sc *SmartContract) AccessTable(table, action string) error

func (*SmartContract) AccessTablePerm

func (sc *SmartContract) AccessTablePerm(table, action string) (map[string]string, error)

AccessTable checks the access right to the table

func (*SmartContract) CallContract

func (sc *SmartContract) CallContract(flags int) (string, error)

CallContract calls the contract functions according to the specified flags

func (*SmartContract) EvalIf

func (sc *SmartContract) EvalIf(conditions string) (bool, error)

EvalIf counts and returns the logical value of the specified expression

func (*SmartContract) GetContractLimit

func (sc *SmartContract) GetContractLimit() (ret int64)

GetContractLimit returns the default maximal cost of contract

func (SmartContract) GetLogger

func (sc SmartContract) GetLogger() *log.Entry

GetLogger is returning logger

func (*SmartContract) IsCustomTable

func (sc *SmartContract) IsCustomTable(table string) (isCustom bool, err error)

type TxSignJSON

type TxSignJSON struct {
	ForSign string    `json:"forsign"`
	Field   string    `json:"field"`
	Title   string    `json:"title"`
	Params  []SignRes `json:"params"`
}

TxSignJSON is a structure for additional signs of transaction

Jump to

Keyboard shortcuts

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