예제 #1
0
        private async Task UpdateIndexes(InventorySnapshotEntity inventorySnapshotEntity)
        {
            var existingIndex = await _indexStorage.GetDataAsync(GetIndexPartitionKey(inventorySnapshotEntity.Time),
                                                                 IndexForLastRowKey);

            if (existingIndex == null || (await _storage.GetDataAsync(existingIndex)).Time < inventorySnapshotEntity.Time)
            {
                // Update index for current day, it now must point to this the last received snapshot
                await _indexStorage.InsertOrReplaceAsync(
                    AzureIndex.Create(GetIndexPartitionKey(inventorySnapshotEntity.Time), IndexForLastRowKey,
                                      inventorySnapshotEntity));
            }

            // If we have index entries for any future date, they are now are invalid, we can just remove them,
            // as they will be reconstructed if needed

            var filter = TableQuery.GenerateFilterCondition(nameof(AzureIndex.PartitionKey),
                                                            QueryComparisons.GreaterThan,
                                                            GetIndexPartitionKey(inventorySnapshotEntity.Time));

            var query = new TableQuery <AzureIndex>().Where(filter);

            var allNowInvalidIndexEntriesFromTheFuture = (await _indexStorage.WhereAsync(query)).ToList();

            foreach (var indexEntity in allNowInvalidIndexEntriesFromTheFuture)
            {
                await _indexStorage.DeleteAsync(indexEntity);
            }
        }
예제 #2
0
        public async Task InsertOrReplaceAsync(IBcnCredentialsRecord credsRecord)
        {
            var byClientEntity       = FirstGenerationBlockchainWalletEntity.FromBcnClientCredentials.ByClientId.Create(credsRecord);
            var byAssetAddressEntity = FirstGenerationBlockchainWalletEntity.FromBcnClientCredentials.ByAssetAddress.Create(credsRecord);

            await _bcnClientCredentialsWalletTable.InsertOrReplaceAsync(byClientEntity);

            await _bcnClientCredentialsWalletTable.InsertOrReplaceAsync(byAssetAddressEntity);
        }
        public async Task <IMarginTradingWatchList> AddAsync(IMarginTradingWatchList watchList)
        {
            await _tableStorage.InsertOrReplaceAsync(MarginTradingWatchListEntity.Create(watchList));

            var entity =
                await _tableStorage.GetDataAsync(MarginTradingWatchListEntity.GeneratePartitionKey(watchList.ClientId),
                                                 MarginTradingWatchListEntity.GenerateRowKey(watchList.Id));

            return(MarginTradingWatchList.Create(entity));
        }
        public async Task UpdateAsync(IEthereumTransactionRequest request)
        {
            var byId = EthereumTransactionReqEntity.ById.Create(request);
            await _tableStorage.InsertOrReplaceAsync(byId);

            if (!string.IsNullOrEmpty(request.OrderId))
            {
                var byOrder = EthereumTransactionReqEntity.ByOrderId.Create(request);
                await _tableStorage.InsertOrReplaceAsync(byOrder);
            }
        }
        public async Task AddAsync(string clientId, AccountTier tier, KycStatus status, string comment = null, DateTime?date = null)
        {
            var item = TierUpgradeRequestEntity.Create(clientId, tier, status, comment, date);
            await _tableStorage.InsertOrReplaceAsync(item);

            if (status == KycStatus.Pending)
            {
                var indexEntity = AzureIndex.Create(PendingRequestsIndex, GetPendingRequestIndexRk(clientId, tier), item);
                await _index.InsertOrMergeAsync(indexEntity);
            }
        }
