public Node() { #if DEBUG Logging.warn("Testing language files"); SpixiLocalization.testLanguageFiles("en-us"); #endif Logging.info("Initing node constructor"); Instance = this; IxianHandler.init(Config.version, this, Config.networkType); // Prepare the wallet walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile)); PeerStorage.init(Config.spixiUserFolder); // Init TIV tiv = new TransactionInclusion(); Logging.info("Initing local storage"); // Prepare the local storage localStorage = new SPIXI.Storage.LocalStorage(Config.spixiUserFolder); customAppManager = new CustomAppManager(Config.spixiUserFolder); FriendList.init(Config.spixiUserFolder); Logging.info("Node init done"); }
static public void start() { // Initialize the crypto manager CryptoManager.initLib(); // Prepare the wallet string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); walletStorage = new WalletStorage(Path.Combine(path, Config.walletFile)); // Initialize the wallet state walletState = new WalletState(); // Prepare the local storage localStorage = new SPIXI.Storage.LocalStorage(); // Read the account file localStorage.readAccountFile(); // Start the network queue NetworkQueue.start(); // Prepare the stream processor StreamProcessor.initialize(); // Start the keepalive thread PresenceList.startKeepAlive(); // Setup a timer to handle routine updates mainLoopTimer = new System.Timers.Timer(2500); mainLoopTimer.Elapsed += new ElapsedEventHandler(onUpdate); mainLoopTimer.Start(); }
public Node() { Instance = this; CoreConfig.productVersion = Config.version; IxianHandler.setHandler(this); CoreConfig.isTestNet = Config.isTestNet; // Initialize the crypto manager CryptoManager.initLib(); // Prepare the wallet walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile)); string peers_filename = "peers.ixi"; if (CoreConfig.isTestNet) { peers_filename = "testnet-peers.ixi"; } PeerStorage.init(Config.spixiUserFolder, peers_filename); ulong block_height = 1; byte[] block_checksum = null; if (!walletStorage.walletExists()) { block_height = Config.bakedBlockHeight; block_checksum = Config.bakedBlockChecksum; } string headers_path = ""; if (!Config.isTestNet) { headers_path = Path.Combine(Config.spixiUserFolder, "headers"); } else { // Temporary hack for our beta testers, remove before release string tmp_path = Path.Combine(Config.spixiUserFolder, "headers"); BlockHeaderStorage.init(tmp_path); BlockHeaderStorage.deleteCache(); BlockHeaderStorage.stop(); // End of hack headers_path = Path.Combine(Config.spixiUserFolder, "testnet-headers"); } // Init TIV tiv = new TransactionInclusion(headers_path, block_height, block_checksum); // Prepare the local storage localStorage = new SPIXI.Storage.LocalStorage(Config.spixiUserFolder); customAppManager = new CustomAppManager(Config.spixiUserFolder); }
public Node() { Instance = this; CoreConfig.productVersion = Config.version; IxianHandler.setHandler(this); CoreConfig.isTestNet = Config.isTestNet; // Prepare the wallet walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile)); string peers_filename = "peers.ixi"; if (CoreConfig.isTestNet) { peers_filename = "testnet-peers.ixi"; } PeerStorage.init(Config.spixiUserFolder, peers_filename); ulong block_height = 1; byte[] block_checksum = null; string headers_path; if (Config.isTestNet) { headers_path = Path.Combine(Config.spixiUserFolder, "testnet-headers"); } else { headers_path = Path.Combine(Config.spixiUserFolder, "headers"); if (!walletStorage.walletExists()) { block_height = Config.bakedBlockHeight; block_checksum = Config.bakedBlockChecksum; } else { block_height = Config.bakedRecoveryBlockHeight; block_checksum = Config.bakedRecoveryBlockChecksum; } } // Init TIV tiv = new TransactionInclusion(headers_path, block_height, block_checksum); // Prepare the local storage localStorage = new SPIXI.Storage.LocalStorage(Config.spixiUserFolder); customAppManager = new CustomAppManager(Config.spixiUserFolder); }
static public bool generateWallet(string pass) { if (IxianHandler.getWalletList().Count == 0) { WalletStorage ws = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile)); if (ws.generateWallet(pass)) { return(IxianHandler.addWallet(ws)); } } return(false); }
private void doUnlock(string pass) { string target_filepath = Path.Combine(Config.spixiUserFolder, Config.walletFile); WalletStorage ws = new WalletStorage(target_filepath); if (!ws.verifyWallet(target_filepath, pass)) { displaySpixiAlert(SpixiLocalization._SL("intro-restore-file-invalidpassword-title"), SpixiLocalization._SL("intro-restore-file-invalidpassword-text"), SpixiLocalization._SL("global-dialog-ok")); } else { performUnlock(); } }
static public bool loadWallet() { if (Application.Current.Properties.ContainsKey("walletpass") == false) { return(false); } // TODO: decrypt the password string password = Application.Current.Properties["walletpass"].ToString(); WalletStorage walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile)); if (walletStorage.readWallet(password)) { IxianHandler.addWallet(walletStorage); return(true); } return(false); }
public Node() { CoreConfig.productVersion = Config.version; IxianHandler.setHandler(this); CoreConfig.isTestNet = Config.isTestNet; // Initialize the crypto manager CryptoManager.initLib(); // Prepare the wallet walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile)); string peers_filename = "peers.ixi"; if (CoreConfig.isTestNet) { peers_filename = "testnet-peers.ixi"; } PeerStorage.init(Config.spixiUserFolder, peers_filename); }
private bool restoreWalletFile(string source_path, string pass) { // TODO add file header string target_filepath = Path.Combine(Config.spixiUserFolder, Config.walletFile); WalletStorage ws = new WalletStorage(source_path); if (!ws.verifyWallet(source_path, pass)) { displaySpixiAlert(SpixiLocalization._SL("intro-restore-file-invalidpassword-title"), SpixiLocalization._SL("intro-restore-file-invalidpassword-text"), SpixiLocalization._SL("global-dialog-ok")); // Remove overlay Utils.sendUiCommand(webView, "removeLoadingOverlay"); return(false); } else { File.Move(source_path, target_filepath); Node.loadWallet(); } Navigation.PushAsync(HomePage.Instance(true), Config.defaultXamarinAnimations); Navigation.RemovePage(this); return(true); }
private bool initWallet() { walletStorage = new WalletStorage(Config.walletFile); Logging.flush(); if (!walletStorage.walletExists()) { ConsoleHelpers.displayBackupText(); // Request a password // NOTE: This can only be done in testnet to enable automatic testing! string password = ""; if (Config.dangerCommandlinePasswordCleartextUnsafe != "") { Logging.warn("Warning: Wallet password has been specified on the command line!"); password = Config.dangerCommandlinePasswordCleartextUnsafe; // Also note that the commandline password still has to be >= 10 characters } while (password.Length < 10) { Logging.flush(); password = ConsoleHelpers.requestNewPassword("Enter a password for your new wallet: "); if (IxianHandler.forceShutdown) { return(false); } } walletStorage.generateWallet(password); } else { ConsoleHelpers.displayBackupText(); bool success = false; while (!success) { // NOTE: This is only permitted on the testnet for dev/testing purposes! string password = ""; if (Config.dangerCommandlinePasswordCleartextUnsafe != "") { Logging.warn("Warning: Attempting to unlock the wallet with a password from commandline!"); password = Config.dangerCommandlinePasswordCleartextUnsafe; } if (password.Length < 10) { Logging.flush(); Console.Write("Enter wallet password: "******"Your IXIAN addresses are: "); Console.ForegroundColor = ConsoleColor.Green; foreach (var entry in walletStorage.getMyAddressesBase58()) { Console.WriteLine(entry); } Console.ResetColor(); Console.WriteLine(); if (Config.onlyShowAddresses) { return(false); } // Check if we should change the password of the wallet if (Config.changePass == true) { // Request a new password string new_password = ""; while (new_password.Length < 10) { new_password = ConsoleHelpers.requestNewPassword("Enter a new password for your wallet: "); if (IxianHandler.forceShutdown) { return(false); } } walletStorage.writeWallet(new_password); } Logging.info("Public Node Address: {0}", Base58Check.Base58CheckEncoding.EncodePlain(walletStorage.getPrimaryAddress())); return(true); }
private bool initWallet() { WalletStorage walletStorage = new WalletStorage(Config.walletFile); Logging.flush(); if (!walletStorage.walletExists()) { ConsoleHelpers.displayBackupText(); // Request a password string password = ""; while (password.Length < 10) { Logging.flush(); password = ConsoleHelpers.requestNewPassword("Enter a password for your new wallet: "); if (IxianHandler.forceShutdown) { return(false); } } walletStorage.generateWallet(password); generatedNewWallet = true; } else { ConsoleHelpers.displayBackupText(); bool success = false; while (!success) { string password = ""; if (password.Length < 10) { Logging.flush(); Console.Write("Enter wallet password: "******"Your IXIAN addresses are: "); Console.ForegroundColor = ConsoleColor.Green; foreach (var entry in walletStorage.getMyAddressesBase58()) { Console.WriteLine(entry); } Console.ResetColor(); Console.WriteLine(); if (Config.onlyShowAddresses) { return(false); } if (walletStorage.viewingWallet) { Logging.error("Viewing-only wallet {0} cannot be used as the primary DLT Node wallet.", Base58Check.Base58CheckEncoding.EncodePlain(walletStorage.getPrimaryAddress())); return(false); } IxianHandler.addWallet(walletStorage); return(true); }
static void onStart(string[] args) { bool verboseConsoleOutputSetting = Config.verboseConsoleOutput; Config.verboseConsoleOutput = true; Console.WriteLine(string.Format("IXIAN DLT {0}", Config.version)); // Check for critical files in the exe dir checkRequiredFiles(); // Read configuration from command line Config.readFromCommandLine(args); // Benchmark keys is a special case, because it will not start any part of the node. if (Config.benchmarkKeys > 0) { if (Config.benchmarkKeys != 1024 && Config.benchmarkKeys != 2048 && Config.benchmarkKeys != 4096) { Logging.error(String.Format("Invalid key bit length: {0}. Allowed values are 1024, 2048 or 4096!", Config.benchmarkKeys)); } else { IXICore.CryptoKey.KeyDerivation.BenchmarkKeyGeneration(10000, Config.benchmarkKeys, "bench_keys.out"); } noStart = true; } // Debugging option: generate wallet only and set password from commandline if (Config.generateWalletOnly) { noStart = true; if (Config.isTestNet) { if (File.Exists(Config.walletFile)) { Logging.error(String.Format("Wallet file {0} already exists. Cowardly refusing to overwrite!", Config.walletFile)); } else { Logging.info("Generating a new wallet."); CryptoManager.initLib(); WalletStorage wst = new WalletStorage(Config.walletFile); wst.writeWallet(Config.dangerCommandlinePasswordCleartextUnsafe); } } else { // the main reason we don't allow stuff like 'generateWallet' in mainnet, is because the resulting wallet will have to: // a. Have an empty password (easy to steal via a misconfifured file sharing program) // b. Have a predefined password (ditto) // c. Require password on the command line, which usually leads to people making things like 'start.bat' with cleartext passwords, thus defeating // wallet encryption // However, it is useful to be able to spin up a lot of nodes automatically and know their wallet addresses, therefore this sort of behavior is allowed // for testnet. Logging.error("Due to security reasons, the 'generateWallet' option is only valid when starting a TestNet node!"); } } if (noStart) { Thread.Sleep(1000); return; } // Set the logging options Logging.setOptions(Config.maxLogSize, Config.maxLogCount); Logging.info(string.Format("Starting IXIAN DLT {0}", Config.version)); Logging.flush(); // Check for the right vc++ redist for the argon miner // Ignore if we're on Mono if (IXICore.Platform.onMono() == false) { Logging.info("Runtime environment is .NET"); checkVCRedist(); } else { Logging.info("Runtime environment is Mono"); } // Log the parameters to notice any changes Logging.info(String.Format("Mainnet: {0}", !Config.isTestNet)); if (Config.workerOnly) { Logging.info("Miner: worker-only"); } else { Logging.info(String.Format("Miner: {0}", !Config.disableMiner)); } Logging.info(String.Format("Server Port: {0}", Config.serverPort)); Logging.info(String.Format("API Port: {0}", Config.apiPort)); Logging.info(String.Format("Wallet File: {0}", Config.walletFile)); // Initialize the crypto manager CryptoManager.initLib(); // Initialize the node Node.init(); if (noStart) { Thread.Sleep(1000); return; } // Start the actual DLT node Node.start(verboseConsoleOutputSetting); // Setup a timer to handle routine updates mainLoopTimer = new System.Timers.Timer(1000); mainLoopTimer.Elapsed += new ElapsedEventHandler(onUpdate); mainLoopTimer.Start(); if (Config.verboseConsoleOutput) { Console.WriteLine("-----------\nPress Ctrl-C or use the /shutdown API to stop the DLT process at any time.\n"); } }
private bool restoreAccountFile(string source_path, string pass) { // TODO add file header string tmpDirectory = Path.Combine(Config.spixiUserFolder, "tmp_zip"); try { if (Directory.Exists(tmpDirectory)) { Directory.Delete(tmpDirectory, true); } Directory.CreateDirectory(tmpDirectory); byte[] decrypted = CryptoManager.lib.decryptWithPassword(File.ReadAllBytes(source_path), pass, true); byte[] header = UTF8Encoding.UTF8.GetBytes("SPIXIACCB1"); for (int i = 0; i < header.Length; i++) { if (decrypted[i] != header[i]) { Directory.Delete(tmpDirectory, true); return(false); } } byte[] zipFileBytes = decrypted.Skip(header.Length).ToArray(); File.WriteAllBytes(source_path, zipFileBytes); ZipFile.ExtractToDirectory(source_path, tmpDirectory); string tmpWalletFile = Path.Combine(tmpDirectory, Config.walletFile); WalletStorage ws = new WalletStorage(tmpWalletFile); if (!ws.verifyWallet(tmpWalletFile, pass)) { Directory.Delete(tmpDirectory, true); displaySpixiAlert(SpixiLocalization._SL("intro-restore-file-invalidpassword-title"), SpixiLocalization._SL("intro-restore-file-invalidpassword-text"), SpixiLocalization._SL("global-dialog-ok")); // Remove overlay Utils.sendUiCommand(webView, "removeLoadingOverlay"); return(false); } Directory.Delete(Path.Combine(Config.spixiUserFolder, "Acc"), true); Directory.Move(Path.Combine(tmpDirectory, "Acc"), Path.Combine(Config.spixiUserFolder, "Acc")); if (File.Exists(Path.Combine(tmpDirectory, "account.ixi"))) { File.Move(Path.Combine(tmpDirectory, "account.ixi"), Path.Combine(Config.spixiUserFolder, "account.ixi")); } if (File.Exists(Path.Combine(tmpDirectory, "avatar.jpg"))) { File.Move(Path.Combine(tmpDirectory, "avatar.jpg"), Path.Combine(Config.spixiUserFolder, "avatar.jpg")); } if (File.Exists(Path.Combine(tmpDirectory, "txcache.ixi"))) { File.Move(Path.Combine(tmpDirectory, "txcache.ixi"), Path.Combine(Config.spixiUserFolder, "txcache.ixi")); } File.Move(Path.Combine(tmpDirectory, "wallet.ixi"), Path.Combine(Config.spixiUserFolder, "wallet.ixi")); Node.loadWallet(); Directory.Delete(tmpDirectory, true); File.Delete(source_path); Navigation.PushAsync(HomePage.Instance(true), Config.defaultXamarinAnimations); Navigation.RemovePage(this); return(true); }catch (Exception e) { Logging.warn("Exception occured while trying to restore account file: " + e); Directory.Delete(tmpDirectory, true); } return(false); }
private bool initWallet() { walletStorage = new WalletStorage(Config.walletFile); Logging.flush(); if (!walletStorage.walletExists()) { ConsoleHelpers.displayBackupText(); // Request a password // NOTE: This can only be done in testnet to enable automatic testing! string password = ""; while (password.Length < 10) { Logging.flush(); password = ConsoleHelpers.requestNewPassword("Enter a password for your new wallet: "); if (IxianHandler.forceShutdown) { return(false); } } walletStorage.generateWallet(password); } else { ConsoleHelpers.displayBackupText(); bool success = false; while (!success) { // NOTE: This is only permitted on the testnet for dev/testing purposes! string password = ""; if (password.Length < 10) { Logging.flush(); Console.Write("Enter wallet password: "******"Your IXIAN addresses are: "); Console.ForegroundColor = ConsoleColor.Green; foreach (var entry in walletStorage.getMyAddressesBase58()) { Console.WriteLine(entry); } Console.ResetColor(); Console.WriteLine(); if (Config.onlyShowAddresses) { return(false); } return(true); }