-
Notifications
You must be signed in to change notification settings - Fork 4
/
vcallresult.go
63 lines (48 loc) · 1.69 KB
/
vcallresult.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
//go:generate sm-uml-gen -f $GOFILE
package handlers
import (
"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/vanilla/throw"
)
type SMVCallResult struct {
// input arguments
Meta *rms.Meta
Payload *rms.VCallResult
}
/* -------- Declaration ------------- */
var dSMVCallResultInstance smachine.StateMachineDeclaration = &dSMVCallResult{}
type dSMVCallResult struct {
smachine.StateMachineDeclTemplate
}
func (*dSMVCallResult) InjectDependencies(_ smachine.StateMachine, _ smachine.SlotLink, _ injector.DependencyInjector) {
}
func (*dSMVCallResult) GetInitStateFor(sm smachine.StateMachine) smachine.InitFunc {
s := sm.(*SMVCallResult)
return s.Init
}
/* -------- Instance ------------- */
func (s *SMVCallResult) GetStateMachineDeclaration() smachine.StateMachineDeclaration {
return dSMVCallResultInstance
}
func (s *SMVCallResult) Init(ctx smachine.InitializationContext) smachine.StateUpdate {
return ctx.Jump(s.stepProcess)
}
func (s *SMVCallResult) stepProcess(ctx smachine.ExecutionContext) smachine.StateUpdate {
if s.Payload.CallType != rms.CallTypeMethod && s.Payload.CallType != rms.CallTypeConstructor {
panic(throw.IllegalValue())
}
link, bargeInCallback := ctx.GetPublishedGlobalAliasAndBargeIn(s.Payload.CallOutgoing)
if link.IsZero() {
return ctx.Error(throw.E("no one is waiting"))
}
if bargeInCallback == nil {
return ctx.Error(throw.Impossible())
}
done := bargeInCallback.CallWithParam(s.Payload)
if !done {
return ctx.Error(throw.E("no one is waiting anymore"))
}
return ctx.Stop()
}