/* public async Task UpdateIndexec()
         * {
         *   var partitionKey = TransactionEntity.GeneratePartiteonKey();
         *   var tableQuery =
         *       TableStorageUtils.QueryGenerator<TransactionEntity>.PartitionKeyOnly.GetTableQuery(partitionKey);
         *   await _tableStorage.ExecuteQueryAsync(tableQuery, chank =>
         *   {
         *       foreach (var items in chank.ToPieces(100))
         *       {
         *           var newEntits = items.Select(itm => AzureIndex.Create(IndexByBlockHash, itm.Blockhash, itm)).ToArray();
         *           _azureIndex.InsertOrReplaceBatchAsync(newEntits).Wait();
         *           Console.WriteLine("Add new"+ newEntits.Length + "items");
         *       }
         *   });
         * }*/



        public async Task <ITransaction> GetTransaction(string tx)
        {
            var rowKey       = TransactionEntity.GenerateRowKey(tx);
            var partitionKey = TransactionEntity.GeneratePartiteonKey();

            return(await _tableStorage.GetDataAsync(partitionKey, rowKey));
        }
        public async Task SaveAsync(Transaction transaction)
        {
            var newEntity = TransactionEntity.CreateNew(transaction);
            await _tableStorage.InsertOrReplaceAsync(newEntity);

            //Добавляем еще одну запись но с другим PartitionKey
            newEntity.PartitionKey = newEntity.Blockhash;
            await _tableStorage.InsertOrReplaceAsync(newEntity);
        }
        public static TransactionEntity CreateNew(ITransaction transaction)
        {
            var result = new TransactionEntity
            {
                Time          = transaction.Time,
                Confirmations = transaction.Confirmations,
                Height        = transaction.Height,
                Blockhash     = transaction.Blockhash,
                RowKey        = GenerateRowKey(transaction.Txid),
                PartitionKey  = GeneratePartiteonKey()
            };

            return(result);
        }