Inline Actions to External Contracts
Step 1: The Addressbook Counter Contract
cd CONTRACTS_DIR
mkdir abcounter
cd abcounter
touch abcounter.cpp#include <eosio/eosio.hpp>
using namespace eosio;
class [[eosio::contract("abcounter")]] abcounter : public eosio::contract {
public:
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(get_first_receiver(), get_first_receiver().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; }
});
}
}
using count_action = action_wrapper<"count"_n, &abcounter::count>;
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<"counts"_n, counter>;
};Step 2: Create Account for abcounter Contract
Step 3: Compile and Deploy
Step 4: Modify addressbook contract to send inline-action to abcounter
Step 5: Recompile and redeploy the addressbook contract
Step 6: Test It.
Extra Credit: More Verbose Receipts
What's Next?
Last updated