code

package
v0.0.0-...-a048d37 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusOK is used when contract successfully ends.
	StatusOK = 200
	// StatusErrorThreshold is the status dividing line for the normal operation of the contract
	StatusErrorThreshold = 400
	// StatusError is used when contract fails.
	StatusError = 500
)

Variables

This section is empty.

Functions

func IsStatusError

func IsStatusError(status int) bool

IsStatusError is used to determine if the given status is error

Types

type Context

type Context interface {
	Caller() string
	Args() map[string][]byte
	Method() string
	PutObject(key []byte, value []byte) error
	GetObject(key []byte) ([]byte, error)
	DeleteObject(key []byte) error
	Call(module, contract, method string, args map[string][]byte) (*Response, error)
}

GetContractState is the context in which the contract runs

type Contract

type Contract interface {
	Initialize(ctx Context) Response
}

Contract is the interface of contract

type Driver

type Driver interface {
	Serve(contract Contract)
}

Driver 接口用于抽象执行合约的框架

type Response

type Response struct {
	// Status 用于反映合约的运行结果,如果status值超过CodeErrorThreshold则认为合约执行失败
	// 所有的操作将会被回滚
	Status int `json:"status"`
	// Message 用于携带一些有用的debug信息
	Message string `json:"message"`
	// Data 字段用于存储合约执行的结果
	Body []byte `json:"body"`
}

Response is the result of the contract run

func Error

func Error(err error) Response

Error generates a response with StatusError and uses err as message

func Errors

func Errors(err string) Response

Errors generates a response with StatusError and the given message

func JSON

func JSON(body interface{}) Response

JSON is used to assist in generating a response in which the body is in JSON format

func OK

func OK(body []byte) Response

OK generates a response with StatusOK and the given body

Jump to

Keyboard shortcuts

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