예제 #6
0
        public async Task <IOffchainRequest> CreateRequest(string transferId, string clientId, string assetId, RequestType type, OffchainTransferType transferType, DateTime?serverLock = null)
        {
            var id = Guid.NewGuid().ToString();

            var byClient = OffchainRequestEntity.ByClient.Create(id, transferId, clientId, assetId, type, transferType, serverLock);
            await _table.InsertOrReplaceAsync(byClient);

            var byRecord = OffchainRequestEntity.ByRecord.Create(id, transferId, clientId, assetId, type, transferType, serverLock);
            await _table.InsertOrReplaceAsync(byRecord);

            return(byRecord);
        }
        //clientLatestDepositIndexManualPartitionKey let it be null for common operations
        public async Task AddAsync(string blockchainType, Guid clientId, string address,
                                   CreatorType createdBy, string clientLatestDepositIndexManualPartitionKey = null, bool addAsLatest = true)
        {
            var partitionKey = BlockchainWalletEntity.GetPartitionKey(blockchainType, clientId);
            var rowKey       = BlockchainWalletEntity.GetRowKey(address);

            var clientLatestDepositIndexPartitionKey = GetClientLatestIndexPartitionKey(clientId);
            var clientLatestDepositIndexRowKey       = GetClientLatestIndexRowKey(blockchainType);

            var(indexPartitionKey, indexRowKey) = GetAddressIndexKeys(blockchainType, address);
            var(clientBtIndexPartitionKey, clientBtIndexRowKey) = GetClientBlockchainTypeIndexKeys(blockchainType, clientId);

            clientBtIndexRowKey = clientLatestDepositIndexManualPartitionKey ?? clientBtIndexRowKey;

            await _addressIndexTable.InsertOrReplaceAsync(new AzureIndex(
                                                              indexPartitionKey,
                                                              indexRowKey,
                                                              partitionKey,
                                                              rowKey
                                                              ));

            await _clientBlockchainTypeIndexTable.InsertOrReplaceAsync(new AzureIndex(
                                                                           clientBtIndexPartitionKey,
                                                                           clientBtIndexRowKey,
                                                                           partitionKey,
                                                                           rowKey
                                                                           ));

            if (addAsLatest)
            {
                await _clientLatestDepositsIndexTable.InsertOrReplaceAsync(new AzureIndex(
                                                                               clientLatestDepositIndexPartitionKey,
                                                                               clientLatestDepositIndexRowKey,
                                                                               partitionKey,
                                                                               rowKey
                                                                               ));
            }

            // Wallet entity

            await _walletsTable.InsertOrReplaceAsync(new BlockchainWalletEntity
            {
                PartitionKey = partitionKey,
                RowKey       = rowKey,

                Address            = address,
                ClientId           = clientId,
                IntegrationLayerId = blockchainType,
                CreatedBy          = createdBy
            });
        }
        public async Task <ISpiderDocumentInfo> AddOrUpdateAsync(ISpiderDocumentInfo entity)
        {
            var newEntity = SpiderDocumentInfoEntity.Create(entity);
            await _tableStorage.InsertOrReplaceAsync(newEntity);

            return(newEntity);
        }
        public async Task <ICustomerChecksInfo> AddAsync(ICustomerChecksInfo entity)
        {
            var newEntity = CustomerChecksInfoEntity.Create(entity);
            await _tableStorage.InsertOrReplaceAsync(newEntity);

            return(newEntity);
        }
예제 #10
0
        public async Task <OperationEntity> UpdateAsync(Guid operationId, DateTime?sendTime = null, DateTime?completionTime = null,
                                                        DateTime?blockTime = null, DateTime?failTime             = null, DateTime?deleteTime    = null, string transactionHash = null, long?blockNumber = null,
                                                        string error       = null, BlockchainErrorCode?errorCode = null, string broadcastResult = null)
        {
            if (!string.IsNullOrEmpty(transactionHash))
            {
                await _operationIndexStorage.InsertOrReplaceAsync(new OperationIndexEntity(transactionHash, operationId));
            }

            return(await _operationStorage.MergeAsync(
                       OperationEntity.Partition(operationId),
                       OperationEntity.Row(),
                       op =>
            {
                op.SendTime = sendTime ?? op.SendTime;
                op.CompletionTime = completionTime ?? op.CompletionTime;
                op.BlockTime = blockTime ?? op.BlockTime;
                op.FailTime = failTime ?? op.FailTime;
                op.DeleteTime = deleteTime ?? op.DeleteTime;
                op.TransactionHash = transactionHash ?? op.TransactionHash;
                op.BlockNumber = blockNumber ?? op.BlockNumber;
                op.Error = error ?? op.Error;
                op.ErrorCode = errorCode ?? op.ErrorCode;
                op.BroadcastResult = broadcastResult ?? op.BroadcastResult;
                return op;
            }
                       ));
        }
