Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eosproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"main": "src\\niftyshopper.cpp",
"contract": "niftyshopper",
"main": "src\\monkeymarket.cpp",
"contract": "monkeymarket",
"include": "",
"resource": "",
"cdt": "v1.7.0",
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

niftyshopper.abi
*.abi

niftyshopper.wasm
*.wasm
8 changes: 2 additions & 6 deletions include/atomicassets.hpp
Original file line number Diff line number Diff line change
@@ -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 <eosio/eosio.hpp>
#include <eosio/asset.hpp>
Expand All @@ -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;
Expand Down
40 changes: 17 additions & 23 deletions include/niftyshopper.hpp → include/monkeymarket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@

#include <atomicassets.hpp>

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<uint64_t> & 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(
Expand Down Expand Up @@ -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);
}
}
23 changes: 16 additions & 7 deletions src/contract_actions.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
void monkeymarket::_dummy_aa(
eosio::name & from,
eosio::name & to,
std::vector<uint64_t> & asset_ids,
std::string & memo)
{
return;
}

/*
Adds an entry to the allowed templates that can be bought from the smart contract.

Expand All @@ -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());
Expand Down Expand Up @@ -44,7 +53,7 @@

@auth self
*/
[[eosio::action]] void niftyshopper::rmstore(
void monkeymarket::rmstore(
uint64_t template_id)
{
require_auth(get_self());
Expand All @@ -60,7 +69,7 @@

@auth self
*/
[[eosio::action]] void niftyshopper::init()
void monkeymarket::init()
{
require_auth(get_self());
get_config().remove();
Expand All @@ -73,7 +82,7 @@

@auth self
*/
[[eosio::action]] void niftyshopper::destruct()
void monkeymarket::destruct()
{
require_auth(get_self());
get_config().remove();
Expand All @@ -88,7 +97,7 @@

@auth self
*/
[[eosio::action]] void niftyshopper::maintenance(bool maintenance)
void monkeymarket::maintenance(bool maintenance)
{
require_auth(get_self());

Expand Down
33 changes: 23 additions & 10 deletions src/niftyshopper.cpp → src/monkeymarket.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include <niftyshopper.hpp>
#include <monkeymarket.hpp>

#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")
{
Expand All @@ -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")},
Expand All @@ -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();
Expand Down