Beispiel #1
0
        private bool OnUpgradeWalletCommand(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("error");
                return(true);
            }
            string path = args[2];

            if (Path.GetExtension(path) != ".db3")
            {
                Console.WriteLine("Can't upgrade the wallet file.");
                return(true);
            }
            if (!File.Exists(path))
            {
                Console.WriteLine("File does not exist.");
                return(true);
            }
            string password = ReadPassword("password");

            if (password.Length == 0)
            {
                Console.WriteLine("cancelled");
                return(true);
            }
            string path_new = Path.ChangeExtension(path, ".json");

            BRC6Wallet.Migrate(GetIndexer(), path_new, path, password).Save();
            Console.WriteLine($"Wallet file upgrade complete. New wallet file has been auto-saved at: {path_new}");
            return(true);
        }
Beispiel #2
0
 private Wallet OpenWallet(WalletIndexer indexer, string path, string password)
 {
     if (Path.GetExtension(path) == ".db3")
     {
         return(UserWallet.Open(indexer, path, password));
     }
     else
     {
         BRC6Wallet brc6wallet = new BRC6Wallet(indexer, path);
         brc6wallet.Unlock(password);
         return(brc6wallet);
     }
 }
Beispiel #3
0
        private bool OnCreateWalletCommand(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("error");
                return(true);
            }
            string path     = args[2];
            string password = ReadPassword("password");

            if (password.Length == 0)
            {
                Console.WriteLine("cancelled");
                return(true);
            }
            string password2 = ReadPassword("password");

            if (password != password2)
            {
                Console.WriteLine("error");
                return(true);
            }
            switch (Path.GetExtension(path))
            {
            case ".db3":
            {
                Program.Wallet = UserWallet.Create(GetIndexer(), path, password);
                WalletAccount account = Program.Wallet.CreateAccount();
                Console.WriteLine($"address: {account.Address}");
                Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}");
            }
            break;

            case ".json":
            {
                BRC6Wallet wallet = new BRC6Wallet(GetIndexer(), path);
                wallet.Unlock(password);
                WalletAccount account = wallet.CreateAccount();
                wallet.Save();
                Program.Wallet = wallet;
                Console.WriteLine($"address: {account.Address}");
                Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}");
            }
            break;

            default:
                Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
                break;
            }
            return(true);
        }
Beispiel #4
0
 private void 创建钱包数据库NToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (CreateWalletDialog dialog = new CreateWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         BRC6Wallet wallet = new BRC6Wallet(GetIndexer(), dialog.WalletPath);
         wallet.Unlock(dialog.Password);
         wallet.CreateAccount();
         wallet.Save();
         ChangeWallet(wallet);
         Settings.Default.LastWalletPath = dialog.WalletPath;
         Settings.Default.Save();
     }
 }
        /// <summary>
        /// create wallets
        /// </summary>
        /// <param name="num"></param>
        private void CreateWallets(int num)
        {
            List <WalletSnapshot> wss = new List <WalletSnapshot>();

            for (int i = 0; i < num; i++)
            {
                string walletName = $"wallet{i}.json";
                string spath      = Path.Combine(path, walletName);
                if (File.Exists(spath))
                {
                    continue;
                }
                BRC6Wallet wallet = new BRC6Wallet(GetIndexer(), spath);
                wallet.Unlock(password);
                wallet.CreateAccount();
                wallet.Save();
                WalletSnapshot ws = new WalletSnapshot();
                ws.walletName = walletName;
                ws.address    = wallet.GetAccounts().ToArray()[0].Address;
                ws.priKey     = wallet.GetAccount(ws.address.ToScriptHash()).GetKey().PrivateKey.ToHexString();
                ws.pubKey     = wallet.GetAccount(ws.address.ToScriptHash()).GetKey().PublicKey.ToString();
                ws.script     = wallet.GetAccounts().ToArray()[0].Contract.ScriptHash.ToString();
                wss.Add(ws);
                this.Invoke(new Action(() =>
                {
                    listBox1.Items.Add($"{i} : {spath}");
                }));
            }
            JObject json = new JObject();

            json = new JArray(wss.Select(p =>
            {
                JObject jobj       = new JObject();
                jobj["walletName"] = p.walletName;
                jobj["address"]    = p.address;
                jobj["privKye"]    = p.priKey;
                jobj["pubKye"]     = p.pubKey;
                jobj["script"]     = p.script;
                return(jobj);
            }));
            File.WriteAllLines(Path.Combine(path, "walletsnapshot.txt"), new string[] { json.ToString() });
        }
