Graphene Updates and DApp Support #643

Closed
nathanielhourt wants to merge 84 commits from dapp-support into develop
2 changed files with 28 additions and 0 deletions
Showing only changes of commit 8df442a65f - Show all commits

View file

@ -183,6 +183,13 @@ namespace graphene { namespace db {
FC_THROW_EXCEPTION( fc::assert_exception, "invalid index type" );
}
void delete_secondary_index(const secondary_index& secondary) {
auto itr = std::find_if(_sindex.begin(), _sindex.end(),
[&secondary](const auto& ptr) { return &secondary == ptr.get(); });
FC_ASSERT(itr != _sindex.end(), "Cannot remove secondary index: secondary index not found");
_sindex.erase(itr);
}
protected:
vector< shared_ptr<index_observer> > _observers;
vector< unique_ptr<secondary_index> > _sindex;

View file

@ -152,6 +152,27 @@ namespace graphene { namespace db {
{
return get_mutable_index_type<PrimaryIndexType>().template add_secondary_index<SecondaryIndexType>();
}
template<typename SecondaryIndexType>
SecondaryIndexType* add_secondary_index(const uint8_t space_id, const uint8_t type_id)
{
auto* base_primary = dynamic_cast<base_primary_index*>(&get_mutable_index(space_id, type_id));
FC_ASSERT(base_primary != nullptr,
"Cannot add secondary index: index for space ID ${S} and type ID ${T} does not support secondary indexes.",
("S", space_id)("T", type_id));
return base_primary->template add_secondary_index<SecondaryIndexType>();
}
template<typename PrimaryIndexType>
void delete_secondary_index(const secondary_index& secondary) {
get_mutable_index_type<PrimaryIndexType>().delete_secondary_index(secondary);
}
void delete_secondary_index(const uint8_t space_id, const uint8_t type_id, const secondary_index& secondary) {
auto* base_primary = dynamic_cast<base_primary_index*>(&get_mutable_index(space_id, type_id));
FC_ASSERT(base_primary != nullptr,
"Cannot add secondary index: index for space ID ${S} and type ID ${T} does not support secondary indexes.",
("S", space_id)("T", type_id));
base_primary->delete_secondary_index(secondary);
}
void pop_undo();