github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/cron/cron_actor.go (about) 1 package cron 2 3 import ( 4 "github.com/filecoin-project/go-state-types/abi" 5 "github.com/filecoin-project/go-state-types/cbor" 6 cron0 "github.com/filecoin-project/specs-actors/actors/builtin/cron" 7 "github.com/ipfs/go-cid" 8 9 "github.com/filecoin-project/specs-actors/v4/actors/builtin" 10 "github.com/filecoin-project/specs-actors/v4/actors/runtime" 11 ) 12 13 // The cron actor is a built-in singleton that sends messages to other registered actors at the end of each epoch. 14 type Actor struct{} 15 16 func (a Actor) Exports() []interface{} { 17 return []interface{}{ 18 builtin.MethodConstructor: a.Constructor, 19 2: a.EpochTick, 20 } 21 } 22 23 func (a Actor) Code() cid.Cid { 24 return builtin.CronActorCodeID 25 } 26 27 func (a Actor) IsSingleton() bool { 28 return true 29 } 30 31 func (a Actor) State() cbor.Er { 32 return new(State) 33 } 34 35 var _ runtime.VMActor = Actor{} 36 37 //type ConstructorParams struct { 38 // Entries []Entry 39 //} 40 type ConstructorParams = cron0.ConstructorParams 41 42 type EntryParam = cron0.Entry 43 44 func (a Actor) Constructor(rt runtime.Runtime, params *ConstructorParams) *abi.EmptyValue { 45 rt.ValidateImmediateCallerIs(builtin.SystemActorAddr) 46 entries := make([]Entry, len(params.Entries)) 47 for i, e := range params.Entries { 48 entries[i] = Entry(e) // Identical 49 } 50 rt.StateCreate(ConstructState(entries)) 51 return nil 52 } 53 54 // Invoked by the system after all other messages in the epoch have been processed. 55 func (a Actor) EpochTick(rt runtime.Runtime, _ *abi.EmptyValue) *abi.EmptyValue { 56 rt.ValidateImmediateCallerIs(builtin.SystemActorAddr) 57 58 var st State 59 rt.StateReadonly(&st) 60 for _, entry := range st.Entries { 61 _ = rt.Send(entry.Receiver, entry.MethodNum, nil, abi.NewTokenAmount(0), &builtin.Discard{}) 62 // Any error and return value are ignored. 63 } 64 65 return nil 66 }