Skip to content

Commit

Permalink
NFT Marketplace HRP Beatrice Merge (#371)
Browse files Browse the repository at this point in the history
* private-key option update

* ppy marketplace 1 - add evaluators and objects

* NFT object and basic operations

* ci: update .gitlab-ci.yml

* ci: update .gitlab-ci.yml

* NFT evaluators and basic tests, no evaluator checks

* Evaluator checks in place

* ppy marketplace 2 - batch sale, offer_object escrow

* Database API

* Wallet API

* NFT metadata implemented

* Fix NFT tests

* Database API for NFT metadata and enumerables

* ppy marketplace 4 - Add tests NFT+Marketplace

* ppy marketplace 5 - Add revenue split

* ppy marketplace 6 - Remove unnecessary files

* ppy marketplace 7 - Add db, wallet changes and some NFT fixes

* ppy marketplace 8 - Add pagination for list APIs

* ci: update .gitlab-ci.yml

* New DB API, list all NFTs, list NFTs by owner

* Marketplace + NFT + RBAC (#368)

* rbac1 - evaluators and op validators added
* rbac2 - op_type hf checks
* rbac3 - tx auth verify changes
* Update .gitlab-ci.yml
* rbac4 - basic op tests
* rbac5 - clear expired and deleted permission linked auths
* rbac6 - more tests
* rbac7 - more tests
* rbac8 - more tests
* rbac9 - wallet and db api changes
* rbac10 - db api changes for required signature fetch
* rbac11 - add db_api tests
* rbac12 - add missing code for key auths

Co-authored-by: Roshan Syed <roshan.syed.rs@gmail.com>
Co-authored-by: sierra19XX <15652887+sierra19XX@users.noreply.github.com>

* Fix nft_get_token_uri returning empty string

* Fix nft_mint_evaluator to save token_uri

* Fix cli_wallet to properly pass metadata id for nft_create

* ppy marketplace 9 - FC_REFLECT offer create op

* Add stricter checks to NFTs

* GPOS2 HF - Handle rolling period on missing blocks (#369)

* Mainnet chain halt 5050 Issue (#370)

* Unlisting offers, add result in offer history object

* Reverting genesis.json wrong commit

* Add non-transferable non-sellable properties to NFTs

* Review comments - change variable names, use scoped enums

* nft_metadata_update changes

* NFT HF checks and op fee addition changes

* NFT make revenue_split integer from double

* revenue_split condition check allow zero or above

* Peerplays Marketplace + NFT (#367)

* ppy marketplace 1 - add evaluators and objects

* NFT object and basic operations

* ci: update .gitlab-ci.yml

* ci: update .gitlab-ci.yml

* NFT evaluators and basic tests, no evaluator checks

* Evaluator checks in place

* ppy marketplace 2 - batch sale, offer_object escrow

* Database API

* Wallet API

* NFT metadata implemented

* Fix NFT tests

* Database API for NFT metadata and enumerables

* ppy marketplace 4 - Add tests NFT+Marketplace

* ppy marketplace 5 - Add revenue split

* ppy marketplace 6 - Remove unnecessary files

* ppy marketplace 7 - Add db, wallet changes and some NFT fixes

* ppy marketplace 8 - Add pagination for list APIs

* New DB API, list all NFTs, list NFTs by owner

* Marketplace + NFT + RBAC (#368)

* rbac1 - evaluators and op validators added
* rbac2 - op_type hf checks
* rbac3 - tx auth verify changes
* Update .gitlab-ci.yml
* rbac4 - basic op tests
* rbac5 - clear expired and deleted permission linked auths
* rbac6 - more tests
* rbac7 - more tests
* rbac8 - more tests
* rbac9 - wallet and db api changes
* rbac10 - db api changes for required signature fetch
* rbac11 - add db_api tests
* rbac12 - add missing code for key auths

Co-authored-by: Roshan Syed <roshan.syed.rs@gmail.com>
Co-authored-by: sierra19XX <15652887+sierra19XX@users.noreply.github.com>

* Fix nft_get_token_uri returning empty string

* Fix nft_mint_evaluator to save token_uri

* Fix cli_wallet to properly pass metadata id for nft_create

* ppy marketplace 9 - FC_REFLECT offer create op

* Add stricter checks to NFTs

* Unlisting offers, add result in offer history object

* Reverting genesis.json wrong commit

* Add non-transferable non-sellable properties to NFTs

* Review comments - change variable names, use scoped enums

* nft_metadata_update changes

* NFT HF checks and op fee addition changes

* NFT make revenue_split integer from double

* revenue_split condition check allow zero or above

Co-authored-by: Srdjan Obucina <obucinac@gmail.com>
Co-authored-by: Roshan Syed <roshan.syed.rs@gmail.com>
Co-authored-by: obucina <11353193+obucina@users.noreply.github.com>

* Beatrice NFT HF

Co-authored-by: pbattu123 <43043205+pbattu123@users.noreply.github.com>
Co-authored-by: pbattu123 <p.battu@pbsa.info>
Co-authored-by: Srdjan Obucina <obucinac@gmail.com>
Co-authored-by: Roshan Syed <roshan.syed.rs@gmail.com>
Co-authored-by: obucina <11353193+obucina@users.noreply.github.com>
  • Loading branch information
6 people authored Aug 10, 2020
1 parent 3bc945a commit 6514f8f
Show file tree
Hide file tree
Showing 53 changed files with 7,120 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ else( WIN32 ) # Apple AND Linux
endif( APPLE )

if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp -Wno-class-memaccess -Wno-parentheses -Wno-terminate -Wno-invalid-offsetof" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp -Wno-parentheses -Wno-terminate -Wno-invalid-offsetof" )
elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
if( CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.0.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0.0 )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization" )
Expand Down
5 changes: 5 additions & 0 deletions docker/peerplaysentry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ VERSION=`cat /etc/peerplays/version`
# * $PEERPLAYSD_P2P_ENDPOINT
# * $PEERPLAYSD_WITNESS_ID
# * $PEERPLAYSD_PRIVATE_KEY
# * $PEERPLAYSD_DEBUG_PRIVATE_KEY
# * $PEERPLAYSD_TRACK_ACCOUNTS
# * $PEERPLAYSD_PARTIAL_OPERATIONS
# * $PEERPLAYSD_MAX_OPS_PER_ACCOUNT
Expand Down Expand Up @@ -51,6 +52,10 @@ if [[ ! -z "$PEERPLAYSD_PRIVATE_KEY" ]]; then
ARGS+=" --private-key=$PEERPLAYSD_PRIVATE_KEY"
fi

if [[ ! -z "$PEERPLAYSD_DEBUG_PRIVATE_KEY" ]]; then
ARGS+=" --debug-private-key=$PEERPLAYSD_DEBUG_PRIVATE_KEY"
fi

if [[ ! -z "$PEERPLAYSD_TRACK_ACCOUNTS" ]]; then
for ACCOUNT in $PEERPLAYSD_TRACK_ACCOUNTS ; do
ARGS+=" --track-account=$ACCOUNT"
Expand Down
585 changes: 585 additions & 0 deletions libraries/app/database_api.cpp

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/tournament_object.hpp>

#include <graphene/chain/custom_permission_object.hpp>
#include <graphene/chain/custom_account_authority_object.hpp>
#include <graphene/chain/nft_object.hpp>
#include <graphene/chain/offer_object.hpp>

#include <graphene/market_history/market_history_plugin.hpp>

#include <fc/api.hpp>
Expand Down Expand Up @@ -709,8 +714,121 @@ class database_api
*/
gpos_info get_gpos_info(const account_id_type account) const;

//////////
// RBAC //
//////////
/**
* @return account and custom permissions/account-authorities info
*/
vector<custom_permission_object> get_custom_permissions(const account_id_type account) const;
fc::optional<custom_permission_object> get_custom_permission_by_name(const account_id_type account, const string& permission_name) const;
vector<custom_account_authority_object> get_custom_account_authorities(const account_id_type account) const;
vector<custom_account_authority_object> get_custom_account_authorities_by_permission_id(const custom_permission_id_type permission_id) const;
vector<custom_account_authority_object> get_custom_account_authorities_by_permission_name(const account_id_type account, const string& permission_name) const;
vector<authority> get_active_custom_account_authorities_by_operation(const account_id_type account, int operation_type) const;

/////////
// NFT //
/////////
/**
* @brief Returns the number of NFT owned by account
* @param owner Owner account ID
* @return Number of NFTs owned by account
*/
uint64_t nft_get_balance(const account_id_type owner) const;

/**
* @brief Returns the NFT owner
* @param token_id NFT ID
* @return NFT owner account ID
*/
optional<account_id_type> nft_owner_of(const nft_id_type token_id) const;

/**
* @brief Returns the NFT approved account ID
* @param token_id NFT ID
* @return NFT approved account ID
*/
optional<account_id_type> nft_get_approved(const nft_id_type token_id) const;

/**
* @brief Returns operator approved state for all NFT owned by owner
* @param owner NFT owner account ID
* @param token_id NFT ID
* @return True if operator is approved for all NFT owned by owner, else False
*/
bool nft_is_approved_for_all(const account_id_type owner, const account_id_type operator_) const;

/**
* @brief Returns NFT name from NFT metadata
* @param nft_metadata_id NFT metadata ID
* @return NFT name
*/
string nft_get_name(const nft_metadata_id_type nft_metadata_id) const;

/**
* @brief Returns NFT symbol from NFT metadata
* @param nft_metadata_id NFT metadata ID
* @return NFT symbol
*/
string nft_get_symbol(const nft_metadata_id_type nft_metadata_id) const;

/**
* @brief Returns NFT URI
* @param token_id NFT ID
* @return NFT URI
*/
string nft_get_token_uri(const nft_id_type token_id) const;

/**
* @brief Returns total number of NFTs assigned to NFT metadata
* @param nft_metadata_id NFT metadata ID
* @return Total number of NFTs assigned to NFT metadata
*/
uint64_t nft_get_total_supply(const nft_metadata_id_type nft_metadata_id) const;

/**
* @brief Returns NFT by index from NFT metadata
* @param nft_metadata_id NFT metadata ID
* @param token_idx NFT index in the list of tokens
* @return NFT symbol
*/
nft_object nft_token_by_index(const nft_metadata_id_type nft_metadata_id, const uint64_t token_idx) const;

/**
* @brief Returns NFT by owner and index
* @param nft_metadata_id NFT metadata ID
* @param owner NFT owner
* @param token_idx NFT index in the list of tokens
* @return NFT object
*/
nft_object nft_token_of_owner_by_index(const nft_metadata_id_type nft_metadata_id, const account_id_type owner, const uint64_t token_idx) const;

/**
* @brief Returns list of all available NTF's
* @return List of all available NFT's
*/
vector<nft_object> nft_get_all_tokens() const;

/**
* @brief Returns NFT's owned by owner
* @param owner NFT owner
* @return List of NFT owned by owner
*/
vector<nft_object> nft_get_tokens_by_owner(const account_id_type owner) const;

//////////////////
// MARKET PLACE //
//////////////////
vector<offer_object> list_offers(const offer_id_type lower_id, uint32_t limit) const;
vector<offer_object> list_sell_offers(const offer_id_type lower_id, uint32_t limit) const;
vector<offer_object> list_buy_offers(const offer_id_type lower_id, uint32_t limit) const;
vector<offer_history_object> list_offer_history(const offer_history_id_type lower_id, uint32_t limit) const;
vector<offer_object> get_offers_by_issuer(const offer_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const;
vector<offer_object> get_offers_by_item(const offer_id_type lower_id, const nft_id_type item, uint32_t limit) const;
vector<offer_history_object> get_offer_history_by_issuer(const offer_history_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const;
vector<offer_history_object> get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const;
vector<offer_history_object> get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const;
private:
std::shared_ptr< database_api_impl > my;
};
Expand Down Expand Up @@ -848,4 +966,37 @@ FC_API(graphene::app::database_api,

// gpos
(get_gpos_info)

//rbac
(get_custom_permissions)
(get_custom_permission_by_name)
(get_custom_account_authorities)
(get_custom_account_authorities_by_permission_id)
(get_custom_account_authorities_by_permission_name)
(get_active_custom_account_authorities_by_operation)

// NFT
(nft_get_balance)
(nft_owner_of)
(nft_get_approved)
(nft_is_approved_for_all)
(nft_get_name)
(nft_get_symbol)
(nft_get_token_uri)
(nft_get_total_supply)
(nft_token_by_index)
(nft_token_of_owner_by_index)
(nft_get_all_tokens)
(nft_get_tokens_by_owner)

// Marketplace
(list_offers)
(list_sell_offers)
(list_buy_offers)
(list_offer_history)
(get_offers_by_issuer)
(get_offers_by_item)
(get_offer_history_by_issuer)
(get_offer_history_by_item)
(get_offer_history_by_bidder)
)
10 changes: 10 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ add_library( graphene_chain
protocol/vote.cpp
protocol/tournament.cpp
protocol/small_ops.cpp
protocol/custom_permission.cpp
protocol/custom_account_authority.cpp
protocol/offer.cpp

genesis_state.cpp
get_config.cpp
Expand Down Expand Up @@ -112,9 +115,16 @@ add_library( graphene_chain
betting_market_evaluator.cpp
betting_market_object.cpp
betting_market_group_object.cpp
custom_permission_evaluator.cpp
custom_account_authority_evaluator.cpp

affiliate_payout.cpp

offer_object.cpp
offer_evaluator.cpp
nft_evaluator.cpp
protocol/nft.cpp

${HEADERS}
${PROTOCOL_HEADERS}
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/asset_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ map< account_id_type, vector< uint16_t > > asset_object::distribute_winners_part
reward_op.lottery = get_id();
reward_op.is_benefactor_reward = false;
reward_op.winner = holders[winner_num];
if(db.head_block_time() > HARDFORK_5050_1_TIME && ticket_ids.size() >= winner_num)
if(db.head_block_time() > HARDFORK_5050_1_TIME && ticket_ids.size() > winner_num)
{
const static_variant<uint64_t, void_t> tkt_id = ticket_ids[winner_num];
reward_op.winner_ticket_id = tkt_id;
Expand Down
152 changes: 152 additions & 0 deletions libraries/chain/custom_account_authority_evaluator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#include <graphene/chain/custom_account_authority_evaluator.hpp>

#include <graphene/chain/database.hpp>
#include <graphene/chain/custom_account_authority_object.hpp>
#include <graphene/chain/custom_permission_object.hpp>
#include <graphene/chain/hardfork.hpp>

namespace graphene
{
namespace chain
{

struct rbac_operation_hardfork_visitor
{
typedef void result_type;
const fc::time_point_sec block_time;

rbac_operation_hardfork_visitor(const fc::time_point_sec bt) : block_time(bt) {}
void operator()(int op_type) const
{
int first_allowed_op = operation::tag<custom_permission_create_operation>::value;
switch (op_type)
{
case operation::tag<custom_permission_create_operation>::value:
case operation::tag<custom_permission_update_operation>::value:
case operation::tag<custom_permission_delete_operation>::value:
case operation::tag<custom_account_authority_create_operation>::value:
case operation::tag<custom_account_authority_update_operation>::value:
case operation::tag<custom_account_authority_delete_operation>::value:
FC_ASSERT(block_time >= HARDFORK_NFT_TIME, "Custom permission not allowed on this operation yet!");
break;
default:
FC_ASSERT(op_type < first_allowed_op, "Custom permission not allowed on this operation!");
}
}
};

void_result create_custom_account_authority_evaluator::do_evaluate(const custom_account_authority_create_operation &op)
{
try
{
const database &d = db();
auto now = d.head_block_time();
FC_ASSERT(now >= HARDFORK_NFT_TIME, "Not allowed until NFT HF");
op.owner_account(d);
const custom_permission_object &pobj = op.permission_id(d);
FC_ASSERT(pobj.account == op.owner_account, "Only owner account can update account authority object");
FC_ASSERT(op.valid_to > now, "valid_to expiry should be in future");
FC_ASSERT((op.valid_to - op.valid_from) <= fc::seconds(d.get_global_properties().parameters.rbac_max_account_authority_lifetime()), "Validity of the auth beyond max expiry");
rbac_operation_hardfork_visitor rvtor(now);
rvtor(op.operation_type);
const auto& cindex = d.get_index_type<custom_account_authority_index>().indices().get<by_permission_and_op>();
auto count = cindex.count(boost::make_tuple(op.permission_id));
FC_ASSERT(count < d.get_global_properties().parameters.rbac_max_authorities_per_permission(), "Max operations that can be linked to a permission reached");
return void_result();
}
FC_CAPTURE_AND_RETHROW((op))
}

object_id_type create_custom_account_authority_evaluator::do_apply(const custom_account_authority_create_operation &op)
{
try
{
database &d = db();
return d.create<custom_account_authority_object>([&op](custom_account_authority_object &obj) mutable {
obj.permission_id = op.permission_id;
obj.operation_type = op.operation_type;
obj.valid_from = op.valid_from;
obj.valid_to = op.valid_to;
})
.id;
}
FC_CAPTURE_AND_RETHROW((op))
}

void_result update_custom_account_authority_evaluator::do_evaluate(const custom_account_authority_update_operation &op)
{
try
{
const database &d = db();
auto now = d.head_block_time();
FC_ASSERT(now >= HARDFORK_NFT_TIME, "Not allowed until NFT HF");
op.owner_account(d);
const custom_account_authority_object &aobj = op.auth_id(d);
const custom_permission_object &pobj = aobj.permission_id(d);
FC_ASSERT(pobj.account == op.owner_account, "Only owner account can update account authority object");
auto valid_from = aobj.valid_from;
auto valid_to = aobj.valid_to;
if (op.new_valid_from)
{
valid_from = *op.new_valid_from;
}

if (op.new_valid_to)
{
FC_ASSERT(*op.new_valid_to > now, "New valid_to expiry should be in the future");
valid_to = *op.new_valid_to;
}
FC_ASSERT(valid_from < valid_to, "valid_from should be before valid_to");
FC_ASSERT((valid_to - valid_from) <= fc::seconds(d.get_global_properties().parameters.rbac_max_account_authority_lifetime()), "Validity of the auth beyond max expiry");
return void_result();
}
FC_CAPTURE_AND_RETHROW((op))
}

object_id_type update_custom_account_authority_evaluator::do_apply(const custom_account_authority_update_operation &op)
{
try
{
database &d = db();
const custom_account_authority_object &aobj = op.auth_id(d);
d.modify(aobj, [&op](custom_account_authority_object &obj) {
if (op.new_valid_from)
obj.valid_from = *op.new_valid_from;
if (op.new_valid_to)
obj.valid_to = *op.new_valid_to;
});
return op.auth_id;
}
FC_CAPTURE_AND_RETHROW((op))
}

void_result delete_custom_account_authority_evaluator::do_evaluate(const custom_account_authority_delete_operation &op)
{
try
{
const database &d = db();
auto now = d.head_block_time();
FC_ASSERT(now >= HARDFORK_NFT_TIME, "Not allowed until NFT HF");
op.owner_account(d);
const custom_account_authority_object &aobj = op.auth_id(d);
const custom_permission_object &pobj = aobj.permission_id(d);
FC_ASSERT(pobj.account == op.owner_account, "Only owner account can delete account authority object");
return void_result();
}
FC_CAPTURE_AND_RETHROW((op))
}

void_result delete_custom_account_authority_evaluator::do_apply(const custom_account_authority_delete_operation &op)
{
try
{
database &d = db();
const custom_account_authority_object &aobj = op.auth_id(d);
d.remove(aobj);
return void_result();
}
FC_CAPTURE_AND_RETHROW((op))
}

} // namespace chain
} // namespace graphene
Loading

0 comments on commit 6514f8f

Please sign in to comment.