-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtransaction_object.cpp
More file actions
72 lines (56 loc) · 2.02 KB
/
transaction_object.cpp
File metadata and controls
72 lines (56 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <steemit/chain/transaction_object.hpp>
namespace steemit { namespace chain {
const object* transaction_index::create(const std::function<void (object*)>& constructor, object_id_type)
{
transaction_object obj;
obj.id = get_next_available_id();
constructor(&obj);
auto result = _index.insert(std::move(obj));
FC_ASSERT(result.second, "Could not create transaction_object! Most likely a uniqueness constraint is violated.");
return &*result.first;
}
void transaction_index::modify(const object* obj,
const std::function<void (object*)>& m)
{
assert(obj != nullptr);
FC_ASSERT(obj->id < _index.size());
const transaction_object* t = dynamic_cast<const transaction_object*>(obj);
assert(t != nullptr);
auto itr = _index.find(obj->id.instance());
assert(itr != _index.end());
_index.modify(itr, [&m](transaction_object& o) { m(&o); });
}
void transaction_index::add(unique_ptr<object> o)
{
assert(o);
object_id_type id = o->id;
assert(id.space() == transaction_object::space_id);
assert(id.type() == transaction_object::type_id);
assert(id.instance() == size());
auto trx = dynamic_cast<transaction_object*>(o.get());
assert(trx != nullptr);
o.release();
auto result = _index.insert(std::move(*trx));
FC_ASSERT(result.second, "Could not insert transaction_object! Most likely a uniqueness constraint is violated.");
}
void transaction_index::remove(object_id_type id)
{
auto& index = _index.get<instance>();
auto itr = index.find(id.instance());
if( itr == index.end() )
return;
assert(id.space() == transaction_object::space_id);
assert(id.type() == transaction_object::type_id);
index.erase(itr);
}
const object*transaction_index::get(object_id_type id) const
{
if( id.type() != transaction_object::type_id ||
id.space() != transaction_object::space_id )
return nullptr;
auto itr = _index.find(id.instance());
if( itr == _index.end() )
return nullptr;
return &*itr;
}
} } // steemit::chain