protected override void Load(ContainerBuilder builder) { var connectionString = _dbSettings.Nested(x => x.DataConnString); builder .Register(c => WalletRepository.Create(connectionString, c.Resolve <ILogFactory>())) .As <IWalletRepository>() .SingleInstance(); builder .Register(c => BlockchainWalletsRepository.Create(connectionString, c.Resolve <ILogFactory>())) .As <IBlockchainWalletsRepository>() .SingleInstance(); builder .Register(c => FirstGenerationBlockchainWalletRepository.Create(_dbSettings.Nested(x => x.ClientPersonalInfoConnString), c.Resolve <ILogFactory>())) .As <IFirstGenerationBlockchainWalletRepository>() .SingleInstance(); builder .Register(c => MonitoringSubscriptionRepository.Create(connectionString, c.Resolve <ILogFactory>())) .As <IMonitoringSubscriptionRepository>() .SingleInstance(); builder .Register(c => WalletCredentialsHistoryRepository.Create(_dbSettings.Nested(x => x.ClientPersonalInfoConnString), c.Resolve <ILogFactory>())) .As <IWalletCredentialsHistoryRepository>() .SingleInstance(); }
private static async Task Execute(string bitcoinCashDataConnString, string settingsUrl, string bitcoinCashNetwork, string blockchainType) { BCash.Instance.EnsureRegistered(); var network = Network.GetNetwork(bitcoinCashNetwork); var bcashNetwork = network == Network.Main ? BCash.Instance.Mainnet : BCash.Instance.Regtest; var logConsole = LogFactory.Create().AddConsole(); var settings = new SettingsServiceReloadingManager <AppSettings>(settingsUrl, p => {}); var walletRepo = BlockchainWalletsRepository.Create(settings.Nested(p => p.BlockchainWalletsService.Db.DataConnString), logConsole); var firstGenerationBlockchainWalletRepository = FirstGenerationBlockchainWalletRepository.Create(settings.Nested(x => x.BlockchainWalletsService.Db.ClientPersonalInfoConnString), logConsole); var observableWalletsRepo = ObservableWalletRepository.Create(new ReloadingManagerAdapter <string>(bitcoinCashDataConnString), logConsole); var addressValidator = new AddressValidator(network, bcashNetwork); Console.WriteLine("Retrieving observable wallets"); var observableWallets = (await observableWalletsRepo.GetAll()).ToList(); Console.WriteLine("Processing items"); var counter = 0; foreach (var observableWallet in observableWallets) { counter++; var address = addressValidator.GetBitcoinAddress(observableWallet.Address); if (address == null) { throw new ArgumentException($"Unrecognized address {observableWallet.Address}", nameof(observableWallet.Address)); } var oldAdrr = address.ScriptPubKey.GetDestinationAddress(network).ToString(); var newAddr = address.ScriptPubKey.GetDestinationAddress(bcashNetwork).ToString(); Console.WriteLine($"Processing {observableWallet.Address}:{oldAdrr}:{newAddr} -- {counter} of {observableWallets.Count}"); var wallet = await walletRepo.TryGetAsync(blockchainType, oldAdrr); if (wallet == null) { var prevColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Wallet not found {observableWallet.Address} -{blockchainType}. Queued by {oldAdrr}"); Console.ForegroundColor = prevColor; continue; } var oldCredsRecord = new BcnCredentialsRecord { Address = string.Empty, AssetAddress = oldAdrr, ClientId = wallet.ClientId.ToString(), EncodedKey = string.Empty, PublicKey = string.Empty, AssetId = $"{blockchainType} ({wallet.AssetId})" }; var newCredsRecord = new BcnCredentialsRecord { Address = string.Empty, AssetAddress = newAddr, ClientId = wallet.ClientId.ToString(), EncodedKey = string.Empty, PublicKey = string.Empty, AssetId = $"{blockchainType} ({wallet.AssetId})" }; await firstGenerationBlockchainWalletRepository.DeleteIfExistAsync(oldCredsRecord); await firstGenerationBlockchainWalletRepository.InsertOrReplaceAsync(newCredsRecord); await walletRepo.DeleteIfExistsAsync(wallet.BlockchainType, wallet.ClientId, oldAdrr); await walletRepo.AddAsync(wallet.BlockchainType, wallet.ClientId, newAddr, wallet.CreatorType); } Console.WriteLine("All done"); }
private static async Task Migrate(string bwSettingsUrl, string bitcoinSettingsUrl, string apiKey) { if (!ValidateSettingsUrl(bwSettingsUrl)) { return; } if (!ValidateSettingsUrl(bitcoinSettingsUrl)) { return; } var logFactory = LogFactory.Create().AddConsole(); var appSettings = new SettingsServiceReloadingManager <AppSettings>(bwSettingsUrl, p => {}); var bitcoinSettings = new SettingsServiceReloadingManager <BitcoinAppSettings>(bitcoinSettingsUrl, p => { }) .CurrentValue.BitcoinService; var signingService = RestClient.For <ISigningServiceApi>(new HttpClient { BaseAddress = new Uri(bitcoinSettings.SignatureProviderUrl) }); signingService.ApiKey = bitcoinSettings.SigningServiceApiKey; var walletRepository = BlockchainWalletsRepository.Create(appSettings.Nested(o => o.BlockchainWalletsService.Db.DataConnString), logFactory); var firstGenerationBlockchainWalletRepository = FirstGenerationBlockchainWalletRepository.Create( appSettings.Nested(o => o.BlockchainWalletsService.Db.ClientPersonalInfoConnString), logFactory); var cqrs = Cqrs.CreateCqrsEngine(appSettings.CurrentValue.BlockchainWalletsService.Cqrs.RabbitConnectionString, logFactory); var blockchainSignFacade = new BlockchainSignFacadeClient ( appSettings.CurrentValue.BlockchainSignFacadeClient.ServiceUrl, apiKey, logFactory.CreateLog(nameof(BlockchainSignFacadeClient)) ); var counter = 0; const int batchSize = 10; await firstGenerationBlockchainWalletRepository.EnumerateBcnCredsByChunksAsync(AssetId, async records => { foreach (var batch in records.Batch(batchSize)) { await batch.SelectAsync(async o => { await Migrate(walletRepository, signingService, blockchainSignFacade, cqrs, o); return(true); }); counter += batchSize; Console.SetCursorPosition(0, Console.CursorTop); Console.Write($"{counter} wallets migrated"); } }); Console.WriteLine(); Console.WriteLine("Migration completed"); }