Skip to content

Commit

Permalink
chore: simplify Move model
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent 3d87d01 commit e5eeb81
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 8 deletions.
1 change: 0 additions & 1 deletion internal/moves.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
type Move struct {
bun.BaseModel `bun:"table:moves"`

Ledger string `bun:"ledger,type:varchar"`
TransactionID int `bun:"transactions_id,type:bigint"`
IsSource bool `bun:"is_source,type:bool"`
Account string `bun:"accounts_address,type:varchar"`
Expand Down
1 change: 1 addition & 0 deletions internal/storage/ledger/moves.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (s *Store) InsertMoves(ctx context.Context, moves ...*ledger.Move) error {
_, err := tracing.TraceWithLatency(ctx, "InsertMoves", tracing.NoResult(func(ctx context.Context) error {
_, err := s.db.NewInsert().
Model(&moves).
Value("ledger", "?", s.ledger.Name).
ModelTableExpr(s.GetPrefixedRelationName("moves")).
Returning("post_commit_volumes, post_commit_effective_volumes").
Exec(ctx)
Expand Down
5 changes: 0 additions & 5 deletions internal/storage/ledger/moves_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func TestMovesInsert(t *testing.T) {

// Insert a first move at t0
m1 := ledger.Move{
Ledger: store.GetLedger().Name,
IsSource: true,
Account: "world",
Amount: (*bunpaginate.BigInt)(big.NewInt(100)),
Expand All @@ -71,7 +70,6 @@ func TestMovesInsert(t *testing.T) {

// Add a second move at t3
m2 := ledger.Move{
Ledger: store.GetLedger().Name,
IsSource: false,
Account: "world",
Amount: (*bunpaginate.BigInt)(big.NewInt(50)),
Expand All @@ -88,7 +86,6 @@ func TestMovesInsert(t *testing.T) {

// Add a third move at t1
m3 := ledger.Move{
Ledger: store.GetLedger().Name,
IsSource: true,
Account: "world",
Amount: (*bunpaginate.BigInt)(big.NewInt(200)),
Expand All @@ -105,7 +102,6 @@ func TestMovesInsert(t *testing.T) {

// Add a fourth move at t2
m4 := ledger.Move{
Ledger: store.GetLedger().Name,
IsSource: false,
Account: "world",
Amount: (*bunpaginate.BigInt)(big.NewInt(50)),
Expand All @@ -122,7 +118,6 @@ func TestMovesInsert(t *testing.T) {

// Add a fifth move at t4
m5 := ledger.Move{
Ledger: store.GetLedger().Name,
IsSource: false,
Account: "world",
Amount: (*bunpaginate.BigInt)(big.NewInt(50)),
Expand Down
2 changes: 0 additions & 2 deletions internal/storage/ledger/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ func (s *Store) CommitTransaction(ctx context.Context, tx *ledger.Transaction) e

for _, posting := range postings {
moves = append(moves, &ledger.Move{
Ledger: s.ledger.Name,
Account: posting.Destination,
Amount: (*bunpaginate.BigInt)(posting.Amount),
Asset: posting.Asset,
Expand All @@ -278,7 +277,6 @@ func (s *Store) CommitTransaction(ctx context.Context, tx *ledger.Transaction) e
postCommitVolumes.AddInput(posting.Destination, posting.Asset, new(big.Int).Neg(posting.Amount))

moves = append(moves, &ledger.Move{
Ledger: s.ledger.Name,
IsSource: true,
Account: posting.Source,
Amount: (*bunpaginate.BigInt)(posting.Amount),
Expand Down

0 comments on commit e5eeb81

Please sign in to comment.