diff --git a/.eosproj b/.eosproj index 17befdb..4a94512 100644 --- a/.eosproj +++ b/.eosproj @@ -1,6 +1,6 @@ { - "main": "src\\niftyshopper.cpp", - "contract": "niftyshopper", + "main": "src\\monkeymarket.cpp", + "contract": "monkeymarket", "include": "", "resource": "", "cdt": "v1.7.0", diff --git a/.gitignore b/.gitignore index 13e272c..57341ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -niftyshopper.abi +*.abi -niftyshopper.wasm +*.wasm diff --git a/include/atomicassets.hpp b/include/atomicassets.hpp index ec443a3..be53b79 100644 --- a/include/atomicassets.hpp +++ b/include/atomicassets.hpp @@ -1,8 +1,4 @@ -/* -This file is not used for the actual atomicassets contract. -It can be used as a header file for other contracts to access the atomicassets tables -and custom data types. -*/ +#pragma once #include #include @@ -11,7 +7,7 @@ namespace atomicassets { static constexpr eosio::name ATOMICASSETS_ACCOUNT = eosio::name("atomicassets"); - //Scope: owner + // Scope: owner struct assets_s { uint64_t asset_id; diff --git a/include/niftyshopper.hpp b/include/monkeymarket.hpp similarity index 62% rename from include/niftyshopper.hpp rename to include/monkeymarket.hpp index 246574c..1992d59 100644 --- a/include/niftyshopper.hpp +++ b/include/monkeymarket.hpp @@ -5,22 +5,31 @@ #include -CONTRACT niftyshopper : public eosio::contract +CONTRACT monkeymarket : public eosio::contract { public: using eosio::contract::contract; - void receive_token_transfer( - eosio::name from, - eosio::name to, - eosio::asset quantity, - std::string memo); + [[eosio::on_notify("*::transfer")]] void receive_token_transfer( + eosio::name & from, + eosio::name & to, + eosio::asset & quantity, + std::string & memo); + + // atomicassets listener in order to prevent issues on *::transfer + // this has priortiy over the wildcard * + // this notify actions does nothing functionality wise + [[eosio::on_notify("atomicassets::transfer")]] void _dummy_aa( + eosio::name & from, + eosio::name & to, + std::vector & asset_ids, + std::string & memo); [[eosio::action]] void setstore( uint64_t template_id, - eosio::name token_contract, - eosio::asset buy_price, + eosio::name & token_contract, + eosio::asset & buy_price, bool burn_token); [[eosio::action]] void rmstore( @@ -62,18 +71,3 @@ CONTRACT niftyshopper : public eosio::contract void maintenace_check(); }; - -extern "C" void apply(uint64_t receiver, uint64_t code, uint64_t action) -{ - if (code == receiver) - { - switch (action) - { - EOSIO_DISPATCH_HELPER(niftyshopper, (setstore)(rmstore)(init)(destruct)(maintenance)) - } - } - else if (code != atomicassets::ATOMICASSETS_ACCOUNT.value && action == eosio::name("transfer").value) - { - eosio::execute_action(eosio::name(receiver), eosio::name(code), &niftyshopper::receive_token_transfer); - } -} \ No newline at end of file diff --git a/src/contract_actions.cpp b/src/contract_actions.cpp index 9d7eefc..fda5ff4 100644 --- a/src/contract_actions.cpp +++ b/src/contract_actions.cpp @@ -1,3 +1,12 @@ +void monkeymarket::_dummy_aa( + eosio::name & from, + eosio::name & to, + std::vector & asset_ids, + std::string & memo) +{ + return; +} + /* Adds an entry to the allowed templates that can be bought from the smart contract. @@ -7,11 +16,11 @@ @auth self */ -[[eosio::action]] void niftyshopper::setstore( +void monkeymarket::setstore( uint64_t template_id, - eosio::name token_contract, - eosio::asset buy_price, + eosio::name &token_contract, + eosio::asset &buy_price, bool burn_token) { require_auth(get_self()); @@ -44,7 +53,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::rmstore( +void monkeymarket::rmstore( uint64_t template_id) { require_auth(get_self()); @@ -60,7 +69,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::init() +void monkeymarket::init() { require_auth(get_self()); get_config().remove(); @@ -73,7 +82,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::destruct() +void monkeymarket::destruct() { require_auth(get_self()); get_config().remove(); @@ -88,7 +97,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::maintenance(bool maintenance) +void monkeymarket::maintenance(bool maintenance) { require_auth(get_self()); diff --git a/src/niftyshopper.cpp b/src/monkeymarket.cpp similarity index 69% rename from src/niftyshopper.cpp rename to src/monkeymarket.cpp index e74f591..9908717 100644 --- a/src/niftyshopper.cpp +++ b/src/monkeymarket.cpp @@ -1,17 +1,17 @@ -#include +#include #include "contract_actions.cpp" -void niftyshopper::maintenace_check() +void monkeymarket::maintenace_check() { eosio::check(!get_config().get().maintenance, "Contract is in maintenance"); } -void niftyshopper::receive_token_transfer( - eosio::name from, - eosio::name to, - eosio::asset token, - std::string memo) +void monkeymarket::receive_token_transfer( + eosio::name &from, + eosio::name &to, + eosio::asset &token, + std::string &memo) { if (from == get_self() || to != get_self() || memo == "ignore_memo") { @@ -36,7 +36,7 @@ void niftyshopper::receive_token_transfer( // Check if item can be bought eosio::check(entity->token_contract == get_first_receiver(), "Token contract does not match"); eosio::check(entity->buy_price == token, "Token price does not match"); - + // Send item eosio::action( eosio::permission_level{get_self(), eosio::name("active")}, @@ -49,13 +49,26 @@ void niftyshopper::receive_token_transfer( std::string("Bought NFT"))) .send(); - if (entity->burn_token == true) { + if (entity->burn_token == true) + { + // Transfer the recieved tokens from us to the token contract eosio::action( eosio::permission_level{get_self(), eosio::name("active")}, entity->token_contract, - eosio::name("retire"), + eosio::name("transfer"), std::make_tuple( get_self(), + entity->token_contract, + token, + std::string("Automatic token burn after NFT sale"))) + .send(); + + // Retire the tokens from the contract, requires @eosio.code access to the contract + eosio::action( + eosio::permission_level{entity->token_contract, eosio::name("active")}, + entity->token_contract, + eosio::name("retire"), + std::make_tuple( token, std::string("Automatic token burn after NFT sale"))) .send();