Esempio n. 1
0
        public async Task <string> GetUnderlyingAddressAsync(string blockchainType, string address)
        {
            var capabilityQueryResult = _blockchainExtensionsService.IsAddressMappingRequired(blockchainType);

            if (capabilityQueryResult ?? false)
            {
                var apiClient = _blockchainIntegrationService.GetApiClient(blockchainType);

                try
                {
                    var underlyingAddress = await apiClient.GetUnderlyingAddressAsync(address);

                    if (!string.IsNullOrWhiteSpace(underlyingAddress))
                    {
                        return(underlyingAddress);
                    }
                }
                catch (Exception ex) when(!(ex is ArgumentException))  // BlockchainAPiClient thows ArgumentException when input parameter validation's failed.
                {
                    _log.Warning($"Unable to access API service for blockchain {blockchainType}.", ex);
                }
            }

            return(null);
        }
Esempio n. 2
0
        public async Task <WalletWithAddressExtensionDto> CreateWalletAsync(string blockchainType, string assetId,
                                                                            Guid clientId)
        {
            string address;

            if (blockchainType != SpecialBlockchainTypes.FirstGenerationBlockchain)
            {
                var wallet = await _blockchainSignFacadeClient.CreateWalletAsync(blockchainType);

                address = wallet.PublicAddress;

                var isAddressMappingRequired = _blockchainExtensionsService.IsAddressMappingRequired(blockchainType);
                var underlyingAddress        = await _addressService.GetUnderlyingAddressAsync(blockchainType, address);

                if (isAddressMappingRequired.HasValue && isAddressMappingRequired.Value && underlyingAddress == null)
                {
                    throw new ArgumentException(
                              $"Failed to get UnderlyingAddress for blockchainType={blockchainType} and address={address}");
                }

                await _walletRepository.AddAsync(blockchainType, clientId, address, CreatorType.LykkeWallet);

                var @event = new WalletCreatedEvent
                {
                    Address            = address,
                    AssetId            = assetId,
                    BlockchainType     = blockchainType,
                    IntegrationLayerId = blockchainType,
                    ClientId           = clientId
                };

                await _firstGenerationBlockchainWalletRepository.InsertOrReplaceAsync(new BcnCredentialsRecord
                {
                    Address      = string.Empty,
                    AssetAddress = address,
                    ClientId     = clientId.ToString(),
                    EncodedKey   = string.Empty,
                    PublicKey    = string.Empty,
                    AssetId      = $"{blockchainType} ({assetId})"
                });

                _cqrsEngine.PublishEvent
                (
                    @event,
                    BlockchainWalletsBoundedContext.Name
                );

                return(ConvertWalletToWalletWithAddressExtension
                       (
                           new WalletDto
                {
                    Address = isAddressMappingRequired.HasValue && isAddressMappingRequired.Value ? underlyingAddress : address,
                    AssetId = assetId,
                    BlockchainType = blockchainType,
                    ClientId = clientId,
                    CreatorType = CreatorType.LykkeWallet
                }
                       ));
            }

            address = await _legacyWalletService.CreateWalletAsync(clientId, assetId);

            return(new WalletWithAddressExtensionDto()
            {
                Address = address,
                AssetId = assetId,
                BlockchainType = blockchainType,
                ClientId = clientId,
                BaseAddress = address
            });
        }