mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-10 06:38:04 -05:00
fix: ensure stage is changed if funds are locked, even in error case (#319)
This commit is contained in:
@@ -193,7 +193,9 @@ func (s *swapState) handleEvent(event Event) {
|
||||
err := s.handleEventETHLocked(e)
|
||||
if err != nil {
|
||||
e.errCh <- fmt.Errorf("failed to handle EventETHLocked: %w", err)
|
||||
return
|
||||
if !s.fundsLocked {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = s.setNextExpectedEvent(EventContractReadyType)
|
||||
|
||||
@@ -71,6 +71,8 @@ type swapState struct {
|
||||
|
||||
// tracks the state of the swap
|
||||
nextExpectedEvent EventType
|
||||
// set to true once funds are locked
|
||||
fundsLocked bool
|
||||
|
||||
// channels
|
||||
|
||||
@@ -529,6 +531,7 @@ func (s *swapState) lockFunds(amount *coins.PiconeroAmount) (*message.NotifyXMRL
|
||||
}
|
||||
log.Infof("Successfully locked XMR funds: txID=%s address=%s block=%d",
|
||||
transfer.TxID, swapDestAddr, transfer.Height)
|
||||
s.fundsLocked = true
|
||||
|
||||
txID, err := types.HexToHash(transfer.TxID)
|
||||
if err != nil {
|
||||
|
||||
@@ -229,7 +229,9 @@ func (s *swapState) handleEvent(event Event) {
|
||||
err := s.handleEventKeysReceived(e)
|
||||
if err != nil {
|
||||
e.errCh <- fmt.Errorf("failed to handle %s: %w", e.Type(), err)
|
||||
return
|
||||
if !s.fundsLocked {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = s.setNextExpectedEvent(EventXMRLockedType)
|
||||
|
||||
@@ -77,6 +77,8 @@ type swapState struct {
|
||||
|
||||
// tracks the state of the swap
|
||||
nextExpectedEvent EventType
|
||||
// set to true once funds are locked
|
||||
fundsLocked bool
|
||||
|
||||
// channels
|
||||
|
||||
@@ -613,6 +615,7 @@ func (s *swapState) lockAsset() (ethcommon.Hash, error) {
|
||||
return ethcommon.Hash{}, fmt.Errorf("timeouts not found in transaction receipt's logs: %w", err)
|
||||
}
|
||||
|
||||
s.fundsLocked = true
|
||||
s.setTimeouts(t0, t1)
|
||||
|
||||
s.contractSwap = &contracts.SwapFactorySwap{
|
||||
|
||||
Reference in New Issue
Block a user