Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Sep 8, 2024
1 parent 4318df5 commit 5fd3b71
Show file tree
Hide file tree
Showing 26 changed files with 602 additions and 158 deletions.
9 changes: 5 additions & 4 deletions components/ledger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ replace github.com/formancehq/stack/libs/core => ../../libs/core

require (
github.com/ThreeDotsLabs/watermill v1.3.7
github.com/alitto/pond v1.9.2
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10
github.com/bluele/gcache v0.0.2
github.com/formancehq/stack/ledger/client v0.0.0-00010101000000-000000000000
Expand All @@ -23,12 +22,12 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.6.0
github.com/lib/pq v1.10.9
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -110,6 +109,7 @@ require (
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -121,7 +121,6 @@ require (
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/onsi/gomega v1.34.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runc v1.1.13 // indirect
Expand All @@ -135,6 +134,8 @@ require (
github.com/rs/cors v1.10.1 // indirect
github.com/shirou/gopsutil/v4 v4.24.6 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/shomali11/util v0.0.0-20180607005212-e0f70fd665ff // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
Expand Down
6 changes: 4 additions & 2 deletions components/ledger/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ github.com/ThreeDotsLabs/watermill-kafka/v3 v3.0.1 h1:xqSjxMpZUROIjFTLqmKDJfOn/1
github.com/ThreeDotsLabs/watermill-kafka/v3 v3.0.1/go.mod h1:VPGwfsuZOEBcS2DKuq8DYMAMzir/eqCSXbNvMUy5bvs=
github.com/ThreeDotsLabs/watermill-nats/v2 v2.0.2 h1:/87LcdSzUEdCKbJptaLE987hOVOs852b+v5pukegggo=
github.com/ThreeDotsLabs/watermill-nats/v2 v2.0.2/go.mod h1:uslCjpuzANBzawXYlwx2IDyGjpv9M42U2TQH6JMMQis=
github.com/alitto/pond v1.9.2 h1:9Qb75z/scEZVCoSU+osVmQ0I0JOeLfdTDafrbcJ8CLs=
github.com/alitto/pond v1.9.2/go.mod h1:xQn3P/sHTYcU/1BR3i86IGIrilcrGC2LiS+E2+CJWsI=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 h1:yL7+Jz0jTC6yykIK/Wh74gnTJnrGr5AyrNMXuA0gves=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/aws/aws-msk-iam-sasl-signer-go v1.0.0 h1:UyjtGmO0Uwl/K+zpzPwLoXzMhcN9xmnR2nrqJoBrg3c=
Expand Down Expand Up @@ -258,6 +256,10 @@ github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFt
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/shomali11/util v0.0.0-20180607005212-e0f70fd665ff h1:A47HTOEURe8GFXu/9ztnUzVgBBo0NlWoKmVPmfJ4LR8=
github.com/shomali11/util v0.0.0-20180607005212-e0f70fd665ff/go.mod h1:WWE2GJM9B5UpdOiwH2val10w/pvJ2cUUQOOA/4LgOng=
github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df h1:SVCDTuzM3KEk8WBwSSw7RTPLw9ajzBaXDg39Bo6xIeU=
github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df/go.mod h1:K8jR5lDI2MGs9Ky+X2jIF4MwIslI0L8o8ijIlEq7/Vw=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
Expand Down
10 changes: 5 additions & 5 deletions components/ledger/internal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ type Account struct {
// todo: clean models by keeping all related bun specificity in the storage package
bun.BaseModel `bun:"table:accounts,alias:accounts"`

Address string `json:"address"`
Metadata metadata.Metadata `json:"metadata"`
FirstUsage time.Time `json:"-" bun:"first_usage"`
InsertionDate time.Time `bun:"insertion_date"`
UpdatedAt time.Time `bun:"updated_at"`
Address string `json:"address,type:varchar"`
Metadata metadata.Metadata `json:"metadata,type:jsonb"`
FirstUsage time.Time `json:"-" bun:"first_usage,type:timestamp"`
InsertionDate time.Time `bun:"insertion_date,type:timestamp"`
UpdatedAt time.Time `bun:"updated_at,type:timestamp"`
}

func (a Account) copy() Account {
Expand Down
2 changes: 1 addition & 1 deletion components/ledger/internal/controller/ledger/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func New(
// monitor = bus.NewLedgerMonitor(publisher, store.Name())
//}
ret := &Controller{
engine: writer.New(name, store, machineFactory),
engine: writer.New(store, machineFactory),
store: store,
}
return ret
Expand Down

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

6 changes: 5 additions & 1 deletion components/ledger/internal/controller/ledger/writer/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package writer

import (
"context"
"database/sql"
ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/stack/libs/go-libs/metadata"
"github.com/uptrace/bun"
)

//go:generate mockgen -source store.go -destination store_generated.go -package writer . TX
type TX interface {
LockAccounts(ctx context.Context, accounts ...string) error
InsertTransaction(ctx context.Context, transaction ledger.TransactionData) (*ledger.Transaction, error)
InsertMoves(ctx context.Context, move ...ledger.Move) error
UpsertAccount(ctx context.Context, account ledger.Account) error
UpsertAccount(ctx context.Context, account ledger.Account) (bool, error)
// RevertTransaction revert the transaction with identifier id
// it returns :
// * the reverted transaction
Expand All @@ -25,9 +27,11 @@ type TX interface {
InsertLog(ctx context.Context, log ledger.Log) (*ledger.ChainedLog, error)
Commit(ctx context.Context) error
Rollback(ctx context.Context) error
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}

//go:generate mockgen -source store.go -destination store_generated.go -package writer . Store
type Store interface {
BeginTX(ctx context.Context) (TX, error)
GetDB() bun.IDB
}

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

Loading

0 comments on commit 5fd3b71

Please sign in to comment.