Created
April 13, 2020 13:37
-
-
Save MitchPierias/67e1f7bba3525378feab6998dc17df7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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