NFT object and basic operations
This commit is contained in:
parent
d8ca4d4625
commit
de9ede0d5c
11 changed files with 248 additions and 3 deletions
|
|
@ -135,7 +135,7 @@ else( WIN32 ) # Apple AND Linux
|
||||||
endif( APPLE )
|
endif( APPLE )
|
||||||
|
|
||||||
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
|
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" )
|
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 )
|
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" )
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization" )
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,8 @@ add_library( graphene_chain
|
||||||
|
|
||||||
affiliate_payout.cpp
|
affiliate_payout.cpp
|
||||||
|
|
||||||
|
nft_evaluator.cpp
|
||||||
|
|
||||||
${HEADERS}
|
${HEADERS}
|
||||||
${PROTOCOL_HEADERS}
|
${PROTOCOL_HEADERS}
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
|
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
#include <graphene/chain/tournament_object.hpp>
|
#include <graphene/chain/tournament_object.hpp>
|
||||||
#include <graphene/chain/match_object.hpp>
|
#include <graphene/chain/match_object.hpp>
|
||||||
#include <graphene/chain/game_object.hpp>
|
#include <graphene/chain/game_object.hpp>
|
||||||
|
#include <graphene/chain/nft_object.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/sport_object.hpp>
|
#include <graphene/chain/sport_object.hpp>
|
||||||
#include <graphene/chain/event_group_object.hpp>
|
#include <graphene/chain/event_group_object.hpp>
|
||||||
|
|
@ -77,6 +77,7 @@
|
||||||
#include <graphene/chain/event_evaluator.hpp>
|
#include <graphene/chain/event_evaluator.hpp>
|
||||||
#include <graphene/chain/betting_market_evaluator.hpp>
|
#include <graphene/chain/betting_market_evaluator.hpp>
|
||||||
#include <graphene/chain/tournament_evaluator.hpp>
|
#include <graphene/chain/tournament_evaluator.hpp>
|
||||||
|
#include <graphene/chain/nft_evaluator.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||||
|
|
||||||
|
|
@ -163,6 +164,9 @@ const uint8_t betting_market_object::type_id;
|
||||||
const uint8_t bet_object::space_id;
|
const uint8_t bet_object::space_id;
|
||||||
const uint8_t bet_object::type_id;
|
const uint8_t bet_object::type_id;
|
||||||
|
|
||||||
|
const uint8_t nft_object::space_id;
|
||||||
|
const uint8_t nft_object::type_id;
|
||||||
|
|
||||||
const uint8_t betting_market_position_object::space_id;
|
const uint8_t betting_market_position_object::space_id;
|
||||||
const uint8_t betting_market_position_object::type_id;
|
const uint8_t betting_market_position_object::type_id;
|
||||||
|
|
||||||
|
|
@ -243,6 +247,10 @@ void database::initialize_evaluators()
|
||||||
register_evaluator<lottery_reward_evaluator>();
|
register_evaluator<lottery_reward_evaluator>();
|
||||||
register_evaluator<lottery_end_evaluator>();
|
register_evaluator<lottery_end_evaluator>();
|
||||||
register_evaluator<sweeps_vesting_claim_evaluator>();
|
register_evaluator<sweeps_vesting_claim_evaluator>();
|
||||||
|
register_evaluator<nft_create_evaluator>();
|
||||||
|
register_evaluator<nft_safe_transfer_from_evaluator>();
|
||||||
|
register_evaluator<nft_approve_evaluator>();
|
||||||
|
register_evaluator<nft_set_approval_for_all_evaluator>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::initialize_indexes()
|
void database::initialize_indexes()
|
||||||
|
|
@ -285,6 +293,8 @@ void database::initialize_indexes()
|
||||||
add_index< primary_index<match_index> >();
|
add_index< primary_index<match_index> >();
|
||||||
add_index< primary_index<game_index> >();
|
add_index< primary_index<game_index> >();
|
||||||
|
|
||||||
|
add_index< primary_index<nft_index > >();
|
||||||
|
|
||||||
//Implementation object indexes
|
//Implementation object indexes
|
||||||
add_index< primary_index<transaction_index > >();
|
add_index< primary_index<transaction_index > >();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,18 @@ struct get_impacted_account_visitor
|
||||||
void operator()( const sweeps_vesting_claim_operation& op ) {
|
void operator()( const sweeps_vesting_claim_operation& op ) {
|
||||||
_impacted.insert( op.account );
|
_impacted.insert( op.account );
|
||||||
}
|
}
|
||||||
|
void operator()( const nft_create_operation& op ) {
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
|
void operator()( const nft_safe_transfer_from_operation& op ) {
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
|
void operator()( const nft_approve_operation& op ) {
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
|
void operator()( const nft_set_approval_for_all_operation& op ) {
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
||||||
|
|
|
||||||
43
libraries/chain/include/graphene/chain/nft_evaluator.hpp
Normal file
43
libraries/chain/include/graphene/chain/nft_evaluator.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <graphene/chain/database.hpp>
|
||||||
|
#include <graphene/chain/evaluator.hpp>
|
||||||
|
#include <graphene/chain/protocol/operations.hpp>
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
class nft_create_evaluator : public evaluator<nft_create_evaluator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef nft_create_operation operation_type;
|
||||||
|
void_result do_evaluate( const nft_create_operation& o );
|
||||||
|
void_result do_apply( const nft_create_operation& o );
|
||||||
|
};
|
||||||
|
|
||||||
|
class nft_safe_transfer_from_evaluator : public evaluator<nft_safe_transfer_from_evaluator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef nft_safe_transfer_from_operation operation_type;
|
||||||
|
void_result do_evaluate( const nft_safe_transfer_from_operation& o );
|
||||||
|
void_result do_apply( const nft_safe_transfer_from_operation& o );
|
||||||
|
};
|
||||||
|
|
||||||
|
class nft_approve_evaluator : public evaluator<nft_approve_evaluator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef nft_approve_operation operation_type;
|
||||||
|
void_result do_evaluate( const nft_approve_operation& o );
|
||||||
|
void_result do_apply( const nft_approve_operation& o );
|
||||||
|
};
|
||||||
|
|
||||||
|
class nft_set_approval_for_all_evaluator : public evaluator<nft_set_approval_for_all_evaluator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef nft_set_approval_for_all_operation operation_type;
|
||||||
|
void_result do_evaluate( const nft_set_approval_for_all_operation& o );
|
||||||
|
void_result do_apply( const nft_set_approval_for_all_operation& o );
|
||||||
|
};
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
47
libraries/chain/include/graphene/chain/nft_object.hpp
Normal file
47
libraries/chain/include/graphene/chain/nft_object.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
#pragma once
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
#include <graphene/db/object.hpp>
|
||||||
|
#include <graphene/db/generic_index.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
using namespace graphene::db;
|
||||||
|
|
||||||
|
class nft_object : public abstract_object<nft_object>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint8_t space_id = protocol_ids;
|
||||||
|
static const uint8_t type_id = nft_object_type;
|
||||||
|
|
||||||
|
account_id_type owner;
|
||||||
|
vector<account_id_type> approved_operators;
|
||||||
|
std::string metadata;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct by_owner;
|
||||||
|
struct by_owner_and_id;
|
||||||
|
using nft_multi_index_type = multi_index_container<
|
||||||
|
nft_object,
|
||||||
|
indexed_by<
|
||||||
|
ordered_unique< tag<by_id>,
|
||||||
|
member<object, object_id_type, &object::id>
|
||||||
|
>,
|
||||||
|
ordered_non_unique< tag<by_owner>,
|
||||||
|
member<nft_object, account_id_type, &nft_object::owner>
|
||||||
|
>,
|
||||||
|
ordered_unique< tag<by_owner_and_id>,
|
||||||
|
composite_key<nft_object,
|
||||||
|
member<nft_object, account_id_type, &nft_object::owner>,
|
||||||
|
member<object, object_id_type, &object::id>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
using nft_index = generic_index<nft_object, nft_multi_index_type>;
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::nft_object, (graphene::db::object),
|
||||||
|
(owner)
|
||||||
|
(approved_operators)
|
||||||
|
(metadata) )
|
||||||
|
|
||||||
62
libraries/chain/include/graphene/chain/protocol/nft_ops.hpp
Normal file
62
libraries/chain/include/graphene/chain/protocol/nft_ops.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#pragma once
|
||||||
|
#include <graphene/chain/protocol/base.hpp>
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
struct nft_create_operation : public base_operation
|
||||||
|
{
|
||||||
|
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
||||||
|
asset fee;
|
||||||
|
|
||||||
|
account_id_type payer;
|
||||||
|
nft_id_type nft_id;
|
||||||
|
|
||||||
|
account_id_type fee_payer()const { return payer; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nft_safe_transfer_from_operation : public base_operation
|
||||||
|
{
|
||||||
|
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
||||||
|
asset fee;
|
||||||
|
|
||||||
|
account_id_type payer;
|
||||||
|
nft_id_type nft_id;
|
||||||
|
|
||||||
|
account_id_type fee_payer()const { return payer; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nft_approve_operation : public base_operation
|
||||||
|
{
|
||||||
|
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
||||||
|
asset fee;
|
||||||
|
|
||||||
|
account_id_type payer;
|
||||||
|
nft_id_type nft_id;
|
||||||
|
|
||||||
|
account_id_type fee_payer()const { return payer; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nft_set_approval_for_all_operation : public base_operation
|
||||||
|
{
|
||||||
|
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
||||||
|
asset fee;
|
||||||
|
|
||||||
|
account_id_type payer;
|
||||||
|
nft_id_type nft_id;
|
||||||
|
|
||||||
|
account_id_type fee_payer()const { return payer; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT( graphene::chain::nft_create_operation::fee_parameters_type, (fee) )
|
||||||
|
FC_REFLECT( graphene::chain::nft_safe_transfer_from_operation::fee_parameters_type, (fee) )
|
||||||
|
FC_REFLECT( graphene::chain::nft_approve_operation::fee_parameters_type, (fee) )
|
||||||
|
FC_REFLECT( graphene::chain::nft_set_approval_for_all_operation::fee_parameters_type, (fee) )
|
||||||
|
|
||||||
|
FC_REFLECT( graphene::chain::nft_create_operation, (fee) (payer) (nft_id) )
|
||||||
|
FC_REFLECT( graphene::chain::nft_safe_transfer_from_operation, (fee) (payer) (nft_id) )
|
||||||
|
FC_REFLECT( graphene::chain::nft_approve_operation, (fee) (payer) (nft_id) )
|
||||||
|
FC_REFLECT( graphene::chain::nft_set_approval_for_all_operation, (fee) (payer) (nft_id) )
|
||||||
|
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
#include <graphene/chain/protocol/event.hpp>
|
#include <graphene/chain/protocol/event.hpp>
|
||||||
#include <graphene/chain/protocol/betting_market.hpp>
|
#include <graphene/chain/protocol/betting_market.hpp>
|
||||||
#include <graphene/chain/protocol/tournament.hpp>
|
#include <graphene/chain/protocol/tournament.hpp>
|
||||||
|
#include <graphene/chain/protocol/nft_ops.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
|
@ -135,7 +136,11 @@ namespace graphene { namespace chain {
|
||||||
ticket_purchase_operation,
|
ticket_purchase_operation,
|
||||||
lottery_reward_operation,
|
lottery_reward_operation,
|
||||||
lottery_end_operation,
|
lottery_end_operation,
|
||||||
sweeps_vesting_claim_operation
|
sweeps_vesting_claim_operation,
|
||||||
|
nft_create_operation,
|
||||||
|
nft_safe_transfer_from_operation,
|
||||||
|
nft_approve_operation,
|
||||||
|
nft_set_approval_for_all_operation
|
||||||
> operation;
|
> operation;
|
||||||
|
|
||||||
/// @} // operations group
|
/// @} // operations group
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,7 @@ namespace graphene { namespace chain {
|
||||||
betting_market_group_object_type,
|
betting_market_group_object_type,
|
||||||
betting_market_object_type,
|
betting_market_object_type,
|
||||||
bet_object_type,
|
bet_object_type,
|
||||||
|
nft_object_type,
|
||||||
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -230,6 +231,7 @@ namespace graphene { namespace chain {
|
||||||
class betting_market_group_object;
|
class betting_market_group_object;
|
||||||
class betting_market_object;
|
class betting_market_object;
|
||||||
class bet_object;
|
class bet_object;
|
||||||
|
class nft_object;
|
||||||
|
|
||||||
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
||||||
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
||||||
|
|
@ -256,6 +258,7 @@ namespace graphene { namespace chain {
|
||||||
typedef object_id< protocol_ids, betting_market_group_object_type, betting_market_group_object> betting_market_group_id_type;
|
typedef object_id< protocol_ids, betting_market_group_object_type, betting_market_group_object> betting_market_group_id_type;
|
||||||
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
||||||
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
||||||
|
typedef object_id< protocol_ids, nft_object_type, nft_object> nft_id_type;
|
||||||
|
|
||||||
// implementation types
|
// implementation types
|
||||||
class global_property_object;
|
class global_property_object;
|
||||||
|
|
@ -436,6 +439,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type,
|
||||||
(betting_market_group_object_type)
|
(betting_market_group_object_type)
|
||||||
(betting_market_object_type)
|
(betting_market_object_type)
|
||||||
(bet_object_type)
|
(bet_object_type)
|
||||||
|
(nft_object_type)
|
||||||
(OBJECT_TYPE_COUNT)
|
(OBJECT_TYPE_COUNT)
|
||||||
)
|
)
|
||||||
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
||||||
|
|
@ -505,6 +509,7 @@ FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
|
||||||
|
FC_REFLECT_TYPENAME( graphene::chain::nft_id_type )
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::void_t, )
|
FC_REFLECT( graphene::chain::void_t, )
|
||||||
|
|
||||||
|
|
|
||||||
58
libraries/chain/nft_evaluator.cpp
Normal file
58
libraries/chain/nft_evaluator.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include <graphene/chain/nft_evaluator.hpp>
|
||||||
|
#include <graphene/chain/nft_object.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
void_result nft_create_evaluator::do_evaluate( const nft_create_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
void_result nft_create_evaluator::do_apply( const nft_create_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
|
||||||
|
void_result nft_safe_transfer_from_evaluator::do_evaluate( const nft_safe_transfer_from_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
void_result nft_safe_transfer_from_evaluator::do_apply( const nft_safe_transfer_from_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
|
||||||
|
void_result nft_approve_evaluator::do_evaluate( const nft_approve_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
void_result nft_approve_evaluator::do_apply( const nft_approve_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
|
||||||
|
void_result nft_set_approval_for_all_evaluator::do_evaluate( const nft_set_approval_for_all_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
void_result nft_set_approval_for_all_evaluator::do_apply( const nft_set_approval_for_all_operation& op )
|
||||||
|
{ try {
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
|
@ -43,6 +43,7 @@
|
||||||
#include <graphene/chain/tournament_object.hpp>
|
#include <graphene/chain/tournament_object.hpp>
|
||||||
#include <graphene/chain/match_object.hpp>
|
#include <graphene/chain/match_object.hpp>
|
||||||
#include <graphene/chain/game_object.hpp>
|
#include <graphene/chain/game_object.hpp>
|
||||||
|
#include <graphene/chain/nft_object.hpp>
|
||||||
|
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue