コード例 #1
0
        private async Task <HashSet <string> > GetLatestInclusionStates(string hash, HashSet <string> hashes) // non-public function
        {
            if (hashes.Count == 0)
            {
                return(null);
            }

            // get a list of confirmed TXs to the given address
            var callerID = $"{nameof(GetLatestInclusionStates)}::{hash}";

            // Get from a partial cache - list of confirmed TX hashes
            var cached = await FS.GetFSPartialCacheEntryAsync(call : callerID);

            var CachedOutput    = cached == null ? new HashSet <string>() : (HashSet <string>)cached;
            var loadedfromcache = CachedOutput.Count();

            hashes.ExceptWith(CachedOutput); // removing all hashes that were already confirmed

            InclusionStates  res;
            HashSet <string> OnlyNewlyConfirmedHashes = null;

            if (hashes.Count > 0) // are there any non-confirmed left?
            {
                try
                {
                    res = await Repo.GetLatestInclusionAsync((from h in hashes select new Hash(h)).ToList());
                }
                catch (Exception)
                {
                    throw;
                }

                OnlyNewlyConfirmedHashes = (from v in res.States where v.Value == true select v.Key.Value).ToHashSet();

                if (OnlyNewlyConfirmedHashes.Count > 0)
                {
                    CachedOutput.UnionWith(OnlyNewlyConfirmedHashes); // saving all back to the cache
                                                                      //Write to partial cache
                    await FS.AddFSPartialCacheEntryAsync(
                        call : callerID,
                        result : CachedOutput);
                }
            }

            Logger.LogInformation("{callerID} in action. {loadedfromcache} confirmed hashes loaded from cache. {OnlyNewlyConfirmedHashes.Count} hashes were new ones.", callerID.Substring(0, 25), loadedfromcache, OnlyNewlyConfirmedHashes?.Count);

            //returning all from cache + new one from API call
            return(CachedOutput);
        }
コード例 #2
0
        public async Task <HashSet <string> > GetTransactionsByBundle(string bundleHash)
        {
            // get a list of transactions to the given address
            var callerID = $"{nameof(GetTransactionsByBundle)}::{bundleHash}";

            // Get from a partial cache
            var cached = await FS.GetFSPartialCacheEntryAsync(call : callerID);

            HashSet <string> CachedOutput = cached == null ? new HashSet <string>() : (HashSet <string>)cached;

            // Get info from node
            TransactionHashList res;

            try
            {
                res = await Repo.FindTransactionsByBundlesAsync(new List <Hash>() { new Hash(bundleHash) });
            }
            catch (Exception)
            {
                throw;
            }

            var origCnt = CachedOutput.Count;

            CachedOutput.UnionWith((from i in res.Hashes select i.Value).ToArray());

            if (origCnt < CachedOutput.Count) // need to update the record
            {
                //Write to partial cache
                await FS.AddFSPartialCacheEntryAsync(
                    call : callerID,
                    result : CachedOutput);
            }

            Logger.LogInformation("{callerID} in action. {origCnt} transaction hashes loaded from cache. {CachedOutput.Count} hashes in total.", callerID.Substring(0, 50), origCnt, CachedOutput.Count);

            return(CachedOutput);
        }