Exemple #1
0
        private void UpdateBalanceIndex(string fromAddress, string toAddress, string tokenSymbol, long amount)
        {
            if (tokenSymbol == null)
            {
                return;
            }

            //Create sender index
            CreateIndexIfNotExist(fromAddress, tokenSymbol);

            //Create recipient index
            CreateIndexIfNotExist(toAddress, tokenSymbol);

            //Update sender balance
            if (fromAddress != null)
            {
                BalanceIndexItem index = database.GetBalanceIndex(fromAddress, tokenSymbol);
                index.Balance = index.Balance - amount;
                database.SaveBalanceIndex(index);
                IndexBalanceCache.AddOrUpdate(index);
            }

            //Update recipient balance
            if (toAddress != null)
            {
                BalanceIndexItem index = database.GetBalanceIndex(toAddress, tokenSymbol);
                index.Balance = index.Balance + amount;
                database.SaveBalanceIndex(index);
                IndexBalanceCache.AddOrUpdate(index);
            }
        }
Exemple #2
0
        public void DeleteIndex(TransactionTransfer record)
        {
            database.DeleteBalanceIndex(record.FromAddress, record.TokenSymbol);
            database.DeleteBalanceIndex(record.ToAddress, record.TokenSymbol);

            IndexBalanceCache.Remove(record.FromAddress, record.TokenSymbol);
            IndexBalanceCache.Remove(record.ToAddress, record.TokenSymbol);
        }
Exemple #3
0
        public BalanceIndexItem Get(string address, string token)
        {
            var cachedIndex = IndexBalanceCache.Get(address, token);

            if (cachedIndex != null)
            {
                return(cachedIndex);
            }

            var index = database.GetBalanceIndex(address, token);

            if (index != null)
            {
                IndexBalanceCache.AddOrUpdate(index);
            }
            return(index);
        }
Exemple #4
0
        private void CreateIndexIfNotExist(string address, string tokenSymbol)
        {
            if (address != null)
            {
                var index = database.GetBalanceIndex(address, tokenSymbol);
                if (index == null)
                {
                    index             = new BalanceIndexItem();
                    index.TokenSymbol = tokenSymbol;
                    index.Balance     = 0;
                    index.Address     = address;

                    database.SaveBalanceIndex(index);
                    IndexBalanceCache.AddOrUpdate(index);
                }
            }
        }