private async Task AcceptorPaymentSpent( ICurrencySwap currencySwap, SwapEventArgs swapArgs, CancellationToken cancellationToken = default) { var swap = swapArgs.Swap; Log.Debug("Acceptor payment spent event for swap {@swapId}", swap.Id); try { // redeem by acceptor async (using purchased currency protocol) if (swap.IsAcceptor && swap.IsSoldCurrency(currencySwap.Currency) && swap.RewardForRedeem == 0) { await GetCurrencySwap(swap.PurchasedCurrency) .RedeemAsync(swap, cancellationToken) .ConfigureAwait(false); } } catch (Exception e) { Log.Error(e, "Acceptor payment spent handler error"); } }
private async Task AcceptorPaymentConfirmed( ICurrencySwap currencySwap, SwapEventArgs swapArgs, CancellationToken cancellationToken = default) { var swap = swapArgs.Swap; Log.Debug("Acceptor payment confirmed event for swap {@swapId}", swap.Id); try { // party redeem if (swap.IsInitiator && swap.IsPurchasedCurrency(currencySwap.Currency) && swap.PartyRewardForRedeem > 0) // todo: user param >= 2*RedeemFee { await GetCurrencySwap(swap.SoldCurrency) .RedeemForPartyAsync(swap, cancellationToken) .ConfigureAwait(false); } } catch (Exception e) { Log.Error(e, "Acceptor payment confirmed handler error"); } }
private async Task SwapUpdatedHandler( object sender, SwapEventArgs args, CancellationToken cancellationToken = default) { try { Log.Debug("Update swap {@swap} in db", args.Swap.Id); var result = await _account .UpdateSwapAsync(args.Swap) .ConfigureAwait(false); if (!result) { Log.Error("Swap update error"); } SwapUpdated?.Invoke(this, args); } catch (Exception e) { Log.Error(e, "Swap update error"); } }
private async void InitiatorPaymentConfirmed( ICurrencySwap currencySwap, SwapEventArgs swapArgs) { var swap = swapArgs.Swap; Log.Debug("Initiator payment confirmed event for swap {@swapId}", swap.Id); try { // broadcast acceptors payment tx (using sold currency protocol) if (swap.IsAcceptor && swap.IsPurchasedCurrency(currencySwap.Currency)) { await GetCurrencySwap(swap.SoldCurrency) .PayAsync(swap) .ConfigureAwait(false); // wait for redeem by other party or someone else if (swap.RewardForRedeem > 0) { await GetCurrencySwap(swap.PurchasedCurrency) .StartWaitForRedeemBySomeoneAsync(swap) .ConfigureAwait(false); } } } catch (Exception e) { Log.Error(e, "Initiator payment confirmed handler error"); } }
private async void SwapUpdatedHandler( object sender, SwapEventArgs args) { try { Log.Debug("Update swap {@swap} in db", args.Swap.Id); var result = await _account .UpdateSwapAsync(args.Swap) .ConfigureAwait(false); if (!result) { Log.Error("Swap update error"); } //_account.AssetWarrantyManager.Alloc() SwapUpdated?.Invoke(this, args); } catch (Exception e) { Log.Error(e, "Swap update error"); } }
private async Task InitiatorPaymentConfirmed( ICurrencySwap currencySwap, SwapEventArgs swapArgs, CancellationToken cancellationToken = default) { var swap = swapArgs.Swap; Log.Debug("Initiator payment confirmed event for swap {@swapId}", swap.Id); try { // broadcast acceptors payment tx (using sold currency protocol) if (swap.IsAcceptor && swap.IsPurchasedCurrency(currencySwap.Currency)) { await GetCurrencySwap(swap.SoldCurrency) .PayAsync(swap, cancellationToken) .ConfigureAwait(false); if (swap.StateFlags.HasFlag(SwapStateFlags.IsPaymentBroadcast)) { // start redeem control async await GetCurrencySwap(swap.SoldCurrency) .StartWaitForRedeemAsync(swap, cancellationToken) .ConfigureAwait(false); } // wait for redeem by other party or someone else if (swap.RewardForRedeem > 0) { await GetCurrencySwap(swap.PurchasedCurrency) .StartWaitForRedeemBySomeoneAsync(swap, cancellationToken) .ConfigureAwait(false); } } } catch (Exception e) { Log.Error(e, "Initiator payment confirmed handler error"); } }