public async Task <NewTransactionDTO> LoadInfoFromAPI() { if (string.IsNullOrEmpty(WalletName)) { return(null); } if (string.IsNullOrEmpty(Address)) { return(null); } if (string.IsNullOrEmpty(TxId)) { return(null); } try { var txd = await NeblioTransactionHelpers.TransactionInfoAsync(null, TransactionTypes.Neblio, TxId, Address); if (txd != null) { var dto = new NewTransactionDTO(); dto.AccountAddress = Address; dto.WalletName = WalletName; dto.Type = TransactionTypes.Neblio; dto.TxId = TxId; dto.TransactionDetails = txd; VinTokens = dto.TransactionDetails.VinTokens; VoutTokens = dto.TransactionDetails.VoutTokens; Amount = dto.TransactionDetails.Amount; Confirmations = dto.TransactionDetails.Confirmations; Direction = dto.TransactionDetails.Direction; From = dto.TransactionDetails.From; To = dto.TransactionDetails.To; TimeStamp = dto.TransactionDetails.TimeStamp; Metadata = dto.TransactionDetails.Metadata; if (dto.TransactionDetails != null) { DetailsLoaded?.Invoke(this, dto); } return(dto); } } catch (Exception ex) { attempts--; //log.Error("Cannot load tx details: ", ex); } return(null); }
public override async Task <string> StartRefreshingData(int interval = 1000) { AutoTxReload(); // start autoTxreload task, not awaited. It runs at background. It should be placed in main loop with recovery // todo cancelation token _ = Task.Run(async() => { GetAddressResponse addrinfo = null; while (true) { try { addrinfo = await NeblioTransactionHelpers.AddressInfoAsync(Address); } catch (Exception ex) { // todo } if (addrinfo != null) { TotalBalance = addrinfo.Balance; TotalUnconfirmedBalance = addrinfo.UnconfirmedBalance; if (addrinfo.Transactions != null) { SpendableTxId = addrinfo.Transactions.LastOrDefault(); // this will run just in first turn after init of account // if there is some stored LastProcessedTxId it will load all tx until this one without invoke event // if there is no last tx stored it will count until end and set all as already handled in some previous run of the app if (NumberOfTransaction == 0) { var txs = addrinfo.Transactions.ToArray(); for (int t = 0; t < txs.Length; t++) { if (txs[t] == LastProcessedTxId) { initNumberOfTx = t; } } if (initNumberOfTx == 0) { initNumberOfTx = addrinfo.Transactions.Count; } } NumberOfTransaction = addrinfo.Transactions.Count; try { await ReloadTransactions(addrinfo.Transactions); } catch (Exception ex) { // todo } } DetailsLoaded?.Invoke(null, this); // check if some new tx was processed or confirmed and save them for recovery as last processed if (lastTxSaveDto.LastConfirmedTxId != LastConfirmedTxId || lastTxSaveDto.LastProcessedTxId != LastProcessedTxId) { try { lastTxSaveDto.LastConfirmedTxId = LastConfirmedTxId; lastTxSaveDto.LastProcessedTxId = LastProcessedTxId; var output = JsonConvert.SerializeObject(lastTxSaveDto); FileHelpers.WriteTextToFile(Path.Join(EconomyMainContext.CurrentLocation, $"Accounts/{Address}.txt"), output); } catch (Exception ex) { log.Error("Cannot write file with last processed confirmed Tx!", ex); } } } await Task.Delay(interval); } }); return(await Task.FromResult("END")); }