public AddressParseResultDto ExtractAddressParts(string blockchainType, string address)
        {
            var addressExtension = string.Empty;
            var baseAddress      = string.Empty;
            var isPublicAddressExtensionRequired = false;

            var constants = _extensionsService.TryGetAddressExtensionConstants(blockchainType);

            if (constants != null)
            {
                var addressAndExtension = address.Split(constants.Separator, 2);

                isPublicAddressExtensionRequired = true;
                baseAddress = addressAndExtension[0];

                if (addressAndExtension.Length == 2)
                {
                    addressExtension = addressAndExtension[1];
                }
            }

            return(new AddressParseResultDto
            {
                AddressExtension = addressExtension,
                BaseAddress = baseAddress,
                IsPublicAddressExtensionRequired = isPublicAddressExtensionRequired
            });
        }
示例#2
0
        public IActionResult GetAddressExtensionConstants(string blockchainType)
        {
            if (string.IsNullOrEmpty(blockchainType))
            {
                return(BadRequest
                       (
                           BlockchainWalletsErrorResponse.Create($"{nameof(blockchainType)} should not be null or empty.")
                       ));
            }

            if (blockchainType == LykkeConstants.SolarBlockchainType)
            {
                return(Ok(new AddressExtensionConstantsResponse
                {
                    ProhibitedSymbolsForAddressExtension = null,
                    ProhibitedSymbolsForBaseAddress = null,
                    AddressExtensionDisplayName = "",
                    BaseAddressDisplayName = "",
                    TypeForDeposit = AddressExtensionTypeForDeposit.NotSupported,
                    TypeForWithdrawal = AddressExtensionTypeForWithdrawal.NotSupported
                }));
            }

            if (!_blockchainIntegrationService.BlockchainIsSupported(blockchainType))
            {
                return(BadRequest
                       (
                           BlockchainWalletsErrorResponse.Create($"Blockchain type [{blockchainType}] is not supported.")
                       ));
            }

            var  constants       = _blockchainExtensionsService.TryGetAddressExtensionConstants(blockchainType);
            bool separatorExists = constants?.SeparatorExists ?? false;

            return(Ok(new AddressExtensionConstantsResponse
            {
                Separator = separatorExists ? constants.Separator.ToString() : null,
                ProhibitedSymbolsForAddressExtension = separatorExists ? new char[] { constants.Separator } : null,
                ProhibitedSymbolsForBaseAddress = separatorExists ? new char[] { constants.Separator } : null,
                AddressExtensionDisplayName = constants?.AddressExtensionDisplayName,
                BaseAddressDisplayName = !string.IsNullOrEmpty(constants?.BaseAddressDisplayName) ? constants.BaseAddressDisplayName : LykkeConstants.PublicAddressExtension.BaseAddressDisplayName,
                TypeForDeposit = constants?.TypeForDeposit ?? AddressExtensionTypeForDeposit.NotSupported,
                TypeForWithdrawal = constants?.TypeForWithdrawal ?? AddressExtensionTypeForWithdrawal.NotSupported
            }));
        }
示例#3
0
        public string Merge(string blockchainType, string baseAddress, string addressExtension)
        {
            string mergedAddress = null;

            if (string.IsNullOrEmpty(baseAddress))
            {
                throw new OperationException("Base address is empty",
                                             OperationErrorCode.BaseAddressIsEmpty);
            }

            var constants = _blockchainExtensionsService.TryGetAddressExtensionConstants(blockchainType);

            if (baseAddress.Contains(constants.Separator))
            {
                throw new OperationException($"Base address should not contain a separator({constants.Separator})",
                                             OperationErrorCode.BaseAddressShouldNotContainSeparator);
            }

            if (!string.IsNullOrEmpty(addressExtension))
            {
                var capabilityQueryResult = _blockchainExtensionsService.IsPublicAddressExtensionRequired(blockchainType);
                if (!capabilityQueryResult.HasValue)
                {
                    throw new InvalidOperationException($"API service for blockchain type [{blockchainType}] is not currently available.");
                }
                if (!capabilityQueryResult.Value)
                {
                    throw new NotSupportedException($"Blockchain type [{blockchainType}] is not supported.");
                }

                if (addressExtension.Contains(constants.Separator))
                {
                    throw new OperationException($"Extension address should not contain a separator({constants.Separator})",
                                                 OperationErrorCode.ExtensionAddressShouldNotContainSeparator);
                }

                mergedAddress = $"{baseAddress}{constants.Separator}{addressExtension}";
            }
            else
            {
                mergedAddress = baseAddress;
            }

            return(mergedAddress);
        }