Esempio n. 1
0
 public NEP6Wallet(WalletIndexer indexer, string path, string name = null)
 {
     this.indexer = indexer;
     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"];
         indexer.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;
     }
     indexer.WalletTransaction += WalletIndexer_WalletTransaction;
 }
Esempio n. 2
0
 private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dictionary <UInt160, NEP6Account> accounts, out JObject extra)
 {
     this.name    = wallet["name"]?.AsString();
     this.version = Version.Parse(wallet["version"].AsString());
     scrypt       = ScryptParameters.FromJson(wallet["scrypt"]);
     accounts     = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson(p, this)).ToDictionary(p => p.ScriptHash);
     extra        = wallet["extra"];
 }
Esempio n. 3
0
 private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dictionary <UInt160, NEP6Account> accounts, out JObject extra)
 {
     this.version = Version.Parse(wallet["version"].AsString());
     this.name    = wallet["name"]?.AsString();
     scrypt       = ScryptParameters.FromJson(wallet["scrypt"]);
     accounts     = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson(p, this)).ToDictionary(p => p.ScriptHash);
     extra        = wallet["extra"];
     if (!VerifyPasswordInternal(password))
     {
         throw new InvalidOperationException("Wrong password.");
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Loads or creates a wallet at the specified path.
 /// </summary>
 /// <param name="path">The path of the wallet file.</param>
 /// <param name="settings">The <see cref="ProtocolSettings"/> to be used by the wallet.</param>
 /// <param name="name">The name of the wallet. If the wallet is loaded from an existing file, this parameter is ignored.</param>
 public NEP6Wallet(string path, ProtocolSettings settings, string name = null) : base(path, settings)
 {
     if (File.Exists(path))
     {
         JObject wallet = JObject.Parse(File.ReadAllBytes(path));
         LoadFromJson(wallet, out Scrypt, out accounts, out extra);
     }
     else
     {
         this.name     = name;
         this.version  = Version.Parse("1.0");
         this.Scrypt   = ScryptParameters.Default;
         this.accounts = new Dictionary <UInt160, NEP6Account>();
         this.extra    = JObject.Null;
     }
 }
Esempio n. 5
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);
         }
         LoadFromJson(wallet, out Scrypt, out accounts, out extra);
     }
     else
     {
         this.name     = name;
         this.version  = Version.Parse("1.0");
         this.Scrypt   = ScryptParameters.Default;
         this.accounts = new Dictionary <UInt160, NEP6Account>();
         this.extra    = JObject.Null;
     }
 }