Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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;
 }