Last active
April 29, 2018 19:14
-
-
Save johnX9/8e8d88c0b497623364354aa069ae3e2f to your computer and use it in GitHub Desktop.
This file contains 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
//@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