Skip to content

Commit 0650e06

Browse files
authored
Market actor methods (#145)
Signed-off-by: turuslan <[email protected]>
1 parent 81953dd commit 0650e06

File tree

11 files changed

+1197
-30
lines changed

11 files changed

+1197
-30
lines changed

core/adt/balance_table.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ OUTCOME_CPP_DEFINE_CATEGORY(fc::adt, BalanceTableError, e) {
1414
}
1515

1616
namespace fc::adt {
17-
outcome::result<TokenAmount> BalanceTable::get(const Key &key) {
18-
OUTCOME_TRY(value, tryGet(key));
19-
if (value) {
20-
return *value;
21-
}
22-
return 0;
23-
}
24-
2517
outcome::result<void> BalanceTable::add(const Key &key, TokenAmount amount) {
2618
OUTCOME_TRY(value, get(key));
2719
value += amount;
2820
OUTCOME_TRY(set(key, value));
2921
return outcome::success();
3022
}
3123

24+
outcome::result<void> BalanceTable::addCreate(const Key &key, TokenAmount amount) {
25+
OUTCOME_TRY(value, tryGet(key));
26+
if (value) {
27+
amount += *value;
28+
}
29+
return set(key, amount);
30+
}
31+
3232
outcome::result<TokenAmount> BalanceTable::subtractWithMin(const Key &key,
3333
TokenAmount amount,
3434
TokenAmount min) {

core/adt/balance_table.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace fc::adt {
1818
struct BalanceTable : public Map<TokenAmount, AddressKeyer> {
1919
using Map::Map;
2020

21-
outcome::result<TokenAmount> get(const Key &key);
22-
2321
outcome::result<void> add(const Key &key, TokenAmount amount);
2422

23+
outcome::result<void> addCreate(const Key &key, TokenAmount amount);
24+
2525
outcome::result<TokenAmount> subtractWithMin(const Key &key,
2626
TokenAmount amount,
2727
TokenAmount min);

core/adt/map.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ namespace fc::adt {
8080

8181
/// Cbor encode map
8282
template <class Stream,
83-
typename V,
84-
typename K,
83+
typename Value,
84+
typename Keyer,
8585
size_t bit_width,
8686
typename = std::enable_if_t<
8787
std::remove_reference_t<Stream>::is_cbor_encoder_stream>>
88-
Stream &operator<<(Stream &&s, const Map<V, K, bit_width> &map) {
88+
Stream &operator<<(Stream &&s, const Map<Value, Keyer, bit_width> &map) {
8989
return s << map.hamt.cid();
9090
}
9191

9292
/// Cbor decode map
9393
template <class Stream,
94-
typename V,
95-
typename K,
94+
typename Value,
95+
typename Keyer,
9696
size_t bit_width,
9797
typename = std::enable_if_t<
9898
std::remove_reference_t<Stream>::is_cbor_decoder_stream>>
99-
Stream &operator>>(Stream &&s, Map<V, K, bit_width> &map) {
99+
Stream &operator>>(Stream &&s, Map<Value, Keyer, bit_width> &map) {
100100
CID root;
101101
s >> root;
102102
map.hamt = {nullptr, root, bit_width};

core/primitives/piece/piece.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,9 @@ namespace fc::primitives::piece {
7575
CID cid;
7676
};
7777

78+
inline bool operator==(const PieceInfo &lhs, const PieceInfo &rhs) {
79+
return lhs.size == rhs.size && lhs.cid == rhs.cid;
80+
}
81+
7882
}; // namespace fc::primitives::piece
7983
#endif // CPP_FILECOIN_PIECE_HPP

core/storage/amt/amt.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ namespace fc::storage::amt {
152152
gsl::span<const uint8_t> value) {
153153
node.has_bits = true;
154154
if (height == 0) {
155-
return boost::get<Node::Values>(node.items)
156-
.insert(std::make_pair(key, value))
157-
.second;
155+
auto &values = boost::get<Node::Values>(node.items);
156+
if (values.insert(std::make_pair(key, value)).second) {
157+
return true;
158+
}
159+
values.at(key) = Value(value);
160+
return false;
158161
}
159162
auto mask = maskAt(height);
160163
OUTCOME_TRY(child, loadLink(node, key / mask, true));

0 commit comments

Comments
 (0)