Skip to content

Commit

Permalink
feat: renamed Machine into NumscriptRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone authored and gfyrag committed Oct 16, 2024
1 parent 861f7f2 commit 2c87e77
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion internal/controller/ledger/controller_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (ctrl *DefaultController) createTransaction(ctx context.Context, sqlTX TX,
"ExecuteMachine",
ctrl.tracer,
ctrl.executeMachineHistogram,
func(ctx context.Context) (*MachineResult, error) {
func(ctx context.Context) (*NumscriptExecutionResult, error) {
return m.Execute(ctx, sqlTX, parameters.Input.Vars)
},
)
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/ledger/controller_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCreateTransaction(t *testing.T) {
ctrl := gomock.NewController(t)

store := NewMockStore(ctrl)
machine := NewMockMachine(ctrl)
numscriptRuntime := NewMockNumscriptRuntime(ctrl)
parser := NewMockNumscriptParser(ctrl)
sqlTX := NewMockTX(ctrl)

Expand All @@ -34,7 +34,7 @@ func TestCreateTransaction(t *testing.T) {

parser.EXPECT().
Parse(runScript.Plain).
Return(machine, nil)
Return(numscriptRuntime, nil)

store.EXPECT().
WithTX(gomock.Any(), nil, gomock.Any()).
Expand All @@ -44,9 +44,9 @@ func TestCreateTransaction(t *testing.T) {
})

posting := ledger.NewPosting("world", "bank", "USD", big.NewInt(100))
machine.EXPECT().
numscriptRuntime.EXPECT().
Execute(gomock.Any(), sqlTX, runScript.Vars).
Return(&MachineResult{
Return(&NumscriptExecutionResult{
Postings: ledger.Postings{posting},
}, nil)

Expand Down
18 changes: 9 additions & 9 deletions internal/controller/ledger/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ import (
"github.com/formancehq/ledger/internal/machine/vm/program"
)

type MachineResult struct {
type NumscriptExecutionResult struct {
Postings ledger.Postings `json:"postings"`
Metadata metadata.Metadata `json:"metadata"`
AccountMetadata map[string]metadata.Metadata
}

//go:generate mockgen -write_source_comment=false -write_package_comment=false -source machine.go -destination machine_generated_test.go -package ledger . Machine
type Machine interface {
Execute(context.Context, TX, map[string]string) (*MachineResult, error)
type NumscriptRuntime interface {
Execute(context.Context, TX, map[string]string) (*NumscriptExecutionResult, error)
}

type DefaultMachineAdapter struct {
type MachineNumscriptRuntimeAdapter struct {
program program.Program
machine *vm.Machine
}

func (d *DefaultMachineAdapter) Execute(ctx context.Context, tx TX, vars map[string]string) (*MachineResult, error) {
func (d *MachineNumscriptRuntimeAdapter) Execute(ctx context.Context, tx TX, vars map[string]string) (*NumscriptExecutionResult, error) {
store := newVmStoreAdapter(tx)

d.machine = vm.NewMachine(d.program)
Expand Down Expand Up @@ -65,7 +65,7 @@ func (d *DefaultMachineAdapter) Execute(ctx context.Context, tx TX, vars map[str
}
}

return &MachineResult{
return &NumscriptExecutionResult{
Postings: collectionutils.Map(d.machine.Postings, func(from vm.Posting) ledger.Posting {
return ledger.Posting{
Source: from.Source,
Expand All @@ -79,10 +79,10 @@ func (d *DefaultMachineAdapter) Execute(ctx context.Context, tx TX, vars map[str
}, nil
}

func NewDefaultMachine(p program.Program) *DefaultMachineAdapter {
return &DefaultMachineAdapter{
func NewMachineNumscriptRuntimeAdapter(p program.Program) *MachineNumscriptRuntimeAdapter {
return &MachineNumscriptRuntimeAdapter{
program: p,
}
}

var _ Machine = (*DefaultMachineAdapter)(nil)
var _ NumscriptRuntime = (*MachineNumscriptRuntimeAdapter)(nil)
6 changes: 3 additions & 3 deletions internal/controller/ledger/machine_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ package ledger
type NumscriptParser interface {
// Parse can return following errors:
// * ErrCompilationFailed
Parse(script string) (Machine, error)
Parse(script string) (NumscriptRuntime, error)
}

type DefaultNumscriptParser struct {
compiler Compiler
}

func (d *DefaultNumscriptParser) Parse(script string) (Machine, error) {
func (d *DefaultNumscriptParser) Parse(script string) (NumscriptRuntime, error) {
ret, err := d.compiler.Compile(script)
if err != nil {
return nil, err
}
return NewDefaultMachine(*ret), nil
return NewMachineNumscriptRuntimeAdapter(*ret), nil
}

func NewDefaultMachineFactory(compiler Compiler) *DefaultNumscriptParser {
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/ledger/machine_factory_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions internal/controller/ledger/machine_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2c87e77

Please sign in to comment.