Skip to content

Commit e89c7df

Browse files
Feature/mv builtin actors (#87)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 8066e47 commit e89c7df

35 files changed

+204
-91
lines changed

core/codec/cbor/cbor_decode_stream.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ namespace fc::codec::cbor {
8888
return *this;
8989
}
9090

91+
/// Decodes elements to map
92+
template <typename T>
93+
CborDecodeStream &operator>>(std::map<std::string, T> &items) {
94+
for (auto &m : map()) {
95+
m.second >> items[m.first];
96+
}
97+
return *this;
98+
}
99+
91100
/** Decodes bytes */
92101
CborDecodeStream &operator>>(std::vector<uint8_t> &bytes);
93102
/** Decodes string */

core/codec/cbor/cbor_encode_stream.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ namespace fc::codec::cbor {
6161
return *this << l;
6262
}
6363

64+
/// Encodes elements into map
65+
template <typename T>
66+
CborEncodeStream &operator<<(const std::map<std::string, T> &items) {
67+
auto m = map();
68+
for (auto &item : items) {
69+
m[item.first] << item.second;
70+
}
71+
return *this << m;
72+
}
73+
6474
/// Encodes vector into list
6575
template <typename T>
6676
CborEncodeStream &operator<<(const std::vector<T> &values) {

core/vm/actor/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
add_subdirectory(builtin)
77

88
add_library(actor
9-
account_actor.cpp
109
actor.cpp
11-
init_actor.cpp
12-
cron_actor.cpp
1310
impl/invoker_impl.cpp
14-
storage_power_actor.cpp
1511
)
1612
target_link_libraries(actor
13+
account_actor
1714
address
15+
buffer
1816
cid
1917
exit_code
20-
hamt
21-
power_table
18+
init_actor
2219
multisig_actor
20+
storage_power_actor
21+
cron_actor
2322
)

core/vm/actor/builtin/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

6+
add_subdirectory(account)
7+
add_subdirectory(cron)
8+
add_subdirectory(init)
69
add_subdirectory(multisig)
10+
add_subdirectory(storage_power)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
add_library(account_actor
7+
account_actor.cpp
8+
)
9+
target_link_libraries(account_actor
10+
actor
11+
outcome
12+
)

core/vm/actor/account_actor.cpp renamed to core/vm/actor/builtin/account/account_actor.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
#include "vm/actor/account_actor.hpp"
6+
#include "vm/actor/builtin/account/account_actor.hpp"
77

88
#include "vm/exit_code/exit_code.hpp"
99

10-
namespace fc::vm::actor {
10+
namespace fc::vm::actor::builtin::account {
11+
1112
outcome::result<Actor> AccountActor::create(
1213
const std::shared_ptr<StateTree> &state_tree, const Address &address) {
1314
if (!address.isKeyType()) {
@@ -40,4 +41,4 @@ namespace fc::vm::actor {
4041
state_tree->getStore()->getCbor<AccountActorState>(actor.head));
4142
return account_actor_state.address;
4243
}
43-
} // namespace fc::vm::actor
44+
} // namespace fc::vm::actor::builtin::account

core/vm/actor/account_actor.hpp renamed to core/vm/actor/builtin/account/account_actor.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#include "primitives/address/address_codec.hpp"
1010
#include "vm/state/state_tree.hpp"
1111

12-
namespace fc::vm::actor {
12+
namespace fc::vm::actor::builtin::account {
13+
1314
using primitives::address::Address;
1415
using primitives::address::Protocol;
1516
using state::StateTree;
@@ -47,6 +48,6 @@ namespace fc::vm::actor {
4748
static outcome::result<Address> resolveToKeyAddress(
4849
const std::shared_ptr<StateTree> &state_tree, const Address &address);
4950
};
50-
} // namespace fc::vm::actor
51+
} // namespace fc::vm::actor::builtin::account
5152

5253
#endif // CPP_FILECOIN_CORE_VM_ACTOR_ACCOUNT_ACTOR_HPP
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
add_library(cron_actor
7+
cron_actor.cpp
8+
)
9+
target_link_libraries(cron_actor
10+
actor
11+
outcome
12+
)

core/vm/actor/cron_actor.cpp renamed to core/vm/actor/builtin/cron/cron_actor.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
#include "vm/actor/cron_actor.hpp"
6+
#include "vm/actor/builtin/cron/cron_actor.hpp"
77

8-
namespace fc::vm::actor::cron_actor {
8+
namespace fc::vm::actor::builtin::cron {
99
/**
1010
* Entries is a set of actors (and corresponding methods) to call during
1111
* EpochTick
1212
*/
1313
std::vector<CronTableEntry> entries = {
14-
{kStoragePowerAddress, {SpaMethods::CHECK_PROOF_SUBMISSIONS}}};
14+
{kStoragePowerAddress,
15+
{storage_power::SpaMethods::CHECK_PROOF_SUBMISSIONS}}};
1516

1617
outcome::result<InvocationOutput> epochTick(const Actor &actor,
1718
Runtime &runtime,
@@ -29,4 +30,4 @@ namespace fc::vm::actor::cron_actor {
2930
const ActorExports exports = {
3031
{kEpochTickMethodNumber, ActorMethod(epochTick)},
3132
};
32-
} // namespace fc::vm::actor::cron_actor
33+
} // namespace fc::vm::actor::builtin::cron

core/vm/actor/cron_actor.hpp renamed to core/vm/actor/builtin/cron/cron_actor.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
#define CPP_FILECOIN_CORE_VM_ACTOR_CRON_ACTOR_HPP
88

99
#include "vm/actor/actor_method.hpp"
10-
#include "vm/actor/storage_power_actor.hpp"
10+
#include "vm/actor/builtin/storage_power/storage_power_actor.hpp"
11+
12+
namespace fc::vm::actor::builtin::cron {
1113

12-
namespace fc::vm::actor::cron_actor {
1314
struct CronTableEntry {
1415
Address to_addr;
1516
MethodNumber method_num{};
@@ -30,6 +31,6 @@ namespace fc::vm::actor::cron_actor {
3031

3132
extern const ActorExports exports;
3233

33-
} // namespace fc::vm::actor::cron_actor
34+
} // namespace fc::vm::actor::builtin::cron
3435

3536
#endif // CPP_FILECOIN_CORE_VM_ACTOR_CRON_ACTOR_HPP

0 commit comments

Comments
 (0)