diff --git a/unittests/actiondemo/actiondemo.abi b/unittests/actiondemo/actiondemo.abi index eb3c15c7c13..b02aa55371d 100644 --- a/unittests/actiondemo/actiondemo.abi +++ b/unittests/actiondemo/actiondemo.abi @@ -1,119 +1,159 @@ { - "____comment": "This file was generated by eosio-abigen. DO NOT EDIT - 2019-01-07T10:42:22", - "version": "eosio::abi/1.0", - "types": [], - "structs": [{ - "name": "seedobj", - "base": "", - "fields": [{ - "name": "id", - "type": "uint64" - },{ - "name": "create", - "type": "time_point" - },{ - "name": "seedstr", - "type": "string" - },{ - "name": "txid", - "type": "string" - },{ - "name": "action", - "type": "uint64" + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Sat Apr 27 08:00:01 2019", + "version": "eosio::abi/1.1", + "structs": [ + { + "name": "apply", + "base": "", + "fields": [ + { + "name": "contract", + "type": "name" + }, + { + "name": "act", + "type": "name" + } + ] + }, + { + "name": "args", + "base": "", + "fields": [ + { + "name": "loop", + "type": "uint64" + }, + { + "name": "num", + "type": "uint64" + } + ] + }, + { + "name": "args_name", + "base": "", + "fields": [ + { + "name": "name", + "type": "name" + } + ] + }, + { + "name": "argsinline", + "base": "", + "fields": [ + { + "name": "payer", + "type": "name" + }, + { + "name": "in", + "type": "name" + } + ] + }, + { + "name": "clear", + "base": "", + "fields": [] + }, + { + "name": "generate", + "base": "", + "fields": [ + { + "name": "t", + "type": "args" + } + ] + }, + { + "name": "hascontract", + "base": "", + "fields": [ + { + "name": "t", + "type": "args_name" + } + ] + }, + { + "name": "inlineact", + "base": "", + "fields": [ + { + "name": "t", + "type": "argsinline" + } + ] + }, + { + "name": "seedobj", + "base": "", + "fields": [ + { + "name": "id", + "type": "uint64" + }, + { + "name": "create", + "type": "time_point" + }, + { + "name": "seedstr", + "type": "string" + }, + { + "name": "txid", + "type": "string" + }, + { + "name": "action", + "type": "uint64" + } + ] } - ] - },{ - "name": "args", - "base": "", - "fields": [{ - "name": "loop", - "type": "uint64" - },{ - "name": "num", - "type": "uint64" + ], + "types": [], + "actions": [ + { + "name": "apply", + "type": "apply", + "ricardian_contract": "" + }, + { + "name": "clear", + "type": "clear", + "ricardian_contract": "" + }, + { + "name": "generate", + "type": "generate", + "ricardian_contract": "" + }, + { + "name": "hascontract", + "type": "hascontract", + "ricardian_contract": "" + }, + { + "name": "inlineact", + "type": "inlineact", + "ricardian_contract": "" } - ] - },{ - "name": "generate", - "base": "", - "fields": [{ - "name": "t", - "type": "args" + ], + "tables": [ + { + "name": "seedobjs", + "type": "seedobj", + "index_type": "i64", + "key_names": [], + "key_types": [] } - ] - },{ - "name": "clear", - "base": "", - "fields": [] - },{ - "name": "args_name", - "base": "", - "fields": [{ - "name": "name", - "type": "name" - } - ] - },{ - "name": "hascontract", - "base": "", - "fields": [{ - "name": "t", - "type": "args_name" - } - ] - },{ - "name": "args_inline", - "base": "", - "fields": [{ - "name": "payer", - "type": "name" - },{ - "name": "in", - "type": "name" - } - ] - },{ - "name": "inlineact", - "base": "", - "fields": [{ - "name": "t", - "type": "args_inline" - } - ] - } - ], - "actions": [{ - "name": "generate", - "type": "generate", - "ricardian_contract": "" - },{ - "name": "clear", - "type": "clear", - "ricardian_contract": "" - },{ - "name": "hascontract", - "type": "hascontract", - "ricardian_contract": "" - },{ - "name": "inlineact", - "type": "inlineact", - "ricardian_contract": "" - } - ], - "tables": [{ - "name": "seedobjs", - "index_type": "i64", - "key_names": [ - "id" - ], - "key_types": [ - "uint64" - ], - "type": "seedobj" - } - ], - "ricardian_clauses": [], - "error_messages": [], - "abi_extensions": [], - "variants": [] + ], + "ricardian_clauses": [], + "variants": [], + "abi_extensions": [] } \ No newline at end of file diff --git a/unittests/actiondemo/actiondemo.cpp b/unittests/actiondemo/actiondemo.cpp index 88fb113800e..0d668686bd0 100644 --- a/unittests/actiondemo/actiondemo.cpp +++ b/unittests/actiondemo/actiondemo.cpp @@ -1,25 +1,24 @@ #include "actiondemo.hpp" -#include "../../contracts/eosiolib/print.hpp" -#include "../../contracts/eosiolib/types.hpp" -#include "../../contracts/eosiolib/transaction.h" +#include +#include +#include namespace spaceaction { - void actiondemo::apply( account_name code, account_name act ) { - + void actiondemo::apply( name code, name act ) { if( code != _self ) return; - + switch( act ) { - case N(generate): + case "generate"_n: generate(unpack_action_data()); return; - case N(inlineact): - inlineact(unpack_action_data()); - case N(clear): + case "inlineact"_n: + inlineact(unpack_action_data()); + case "clear"_n: clear(); return; - case N(hascontract): + case "hascontract"_n: hascontract(unpack_action_data()); return; } @@ -27,7 +26,7 @@ namespace spaceaction { void actiondemo::clear(){ //require_auth(_self); - seedobjs table(_self, _self); + seedobjs table{_self, _self.value}; auto iter = table.begin(); while (iter != table.end()) { @@ -54,17 +53,18 @@ namespace spaceaction { checksum256 code; get_contract_code(t.name, &code); - std::string s = to_hex((char*)&code.hash, 32); + std::string s = to_hex((char*)&code, 32); print_f("% contract_code:%", name{t.name}.to_string(),s); // } } void actiondemo::generate(const args& t){ - for (int i = 0; i < t.loop; ++i) { - transaction_id_type txid; + // for (int i = 0; i < 1; ++i) + // { + checksum256 txid; get_transaction_id(&txid); - std::string tx = to_hex((char*)&txid.hash, 32); + std::string tx = to_hex((char*)&txid, 32); uint64_t seq = 0; get_action_sequence(&seq); @@ -78,7 +78,7 @@ namespace spaceaction { std::string seedstr = to_hex(buf,size); - seedobjs table(_self, _self); + seedobjs table(_self, _self.value); uint64_t count = 0; for (auto itr = table.begin(); itr != table.end(); ++itr) { ++count; @@ -92,10 +92,10 @@ namespace spaceaction { a.action = seq; }); print_f("self:%, loop:%, count:%, seedstr:%", name{_self}.to_string(), t.loop, count, r->seedstr); - } + // } } - void actiondemo::inlineact(const args_inline& t){ + void actiondemo::inlineact(const argsinline& t){ auto& payer = t.payer; args gen; gen.loop = 1; @@ -103,21 +103,38 @@ namespace spaceaction { generate(gen); - if(t.in != 0) + if(t.in != ""_n) { - INLINE_ACTION_SENDER(spaceaction::actiondemo, generate)( t.in, {payer,N(active)}, + INLINE_ACTION_SENDER(spaceaction::actiondemo, generate)( t.in, {payer,"active"_n}, { gen}); - INLINE_ACTION_SENDER(spaceaction::actiondemo, generate)( t.in, {payer,N(active)}, + INLINE_ACTION_SENDER(spaceaction::actiondemo, generate)( t.in, {payer,"active"_n}, { gen}); } } } -extern "C" { -[[noreturn]] void apply(uint64_t receiver, uint64_t code, uint64_t action) { - spaceaction::actiondemo obj(receiver); - obj.apply(code, action); - eosio_exit(0); -} -} \ No newline at end of file +// extern "C" { +// [[noreturn]] void apply(uint64_t receiver, uint64_t code, uint64_t action) { +// spaceaction::actiondemo obj(receiver); +// obj.apply(code, action); +// eosio_exit(0); +// } +// } + +#define EOSIO_DISPATCH_CUSTOM(TYPE, MEMBERS) \ + extern "C" \ + { \ + void apply(uint64_t receiver, uint64_t code, uint64_t action) \ + { \ + \ + switch (action) \ + { \ + EOSIO_DISPATCH_HELPER(TYPE, MEMBERS) \ + } \ + /* does not allow destructor of thiscontract to run: eosio_exit(0); */ \ + \ + } \ + } + +EOSIO_DISPATCH_CUSTOM(spaceaction::actiondemo, (apply)(generate)(clear)(hascontract)(inlineact)) diff --git a/unittests/actiondemo/actiondemo.hpp b/unittests/actiondemo/actiondemo.hpp index 2008eb17e6c..7b5e61572df 100644 --- a/unittests/actiondemo/actiondemo.hpp +++ b/unittests/actiondemo/actiondemo.hpp @@ -5,40 +5,50 @@ namespace spaceaction { using namespace eosio; - class actiondemo : public contract { + + class [[eosio::contract]] actiondemo : public contract + { typedef std::chrono::milliseconds duration; public: - actiondemo( account_name self ):contract(self){} + using contract::contract; + + // actiondemo( name self ):contract(self){} - void apply( account_name contract, account_name act ); + ACTION apply( name contract, name act ); struct args{ uint64_t loop; uint64_t num; + + }; //@abi action - void generate(const args& t); + ACTION generate(const args& t); //@abi action - void clear(); + ACTION clear(); - struct args_name{ - account_name name; + struct args_name + { + name name; }; //@abi action - void hascontract(const args_name& t); + ACTION hascontract(const args_name& t); + struct argsinline + { + name payer; + name in; - struct args_inline{ - account_name payer; - account_name in; + }; //@abi action - void inlineact(const args_inline& t); + ACTION inlineact(const argsinline& t); public: // @abi table seedobjs i64 - struct seedobj { + TABLE seedobj + { uint64_t id; time_point create; std::string seedstr; @@ -48,7 +58,7 @@ namespace spaceaction { uint64_t primary_key()const { return id; } EOSLIB_SERIALIZE(seedobj,(id)(create)(seedstr)(txid)(action)) }; - typedef eosio::multi_index< N(seedobjs), seedobj> seedobjs; + typedef eosio::multi_index< "seedobjs"_n, seedobj> seedobjs; };