public async Task <EnrolledBalance> TryGetAsync(DepositWalletKey key)
        {
            if (!_memCache.TryGetValue(key, out EnrolledBalance value))
            {
                value = await _enrolledBalanceRepository.TryGetAsync(key);

                using (var entry = _memCache.CreateEntry(key))
                {
                    entry.Value = EnrolledBalance.Create(key, value?.Balance ?? 0, value?.Block ?? 0);
                }
            }

            return(value);
        }
        public async Task <IActionResult> GetBalanceAsync([FromQuery] CheckBalanceRequest request)
        {
            var key     = new DepositWalletKey(request.BlockchainAssetId, request.BlockchainId, request.WalletAddress);
            var balance = await _balanceRepository.TryGetAsync(key);

            return(Ok(new CheckBalanceResponse()
            {
                BlockchainAssetId = key.BlockchainAssetId,
                BlockchainId = key.BlockchainId,
                WalletAddress = key.WalletAddress,
                Block = balance?.Block ?? 0,
                Balance = balance?.Balance.ToString() ?? "0"
            }));
        }
Exemplo n.º 3
0
        public override async Task <BalanceResponse> GetBalance(GetBalanceRequest request, ServerCallContext context)
        {
            var balance = await _enrolledBalanceRepository.TryGetAsync(
                new DepositWalletKey(
                    request.WalletKey.BlockchainAssetId,
                    request.WalletKey.BlockchainId,
                    request.WalletKey.WalletAddress));

            return(new BalanceResponse()
            {
                Block = balance?.Block ?? 0,
                Balance = balance?.Balance.ToString() ?? "0",
                WalletKey = request.WalletKey
            });
        }
        public async Task <CommandHandlingResult> Handle(LockDepositWalletCommand command, IEventPublisher publisher)
        {
            var depositWalletKey = new DepositWalletKey
                                   (
                command.BlockchainAssetId,
                command.BlockchainType,
                command.DepositWalletAddress
                                   );

            var depositWalletLock = await _depositWalletLockRepository.LockAsync
                                    (
                depositWalletKey,
                command.DepositWalletBalance,
                command.DepositWalletBlock,
                CashinAggregate.GetNextId
                                    );

            var enrolledBalance = await _enrolledBalanceRepository.TryGetAsync(depositWalletKey);

            _chaosKitty.Meow(depositWalletLock.OperationId);

            publisher.PublishEvent(new DepositWalletLockedEvent
            {
                OperationId          = depositWalletLock.OperationId,
                BlockchainType       = command.BlockchainType,
                BlockchainAssetId    = command.BlockchainAssetId,
                DepositWalletAddress = command.DepositWalletAddress,
                LockedAtBalance      = depositWalletLock.Balance,
                LockedAtBlock        = depositWalletLock.Block,
                EnrolledBalance      = enrolledBalance?.Balance ?? 0,
                EnrolledBlock        = enrolledBalance?.Block ?? 0,
                AssetId                 = command.AssetId,
                AssetAccuracy           = command.AssetAccuracy,
                BlockchainAssetAccuracy = command.BlockchainAssetAccuracy,
                CashinMinimalAmount     = command.CashinMinimalAmount,
                HotWalletAddress        = command.HotWalletAddress
            });

            return(CommandHandlingResult.Ok());
        }