Skip to content

Commit

Permalink
feat: make the core defined transactions timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 16, 2024
1 parent d821df5 commit a530b4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 8 additions & 1 deletion internal/controller/ledger/controller_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,17 @@ func (ctrl *DefaultController) CreateTransaction(ctx context.Context, parameters
finalMetadata[k] = v
}

now := time.Now()
ts := runScript.Timestamp
if ts.IsZero() {
ts = now
}

transaction := ledger.NewTransaction().
WithPostings(result.Postings...).
WithMetadata(finalMetadata).
WithTimestamp(runScript.Timestamp). // If empty will be filled by the database
WithTimestamp(ts).
WithInsertedAt(now).
WithReference(runScript.Reference)
err = sqlTX.CommitTransaction(ctx, &transaction)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/ledger/controller_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ func TestCreateTransaction(t *testing.T) {
})

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

sqlTX.EXPECT().
CommitTransaction(gomock.Any(), &tx).
CommitTransaction(gomock.Any(), gomock.Any()).
Return(nil)

sqlTX.EXPECT().
Expand All @@ -60,7 +59,7 @@ func TestCreateTransaction(t *testing.T) {
})

listener.EXPECT().
CommittedTransactions(gomock.Any(), "", tx, ledger.AccountMetadata{})
CommittedTransactions(gomock.Any(), "", gomock.Any(), ledger.AccountMetadata{})

_, err := l.CreateTransaction(context.Background(), Parameters{}, runScript)
require.NoError(t, err)
Expand Down

0 comments on commit a530b4a

Please sign in to comment.