Beispiel #6
0
        static void Mining(BhpSystem system)
        {
            Fixed8 amount_netfee   = Fixed8.Zero;
            Fixed8 transaction_fee = Fixed8.Zero;

            ulong nonce = 100156895;

            BRC6Wallet wallet = new BRC6Wallet(new Bhp.Wallets.WalletIndexer(@"walletindex"), @"D:\BHP\Test\t1.json");

            wallet.Unlock("1");
            wallet.WalletTransaction += Wallet_WalletTransaction;

            MiningTransaction miningTransaction = new MiningTransaction();
            MinerTransaction  tx = miningTransaction.MakeMinerTransaction(wallet, 1000, nonce, Fixed8.Zero, Fixed8.Zero);

            Console.WriteLine(tx.ToJson());

            Console.WriteLine("\n Staring Sign......");
            ContractParametersContext context = new ContractParametersContext(tx);

            wallet.Sign(context);
            if (context.Completed)
            {
                Console.WriteLine("\n Sign successfully.");
                context.Verifiable.Witnesses = context.GetWitnesses();
                string hexString = GetTxHashData(context.Verifiable).ToHexString();
                Console.WriteLine($"\n {hexString}");
                system.LocalNode.Tell(new LocalNode.Relay {
                    Inventory = tx
                });

                RelayResultReason reason = system.Blockchain.Ask <RelayResultReason>(tx).Result;
                Console.WriteLine("\n relay tx: " + reason);
            }

            Console.ReadLine();
        }
Beispiel #7
0
 private void 打开钱包数据库OToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenWalletDialog dialog = new OpenWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         string path = dialog.WalletPath;
         Wallet wallet;
         if (Path.GetExtension(path) == ".db3")
         {
             if (MessageBox.Show(Strings.MigrateWalletMessage, Strings.MigrateWalletCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
             {
                 string path_old = path;
                 path = Path.ChangeExtension(path_old, ".json");
                 BRC6Wallet BRC6Wallet;
                 try
                 {
                     BRC6Wallet = BRC6Wallet.Migrate(GetIndexer(), path, path_old, dialog.Password);
                 }
                 catch (CryptographicException)
                 {
                     MessageBox.Show(Strings.PasswordIncorrect);
                     return;
                 }
                 BRC6Wallet.Save();
                 BRC6Wallet.Unlock(dialog.Password);
                 wallet = BRC6Wallet;
                 MessageBox.Show($"{Strings.MigrateWalletSucceedMessage}\n{path}");
             }
             else
             {
                 try
                 {
                     wallet = UserWallet.Open(GetIndexer(), path, dialog.Password);
                 }
                 catch (CryptographicException)
                 {
                     MessageBox.Show(Strings.PasswordIncorrect);
                     return;
                 }
             }
         }
         else
         {
             BRC6Wallet BRC6Wallet = new BRC6Wallet(GetIndexer(), path);
             try
             {
                 BRC6Wallet.Unlock(dialog.Password);
             }
             catch (CryptographicException)
             {
                 MessageBox.Show(Strings.PasswordIncorrect);
                 return;
             }
             wallet = BRC6Wallet;
         }
         ChangeWallet(wallet);
         Settings.Default.LastWalletPath = path;
         Settings.Default.Save();
     }
 }