From ab7b4d692b6965bd51914e8eaf92a60be09e7b27 Mon Sep 17 00:00:00 2001 From: TheLonelyDev Date: Wed, 23 Feb 2022 22:24:31 +0100 Subject: [PATCH 1/7] feat(atomicassets): add #pragma once --- include/atomicassets.hpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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; From 26f19877086b6d008151c1dc544475deea6c4670 Mon Sep 17 00:00:00 2001 From: TheLonelyDev Date: Wed, 23 Feb 2022 22:25:08 +0100 Subject: [PATCH 2/7] feat(niftyshopper): remove apply, use on_notify and use refs --- include/niftyshopper.hpp | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/include/niftyshopper.hpp b/include/niftyshopper.hpp index 246574c..90ba00d 100644 --- a/include/niftyshopper.hpp +++ b/include/niftyshopper.hpp @@ -10,17 +10,17 @@ CONTRACT niftyshopper : 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); [[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 +62,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 From 117cb16700f0e1054b0a70895a810fb8fadede96 Mon Sep 17 00:00:00 2001 From: TheLonelyDev Date: Wed, 23 Feb 2022 22:25:26 +0100 Subject: [PATCH 3/7] feat(actions): remove redundant eosio::action --- src/contract_actions.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/contract_actions.cpp b/src/contract_actions.cpp index 9d7eefc..170a187 100644 --- a/src/contract_actions.cpp +++ b/src/contract_actions.cpp @@ -7,11 +7,11 @@ @auth self */ -[[eosio::action]] void niftyshopper::setstore( +void niftyshopper::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 +44,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::rmstore( +void niftyshopper::rmstore( uint64_t template_id) { require_auth(get_self()); @@ -60,7 +60,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::init() +void niftyshopper::init() { require_auth(get_self()); get_config().remove(); @@ -73,7 +73,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::destruct() +void niftyshopper::destruct() { require_auth(get_self()); get_config().remove(); @@ -88,7 +88,7 @@ @auth self */ -[[eosio::action]] void niftyshopper::maintenance(bool maintenance) +void niftyshopper::maintenance(bool maintenance) { require_auth(get_self()); From a8d824b9fb4869fe558b64893d02013c45211a39 Mon Sep 17 00:00:00 2001 From: TheLonelyDev Date: Wed, 23 Feb 2022 22:26:06 +0100 Subject: [PATCH 4/7] feat(niftyshopper): make use of the proper eosio permissions --- src/niftyshopper.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/niftyshopper.cpp b/src/niftyshopper.cpp index e74f591..5f5fa2b 100644 --- a/src/niftyshopper.cpp +++ b/src/niftyshopper.cpp @@ -8,10 +8,10 @@ void niftyshopper::maintenace_check() } void niftyshopper::receive_token_transfer( - eosio::name from, - eosio::name to, - eosio::asset token, - std::string memo) + 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,10 +49,24 @@ 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("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( get_self(), From 7bb0ed2285d9478d3356c0d5e6e3bb5148f49cbe Mon Sep 17 00:00:00 2001 From: TheLonelyDev Date: Wed, 23 Feb 2022 22:54:42 +0100 Subject: [PATCH 5/7] feat(atomicassets): add dummy aa transfer notifier --- include/niftyshopper.hpp | 9 +++++++++ src/niftyshopper.cpp | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/niftyshopper.hpp b/include/niftyshopper.hpp index 90ba00d..62ebee4 100644 --- a/include/niftyshopper.hpp +++ b/include/niftyshopper.hpp @@ -16,6 +16,15 @@ CONTRACT niftyshopper : public eosio::contract 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, diff --git a/src/niftyshopper.cpp b/src/niftyshopper.cpp index 5f5fa2b..c140c7b 100644 --- a/src/niftyshopper.cpp +++ b/src/niftyshopper.cpp @@ -69,7 +69,6 @@ void niftyshopper::receive_token_transfer( entity->token_contract, eosio::name("retire"), std::make_tuple( - get_self(), token, std::string("Automatic token burn after NFT sale"))) .send(); From 3e551de7166ad14b8d7a07d31850305a83b1ade2 Mon Sep 17 00:00:00 2001 From: TheLonelyDev Date: Wed, 23 Feb 2022 22:58:15 +0100 Subject: [PATCH 6/7] feat(rebrand): rebrand the contract --- .eosproj | 4 ++-- .gitignore | 4 ++-- include/{niftyshopper.hpp => monkeymarket.hpp} | 2 +- src/contract_actions.cpp | 10 +++++----- src/{niftyshopper.cpp => monkeymarket.cpp} | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) rename include/{niftyshopper.hpp => monkeymarket.hpp} (97%) rename src/{niftyshopper.cpp => monkeymarket.cpp} (95%) 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/niftyshopper.hpp b/include/monkeymarket.hpp similarity index 97% rename from include/niftyshopper.hpp rename to include/monkeymarket.hpp index 62ebee4..1992d59 100644 --- a/include/niftyshopper.hpp +++ b/include/monkeymarket.hpp @@ -5,7 +5,7 @@ #include -CONTRACT niftyshopper : public eosio::contract +CONTRACT monkeymarket : public eosio::contract { public: using eosio::contract::contract; diff --git a/src/contract_actions.cpp b/src/contract_actions.cpp index 170a187..5deb67c 100644 --- a/src/contract_actions.cpp +++ b/src/contract_actions.cpp @@ -7,7 +7,7 @@ @auth self */ -void niftyshopper::setstore( +void monkeymarket::setstore( uint64_t template_id, eosio::name &token_contract, @@ -44,7 +44,7 @@ void niftyshopper::setstore( @auth self */ -void niftyshopper::rmstore( +void monkeymarket::rmstore( uint64_t template_id) { require_auth(get_self()); @@ -60,7 +60,7 @@ void niftyshopper::rmstore( @auth self */ -void niftyshopper::init() +void monkeymarket::init() { require_auth(get_self()); get_config().remove(); @@ -73,7 +73,7 @@ void niftyshopper::init() @auth self */ -void niftyshopper::destruct() +void monkeymarket::destruct() { require_auth(get_self()); get_config().remove(); @@ -88,7 +88,7 @@ void niftyshopper::destruct() @auth self */ -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 95% rename from src/niftyshopper.cpp rename to src/monkeymarket.cpp index c140c7b..9908717 100644 --- a/src/niftyshopper.cpp +++ b/src/monkeymarket.cpp @@ -1,13 +1,13 @@ -#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( +void monkeymarket::receive_token_transfer( eosio::name &from, eosio::name &to, eosio::asset &token, From 8d2e907ef7d3d307a130ce877be565f2567f9a64 Mon Sep 17 00:00:00 2001 From: TheLonelyDev Date: Mon, 14 Mar 2022 09:01:54 +0100 Subject: [PATCH 7/7] fix(compile): add missing action listener --- src/contract_actions.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/contract_actions.cpp b/src/contract_actions.cpp index 5deb67c..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.