private void UpdateTxConfirmations(GetTransactionsResponse txs) { foreach (var tx in txs.ConfirmedTransactions.Transactions) { var ctx = db.ChainTxGet(tx.TransactionId.ToString()); if (ctx != null) { if (ctx.Confirmations != tx.Confirmations) { ctx.Confirmations = tx.Confirmations; db.ChainTxs.Update(ctx); var status = tx.Confirmations > 0 ? ChainTxStatus.Confirmed : ChainTxStatus.Unconfirmed; if (ctx.NetworkStatus != null && ctx.NetworkStatus.Status != status) { // transaction update comes from our trusted node so we will override any status we have set manually ctx.NetworkStatus.Status = status; db.ChainTxNetworkStatus.Update(ctx.NetworkStatus); } } } else { logger.LogError($"No wallet tx found for {tx.TransactionId}"); } } }
public GetTransactionsResponse GetTransactions(GetTransactionsRequest request) { var response = new GetTransactionsResponse { Transactions = new Transactions(_domainActions).Get() }; if (string.IsNullOrEmpty(request.SkuId)) { return(response); } var finalCurrency = "EUR"; response.Transactions = response.Transactions.Where(x => x.Sku == request.SkuId). Select(x => new TransactionEquivalence { Sku = x.Sku, Currency = finalCurrency, Amount = decimal.Round(x.Amount * _transactionInternalService.ConvertFrom( new RateEquivalence { From = x.Currency, To = finalCurrency }).Rate, 2, MidpointRounding.AwayFromZero) }).ToList(); response.TotalAmount = response.Transactions.GroupBy(x => x.Sku).Select(x => x.Sum(y => y.Amount)).FirstOrDefault(); return(response); }
private void ConvertThroughProto(GetTransactionsResponse source) { Com.Daml.Ledger.Api.V1.GetTransactionsResponse protoValue = source.ToProto(); GetTransactionsResponse target = GetTransactionsResponse.FromProto(protoValue); Assert.True(source == target); }
public GetTransactionsResponse GetTransactions(GetTransactionsRequest request, IAuthContext authContext) { var transactionsRepo = _unitOfWork.GetRepository <Transaction>(); var transactions = transactionsRepo.GetList(x => x.AccountId.ToString() == request.AccountId); GetTransactionsResponse response = new GetTransactionsResponse(); response.Items = new List <GetTransactionsResponseItem>(); foreach (Transaction trn in transactions) { response.Items.Add(new GetTransactionsResponseItem() { Amount = trn.Amount, Date = trn.Date.ToString(), Description = trn.Description, MerchantCategory = MerchantCategory.GetInstance(trn.MerchantCategory).Text, ProviderTransactionId = trn.ProviderTransactionId, TransactionCategory = TransactionCategory.GetInstance(trn.TransactionCategory).Text, TransactionStatus = TransactionStatus.GetInstance(trn.TransactionStatus).Text, TransactionType = TransactionType.GetInstance(trn.TransactionType).Text }); } return(response); }
public override GetTransactionsResponse FilterValidTransactions(GetTransactionsResponse response) { TransactionInformationSet Filter(TransactionInformationSet transactionInformationSet) { return(new TransactionInformationSet() { Transactions = transactionInformationSet.Transactions.FindAll(information => information.Outputs.Any(output => output.Value is AssetMoney assetMoney && assetMoney.AssetId == AssetId) || information.Inputs.Any(output => output.Value is AssetMoney assetMoney && assetMoney.AssetId == AssetId)) }); }
public static TransactionResult GetTransaction(string transactionGuidInput, string paymentGuidInput, string transactioGroupInput) { Guid transactionGuid = Guid.Empty; Guid paymentGuid = Guid.Empty; Guid transactionGroupGuid = Guid.Empty; if (!Guid.TryParse(transactionGuidInput, out transactionGuid) || !Guid.TryParse(paymentGuidInput, out paymentGuid) || !Guid.TryParse(transactioGroupInput, out transactionGroupGuid)) { return(null); } Payment payment = Payment.CreateManager().Load(paymentGuid, GuidType.Internal); if (payment == null) { return(null); } ServiceLookupMethodMap slmm = ServiceLookupMethodMap.CreateManager().Load(payment.ServiceOffer.Service, payment.PaymentRequest.Customer.Country, LookupMethod.Wap); TransactionClient transactionClient = new TransactionClient(); transactionClient.AttachLogWriter(new CashflowLog(payment.ServiceOffer.Service)); GetTransactionsRequest getTransactionRequest = new GetTransactionsRequest(RequestMode.Default, payment.ExternalPaymentGuid.ToString(), slmm.PaymentConfiguration.PaymentCredentials.Username, slmm.PaymentConfiguration.PaymentCredentials.Password, transactionGroupGuid, null); GetTransactionsResponse getTransactionResponse = transactionClient.GetTransactions(getTransactionRequest, null); foreach (Cashflow.Message.Data.Transaction transaction in getTransactionResponse.Transactions) { if (transaction.TransactionID == transactionGuid) { return new TransactionResult() { Transaction = transaction, Username = slmm.PaymentConfiguration.PaymentCredentials.Username, Password = slmm.PaymentConfiguration.PaymentCredentials.Password } } } ; return(null); }
public async Task FetchTransactionsAsync_should_retrieve_a_list_of_transactions() { // Arrange using PlaidClient client = new PlaidClient { Environment = Environment.Sandbox }; // Act GetTransactionsRequest request = new GetTransactionsRequest { }; GetTransactionsResponse result = await client.FetchTransactionsAsync(request); // Assert result.SuccessfulOutcome.ShouldBeTrue(); result.Request.ShouldNotBeNullOrEmpty(); result.TransactionsReturned.ShouldBeGreaterThan(0); result.Transactions.Length.ShouldBeGreaterThan(0); result.Transactions[0].Amount.ShouldBeGreaterThan(0); }
public static bool TryReadSignedTransactions(GetTransactionsResponse response, out List <SignedTransaction> transactions) { transactions = new List <SignedTransaction>(); foreach (var signedTransaction in response.Transactions) { try { using (var stream = new ByteStream(Convert.FromBase64String(signedTransaction))) { transactions.Add(stream.ReadSignedTransaction()); } } catch { transactions = null; return(false); } } return(true); }
private GetTransactionsResponse FilterValidTransactions(GetTransactionsResponse response) { return(new GetTransactionsResponse() { Height = response.Height, UnconfirmedTransactions = new TransactionInformationSet() { Transactions = _Network.FilterValidTransactions(response.UnconfirmedTransactions.Transactions) }, ConfirmedTransactions = new TransactionInformationSet() { Transactions = _Network.FilterValidTransactions(response.ConfirmedTransactions.Transactions) }, ReplacedTransactions = new TransactionInformationSet() { Transactions = _Network.FilterValidTransactions(response.ReplacedTransactions.Transactions) } }); }
public List <string> GetLatestPosts(int nPosts, Action <string> progressReportCallback) { UInt64 blockchainHeight = bitprimApi_.GetCurrentBlockchainHeight(); int postsFound = 0; var posts = new List <string>(); while (postsFound < nPosts && blockchainHeight > 1) { progressReportCallback("Searching block " + blockchainHeight + "..."); string blockHash = bitprimApi_.GetBlockHash(blockchainHeight); GetTransactionsResponse txs = bitprimApi_.GetBlockTransactions(blockHash, 0); for (int iPage = 0; iPage < (int)txs.pagesTotal; ++iPage) { progressReportCallback("\tSearching tx page " + (iPage + 1) + "/" + txs.pagesTotal + "..."); txs = bitprimApi_.GetBlockTransactions(blockHash, iPage); foreach (TransactionSummary tx in txs.txs) { if (TransactionIsMemo(tx.txid)) { posts.Add(GetPost(tx.txid)); ++postsFound; progressReportCallback("\t\tFound post " + postsFound + " of " + nPosts + " in tx " + tx.txid + "!"); if (postsFound == nPosts) { break; } } } if (postsFound == nPosts) { break; } } blockchainHeight--; } return(posts); }
public GetTransactionsResponse GetTransactions(TrackedSource trackedSource, GetTransactionsResponse previous, bool longPolling = true, CancellationToken cancellation = default) { return(GetTransactionsAsync(trackedSource, previous, longPolling, cancellation).GetAwaiter().GetResult()); }
public GetTransactionsResponse GetTransactions(DerivationStrategyBase strategy, GetTransactionsResponse previous, bool longPolling = true, CancellationToken cancellation = default) { return(GetTransactionsAsync(strategy, previous, longPolling, cancellation).GetAwaiter().GetResult()); }
public async Task <IActionResult> GetTransactions( string cryptoCode, [ModelBinder(BinderType = typeof(DerivationStrategyModelBinder))] DerivationStrategyBase derivationScheme, [ModelBinder(BinderType = typeof(BitcoinAddressModelBinder))] BitcoinAddress address, [ModelBinder(BinderType = typeof(UInt256ModelBinding))] uint256 txId = null, bool includeTransaction = true) { var trackedSource = GetTrackedSource(derivationScheme, address); if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } TransactionInformation fetchedTransactionInfo = null; var network = GetNetwork(cryptoCode, false); var chain = ChainProvider.GetChain(network); var repo = RepositoryProvider.GetRepository(network); var response = new GetTransactionsResponse(); int currentHeight = chain.Height; response.Height = currentHeight; var txs = await GetAnnotatedTransactions(repo, chain, trackedSource, txId); foreach (var item in new[] { new { TxSet = response.ConfirmedTransactions, AnnotatedTx = txs.ConfirmedTransactions }, new { TxSet = response.UnconfirmedTransactions, AnnotatedTx = txs.UnconfirmedTransactions }, new { TxSet = response.ReplacedTransactions, AnnotatedTx = txs.ReplacedTransactions }, }) { foreach (var tx in item.AnnotatedTx) { var txInfo = new TransactionInformation() { BlockHash = tx.Height.HasValue ? tx.Record.BlockHash : null, Height = tx.Height, TransactionId = tx.Record.TransactionHash, Transaction = includeTransaction ? tx.Record.Transaction : null, Confirmations = tx.Height.HasValue ? currentHeight - tx.Height.Value + 1 : 0, Timestamp = tx.Record.FirstSeen, Inputs = tx.Record.SpentOutpoints.Select(o => txs.GetUTXO(o)).Where(o => o != null).ToList(), Outputs = tx.Record.GetReceivedOutputs().ToList() }; if (txId == null || txId == txInfo.TransactionId) { item.TxSet.Transactions.Add(txInfo); } if (txId != null && txId == txInfo.TransactionId) { fetchedTransactionInfo = txInfo; } txInfo.BalanceChange = txInfo.Outputs.Select(o => o.Value).Sum() - txInfo.Inputs.Select(o => o.Value).Sum(); } item.TxSet.Transactions.Reverse(); // So the youngest transaction is generally first } if (txId == null) { return(Json(response)); } else if (fetchedTransactionInfo == null) { return(NotFound()); } else { return(Json(fetchedTransactionInfo)); } }
public virtual GetTransactionsResponse FilterValidTransactions(GetTransactionsResponse response) { return(response); }
public async Task <GetTransactionsResponse> GetTransactions( string cryptoCode, [ModelBinder(BinderType = typeof(DestinationModelBinder))] DerivationStrategyBase extPubKey, [ModelBinder(BinderType = typeof(BookmarksModelBinding))] HashSet <Bookmark> unconfirmedBookmarks = null, [ModelBinder(BinderType = typeof(BookmarksModelBinding))] HashSet <Bookmark> confirmedBookmarks = null, [ModelBinder(BinderType = typeof(BookmarksModelBinding))] HashSet <Bookmark> replacedBookmarks = null, bool includeTransaction = true, bool longPolling = false) { if (extPubKey == null) { throw new ArgumentNullException(nameof(extPubKey)); } var network = GetNetwork(cryptoCode); var chain = ChainProvider.GetChain(network); var repo = RepositoryProvider.GetRepository(network); var waitingTransaction = longPolling ? WaitingTransaction(extPubKey) : Task.FromResult(false); GetTransactionsResponse response = null; while (true) { response = new GetTransactionsResponse(); int currentHeight = chain.Height; response.Height = currentHeight; var txs = GetAnnotatedTransactions(repo, chain, extPubKey); foreach (var item in new[] { new { TxSet = response.ConfirmedTransactions, KnownBookmarks = confirmedBookmarks ?? new HashSet <Bookmark>(), AnnotatedTx = txs.ConfirmedTransactions }, new { TxSet = response.UnconfirmedTransactions, KnownBookmarks = unconfirmedBookmarks ?? new HashSet <Bookmark>(), AnnotatedTx = txs.UnconfirmedTransactions }, new { TxSet = response.ReplacedTransactions, KnownBookmarks = replacedBookmarks ?? new HashSet <Bookmark>(), AnnotatedTx = txs.ReplacedTransactions }, }) { item.TxSet.Bookmark = Bookmark.Start; item.TxSet.KnownBookmark = item.KnownBookmarks.Contains(Bookmark.Start) ? Bookmark.Start : null; BookmarkProcessor processor = new BookmarkProcessor(32 + 32 + 25); foreach (var tx in item.AnnotatedTx.Values) { processor.PushNew(); processor.AddData(tx.Record.Transaction.GetHash()); processor.AddData(tx.Record.BlockHash ?? uint256.Zero); processor.UpdateBookmark(); var txInfo = new TransactionInformation() { BlockHash = tx.Record.BlockHash, Height = tx.Record.BlockHash == null ? null : tx.Height, TransactionId = tx.Record.Transaction.GetHash(), Transaction = includeTransaction ? tx.Record.Transaction : null, Confirmations = tx.Record.BlockHash == null ? 0 : currentHeight - tx.Height.Value + 1, Timestamp = txs.GetByTxId(tx.Record.Transaction.GetHash()).Select(t => t.Record.FirstSeen).First(), Inputs = ToMatch(txs, tx.Record.Transaction.Inputs.Select(o => txs.GetUTXO(o.PrevOut)).ToList(), extPubKey, tx.Record.TransactionMatch.Inputs), Outputs = ToMatch(txs, tx.Record.Transaction.Outputs, extPubKey, tx.Record.TransactionMatch.Outputs) }; item.TxSet.Transactions.Add(txInfo); txInfo.BalanceChange = txInfo.Outputs.Select(o => o.Value).Sum() - txInfo.Inputs.Select(o => o.Value).Sum(); item.TxSet.Bookmark = processor.CurrentBookmark; if (item.KnownBookmarks.Contains(processor.CurrentBookmark)) { item.TxSet.KnownBookmark = processor.CurrentBookmark; item.TxSet.Transactions.Clear(); } } } if (response.HasChanges() || !(await waitingTransaction)) { break; } waitingTransaction = Task.FromResult(false); //next time, will not wait } return(response); }
public Task <GetTransactionsResponse> GetTransactionsAsync(DerivationStrategyBase strategy, GetTransactionsResponse previous, bool longPolling, CancellationToken cancellation = default) { return(GetTransactionsAsync(strategy, previous == null ? null : new[] { previous.ConfirmedTransactions.Bookmark }, previous == null ? null : new[] { previous.UnconfirmedTransactions.Bookmark }, previous == null ? null : new[] { previous.ReplacedTransactions.Bookmark }, longPolling, cancellation)); }
public ActionResult <GetTransactionsResponse> GetTransactions([FromQuery] GetTransactionsRequest request) { GetTransactionsResponse response = _accountDataService.GetTransactions(request, _authContext); return(Ok(response)); }
public Task <GetTransactionsResponse> GetTransactionsAsync(TrackedSource trackedSource, GetTransactionsResponse previous, bool longPolling, CancellationToken cancellation = default) { return(GetTransactionsAsync(trackedSource, previous == null ? null : new[] { previous.ConfirmedTransactions.Bookmark }, previous == null ? null : new[] { previous.UnconfirmedTransactions.Bookmark }, previous == null ? null : new[] { previous.ReplacedTransactions.Bookmark }, longPolling, cancellation)); }
public async Task <GetTransactionsResponse> GetTransactions( string cryptoCode, [ModelBinder(BinderType = typeof(DerivationStrategyModelBinder))] DerivationStrategyBase derivationScheme, [ModelBinder(BinderType = typeof(BitcoinAddressModelBinder))] BitcoinAddress address, [ModelBinder(BinderType = typeof(BookmarksModelBinding))] HashSet <Bookmark> unconfirmedBookmarks = null, [ModelBinder(BinderType = typeof(BookmarksModelBinding))] HashSet <Bookmark> confirmedBookmarks = null, [ModelBinder(BinderType = typeof(BookmarksModelBinding))] HashSet <Bookmark> replacedBookmarks = null, bool includeTransaction = true, bool longPolling = false) { var trackedSource = GetTrackedSource(derivationScheme, address); if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } GetTransactionsResponse response = null; using (CancellationTokenSource cts = new CancellationTokenSource()) { if (longPolling) { cts.CancelAfter(LongPollTimeout); } var network = GetNetwork(cryptoCode, false); var chain = ChainProvider.GetChain(network); var repo = RepositoryProvider.GetRepository(network); while (true) { response = new GetTransactionsResponse(); int currentHeight = chain.Height; response.Height = currentHeight; var txs = await GetAnnotatedTransactions(repo, chain, trackedSource); foreach (var item in new[] { new { TxSet = response.ConfirmedTransactions, KnownBookmarks = confirmedBookmarks ?? new HashSet <Bookmark>(), AnnotatedTx = txs.ConfirmedTransactions }, new { TxSet = response.UnconfirmedTransactions, KnownBookmarks = unconfirmedBookmarks ?? new HashSet <Bookmark>(), AnnotatedTx = txs.UnconfirmedTransactions }, new { TxSet = response.ReplacedTransactions, KnownBookmarks = replacedBookmarks ?? new HashSet <Bookmark>(), AnnotatedTx = txs.ReplacedTransactions }, }) { item.TxSet.Bookmark = Bookmark.Start; item.TxSet.KnownBookmark = item.KnownBookmarks.Contains(Bookmark.Start) ? Bookmark.Start : null; BookmarkProcessor processor = new BookmarkProcessor(32 + 32 + 25); foreach (var tx in item.AnnotatedTx) { processor.PushNew(); processor.AddData(tx.Record.TransactionHash); processor.AddData(tx.Record.BlockHash ?? uint256.Zero); processor.UpdateBookmark(); var txInfo = new TransactionInformation() { BlockHash = tx.Height.HasValue ? tx.Record.BlockHash : null, Height = tx.Height, TransactionId = tx.Record.TransactionHash, Transaction = includeTransaction ? tx.Record.Transaction : null, Confirmations = tx.Height.HasValue ? currentHeight - tx.Height.Value + 1 : 0, Timestamp = txs.GetByTxId(tx.Record.TransactionHash).Select(t => t.Record.FirstSeen).First(), Inputs = tx.Record.SpentOutpoints.Select(o => txs.GetUTXO(o)).Where(o => o != null).ToList(), Outputs = tx.Record.GetReceivedOutputs(trackedSource).ToList() }; item.TxSet.Transactions.Add(txInfo); txInfo.BalanceChange = txInfo.Outputs.Select(o => o.Value).Sum() - txInfo.Inputs.Select(o => o.Value).Sum(); item.TxSet.Bookmark = processor.CurrentBookmark; if (item.KnownBookmarks.Contains(processor.CurrentBookmark)) { item.TxSet.KnownBookmark = processor.CurrentBookmark; item.TxSet.Transactions.Clear(); } } } if (!longPolling || response.HasChanges()) { break; } if (!await WaitingTransaction(trackedSource, cts.Token)) { break; } } } return(response); }