Documentation ¶
Index ¶
- Constants
- Variables
- func BytesPrefix(prefix []byte) ([]byte, []byte)
- func FormatBytesResult(result []byte, parameters map[string][]byte, ...) ([]byte, error)
- func FormatObjectResult(result interface{}, parameters map[string][]byte, ...) ([]byte, error)
- func GetChainConfig(txSimContext protocol.TxSimContext) (*configPb.ChainConfig, error)
- func GetChainConfigNoRecord(txSimContext protocol.TxSimContext) (*configPb.ChainConfig, error)
- func GetGas(contractName, method string, defaultGas uint64) uint64
- func ResultBytesAndError(returnResult []byte, event []*common.ContractEvent, err error) *common.ContractResult
- func ResultError(err error) *common.ContractResult
- func ResultErrorWithGasUsed(err error, gas uint64) *common.ContractResult
- func ResultJson(obj interface{}) (*common.ContractResult, error)
- func ResultSuccess(result []byte, gas uint64) *common.ContractResult
- func WrapEventResult(...) ...
- func WrapResultFunc(...) ...
- type BaseContract
- type Contract
- type ContractFunc
Constants ¶
const DefaultGas = uint64(100000)
DefaultGas 默认的Gas值
Variables ¶
var ( // ErrContractIdIsNil err msg ErrContractIdIsNil = errors.New("the contractId is empty") // ErrContractNotFound err msg ErrContractNotFound = errors.New("the contractName is not exist") // ErrTxTypeNotSupport err msg ErrTxTypeNotSupport = errors.New("the txType does not support") // ErrMethodNotFound err msg ErrMethodNotFound = errors.New("the method does not found") // ErrParamsEmpty err msg ErrParamsEmpty = errors.New("the params is empty") // ErrContractName err msg ErrContractName = errors.New("the contractName is error") // ErrOutOfRange err msg ErrOutOfRange = errors.New("out of range") // ErrParams err msg ErrParams = errors.New("params is error") // ErrSequence err msg ErrSequence = errors.New("sequence is error") // ErrUnmarshalFailed err msg ErrUnmarshalFailed = errors.New("unmarshal is error") )
Functions ¶
func BytesPrefix ¶
BytesPrefix 根据前缀构造范围查询用的start和limit @param prefix @return []byte @return []byte
func FormatBytesResult ¶
func FormatBytesResult(result []byte, parameters map[string][]byte, defaultFormat syscontract.ContentType) ( []byte, error)
FormatBytesResult 按照指定的ContentType格式化成字节数组 @param result @param parameters @param defaultFormat @return []byte @return error
func FormatObjectResult ¶
func FormatObjectResult(result interface{}, parameters map[string][]byte, defaultFormat syscontract.ContentType) ( []byte, error)
FormatObjectResult 按照指定的ContentType格式化对象成字节数组 @param result @param parameters @param defaultFormat @return []byte @return error
func GetChainConfig ¶
func GetChainConfig(txSimContext protocol.TxSimContext) (*configPb.ChainConfig, error)
GetChainConfig 获得当前的链配置,记入读集 @param txSimContext @return *configPb.ChainConfig @return error
func GetChainConfigNoRecord ¶
func GetChainConfigNoRecord(txSimContext protocol.TxSimContext) (*configPb.ChainConfig, error)
GetChainConfigNoRecord 获得当前的链配置,不记入读集 @param txSimContext @return *configPb.ChainConfig @return error
func GetGas ¶
GetGas 获得一个系统合约的某个方法的Gas值,如果没有配置,则返回默认的Gas值
func ResultBytesAndError ¶
func ResultBytesAndError(returnResult []byte, event []*common.ContractEvent, err error) *common.ContractResult
ResultBytesAndError make *common.ContractResult with data,err
func ResultError ¶
func ResultError(err error) *common.ContractResult
ResultError make *common.ContractResult with err
func ResultErrorWithGasUsed ¶
func ResultErrorWithGasUsed(err error, gas uint64) *common.ContractResult
ResultErrorWithGasUsed 构造一个包含Error结果的ContractResult对象 @param err @param gas @return *common.ContractResult
func ResultJson ¶
func ResultJson(obj interface{}) (*common.ContractResult, error)
ResultJson 构造一个包含输入对象Json作为Result的ContractResult对象 @param obj @return *common.ContractResult @return error
func ResultSuccess ¶
func ResultSuccess(result []byte, gas uint64) *common.ContractResult
ResultSuccess make *common.ContractResult with data
func WrapEventResult ¶
func WrapEventResult(f func(txSimContext protocol.TxSimContext, parameters map[string][]byte) ( []byte, []*common.ContractEvent, error)) func( txSimContext protocol.TxSimContext, parameters map[string][]byte) *common.ContractResult
WrapEventResult 包装原有的返回[]byte的函数,改为返回ContractResult和事件的函数,特别注意:若改为调用此方法则需要做兼容
Types ¶
type BaseContract ¶
type BaseContract struct {
// contains filtered or unexported fields
}
BaseContract 所有Native合约的基础合约,提供了方法注册和获取
func (*BaseContract) GetMethod ¶
func (g *BaseContract) GetMethod(methodName string, blockVersion uint32) ContractFunc
GetMethod 根据合约方法名和版本获得对应的合约函数 @param methodName @param blockVersion @return ContractFunc
func (*BaseContract) InitMethod ¶
func (g *BaseContract) InitMethod(ms map[string]ContractFunc)
InitMethod 初始化一堆没有版本限制的方法 @param ms
func (*BaseContract) RegisterMethod ¶
func (g *BaseContract) RegisterMethod(methodName string, f ContractFunc, startVersion uint32, endVersion uint32)
RegisterMethod 注册一个新的合约方法,并知道生效和失效的版本 @param methodName @param f @param startVersion @param endVersion
type Contract ¶
type Contract interface { //GetMethod get register method by name GetMethod(methodName string, blockVersion uint32) ContractFunc }
Contract define native Contract interface
type ContractFunc ¶
type ContractFunc func(context protocol.TxSimContext, params map[string][]byte) *common.ContractResult
ContractFunc invoke contract method, return result