* 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: satyakoneru <15652887+satyakoneru@users.noreply.github.com> 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: Satyanarayana Koneru <skoneru@SK-GT.local> Co-authored-by: obucina <11353193+obucina@users.noreply.github.com> Co-authored-by: satyakoneru <15652887+satyakoneru@users.noreply.github.com>
133 lines
4.5 KiB
C++
133 lines
4.5 KiB
C++
#include <graphene/chain/custom_permission_evaluator.hpp>
|
|
|
|
#include <graphene/chain/database.hpp>
|
|
#include <graphene/chain/custom_permission_object.hpp>
|
|
#include <graphene/chain/custom_account_authority_object.hpp>
|
|
#include <graphene/chain/hardfork.hpp>
|
|
|
|
namespace graphene
|
|
{
|
|
namespace chain
|
|
{
|
|
|
|
void_result create_custom_permission_evaluator::do_evaluate(const custom_permission_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);
|
|
for (const auto &account_weight_pair : op.auth.account_auths)
|
|
{
|
|
account_weight_pair.first(d);
|
|
}
|
|
|
|
const auto &pindex = d.get_index_type<custom_permission_index>().indices().get<by_account_and_permission>();
|
|
auto pitr = pindex.find(boost::make_tuple(op.owner_account, op.permission_name));
|
|
FC_ASSERT(pitr == pindex.end(), "Permission name already exists for the given account");
|
|
auto count = pindex.count(boost::make_tuple(op.owner_account));
|
|
FC_ASSERT(count < d.get_global_properties().parameters.rbac_max_permissions_per_account(), "Max permissions per account reached");
|
|
return void_result();
|
|
}
|
|
FC_CAPTURE_AND_RETHROW((op))
|
|
}
|
|
|
|
object_id_type create_custom_permission_evaluator::do_apply(const custom_permission_create_operation &op)
|
|
{
|
|
try
|
|
{
|
|
database &d = db();
|
|
return d.create<custom_permission_object>([&op](custom_permission_object &obj) mutable {
|
|
obj.account = op.owner_account;
|
|
obj.permission_name = op.permission_name;
|
|
obj.auth = op.auth;
|
|
})
|
|
.id;
|
|
}
|
|
FC_CAPTURE_AND_RETHROW((op))
|
|
}
|
|
|
|
void_result update_custom_permission_evaluator::do_evaluate(const custom_permission_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_permission_object &pobj = op.permission_id(d);
|
|
FC_ASSERT(pobj.account == op.owner_account, "Only owner account can update permission object");
|
|
if (op.new_auth)
|
|
{
|
|
FC_ASSERT(!(*op.new_auth == pobj.auth), "New authority provided is not different from old authority");
|
|
for (const auto &account_weight_pair : op.new_auth->account_auths)
|
|
{
|
|
account_weight_pair.first(d);
|
|
}
|
|
}
|
|
return void_result();
|
|
}
|
|
FC_CAPTURE_AND_RETHROW((op))
|
|
}
|
|
|
|
object_id_type update_custom_permission_evaluator::do_apply(const custom_permission_update_operation &op)
|
|
{
|
|
try
|
|
{
|
|
database &d = db();
|
|
const custom_permission_object &pobj = op.permission_id(d);
|
|
d.modify(pobj, [&op](custom_permission_object &obj) {
|
|
if (op.new_auth)
|
|
obj.auth = *op.new_auth;
|
|
});
|
|
|
|
return op.permission_id;
|
|
}
|
|
FC_CAPTURE_AND_RETHROW((op))
|
|
}
|
|
|
|
void_result delete_custom_permission_evaluator::do_evaluate(const custom_permission_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_permission_object &pobj = op.permission_id(d);
|
|
FC_ASSERT(pobj.account == op.owner_account, "Only owner account can delete permission object");
|
|
return void_result();
|
|
}
|
|
FC_CAPTURE_AND_RETHROW((op))
|
|
}
|
|
|
|
void_result delete_custom_permission_evaluator::do_apply(const custom_permission_delete_operation &op)
|
|
{
|
|
try
|
|
{
|
|
database &d = db();
|
|
const custom_permission_object &pobj = op.permission_id(d);
|
|
// Remove the account authority objects linked to this permission
|
|
const auto& cindex = d.get_index_type<custom_account_authority_index>().indices().get<by_permission_and_op>();
|
|
vector<std::reference_wrapper<const custom_account_authority_object>> custom_auths;
|
|
auto crange = cindex.equal_range(boost::make_tuple(pobj.id));
|
|
// Store the references to the account authorities
|
|
for(const custom_account_authority_object& cobj : boost::make_iterator_range(crange.first, crange.second))
|
|
{
|
|
custom_auths.push_back(cobj);
|
|
}
|
|
// Now remove the account authorities
|
|
for(const auto& cauth : custom_auths)
|
|
{
|
|
d.remove(cauth);
|
|
}
|
|
// Now finally remove the permission
|
|
d.remove(pobj);
|
|
return void_result();
|
|
}
|
|
FC_CAPTURE_AND_RETHROW((op))
|
|
}
|
|
|
|
} // namespace chain
|
|
} // namespace graphene
|