github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/account/account_actor.go (about) 1 package account 2 3 import ( 4 addr "github.com/filecoin-project/go-address" 5 "github.com/filecoin-project/go-state-types/abi" 6 "github.com/filecoin-project/go-state-types/cbor" 7 "github.com/filecoin-project/go-state-types/exitcode" 8 "github.com/ipfs/go-cid" 9 10 "github.com/filecoin-project/specs-actors/v4/actors/builtin" 11 "github.com/filecoin-project/specs-actors/v4/actors/runtime" 12 ) 13 14 type Actor struct{} 15 16 func (a Actor) Exports() []interface{} { 17 return []interface{}{ 18 1: a.Constructor, 19 2: a.PubkeyAddress, 20 } 21 } 22 23 func (a Actor) Code() cid.Cid { 24 return builtin.AccountActorCodeID 25 } 26 27 func (a Actor) State() cbor.Er { 28 return new(State) 29 } 30 31 var _ runtime.VMActor = Actor{} 32 33 type State struct { 34 Address addr.Address 35 } 36 37 func (a Actor) Constructor(rt runtime.Runtime, address *addr.Address) *abi.EmptyValue { 38 // Account actors are created implicitly by sending a message to a pubkey-style address. 39 // This constructor is not invoked by the InitActor, but by the system. 40 rt.ValidateImmediateCallerIs(builtin.SystemActorAddr) 41 switch address.Protocol() { 42 case addr.SECP256K1: 43 case addr.BLS: 44 break // ok 45 default: 46 rt.Abortf(exitcode.ErrIllegalArgument, "address must use BLS or SECP protocol, got %v", address.Protocol()) 47 } 48 st := State{Address: *address} 49 rt.StateCreate(&st) 50 return nil 51 } 52 53 // Fetches the pubkey-type address from this actor. 54 func (a Actor) PubkeyAddress(rt runtime.Runtime, _ *abi.EmptyValue) *addr.Address { 55 rt.ValidateImmediateCallerAcceptAny() 56 var st State 57 rt.StateReadonly(&st) 58 return &st.Address 59 }