예제 #11
0
        public async Task UpdateOrderAsync(OrderBase updatedOrder)
        {
            var partitionKey = OrderEntity.GeneratePartitionKey(updatedOrder.TraderId);
            var rowKey       = OrderEntity.GenerateRowKey(updatedOrder.Id);


            var oldStatus = OrderStatus.Registered;

            await _tableStorage.ReplaceAsync(partitionKey, rowKey, itm =>
            {
                oldStatus = itm.GetOrder().Status;
                itm.SetOrder(updatedOrder);
                return(itm);
            });



            if (oldStatus == updatedOrder.Status)
            {
                await _tableStorage.ReplaceAsync(OrderEntity.GeneratePartitionAsAllOrders(oldStatus), rowKey, itm =>
                {
                    itm.SetOrder(updatedOrder);
                    return(itm);
                });

                return;
            }


            partitionKey = OrderEntity.GeneratePartitionAsAllOrders(oldStatus);
            await _tableStorage.DeleteAsync(partitionKey, rowKey);

            var newEntity = OrderEntity.Create(updatedOrder);
            await _tableStorage.InsertOrReplaceAsync(newEntity);
        }
예제 #12
0
        public Task InsertSpentOutputsAsync(Guid operationId, IEnumerable <IOutput> outputs)
        {
            var entities = outputs.Select(o => SpentOutputEntity.Create(o.TransactionHash, o.N, operationId));

            return(Task.WhenAll(entities.GroupBy(o => o.PartitionKey)
                                .Select(group => _table.InsertOrReplaceAsync(group))));
        }
        public async Task AddOrReplaceAsync(GasPriceEntity entity)
        {
            entity.PartitionKey = GetPartitionKey();
            entity.RowKey       = GetRowKey();

            await _table.InsertOrReplaceAsync(entity);
        }
예제 #14
0
        public async Task <ISpiderCheckResult> AddAsync(ISpiderCheckResult entity)
        {
            var newEntity = SpiderCheckResultEntity.Create(entity);
            await _tableStorage.InsertOrReplaceAsync(newEntity);

            return(newEntity);
        }
        public async Task UpdateBlockchainHashAsync(string clientId, string id, string hash)
        {
            var partitionkey = CashInOutOperationEntity.ByClientId.GeneratePartitionKey(clientId);
            var rowKey       = CashInOutOperationEntity.ByClientId.GenerateRowKey(id);

            var record = await _tableStorage.GetDataAsync(partitionkey, rowKey);

            var multisigPartitionkey = CashInOutOperationEntity.ByMultisig.GeneratePartitionKey(record.Multisig);
            var multisigRowKey       = CashInOutOperationEntity.ByMultisig.GenerateRowKey(id);

            var indexEntity = AzureIndex.Create(hash, rowKey, partitionkey, rowKey);
            await _blockChainHashIndices.InsertOrReplaceAsync(indexEntity);

            await _tableStorage.MergeAsync(partitionkey, rowKey, entity =>
            {
                entity.BlockChainHash = hash;
                entity.State          = TransactionStates.SettledOnchain;
                return(entity);
            });

            await _tableStorage.MergeAsync(multisigPartitionkey, multisigRowKey, entity =>
            {
                entity.BlockChainHash = hash;
                entity.State          = TransactionStates.SettledOnchain;
                return(entity);
            });
        }
 public Task AddAsync(long brokerAccountId, long cursor)
 {
     return(_tableStorage.InsertOrReplaceAsync(new CursorEntity
     {
         PartitionKey = brokerAccountId.ToString(), RowKey = CursorEntity.GetRk(), Cursor = cursor
     }));
 }
        public async Task UpdateBlockChainHashAsync(string clientId, string id, string blockChainHash)
        {
            var partitionKey = TransferEventEntity.ByClientId.GeneratePartitionKey(clientId);
            var rowKey       = TransferEventEntity.ByClientId.GenerateRowKey(id);

            var item = await _tableStorage.GetDataAsync(partitionKey, rowKey);

            if (item.State == TransactionStates.SettledOffchain || item.State == TransactionStates.InProcessOffchain)
            {
                return;
            }

            item.BlockChainHash = blockChainHash;

            var multisigPartitionKey = TransferEventEntity.ByMultisig.GeneratePartitionKey(item.Multisig);
            var multisigRowKey       = TransferEventEntity.ByMultisig.GenerateRowKey(id);

            var multisigItem = await _tableStorage.GetDataAsync(multisigPartitionKey, multisigRowKey);

            multisigItem.BlockChainHash = blockChainHash;
            multisigItem.State          = TransactionStates.SettledOnchain;

            var indexEntity = AzureIndex.Create(blockChainHash, rowKey, partitionKey, rowKey);
            await _blockChainHashIndices.InsertOrReplaceAsync(indexEntity);

            await _tableStorage.InsertOrReplaceAsync(item);

            await _tableStorage.InsertOrReplaceAsync(multisigItem);
        }
