从逻辑方面划分,可将 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, EasyCodecItems *args, std::string *resp){} | 跨合约调用。 |
参数处理
接口 | 说明 |
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, ...) | 发送合约事件 |