8
8
#include " vm/exit_code/exit_code.hpp"
9
9
10
10
namespace fc ::vm::actor::builtin::account {
11
-
12
- outcome::result<Actor> AccountActor::create (
13
- const std::shared_ptr<StateTree> &state_tree, const Address &address) {
14
- if (!address.isKeyType ()) {
11
+ ACTOR_METHOD_IMPL (Construct) {
12
+ OUTCOME_TRY (runtime.validateImmediateCallerIs (kSystemActorAddress ));
13
+ if (!params.isKeyType ()) {
15
14
return VMExitCode::ACCOUNT_ACTOR_CREATE_WRONG_ADDRESS_TYPE;
16
15
}
17
- OUTCOME_TRY (state,
18
- state_tree->getStore ()->setCbor (AccountActorState{address}));
19
- Actor actor{kAccountCodeCid , ActorSubstateCID{state}, 0 , 0 };
20
- OUTCOME_TRY (state_tree->registerNewAddress (address, actor));
21
- return actor;
22
- }
23
-
24
- outcome::result<Address> AccountActor::resolveToKeyAddress (
25
- const std::shared_ptr<StateTree> &state_tree, const Address &address) {
26
- if (address.isKeyType ()) {
27
- return address;
28
- }
29
- auto maybe_actor = state_tree->get (address);
30
- if (!maybe_actor) {
31
- return VMExitCode::ACCOUNT_ACTOR_RESOLVE_NOT_FOUND;
32
- }
33
- auto actor = maybe_actor.value ();
34
- if (actor.code != kAccountCodeCid ) {
35
- return VMExitCode::ACCOUNT_ACTOR_RESOLVE_NOT_ACCOUNT_ACTOR;
36
- }
37
- OUTCOME_TRY (account_actor_state,
38
- state_tree->getStore ()->getCbor <AccountActorState>(actor.head ));
39
- return account_actor_state.address ;
16
+ OUTCOME_TRY (runtime.commitState (AccountActorState{params}));
17
+ return outcome::success ();
40
18
}
41
19
42
20
ACTOR_METHOD_IMPL (PubkeyAddress) {
@@ -45,6 +23,7 @@ namespace fc::vm::actor::builtin::account {
45
23
}
46
24
47
25
const ActorExports exports{
26
+ exportMethod<Construct>(),
48
27
exportMethod<PubkeyAddress>(),
49
28
};
50
29
} // namespace fc::vm::actor::builtin::account
0 commit comments