8 Inline Action to External Contract
8.1 Addressbook counter address contract
cd CONTRACTS_DIR
mkdir abcounter
cd abcounter
touch abcounter.cpp#include <eosiolib/eosio.hpp>
using namespace eosio;
class [[eosio::contract]] abcounter : public eosio::contract {
private:
struct [[eosio::table]] counter {
name key;
uint64_t emplaced;
uint64_t modified;
uint64_t erased;
uint64_t primary_key() const {
return key.value;
}
};
using count_index = eosio::multi_index<"counter"_n, counter>;
public:
using contract::contract;
abcounter(name receiver, name code, datastream<const char*> ds):
contract(receiver, code, ds) {}
[[eosio::action]]
void count(name user, std::string type) {
require_auth( name("addressbook"));
count_index counts(name(_code), _code.value);
auto iterator = counts.find(user.value);
if (iterator == counts.end()) {
counts.emplace("addressbook"_n, [&]( auto& row ) {
row.key = user;
row.emplaced = (type == "emplace") ? 1 : 0;
row.modified = (type == "modify") ? 1 : 0;
row.erased = (type == "erase") ? 1 : 0;
});
}
else {
counts.modify(iterator, "addressbook"_n, [&]( auto& row ) {
if(type == "emplace") { row.emplaced += 1; }
if(type == "modify") { row.modified += 1; }
if(type == "erase") { row.erased += 1; }
});
}
}
};
EOSIO_DISPATCH( abcounter, (count));8.2 Create an account for abcounter contract
8.3 Compile and install the abcounter contract
8.4 Modify the contract addressbook to send inline actions to a new abcounter contract
8.5 Recompile and set the addressbook contract
8.6 Perform testing of sending an action from an addressbook contract to an abcounter contract
Last updated