Example #1
0
        public static KeyManager FromFile(string filePath)
        {
            filePath = Guard.NotNullOrEmptyOrWhitespace(nameof(filePath), filePath);

            if (!IoHelpers.TryGetSafestFileVersion(filePath, out var safestFile))
            {
                throw new FileNotFoundException($"Wallet file not found at: `{filePath}`.");
            }

            string jsonString = File.ReadAllText(safestFile, Encoding.UTF8);
            var    km         = JsonConvert.DeserializeObject <KeyManager>(jsonString);

            km.SetFilePath(filePath);
            lock (km.HdPubKeyScriptBytesLock)
            {
                km.HdPubKeyScriptBytes.AddRange(km.GetKeys().Select(x => x.GetP2wpkhScript().ToCompressedBytes()));
            }

            lock (km.ScriptHdPubkeyMapLock)
            {
                foreach (var key in km.GetKeys())
                {
                    km.ScriptHdPubkeyMap.Add(key.GetP2wpkhScript(), key);
                }
            }
            return(km);
        }
Example #2
0
        public static KeyManager FromFile(string filePath)
        {
            filePath = Guard.NotNullOrEmptyOrWhitespace(nameof(filePath), filePath);

            if (!IoHelpers.TryGetSafestFileVersion(filePath, out var safestFile))
            {
                throw new FileNotFoundException($"Wallet file not found at: `{filePath}`.");
            }

            string jsonString = File.ReadAllText(safestFile, Encoding.UTF8);
            var    km         = JsonConvert.DeserializeObject <KeyManager>(jsonString);

            km.SetFilePath(filePath);
            return(km);
        }