Esempio n. 1
0
        /// <summary>
        /// 使用钱包文件初始化钱包
        /// Add Code
        /// </summary>
        /// <param name="path">钱包文件路径</param>
        /// <param name="password">密码</param>
        /// <param name="type">账号类型</param>
        public NEP6Wallet(string path, string password, int walletType = 0)
        {
            this.WalletType = walletType;
            this.path       = path;
            this.password   = password;
            // 钱包文件是否存在
            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }
            // 打开钱包
            JObject wallet;

            using (StreamReader reader = new StreamReader(path))
            {
                wallet = JObject.Parse(reader);
            }
            //Console.WriteLine($"Wallet Name: {wallet["version"].AsString()}");
            this.name    = wallet["name"]?.AsString();
            this.version = Version.Parse(wallet["version"].AsString());
            this.Scrypt  = ScryptParameters.FromJson(wallet["scrypt"]);
            // 把文件中的账号信息转换成 NEP6Account 并加入到 accounts  键名是  ScriptHash
            this.accounts = ((JArray)wallet["accounts"]).Select(p => NEP6Account.fromJson(p, this)).ToDictionary(p => p.ScriptHash);
            //foreach (UInt160 key in this.accounts.Keys)
            //{
            //    this.accounts[key].GetKey();
            //}
            this.extra = wallet["extra"];
            WalletIndexer.RegisterAccounts(accounts.Keys);
        }
Esempio n. 2
0
 public NEP6Wallet(string path, string name = null)
 {
     this.path = path;
     if (File.Exists(path))
     {
         JObject wallet;
         using (StreamReader reader = new StreamReader(path))
         {
             wallet = JObject.Parse(reader);
         }
         this.name     = wallet["name"]?.AsString();
         this.version  = Version.Parse(wallet["version"].AsString());
         this.Scrypt   = ScryptParameters.FromJson(wallet["scrypt"]);
         this.accounts = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson(p, this)).ToDictionary(p => p.ScriptHash);
         this.extra    = wallet["extra"];
         WalletIndexer.RegisterAccounts(accounts.Keys);
     }
     else
     {
         this.name     = name;
         this.version  = Version.Parse("1.0");
         this.Scrypt   = ScryptParameters.Default;
         this.accounts = new Dictionary <UInt160, NEP6Account>();
         this.extra    = JObject.Null;
     }
     WalletIndexer.BalanceChanged += WalletIndexer_BalanceChanged;
 }
Esempio n. 3
0
 public NEP6Wallet(string path, string name = null)
 {
     this.type = 0;
     // 以文件的形式打开钱包
     this.path = path;
     //Console.WriteLine($"NEP6Wallet Path: {this.path}");
     if (File.Exists(path)) // 通过文件加载钱包
     {
         //Console.WriteLine($"NEP6Wallet Path: {this.path}");
         JObject wallet;
         using (StreamReader reader = new StreamReader(path))
         {
             wallet = JObject.Parse(reader);
         }
         //Console.WriteLine($"Wallet Name: {wallet["version"].AsString()}");
         this.name    = wallet["name"]?.AsString();
         this.version = Version.Parse(wallet["version"].AsString());
         this.Scrypt  = ScryptParameters.FromJson(wallet["scrypt"]);
         // 把文件中的账号信息转换成 NEP6Account 并加入到 accounts  键名是  ScriptHash
         this.accounts = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson(p, this)).ToDictionary(p => p.ScriptHash);
         //foreach (UInt160 key in this.accounts.Keys)
         //{
         //    this.accounts[key].GetKey();
         //}
         this.extra = wallet["extra"];
         WalletIndexer.RegisterAccounts(accounts.Keys);
     }
     else
     {
         this.name     = name;
         this.version  = Version.Parse("1.0");
         this.Scrypt   = ScryptParameters.Default;
         this.accounts = new Dictionary <UInt160, NEP6Account>();
         this.extra    = JObject.Null;
     }
     WalletIndexer.BalanceChanged += WalletIndexer_BalanceChanged;
 }