outbox for gateways
This commit is contained in:
@@ -6,7 +6,9 @@ import (
|
||||
|
||||
"github.com/tech/sendico/gateway/chain/storage"
|
||||
"github.com/tech/sendico/gateway/chain/storage/mongo/store"
|
||||
gatewayoutbox "github.com/tech/sendico/gateway/common/outbox"
|
||||
"github.com/tech/sendico/pkg/db"
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
@@ -15,13 +17,15 @@ import (
|
||||
|
||||
// Store implements storage.Repository backed by MongoDB.
|
||||
type Store struct {
|
||||
logger mlogger.Logger
|
||||
conn *db.MongoConnection
|
||||
db *mongo.Database
|
||||
logger mlogger.Logger
|
||||
conn *db.MongoConnection
|
||||
db *mongo.Database
|
||||
txFactory transaction.Factory
|
||||
|
||||
wallets storage.WalletsStore
|
||||
transfers storage.TransfersStore
|
||||
deposits storage.DepositsStore
|
||||
outbox gatewayoutbox.Store
|
||||
}
|
||||
|
||||
// New creates a new Mongo-backed repository.
|
||||
@@ -35,9 +39,10 @@ func New(logger mlogger.Logger, conn *db.MongoConnection) (*Store, error) {
|
||||
}
|
||||
|
||||
result := &Store{
|
||||
logger: logger.Named("storage").Named("mongo"),
|
||||
conn: conn,
|
||||
db: conn.Database(),
|
||||
logger: logger.Named("storage").Named("mongo"),
|
||||
conn: conn,
|
||||
db: conn.Database(),
|
||||
txFactory: newMongoTransactionFactory(client),
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
@@ -63,10 +68,16 @@ func New(logger mlogger.Logger, conn *db.MongoConnection) (*Store, error) {
|
||||
result.logger.Error("Failed to initialise deposits store", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
outboxStore, err := gatewayoutbox.NewMongoStore(result.logger, result.db)
|
||||
if err != nil {
|
||||
result.logger.Error("Failed to initialise outbox store", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result.wallets = walletsStore
|
||||
result.transfers = transfersStore
|
||||
result.deposits = depositsStore
|
||||
result.outbox = outboxStore
|
||||
|
||||
result.logger.Info("Chain gateway MongoDB storage initialised")
|
||||
return result, nil
|
||||
@@ -95,4 +106,12 @@ func (s *Store) Deposits() storage.DepositsStore {
|
||||
return s.deposits
|
||||
}
|
||||
|
||||
func (s *Store) Outbox() gatewayoutbox.Store {
|
||||
return s.outbox
|
||||
}
|
||||
|
||||
func (s *Store) TransactionFactory() transaction.Factory {
|
||||
return s.txFactory
|
||||
}
|
||||
|
||||
var _ storage.Repository = (*Store)(nil)
|
||||
|
||||
Reference in New Issue
Block a user