public async Task <IBcnWalletUsage> OccupyAsync(string walletAddress, BlockchainType blockchain, string occupiedBy) { var usage = BcnWalletUsage.Create(walletAddress, blockchain, occupiedBy); bool isLocked = await _walletUsageRepository.TryLockAsync(usage); if (!isLocked) { throw new WalletAddressInUseException(walletAddress, blockchain); } return(usage); }
public async Task <bool> ReleaseAsync(string walletAddress, BlockchainType blockchain) { string partitionKey = BcnWalletUsageEntity.ByWalletAddress.GeneratePartitionKey(walletAddress); string rowKey = BcnWalletUsageEntity.ByWalletAddress.GenerateRowKey(blockchain); var vacant = BcnWalletUsage.CreateVacant(walletAddress, blockchain); return(await _tableStorage.InsertOrModifyAsync(partitionKey, rowKey, () => BcnWalletUsageEntity.ByWalletAddress.Create(vacant), existing => { existing.OccupiedBy = vacant.OccupiedBy; existing.Since = vacant.Since; return true; })); }