有奖捉虫:办公协同&微信生态&物联网文档专题 HOT
ChainMaker C++ 语言版本智能合约有丰富的 API 接口,供用户在撰写智能合约的时候与链进行交互,代码实现详情可以参考API 接口代码实现
从逻辑方面划分,可将 API 划分为以下类型:

账本交互

接口
说明
bool get_object(const std::string& key, std::string* value){}
获取key为"key"的值。
bool put_object(const std::string& key, const std::string& value){}
存储key为"key"的值,注意key长度不允许超过64,且只允许大小写字母、数字、下划线、减号、小数点符号。
bool delete_object(const std::string& key) {}
删除key为"key"的值。
bool call(const std::string& contract, const std::string& method, const std::map
& args, Response* response){}
跨合约调用。

参数处理

接口
说明
bool arg(const std::string& name, std::string& value){}
该接口可返回属性名为 “name” 的参数的属性值。需要注意的是通过arg接口返回的参数,全部为字符串,合约开发者有必要将其他数据类型的参数与字符串做转换,包括atoi、itoa、自定义序列化方式等。

其他辅助类

接口
说明
void success(const std::string& body) {}
返回成功的结果
void error(const std::string& body) {}
返回失败结果
void log(const std::string& body) {}
输出日志事件。查看方式为在链配置的log.yml中,开启vm:debug即可看到类似:wxvm log>> + msg
bool emit_event(const std::string &topic, int data_amount, const std::string data, ...)
发送合约事件