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);
        }
Beispiel #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);
        }
 public SignTransactionCommandsHandler(
     IBlockchainSignFacadeClient signFacadeClient,
     IChaosKitty chaosKitty,
     ICommandHandlerEventRepository commandHandlerEventRepository)
 {
     _signFacadeClient = signFacadeClient;
     _chaosKitty       = chaosKitty;
     _commandHandlerEventRepository = commandHandlerEventRepository;
 }
 private static async Task ImportWalletToSignFacade(IBlockchainSignFacadeClient blockchainSignFacade,
                                                    string privateKey,
                                                    string address)
 {
     try
     {
         await blockchainSignFacade.ImportWalletAsync(BlockchainType, new ImportWalletRequest
         {
             PrivateKey     = privateKey,
             AddressContext =
                 new AddressContextContract {
                 PubKey = Key.Parse(privateKey).PubKey.ToString()
             }.ToJson(),
             PublicAddress = address
         });
     }
     catch (ErrorResponseException e) when(e.StatusCode == HttpStatusCode.Conflict)
     {
         Console.WriteLine($"Private key for address {address} was imported already");
     }
 }
 public SignTransactionCommandHandler(IBlockchainSignFacadeClient client,
                                      IChaosKitty chaosKitty)
 {
     _client     = client;
     _chaosKitty = chaosKitty;
 }