Skip to content

Instantly share code, notes, and snippets.

View johnX9's full-sized avatar

John X johnX9

  • @infiniteXLabs
View GitHub Profile
cleos push action anorak create '{"issuer":"anorak","maximum_supply":"1000000.0000 OAS","can_freeze":"0","can_recall":"0","can_whitelist":"0"}' -p anorak
executed transaction: ed26901b1e7403ef275731e2fb8fcce2c7eb1966c27cd0537750eed8a393a263 120 bytes 316 us
# anorak <= anorak::create {"issuer":"anorak","maximum_supply":"1000000.0000 OAS"}
cleos set contract anorak ./contracts/eosio.token/ ./contracts/eosio.token/eosio.token.wast ./contracts/eosio.token/eosio.token.abi
Reading WAST/WASM from ./contracts/eosio.token/eosio.token.wast...
Assembling WASM...
Publishing contract...
executed transaction: b6b035b7efe07666ed76456c923c14248d535ada064c5851139de7b7f248641a 8104 bytes 1124 us
# eosio <= eosio::setcode {"account":"anorak","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7e7e7f7...
# eosio <= eosio::setabi {"account":"anorak","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d6505087...
# Create asset
# asset({amount}, string_to_symbol({precision}, {symbol}));
asset productPrice = asset(product.price, string_to_symbol(4, "OAS"));
# Do inline trasfer
# action({permission_level}, {contract_deployer}, {contract_action}, {data_to_pass}).send();
action(vector<permission_level>(), N(anorak), N(transfer), make_tuple(buyer, _self, productPrice, string(""))).send();
# Execute action from another contract
# action({permission_level}, {contract_deployer}, {contract_action}, {data_to_pass}).send();
# Players.hpp
//@abi action
void additem(const account_name account, item purchased_item);
# Players.cpp
void Players::additem(const account_name account, item purchased_item) {
playerIndex players(_self, _self);
void Marketplace::buy(account_name buyer, uint64_t productId) {
productIndex products(_self, _self);
auto iterator = products.find(productId);
eosio_assert(iterator != products.end(), "The product not found");
auto product = products.get(productId);
eosio_assert(product.quantity > 0, "The product is out of stock");
asset productPrice = asset(product.price, string_to_symbol(4, "OAS"));
//@abi action
void buy(account_name buyer, uint64_t productId);
//@abi action
void getbyid(uint64_t productId);
/**
* Marketplace processes
*/
cmake_minimum_required(VERSION 3.5)
# Prepare "Catch" library for other executables
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/frameworks)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
# Add unit tests files here
# Example: players_tests.cpp marketplace_tests.cpp and etc.
set(unit_tests_files
//@abi table item i64
struct item {
uint64_t item_id;
string name;
uint64_t power;
uint64_t health;
string ability;
uint64_t level_up;
uint64_t primary_key() const { return item_id; }
cleos push action anorak addability '["anorak","shapeshifting"]' -p anorak@active
executed transaction: 45dbfa10c393de363f42f35027fbeb61e5d576b0111e3da22556ca1c9221771a 120 bytes 1560 us
# anorak <= anorak::addability {"account":"anorak","ability":"shapeshifting"}
cleos push action anorak getplayer '["anorak"]' -p anorak@active
executed transaction: bcfa0e9ef5649b11194b7ac47c6cee7242fceff2390738bcf1bc21b27b3f79f6 104 bytes 477 us
# anorak <= anorak::getplayer {"account":"anorak"}
>> Username: art3mis Level: 4 Health: 925 Energy: 890 Abilities: shapeshifting
print("Username: ", currentPlayer.username.c_str());
print(" Level: ", currentPlayer.level);
print(" Health: ", currentPlayer.health_points);
print(" Energy: ", currentPlayer.energy_points);
if (currentPlayer.abilities.size() > 0) {
print(" Abilities: ");
for (uint32_t i = 0; i < currentPlayer.abilities.size(); i++) {
print(currentPlayer.abilities.at(i).c_str(), " ");