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
// EOSLIB_SERIALIZE(struct_name, (property_1)(property_2)(property_3)...(property_n)) |
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
// typedef multi_index<N(table_name), object_template_to_use> multi_index_name; | |
typedef multi_index<N(player), player> playerIndex; |
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" |
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 update(account_name account, uint64_t level, int64_t healthPoints, int64_t energyPoints) { | |
require_auth(account); | |
playerIndex players(_self, _self); | |
auto iterator = players.find(account); | |
eosio_assert(iterator != players.end(), "Address for account not found"); | |
/** |
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 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 |
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
# cleos push action {account} {action} {data} | |
# account - The account providing the contract to execute | |
# action - The action to execute on the contract | |
# data - The arguments to the contract | |
cleos push action anorak getplayer '["anorak"]' -p anorak@active | |
executed transaction: 759ba984c4f9216d79fc473757a398ee6248c043ab6596cd8336a08512a4f465 104 bytes 2443 us | |
# anorak <= anorak::getplayer {"account":"anorak"} | |
>> Username: art3mis Level: 1 Health: 1000 Energy: 1000 |
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
# cleos set contract {account} {path_to_contract_folder} {path_to_.wast_file} {path_to_.abi_file} | |
cleos set contract anorak ./contracts/Players ./contracts/Players/Players.wast ./contracts/Players/Players.abi | |
Reading WAST/WASM from ./contracts/Players/Players.wast... | |
Assembling WASM... | |
Publishing contract... | |
executed transaction: 2187a85a5e80cbd2c0e6715b6847c95cbb5da5df7ed1171be87709507678795d 6472 bytes 6582 us | |
# eosio <= eosio::setcode {"account":"anorak","vmtype":0,"vmversion":0,"code":"0061736d010000000182011560037f7e7f0060057f7e7e7... | |
# eosio <= eosio::setabi {"account":"anorak","abi":"0e656f73696f3a3a6162692f312e300002046974656d0006076974656d5f69640675696e7... |
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
eosiocpp -o Players.wast Players.cpp |
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
eosiocpp -g Players.abi Players.cpp |
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
# cleos push action {account} {action_name} '{data}' -p {account}@active | |
cleos push action anorak add '["anorak","art3mis"]' -p anorak@active | |
executed transaction: 00ea5aa48e50c33737b253ac24cb6bef3f296399e9a7e61b81044a852bb5c709 112 bytes 3015 us | |
# anorak <= anorak::add {"account":"anorak","username":"art3mis"} |