void LoadCore(Stream stream) { JObject obj = JObject.Load(new JsonTextReader(new StreamReader(stream)) { DateParseHandling = DateParseHandling.DateTimeOffset }); _Parameters = WalletCreation.FromJson((JObject)obj["Parameters"]); _PathStates = new Dictionary <KeyPath, PathState>(); if (obj.Property("CurrentIndex") != null) //legacy { var idx = (int)(long)obj["CurrentIndex"]; var loadedKeys = (int)(long)obj["LoadedKeys"]; _PathStates.Add(_Parameters.DerivationPath.Derive(0), new PathState() { Next = idx, Loaded = loadedKeys }); _PathStates.Add(_Parameters.DerivationPath.Derive(1), new PathState() { Next = idx, Loaded = loadedKeys }); } var indices = obj["Indices"] as JArray; if (indices != null) { foreach (var indice in indices.OfType <JObject>()) { _PathStates.Add(KeyPath.Parse((string)indice["KeyPath"]), new PathState() { Next = (int)(long)indice["Next"], Loaded = (int)(long)indice["Loaded"] }); } } _KeyPoolSize = (int)(long)obj["KeyPoolSize"]; Created = (DateTimeOffset)obj["Created"]; _ScanLocation = new BlockLocator(); _ScanLocation.FromBytes(Encoders.Hex.DecodeData((string)obj["Location"])); _KnownScripts.Clear(); var knownScripts = (JArray)obj["KnownScripts"]; foreach (var known in knownScripts.OfType <JObject>()) { Script script = Script.FromBytesUnsafe(Encoders.Hex.DecodeData((string)known["ScriptPubKey"])); if (known["KeyPath"] != null) //Legacy data { KeyPath keypath = KeyPath.Parse((string)known["KeyPath"]); _KnownScripts.Add(script, _Parameters.DerivationPath.Derive(keypath)); } if (known["AbsoluteKeyPath"] != null) { KeyPath keypath = KeyPath.Parse((string)known["AbsoluteKeyPath"]); _KnownScripts.Add(script, keypath); } } }
void LoadCore(Stream stream) { JObject obj = JObject.Load(new JsonTextReader(new StreamReader(stream)) { DateParseHandling = DateParseHandling.DateTimeOffset }); _CurrentIndex = (int)(long)obj["CurrentIndex"]; _KeyPoolSize = (int)(long)obj["KeyPoolSize"]; _LoadedKeys = (int)(long)obj["LoadedKeys"]; Created = (DateTimeOffset)obj["Created"]; _ScanLocation = new BlockLocator(); _ScanLocation.FromBytes(Encoders.Hex.DecodeData((string)obj["Location"])); _Parameters = WalletCreation.FromJson((JObject)obj["Parameters"]); _KnownScripts.Clear(); var knownScripts = (JArray)obj["KnownScripts"]; foreach (var known in knownScripts.OfType <JObject>()) { Script script = Script.FromBytesUnsafe(Encoders.Hex.DecodeData((string)known["ScriptPubKey"])); KeyPath keypath = KeyPath.Parse((string)known["KeyPath"]); _KnownScripts.Add(script, keypath); } }