-
Notifications
You must be signed in to change notification settings - Fork 4
/
vcallrequest.go
64 lines (49 loc) · 1.9 KB
/
vcallrequest.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
60
61
62
63
64
//go:generate sm-uml-gen -f $GOFILE
package handlers
import (
"github.com/insolar/assured-ledger/ledger-core/conveyor"
"github.com/insolar/assured-ledger/ledger-core/conveyor/smachine"
"github.com/insolar/assured-ledger/ledger-core/rms"
"github.com/insolar/assured-ledger/ledger-core/vanilla/injector"
"github.com/insolar/assured-ledger/ledger-core/virtual/execute"
)
type SMVCallRequest struct {
// input arguments
Meta *rms.Meta
Payload *rms.VCallRequest
pulseSlot *conveyor.PulseSlot
}
/* -------- Declaration ------------- */
var dSMVCallRequestInstance smachine.StateMachineDeclaration = &dSMVCallRequest{}
type dSMVCallRequest struct {
smachine.StateMachineDeclTemplate
}
func (*dSMVCallRequest) InjectDependencies(sm smachine.StateMachine, _ smachine.SlotLink, injector injector.DependencyInjector) {
s := sm.(*SMVCallRequest)
injector.MustInject(&s.pulseSlot)
}
func (*dSMVCallRequest) GetInitStateFor(sm smachine.StateMachine) smachine.InitFunc {
s := sm.(*SMVCallRequest)
return s.Init
}
/* -------- Instance ------------- */
func (s *SMVCallRequest) GetStateMachineDeclaration() smachine.StateMachineDeclaration {
return dSMVCallRequestInstance
}
func (s *SMVCallRequest) Init(ctx smachine.InitializationContext) smachine.StateUpdate {
if s.pulseSlot.State() != conveyor.Present {
ctx.Log().Trace("stop processing VCallRequest since we are not in present pulse")
return ctx.Stop()
}
ctx.SetDefaultMigration(s.migrationDefault)
return ctx.Jump(s.stepExecute)
}
func (s *SMVCallRequest) migrationDefault(ctx smachine.MigrationContext) smachine.StateUpdate {
ctx.Log().Trace("stop processing VCallRequest since pulse was changed")
return ctx.Stop()
}
func (s *SMVCallRequest) stepExecute(ctx smachine.ExecutionContext) smachine.StateUpdate {
return ctx.Replace(func(ctx smachine.ConstructionContext) smachine.StateMachine {
return &execute.SMExecute{Meta: s.Meta, Payload: s.Payload}
})
}