Beispiel #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;
 }
Beispiel #2
0
 /// <summary>
 /// 使用wifkey或nep2key初始化钱包
 /// AddCode
 /// </summary>
 /// <param name="wifKey"></param>
 /// <param name="nep2key"></param>
 /// <param name="password"></param>
 /// <param name="name"></param>
 public NEP6Wallet(string wifKey, string nep2key, string password, string name = null)
 {
     this.type     = 0;
     this.name     = name;
     this.version  = Version.Parse("1.0");
     this.accounts = new Dictionary <UInt160, NEP6Account>();
     this.Scrypt   = ScryptParameters.Default;
     this.extra    = JObject.Null;
     // 以Wif私钥的方式打开钱包 add code
     if (!string.IsNullOrEmpty(wifKey))
     {
         var account = Import(wifKey, password);
         account.GetKey();
         account.Print();
         WalletIndexer.RegisterAccounts(accounts.Keys);
         WalletIndexer.BalanceChanged += WalletIndexer_BalanceChanged;
     }
     else if (!string.IsNullOrEmpty(nep2key))
     {
         this.password = password;
         //Console.WriteLine($"password: {password}");
         var account = Import(nep2key, password);
         account.GetKey();
         account.Print();
         WalletIndexer.RegisterAccounts(accounts.Keys);
         WalletIndexer.BalanceChanged += WalletIndexer_BalanceChanged;
     }
 }
Beispiel #3
0
        /// <summary>
        /// 使用钱包文件初始化钱包
        ///
        /// Add Code
        /// </summary>
        /// <param name="path">钱包文件路径</param>
        /// <param name="password">密码</param>
        /// <param name="type">账号类型</param>
        public NEP6Wallet(string path, string password, int type = 0)
        {
            this.type = type;
            this.path = path;
            // 钱包文件是否存在
            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);
        }
Beispiel #4
0
        /// <summary>
        /// 使用公钥初始化钱包
        /// Add Code
        /// </summary>
        /// <param name="publicKey"></param>
        /// <param name="address"></param>
        /// <param name="name"></param>
        public NEP6Wallet(string publicKey, string address, string name)
        {
            this.type     = 0;
            this.name     = name;
            this.version  = Version.Parse("1.0");
            this.accounts = new Dictionary <UInt160, NEP6Account>();
            this.Scrypt   = ScryptParameters.Default;
            this.extra    = JObject.Null;
            var accout = ImportFromPublicKey(publicKey);

            //account.GetKey();
            WalletIndexer.RegisterAccounts(accounts.Keys);
            WalletIndexer.BalanceChanged += WalletIndexer_BalanceChanged;
        }
Beispiel #5
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;
 }