예제 #18
0
        public Task <bool> UpdateBalanceAsync(string walletId, IWallet wallet, long updateSequenceNumber)
        {
            var entity = WalletEntity.Create(walletId, wallet, updateSequenceNumber);

            return(_tableStorage.InsertOrReplaceAsync(entity,
                                                      x => x.UpdateSequenceNumber == null || x.UpdateSequenceNumber.Value < updateSequenceNumber));
        }
        public async Task UpsertAsync(string assetId, string address, string name, int accuracy)
        {
            var asset = new AssetEntity(assetId, address, name, accuracy);
            await _tableStorage.InsertOrReplaceAsync(asset);

            _cache.AddOrUpdate(assetId, asset, (id, _) => asset);
        }
예제 #20
0
        public async Task SaveAsync(
            SnapshotAggregate snapshot)
        {
            await _balanceTable.InsertOrReplaceBatchAsync
            (
                snapshot.Balances.Select(x => new SnapshotBalanceEntity
            {
                BalanceValue      = x.Value,
                SnapshotTimestamp = snapshot.Timestamp,
                WalletId          = x.WalletId,

                PartitionKey = $"{GetSnapshotPartitionKey(snapshot.Timestamp)}-{GetSnapshotRowKey(snapshot.Timestamp)}",
                RowKey       = $"{x.WalletId}"
            })
            );

            _chaosKitty.Meow(snapshot.Timestamp);

            await _snapshotTable.InsertOrReplaceAsync(new SnapshotEntity
            {
                SnapshotTimestamp = snapshot.Timestamp,

                PartitionKey = GetSnapshotPartitionKey(snapshot.Timestamp),
                RowKey       = GetSnapshotRowKey(snapshot.Timestamp)
            });
        }
예제 #21
0
        public async Task InsertSpentOutputsAsync(Guid transactionId, IEnumerable <Output> outputs)
        {
            var entities = outputs.Select(o => SpentOutputEntity.Create(o.Hash, o.OutputIndex, transactionId));

            await entities.GroupBy(o => o.PartitionKey)
            .ForEachAsyncSemaphore(8, group => _table.InsertOrReplaceAsync(group));
        }
