eos仓库中包含的工具/程序有:
程序
eosd
可以用插件配置运行一个节点的核心EOS守护进程。示例使用的是区块生产、专用API端点和本地开发。
eosc
eosc是一个命令行工具,它为eosd 暴露的REST api提供了交互界面。为了使用eosc,您需要将端点(IP地址和端口号)设置为eosd实例,并配置eosc来加载’eosio::chain_api_plugin’。eosc包含所有的命令文件,为了了解eosc
的所有命令,只需不带参数直接运行eosc即可:
$ eosc
ERROR: RequiredError: Subcommand required
Command Line Interface to Eos Client
Usage: ./eosc [OPTIONS] SUBCOMMAND
Options:
-h,–help 打印此帮助信息并退出
-H,–host TEXT=localhost eosd 正在运行的主机
-p,–port UINT=8888 eosd正在运行的端口
–wallet-host TEXT=localhost eos-walletd正在运行的主机
–wallet-port UINT=8888 eos-walletd正在运行的端口
v,–verbose 输出错误的详细信息
Subcommands:
version 获取版本信息
create 创建各种项目,打开或者关闭区块链
get 从区块链中获取各种项目
set 设置或者更新区块链状态
transfer 将EOS从账户转移到另一个账户
net 与本地p2p网络连接交互
wallet 与本地钱包交互
benchmark 配置和执行标准
push 将任意交易添加到区块链
为了得到任何特定子命令的帮助信息,也可以不带任何参数直接运行它:
$ eosc create
ERROR: RequiredError: Subcommand required
Create various items, on and off the blockchain
Usage: ./eosc create SUBCOMMAND
Subcommands:
key 创建一个新的密匙对并打印公钥和私钥
account 在区块链上创建一个新账户
producer 在区块链上创建一个新的生产者
$ eosc create account
ERROR: RequiredError: creator
Create a newaccount on the blockchain
Usage: ./eosc create account [OPTIONS] creator name OwnerKey ActiveKey
Positionals:
creator TEXT 创建新账户的账户名称
name TEXT 新账户的名称
OwnerKey TEXT 帐户的所有者公钥
ActiveKey TEXT 账户的活动公钥
Options:
-s,–skip-signature 指定未上锁的钱包密钥不能用于给交易签名
x,–expiration 以秒为单位设置交易过期时间,默认为30s
-f,–force-unique 强制交易为唯一。这将消耗额外的带宽,并删除任何 保护,防止意外地发出相同的交易多次
eos-walletd
一个与钱包相关的插件(如HTTP接口和RPC API)加载的EOS钱包守护程序。
启动器
启动应用程序简化了跨LAN或更宽网络的多eosd节点分布。它可以通过CLI配置成每个节点的配置文件,在对等主机之间安全地分发这些文件,然后启动eosd的多个实例。
快照
一个引用自EOSIO / genesis仓库的子模块,它包含一个用于从crowdsale合约中生成一个快照的node.js应用程序,一个用于配置创世区块和其他创世相关工具的Web GUI。
工具
eoscpp
使用eoscpp生成ABI规范文件
eoscpp可以通过检查在合同源代码中声明类型的内容来生成ABI规范文件。为了表明一种类型必须导出为ABI(作为操作或表),必须在类型声明的注释中使用@ abi标记。
注释的语法如下所示:
- @abi 操作[名字1 名字2 … 名字N]
- @abi 表 [索引类型 名字] 为了能够生成ABI文件, eoscpp 调用时候必须有-g参数.
➜eoscpp -g abi.json types.hpp
Generated abi.json …
eoscpp还可以用来生成辅助函数,用于序列化/反序列化在ABI规范中定义的类型。
➜eoscpp -g abi.json -gs types.hpp
Generated abi.json …
Generated types.gen.hpp …
示例
声明一个操作
#include <eoslib/types.hpp>
#include <eoslib/string.hpp>
//@abi action
structaction_name {
uint64_t param1;
uint64_t param2;
eosio::string param3;
};
{
“types”: [],
“structs”: [{
“name”: “action_name”,
“base”: “”,
“fields”: {
“param1”: “uint64”,
“param2”: “uint64”,
“param3”: “string”
}
}
],
“actions”: [{
“action_name”: “actionname”,
“type”: “action_name”
}
],
“tables”: []
}
使用相同的接口声明多个操作
#include <eoslib/types.hpp>
#include <eoslib/string.hpp>
//@abi action action1 action2
structaction_name {
uint64_t param1;
uint64_t param2;
eosio: :string param3;
};
{
“types”: [],
“structs”: [{
“name”: “action_name”,
“base”: “”,
“fields”: {
“param1”: “uint64”,
“param2”: “uint64”,
“param3”: “string”
}
}
],
“actions”: [{
“action_name”: “action1”,
“type”: “action_name”
},{
“action_name”: “action2”,
“type”: “action_name”
}
],
“tables”: []
}
声明一个表
#include <eoslib/types.hpp>
#include <eoslib/string.hpp>
//@abi table
structmy_table {
uint64_t key;
};
{
“types”: [],
“structs”: [{
“name”: “my_table”,
“base”: “”,
“fields”: {
“key”: “uint64”
}
}
],
“actions”: [],
“tables”: [{
“table_name”: “mytable”,
“index_type”: “i64”,
“key_names”: [
“key”
],
“key_types”: [
“uint64”
],
“type”: “my_table”
}
]
}
声明具有显式索引类型的表
*具有3 uint64_t的struct可以是i64或i64i64i64
#include <eoslib/types.hpp>
//@abi table i64
structmy_new_table {
uint64_t key;
uint64_t name;
uint64_t age;
};
{
“types”: [],
“structs”: [{
“name”: “my_new_table”,
“base”: “”,
“fields”: {
“key”: “uint64”,
“name”: “uint64”,
“age”: “uint64”
}
}
],
“actions”: [],
“tables”: [{
“table_name”: “mynewtable”,
“index_type”: “i64”,
“key_names”: [
“key”
],
“key_types”: [
“uint64”
],
“type”: “my_new_table”
}
]
}
使用相同结构声明一个表和一个操作
#include <eoslib/types.hpp>
#include <eoslib/string.hpp>
/*
* @abi table
* @abi action
*/
structmy_type {
eosio::string key;
eosio::name value;
};
{
“types”: [],
“structs”: [{
“name”: “my_type”,
“base”: “”,
“fields”: {
“key”: “string”,
“value”: “name”
}
}
],
“actions”: [{
“action_name”: “mytype”,
“type”: “my_type”
}
],
“tables”: [{
“table_name”: “mytype”,
“index_type”: “str”,
“key_names”: [
“key”
],
“key_types”: [
“string”
],
“type”: “my_type”
}
]
}
定义输出的示例
#include <eoslib/types.hpp>
structsimple {
uint64_t u64;
};
typedefsimple simple_alias;
typedefeosio::name name_alias;
//@abi action
structaction_one : simple_alias {
uint32_t u32;
name_alias name;
};
{
“types”: [{
“new_type_name”: “simple_alias”,
“type”: “simple”
},{
“new_type_name”: “name_alias”,
“type”: “name”
}
],
“structs”: [{
“name”: “simple”,
“base”: “”,
“fields”: {
“u64”: “uint64”
}
},{
“name”: “action_one”,
“base”: “simple_alias”,
“fields”: {
“u32”: “uint32”,
“name”: “name_alias”
}
}
],
“actions”: [{
“action_name”: “actionone”,
“type”: “action_one”
}
],
“tables”: []
}
使用生成的序列化/反序列化功能
#include <eoslib/types.hpp>
#include <eoslib/string.hpp>
structsimple {
uint32_t u32;
fixed_string16 s16;
};
structmy_complex_type {
uint64_t u64;
eosio::string str;
simple simple;
bytes bytes;
public_key pub;
};
typedefmy_complex_type complex;
//@abi action
structtest_action {
uint32_t u32;
complex cplx;
};
voidapply( uint64_t code, uint64_t action ) {
if( code == N(mycontract) ) {
if( action == N(testaction) ) {
auto msg = eosio::current_message<test_action>();
eosio::print(“test_action content\n”);
eosio::dump(msg);
bytes b = eosio::raw::pack(msg);
printhex(b.data, b.len);
}
}
}
注意:表名和操作名称不能使用下划线(“_”)。
调用带有测试值的合约
eosc push message mycontract testaction ‘{“u32″:”1000”, “cplx”:{“u64″:”472”, “str”:”hello”, “bytes”:”B0CA”, “pub”:”EOS8CY2pCW5THmzvPTgEh5WLEAxgpVFXaPogPvgvVpVWCYMRdzmwx”, “simple”:{“u32″:”164″,”s16″:”small-string”}}}’-S mycontract
将会在eosd控制台产生以下输出:
test_action content
u32:[1000]
cplx:[
u64:[472]
str:[hello]
simple:[
u32:[164]
s16:[small-string]
]
bytes:[b0ca]
pub:[03b41078f445628882fe8c1e629909cbbd67ff4b592b832264dac187ac730177f1]
]
e8030000d8010000000000000568656c6c6fa40000000c736d616c6c2d737472696e6702b0ca03b41078f445628882fe8c1e629909cbbd67ff4b592b832264dac187ac730177f1