div#pop_ad { opacity: 0; }

{
"expiration": "2018-04-01T15:20:44",
"region": 0,
"ref_block_num": 42580,
"ref_block_prefix": 3987474256,
"net_usage_words": 21,
"kcpu_usage": 1000,
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "eosio.token",
"name": "issue",
"authorization": [{
"actor": "eosio",
"permission": "active"
}
],
"data": "00000000007015d640420f000000000004454f5300000000046d656d6f"
}
],
"signatures": [
""
],
"context_free_data": []
}
{
"expiration": "...",
"region": 0,
"ref_block_num": ...,
"ref_block_prefix": ...,
"net_usage_words": ..,
"kcpu_usage": ..,
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "...",
"name": "...",
"authorization": [{
"actor": "...",
"permission": "..."
}
],
"data": "..."
}, {
"account": "...",
"name": "...",
"authorization": [{
"actor": "...",
"permission": "..."
}
],
"data": "..."
}
],
"signatures": [
""
],
"context_free_data": []
}
$ eosiocpp -n ${contract}
${contract}.abi ${contract}.hpp ${contract}.cpp
#include
/**
* The init() and apply() methods must have C calling convention so that the blockchain can lookup and
* call these methods.
*/
extern "C" {
/**
* This method is called once when the contract is published or updated.
*/
void init() {
eosio::print( "Init World!\\n" ); // Replace with actual code
}
/// The apply method implements the dispatch of actions to this contract
void apply( uint64_t code, uint64_t action ) {
eosio::print( "Hello World: ", eosio::name(code), "->", eosio::name(action), "\\n" );
}
} // extern "C"
if (code == N(${contract_name}) {
// your handler to respond to particular action
}
if (action == N(${action_name}) {
//your handler to respond to a particular action
}
$ eosiocpp -o ${contract}.wast ${contract}.cpp
$ eosiocpp -g ${contract}.abi ${contract}.hpp
{
"types": [{
"new_type_name": "account_name",
"type": "name"
}
],
"structs": [{
"name": "transfer",
"base": "",
"fields": {
"from": "account_name",
"to": "account_name",
"quantity": "uint64"
}
},{
"name": "account",
"base": "",
"fields": {
"account": "name",
"balance": "uint64"
}
}
],
"actions": [{
"action": "transfer",
"type": "transfer"
}
],
"tables": [{
"table": "account",
"type": "account",
"index_type": "i64",
"key_names" : ["account"],
"key_types" : ["name"]
}
]
}
"structs": [{
"name": "transfer",
"base": "",
"fields": {
"from": "account_name",
"to": "account_name",
"quantity": "uint64"
}
},{
{
"types": [{
"new_type_name": "account_name",
"type": "name"
}
],
...
调试最主要的方法就是用**Caveman Debugging**,我们增强了printing的功能,他可以去输出变量的值并且检查合约的流程。Printing可以通过下面API被合约使用:
这是c([https://github.com/EOSIO/eos/blob/master/contracts/eoslib/print.h](https://github.com/EOSIO/eos/blob/master/contracts/eoslib/print.h))
这是 C++([https://github.com/EOSIO/eos/blob/master/contracts/eoslib/print.hpp](https://github.com/EOSIO/eos/blob/master/contracts/eoslib/print.hpp)) . C++的API是对C的封装,所以大多数我们使用C++的API。
#includedebug.abi
extern "C" {
void init() {
}
void apply( uint64_t code, uint64_t action ) {
if (code == N(debug)) {
eosio::print("Code is debug\\n");
if (action == N(foo)) {
eosio::print("Action is foo\\n");
debug::foo f = eosio::current_message();
if (f.amount >= 100) {
eosio::print("Amount is larger or equal than 100\\n");
} else {
eosio::print("Amount is smaller than 100\\n");
eosio::print("Increase amount by 10\\n");
f.amount += 10;
eosio::print(f);
}
}
}
}
} // extern "C"
{ "structs": [{ "name": "foo", "base": "", "fields": { "from": "account_name", "to": "account_name", "amount": "uint64" } } ], "actions": [{ "action_name": "foo", "type": "foo" } ] }
$ eosiocpp -o debug.wast debug.cpp
$ cleos set contract debug debug.wast debug.abi
$ cleos push message debug foo {"from":"inita", "to":"initb", "amount":10} --scope debug
Code is debug
Action is foo
Amount is smaller than 100
Increase amount by 10
Foo from inita to initb with amount 20
添加新手交流群:币种分析、每日早晚盘分析
添加助理微信,一对一亲自指导:YoYo8abc