diff --git a/cmd/market_maker/atomex.go b/cmd/market_maker/atomex.go index 37d02be..9599754 100644 --- a/cmd/market_maker/atomex.go +++ b/cmd/market_maker/atomex.go @@ -339,7 +339,7 @@ func (mm *MarketMaker) handleAtomexSwapUpdate(swap atomex.Swap) error { return errors.Wrap(err, "atomexSwapToInternal") } - mm.swaps.LoadOrStore(chain.Hex(swap.SecretHash), s) + mm.swaps.Store(chain.Hex(swap.SecretHash), s) return nil } diff --git a/cmd/market_maker/data.go b/cmd/market_maker/data.go index 38103cf..33e2c52 100644 --- a/cmd/market_maker/data.go +++ b/cmd/market_maker/data.go @@ -97,14 +97,14 @@ func (swaps *SwapsMap) Load(hashedSecret chain.Hex) (*tools.Swap, bool) { return val, ok } -// Set - +// Store - func (swaps *SwapsMap) Store(hashedSecret chain.Hex, swap *tools.Swap) { swaps.mx.Lock() swaps.m[hashedSecret] = swap swaps.mx.Unlock() } -// Load - +// LoadOrStore - func (swaps *SwapsMap) LoadOrStore(hashedSecret chain.Hex, swap *tools.Swap) *tools.Swap { val, ok := swaps.Load(hashedSecret) if ok { diff --git a/cmd/market_maker/tracker.go b/cmd/market_maker/tracker.go index cbfb48a..33134cb 100644 --- a/cmd/market_maker/tracker.go +++ b/cmd/market_maker/tracker.go @@ -28,7 +28,7 @@ func (mm *MarketMaker) listenTracker(ctx context.Context) { current.Status = swap.Status current.Acceptor.Status = swap.Acceptor.Status current.Initiator.Status = swap.Initiator.Status - if len(current.Secret) == 0 { + if current.Secret.IsEmpty() { current.Secret = swap.Secret } @@ -40,14 +40,15 @@ func (mm *MarketMaker) listenTracker(ctx context.Context) { mm.log.Info().Str("hashed_secret", current.HashedSecret.String()).Msg("swap is initiated. redeeming...") - if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil { - mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex") - continue - } - - if len(current.Secret) == 0 { - mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before redeem") - continue + if current.Secret.IsEmpty() { + if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil { + mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex") + continue + } + if current.Secret.IsEmpty() { + mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before redeem") + continue + } } if err := mm.tracker.Redeem(ctx, *current, current.Acceptor); err != nil { @@ -62,13 +63,15 @@ func (mm *MarketMaker) listenTracker(ctx context.Context) { mm.log.Info().Str("hashed_secret", current.HashedSecret.String()).Msg("counterparty refunded swap. refunding...") - if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil { - mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex") - continue - } - if len(current.Secret) == 0 { - mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before refund") - continue + if current.Secret.IsEmpty() { + if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil { + mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex") + continue + } + if current.Secret.IsEmpty() { + mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before refund") + continue + } } if err := mm.tracker.Refund(ctx, *current, current.Initiator); err != nil {