コード例 #1
0
    public async Task <List <string> > LoadTransactions(string address, NeblioAccount account, bool subAccount)
    {
        if (!subAccount)
        {
            var inf = await NeblioTransactionHelpers.AddressInfoAsync(account.Address);

            return(inf.Transactions?.Reverse().ToList() ?? new List <string>());
        }
        else
        {
            if (account.SubAccounts.TryGetValue(address, out _))
            {
                var inf = await NeblioTransactionHelpers.AddressInfoAsync(address);

                return(inf.Transactions?.Reverse().ToList() ?? new List <string>());
            }
        }
        return(new List <string>());
    }
コード例 #2
0
        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"));
        }