Skip to content

Instantly share code, notes, and snippets.

@johnX9
Last active April 29, 2018 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnX9/8e8d88c0b497623364354aa069ae3e2f to your computer and use it in GitHub Desktop.
Save johnX9/8e8d88c0b497623364354aa069ae3e2f to your computer and use it in GitHub Desktop.
//@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"
* As parameters we pass code & scope - _self from the parent contract
*/
playerIndex players(_self, _self);
/**
* We must verify that the account doesn't exist yet
* If the account is not found the iterator variable should be players.end()
*/
auto iterator = players.find(account);
eosio_assert(iterator == players.end(), "Address for account already exists");
/**
* We add the new player in the table
* The first argument is the payer of the storage which will store the data
*/
players.emplace(account, [&](auto& player) {
player.account_name = account;
player.username = username;
player.level = 1;
player.health_points = 1000;
player.energy_points = 1000;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment