outbox for gateways
This commit is contained in:
@@ -32,12 +32,12 @@ func NewBalances(logger mlogger.Logger, db *mongo.Database) (storage.BalancesSto
|
||||
Unique: true,
|
||||
}
|
||||
if err := repo.CreateIndex(uniqueIndex); err != nil {
|
||||
logger.Error("failed to ensure balances unique index", zap.Error(err))
|
||||
logger.Error("Failed to ensure balances unique index", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
childLogger := logger.Named(model.AccountBalancesCollection)
|
||||
childLogger.Debug("balances store initialised", zap.String("collection", model.AccountBalancesCollection))
|
||||
childLogger.Debug("Balances store initialised", zap.String("collection", model.AccountBalancesCollection))
|
||||
|
||||
return &balancesStore{
|
||||
logger: childLogger,
|
||||
@@ -47,7 +47,7 @@ func NewBalances(logger mlogger.Logger, db *mongo.Database) (storage.BalancesSto
|
||||
|
||||
func (b *balancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) {
|
||||
if accountRef.IsZero() {
|
||||
b.logger.Warn("attempt to get balance with zero account ID")
|
||||
b.logger.Warn("Attempt to get balance with zero account ID")
|
||||
return nil, merrors.InvalidArgument("balancesStore: zero account ID")
|
||||
}
|
||||
|
||||
@@ -56,25 +56,25 @@ func (b *balancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*mod
|
||||
result := &model.AccountBalance{}
|
||||
if err := b.repo.FindOneByFilter(ctx, query, result); err != nil {
|
||||
if errors.Is(err, merrors.ErrNoData) {
|
||||
b.logger.Debug("balance not found", mzap.AccRef(accountRef))
|
||||
b.logger.Debug("Balance not found", mzap.AccRef(accountRef))
|
||||
return nil, storage.ErrBalanceNotFound
|
||||
}
|
||||
b.logger.Warn("failed to get balance", zap.Error(err), mzap.AccRef(accountRef))
|
||||
b.logger.Warn("Failed to get balance", zap.Error(err), mzap.AccRef(accountRef))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b.logger.Debug("balance loaded", mzap.AccRef(accountRef),
|
||||
b.logger.Debug("Balance loaded", mzap.AccRef(accountRef),
|
||||
zap.String("balance", result.Balance))
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (b *balancesStore) Upsert(ctx context.Context, balance *model.AccountBalance) error {
|
||||
if balance == nil {
|
||||
b.logger.Warn("attempt to upsert nil balance")
|
||||
b.logger.Warn("Attempt to upsert nil balance")
|
||||
return merrors.InvalidArgument("balancesStore: nil balance")
|
||||
}
|
||||
if balance.AccountRef.IsZero() {
|
||||
b.logger.Warn("attempt to upsert balance with zero account ID")
|
||||
b.logger.Warn("Attempt to upsert balance with zero account ID")
|
||||
return merrors.InvalidArgument("balancesStore: zero account ID")
|
||||
}
|
||||
|
||||
@@ -83,24 +83,24 @@ func (b *balancesStore) Upsert(ctx context.Context, balance *model.AccountBalanc
|
||||
|
||||
if err := b.repo.FindOneByFilter(ctx, filter, existing); err != nil {
|
||||
if errors.Is(err, merrors.ErrNoData) {
|
||||
b.logger.Debug("inserting new balance", zap.String("accountRef", balance.AccountRef.Hex()))
|
||||
b.logger.Debug("Inserting new balance", zap.String("accountRef", balance.AccountRef.Hex()))
|
||||
return b.repo.Insert(ctx, balance, filter)
|
||||
}
|
||||
b.logger.Warn("failed to fetch balance", zap.Error(err), zap.String("accountRef", balance.AccountRef.Hex()))
|
||||
b.logger.Warn("Failed to fetch balance", zap.Error(err), zap.String("accountRef", balance.AccountRef.Hex()))
|
||||
return err
|
||||
}
|
||||
|
||||
if existing.GetID() != nil {
|
||||
balance.SetID(*existing.GetID())
|
||||
}
|
||||
b.logger.Debug("updating balance", zap.String("accountRef", balance.AccountRef.Hex()),
|
||||
b.logger.Debug("Updating balance", zap.String("accountRef", balance.AccountRef.Hex()),
|
||||
zap.String("balance", balance.Balance))
|
||||
return b.repo.Update(ctx, balance)
|
||||
}
|
||||
|
||||
func (b *balancesStore) IncrementBalance(ctx context.Context, accountRef bson.ObjectID, amount string) error {
|
||||
if accountRef.IsZero() {
|
||||
b.logger.Warn("attempt to increment balance with zero account ID")
|
||||
b.logger.Warn("Attempt to increment balance with zero account ID")
|
||||
return merrors.InvalidArgument("balancesStore: zero account ID")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user