예제 #22
0
        public async Task Save(IEventHistory eventHistory)
        {
            var now = DateTime.UtcNow;

            var entity =
                new EventHistoryEntity
            {
                PartitionKey              = GeneratePartitionKey(eventHistory.TickPriceTimestamp ?? now),
                RowKey                    = GenerateRowKey(eventHistory.TickPriceTimestamp ?? now),
                Event                     = eventHistory.Event,
                Extreme                   = eventHistory.Extreme,
                ExpectedDcLevel           = eventHistory.ExpectedDcLevel,
                ExpectedOsLevel           = eventHistory.ExpectedOsLevel,
                Reference                 = eventHistory.Reference,
                ExpectedDirectionalChange = eventHistory.ExpectedDirectionalChange,
                DirectionalChangePrice    = eventHistory.DirectionalChangePrice,
                AssetPair                 = eventHistory.AssetPair.ToUpperInvariant(),
                Delta                     = eventHistory.Delta,
                Exchange                  = eventHistory.Exchange.ToUpperInvariant(),
                Ask = eventHistory.Ask,
                Bid = eventHistory.Bid,
                TickPriceTimestamp      = eventHistory.TickPriceTimestamp,
                DcTimestamp             = eventHistory.DcTimestamp,
                IntrinsicEventIndicator = eventHistory.IntrinsicEventIndicator
            };

            await _storage.InsertOrReplaceAsync(entity);
        }
        public async Task <IRefund> AddAsync(string id, string clientId, string walletId, string feeClientId, string assetId, long siriusAssetId, decimal amount, decimal feeAmount)
        {
            var entity = RefundEntity.Create(id, clientId, walletId, feeClientId, assetId, siriusAssetId, amount, feeAmount);
            await _tableStorage.InsertOrReplaceAsync(entity);

            return(entity);
        }
        public async Task Complete(string requestId)
        {
            var record = await _table.DeleteAsync(OffchainRequestEntity.ByRecord.Partition, requestId);

            await _table.DeleteAsync(OffchainRequestEntity.ByClient.GeneratePartition(record.ClientId), requestId);

            await _table.InsertOrReplaceAsync(OffchainRequestEntity.Archieved.Create(record));
        }
예제 #25
0
        /// <summary>
        /// Adds or entirely replaces a default asset conditions.
        /// </summary>
        /// <param name="layerId">The layer id.</param>
        /// <param name="assetDefaultCondition">The default asset conditons.</param>
        public async Task InsertOrReplaceAsync(string layerId, IAssetDefaultCondition assetDefaultCondition)
        {
            var entity = new AssetDefaultConditionEntity(GetPartitionKey(), GetRowKey(layerId), layerId);

            Mapper.Map(assetDefaultCondition, entity);

            await _storage.InsertOrReplaceAsync(entity);
        }
예제 #26
0
        /// <summary>
        /// Adds or entirely replaces a default asset conditions layer.
        /// </summary>
        /// <param name="settings">The asset conditions layer settings.</param>
        public async Task InsertOrReplaceAsync(IAssetConditionLayerSettings settings)
        {
            var entity = new AssetDefaultConditionLayerEntity(GetPartitionKey(), GetRowKey());

            Mapper.Map(settings, entity);

            await _storage.InsertOrReplaceAsync(entity);
        }
예제 #27
0
 public async Task AddAsync(string address)
 {
     await _table.InsertOrReplaceAsync(new BalanceEntity
     {
         PartitionKey = GetPartitionKey(address),
         RowKey       = GetRowKey(address)
     });
 }
        public async Task InsertOrReplaceAsync(Credit credit)
        {
            var entity = new CreditEntity(GetPartitionKey(), GetRowKey(credit.AssetId));

            Mapper.Map(credit, entity);

            await _storage.InsertOrReplaceAsync(entity);
        }
예제 #29
0
        public Task SetValueAsync(string partition, string field, string value)
        {
            var entity = new SetupByPartitionEntity {
                PartitionKey = partition, RowKey = field, Value = value
            };

            return(_tableStorage.InsertOrReplaceAsync(entity));
        }
예제 #30
0
        public async Task UpdateAsync(TimerSettings timerSettings)
        {
            var entity = new TimerSettingsEntity(GetPartitionKey(), GetRowKey());

            Mapper.Map(timerSettings, entity);

            await _storage.InsertOrReplaceAsync(entity);
        }