Skip to content

Instantly share code, notes, and snippets.

View johnX9's full-sized avatar

John X johnX9

  • @infiniteXLabs
View GitHub Profile
# Create the account using the public keys
cleos create account eosio anorak {public_OwnerKey} {public_ActiveKey}
# "eosio" is the name of the account who will create the new one
# "anorak" is the name of the new account
#include "Players.hpp"
namespace Oasis {
using namespace eosio;
using std::string;
}
// EOSLIB_SERIALIZE(struct_name, (property_1)(property_2)(property_3)...(property_n))
// typedef multi_index<N(table_name), object_template_to_use> multi_index_name;
typedef multi_index<N(player), player> playerIndex;
//@abi table player i64
struct player {
uint64_t account_name;
string username;
uint64_t level;
uint64_t health_points = 1000;
uint64_t energy_points = 1000;
uint64_t primary_key() const { return username; }
//@abi action
void add(const account_name account, string& username) {
/**
* We require that only the owner of an account can use this action
* or somebody with the account authorization
*/
require_auth(account);
/**
* We access the "player" table as creating an object of type "playerIndex"
eosiocpp -g Players.abi Players.cpp
//@abi action
void getplayer(const account_name account) {
playerIndex players(_self, _self);
auto iterator = players.find(account);
eosio_assert(iterator != players.end(), "Address for account not found");
/**
* The "get" function returns a constant reference to the object
* containing the specified secondary key
git clone https://github.com/eosio/eos --recursive