public WalletsController(StoreRepository repo, AtomicSwapRepository atomicSwapRepository, WalletRepository walletRepository, CurrencyNameTable currencyTable, BTCPayNetworkProvider networkProvider, UserManager <ApplicationUser> userManager, MvcNewtonsoftJsonOptions mvcJsonOptions, NBXplorerDashboard dashboard, RateFetcher rateProvider, IAuthorizationService authorizationService, ExplorerClientProvider explorerProvider, IFeeProviderFactory feeRateProvider, BTCPayWalletProvider walletProvider, AtomicSwapClientFactory atomicSwapClientFactory) { _currencyTable = currencyTable; Repository = repo; WalletRepository = walletRepository; RateFetcher = rateProvider; _authorizationService = authorizationService; NetworkProvider = networkProvider; _userManager = userManager; _serializerSettings = mvcJsonOptions.SerializerSettings; _dashboard = dashboard; ExplorerClientProvider = explorerProvider; _feeRateProvider = feeRateProvider; _walletProvider = walletProvider; AtomicSwapClientFactory = atomicSwapClientFactory; AtomicSwapRepository = atomicSwapRepository; }
public async Task <IActionResult> AtomicSwapList([ModelBinder(typeof(WalletIdModelBinder))] WalletId walletId) { var derivationStrategy = await GetDerivationStrategy(walletId); if (derivationStrategy == null) { return(NotFound()); } ListViewModel list = new ListViewModel(); list.CryptoCode = walletId.CryptoCode; foreach (var entry in AtomicSwapRepository.GetEntries(walletId)) { ListViewModel.SwapItem item = new ListViewModel.SwapItem() { WalletId = walletId.ToString(), OfferId = entry.Id, Partner = entry.Partner, Role = entry.Role.ToString(), Status = entry.Status.ToString(), Timestamp = entry.Offer.CreatedAt, Sent = FormatAmount(entry.Sent), Received = FormatAmount(entry.Received), }; list.Swaps.Add(item); } return(View(list)); }
public async Task <IActionResult> GetOfferAPI(string offerId) { var entry = await AtomicSwapRepository.GetEntry(offerId); if (entry == null || (entry.Status != XSwapStatus.WaitingTaker && entry.Role == XSwapRole.Maker) || (entry.Status != XSwapStatus.WaitingEscrow && entry.Role == XSwapRole.Taker)) { return(NotFound()); } return(Json(entry.Offer)); }
public async Task <IActionResult> TakeOfferAPI(string offerId, [FromBody] AtomicSwapTakeRequest request) { var entry = await AtomicSwapRepository.GetEntry(offerId); if (entry == null || entry.Status != XSwapStatus.WaitingTaker) { return(NotFound()); } // TODO atomically take the offer var client = AtomicSwapClientFactory.Create(request.TakerUri); AtomicSwapTakeResponse response = null; try { using (var cts = new CancellationTokenSource()) { cts.CancelAfter(5000); var takerOffer = await client.GetOffer(cts.Token); if (takerOffer.MarketMakerUri != entry.Offer.MarketMakerUri) { return(NotFound()); } } } catch { } entry.Partner = request.TakerUri.DnsSafeHost; entry.OtherUri = request.TakerUri; entry.Status = XSwapStatus.WaitingEscrow; entry.Sent.MyKey = new Key(); entry.Sent.OtherKey = request.MakerSentCryptoPubkey; entry.Received.MyKey = new Key(); entry.Received.OtherKey = request.MakerReceivedCryptoPubkey; entry.Preimage = new Preimage(); entry.Hash = entry.Preimage.GetHash(); response = new AtomicSwapTakeResponse() { Hash = entry.Preimage.GetHash(), MakerReceivedCryptoPubkey = entry.Received.MyKey.PubKey, MakerSentCryptoPubkey = entry.Received.MyKey.PubKey }; await AtomicSwapRepository.UpdateEntry(offerId, entry); return(Json(response)); }
public AtomicSwapController(AtomicSwapRepository atomicSwapRepository, AtomicSwapClientFactory atomicSwapClientFactory) { AtomicSwapRepository = atomicSwapRepository; AtomicSwapClientFactory = atomicSwapClientFactory; }