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