Skip to content

Instantly share code, notes, and snippets.

@MitchPierias
Created April 13, 2020 13:37
Show Gist options
  • Save MitchPierias/67e1f7bba3525378feab6998dc17df7a to your computer and use it in GitHub Desktop.
Save MitchPierias/67e1f7bba3525378feab6998dc17df7a to your computer and use it in GitHub Desktop.
class [[eosio::contract("example")]] example : public contract {
public:
using contract::contract;
[[eosio::action]] void post(const name author, const string message) {
require_auth(author);
message_table messages(_self, _self.value);
messages.emplace(author, [&](auto &post) {
post.id = messages.available_primary_key();
post.body = message;
post.author = author;
});
}
private:
struct [[eosio::table]] MessageStruct {
uint64_t id;
string body;
name author;
uint64_t primary_key() const { return id; };
};
typedef multi_index<"messages"_n, MessageStruct> message_table;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment