/// <summary> /// Extract private key by keystore /// </summary> /// <param name="parameters"> /// Parameters Index /// </param> /// <returns></returns> public static bool BackupWallet(string command, string[] parameters) { string[] usage = new string[] { string.Format("{0} [command option] <path>\n", command) }; string[] command_option = new string[] { HelpCommandOption.Help }; if (parameters != null) { OutputHelpMessage(usage, null, command_option, null); return(true); } if (!RpcApi.IsLogin) { return(true); } try { string password = CommandLineUtil.ReadPasswordString("Please input your password."); RpcApiResult result = RpcApi.BackupWallet(password); OutputResultMessage(command, result.Result, result.Code, result.Message); } catch (System.Exception e) { Console.WriteLine(e.Message + "\n\n" + e.StackTrace); } return(true); }
/// <summary> /// Create keystore file /// </summary> /// <param name="parameters"> /// Parameters Index /// </param> /// <returns></returns> public static bool RegisterWallet(string command, string[] parameters) { string[] usage = new string[] { string.Format("{0} [command option] <path>\n", command) }; string[] command_option = new string[] { HelpCommandOption.Help }; if (parameters != null) { OutputHelpMessage(usage, null, command_option, null); return(true); } try { string password = CommandLineUtil.ReadPasswordString("Please input wallet password"); string confirm = CommandLineUtil.ReadPasswordString("Please input confirm wallet password"); if (!password.Equals(confirm)) { Console.WriteLine("Confirm password does not match"); return(true); } RpcApiResult result = RpcApi.RegisterWallet(password); Logout(null, null); OutputResultMessage(command, result.Result, result.Code, result.Message); } catch (System.Exception e) { Console.WriteLine(e.Message + "\n\n" + e.StackTrace); } return(true); }
public static RpcApiResult SignatureTransaction(ref Transaction transaction) { if (transaction.RawData.Timestamp == 0) { transaction.RawData.Timestamp = Helper.CurrentTimeMillis(); } ProtocolUtil.SetExpirationTime(ref transaction); Console.WriteLine("Your transaction details are as follows, please confirm."); Console.WriteLine("transaction hex string is " + transaction.ToByteArray().ToHexString()); Console.WriteLine(PrintUtil.PrintTransaction(transaction)); Console.WriteLine( "Please confirm and input your permission id, if input y or Y means default 0, other non-numeric characters will cancell transaction."); ProtocolUtil.SetPermissionId(ref transaction); try { while (true) { Console.WriteLine("Please choose keystore for signature."); KeyStore key_store = SelectKeyStore(); string password = CommandLineUtil.ReadPasswordString("Please input password"); if (KeyStoreService.DecryptKeyStore(password, key_store, out byte[] privatekey))
public bool SetParam(string[] args, string config_path) { CommanderParser <Args> parser = new CommanderParser <Args>(); try { instance = parser.Add(args).Parse(); } catch (System.Exception e) { Logger.Error(e.Message); return(false); } if (instance.version) { Console.WriteLine(Version); return(false); } string config_filename = instance.config_file.IsNotNullOrEmpty() ? instance.config_file : config_path; if (!Config.Instance.Initialize(config_filename)) { Logger.Error( string.Format("Failed to initialize config. please check config : {0} file", config_path)); return(false); } #region Wallet prefix if (Config.Instance.Net.Type.Equals("mainnet")) { // TODO : Wallet address prefix mainnet } else { // TODO : Wallet address prefix testnet } #endregion #region Local witness if (instance.privatekey.Length > 0) { instance.LocalWitness = new LocalWitness(instance.privatekey.HexToBytes()); if (!string.IsNullOrEmpty(instance.witness_address)) { byte[] address = Wallet.Base58ToAddress(instance.witness_address); if (address.IsNotNullOrEmpty()) { instance.LocalWitness.SetWitnessAccountAddress(address); Logger.Debug("local witness account address from command."); } else { instance.witness_address = ""; Logger.Warning("Local witness account address is incorrect."); } } instance.LocalWitness.InitWitnessAccountAddress(); } else if (Config.Instance.LocalWitness != null && Config.Instance.LocalWitness.LocalWitness != null && Utils.CollectionUtil.IsNotNullOrEmpty(Config.Instance.LocalWitness.LocalWitness)) { instance.LocalWitness = new LocalWitness(); List <byte[]> witness_list = Config.Instance.LocalWitness.LocalWitness; if (witness_list.Count > 1) { Logger.Warning("Local witness count must be one. get the first witness"); witness_list = witness_list.GetRange(0, 1); } instance.LocalWitness.SetPrivateKeys(witness_list); if (Config.Instance.LocalWitness.LocalWitnessAccountAddress.IsNotNullOrEmpty()) { byte[] address = Wallet.Base58ToAddress(Config.Instance.LocalWitness.LocalWitnessAccountAddress); if (address.IsNotNullOrEmpty()) { instance.LocalWitness.SetWitnessAccountAddress(address); Logger.Debug("Local witness account address from \'config.conf\' file."); } else { Logger.Warning("Local witness account address is incorrect."); } } instance.LocalWitness.InitWitnessAccountAddress(); } else if (Config.Instance.LocalWitness != null && Config.Instance.LocalWitness.LocalWitnessKeyStore != null && Utils.CollectionUtil.IsNotNullOrEmpty(Config.Instance.LocalWitness.LocalWitnessKeyStore)) { List <byte[]> privatekeys = new List <byte[]>(); instance.LocalWitness = new LocalWitness(); if (instance.witness) { // TODO : Keystore 로드 CLI와 함께 정리해서 중복제거 if (Config.Instance.LocalWitness.LocalWitnessKeyStore.Count > 0) { string file_path = Config.Instance.LocalWitness.LocalWitnessKeyStore[0]; JObject json; using (var file = File.OpenText(file_path)) { string data = file.ReadToEnd(); json = JObject.Parse(data); } string password = CommandLineUtil.ReadPasswordString("Password: "******"Invalid password." ); } KeyStore keystore = new KeyStore(); keystore = JsonConvert.DeserializeObject <KeyStore>(json.ToString()); if (!KeyStoreService.DecryptKeyStore(password, keystore, out byte[] privatekey))