private static async Task Migrate(IBlockchainWalletsRepository walletRepository, ISigningServiceApi signingServiceApi,
                                          IBlockchainSignFacadeClient blockchainSignFacade, ICqrsEngine cqrs,
                                          IBcnCredentialsRecord bcnCredentialsRecord)
        {
            var clientId       = Guid.Parse(bcnCredentialsRecord.ClientId);
            var existingWallet = await walletRepository.TryGetAsync(BlockchainType, clientId);

            if (existingWallet != null)
            {
                return;
            }
            var address    = bcnCredentialsRecord.AssetAddress;
            var privateKey = await GetPrivateKey(signingServiceApi, address);

            if (privateKey == null)
            {
                return;
            }

            await ImportWalletToSignFacade(blockchainSignFacade, privateKey, address);

            await walletRepository.AddAsync(BlockchainType, clientId, address, CreatorType.LykkeWallet);

            var @event = new WalletCreatedEvent
            {
                Address            = address,
                AssetId            = AssetId,
                BlockchainType     = BlockchainType,
                IntegrationLayerId = BlockchainType,
                ClientId           = clientId,
                CreatedBy          = CreatorType.LykkeWallet
            };

            cqrs.PublishEvent(@event, BlockchainWalletsBoundedContext.Name);
        }
Пример #2
0
        public WalletService(
            ICqrsEngine cqrsEngine,
            IBlockchainWalletsRepository walletRepository,
            IBlockchainSignFacadeClient blockchainSignFacadeClient,
            IAddressParser addressParser,
            IFirstGenerationBlockchainWalletRepository firstGenerationBlockchainWalletRepository,
            IAssetsServiceWithCache assetsServiceWithCache,
            IBlockchainExtensionsService blockchainExtensionsService,
            IAddressService addressService,
            ILegacyWalletService legacyWalletService,
            ILogFactory logFactory)
        {
            _cqrsEngine                 = cqrsEngine ?? throw new ArgumentNullException(nameof(cqrsEngine));
            _walletRepository           = walletRepository ?? throw new ArgumentNullException(nameof(walletRepository));
            _blockchainSignFacadeClient = blockchainSignFacadeClient ??
                                          throw new ArgumentNullException(nameof(blockchainSignFacadeClient));
            _addressParser = addressParser ?? throw new ArgumentNullException(nameof(addressParser));
            _firstGenerationBlockchainWalletRepository = firstGenerationBlockchainWalletRepository ??
                                                         throw new ArgumentNullException(
                                                                   nameof(firstGenerationBlockchainWalletRepository));
            _assetsServiceWithCache =
                assetsServiceWithCache ?? throw new ArgumentNullException(nameof(assetsServiceWithCache));
            _blockchainExtensionsService = blockchainExtensionsService ?? throw new ArgumentNullException(nameof(blockchainExtensionsService));
            _addressService      = addressService ?? throw new ArgumentNullException(nameof(addressService));
            _legacyWalletService = legacyWalletService ?? throw new ArgumentNullException(nameof(legacyWalletService));

            if (logFactory == null)
            {
                throw new ArgumentNullException(nameof(logFactory));
            }
            _log = logFactory.CreateLog(this);
        }