-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_actor.go
59 lines (49 loc) · 1.48 KB
/
account_actor.go
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
package account
import (
addr "github.com/chenjianmei111/go-address"
"github.com/chenjianmei111/go-state-types/abi"
"github.com/chenjianmei111/go-state-types/cbor"
"github.com/chenjianmei111/go-state-types/exitcode"
"github.com/ipfs/go-cid"
"github.com/chenjianmei111/specs-actors/v3/actors/builtin"
"github.com/chenjianmei111/specs-actors/v3/actors/runtime"
)
type Actor struct{}
func (a Actor) Exports() []interface{} {
return []interface{}{
1: a.Constructor,
2: a.PubkeyAddress,
}
}
func (a Actor) Code() cid.Cid {
return builtin.AccountActorCodeID
}
func (a Actor) State() cbor.Er {
return new(State)
}
var _ runtime.VMActor = Actor{}
type State struct {
Address addr.Address
}
func (a Actor) Constructor(rt runtime.Runtime, address *addr.Address) *abi.EmptyValue {
// Account actors are created implicitly by sending a message to a pubkey-style address.
// This constructor is not invoked by the InitActor, but by the system.
rt.ValidateImmediateCallerIs(builtin.SystemActorAddr)
switch address.Protocol() {
case addr.SECP256K1:
case addr.BLS:
break // ok
default:
rt.Abortf(exitcode.ErrIllegalArgument, "address must use BLS or SECP protocol, got %v", address.Protocol())
}
st := State{Address: *address}
rt.StateCreate(&st)
return nil
}
// Fetches the pubkey-type address from this actor.
func (a Actor) PubkeyAddress(rt runtime.Runtime, _ *abi.EmptyValue) *addr.Address {
rt.ValidateImmediateCallerAcceptAny()
var st State
rt.StateReadonly(&st)
return &st.Address
}