public virtual GetAddressInfoResponse LoadFromJson(JObject raw, Network network)
        {
            SetSubInfo(this, raw, network);
            IsMine      = raw.Property("ismine").Value.Value <bool>();
            Solvable    = raw.Property("solvable")?.Value.Value <bool>();
            Desc        = raw.Property("desc") == null ? null : new ScanTxoutDescriptor(raw.Property("desc").Value.Value <string>());
            IsWatchOnly = raw.Property("iswatchonly").Value.Value <bool>();
            IsScript    = raw.Property("isscript").Value.Value <bool>();
            IsWitness   = raw.Property("iswitness").Value.Value <bool>();
            Script      = raw.Property("script")?.Value.Value <string>();
            Hex         = raw.Property("hex")?.Value.Value <string>();
            var jEmbedded = raw.Property("embedded");

            if (jEmbedded != null)
            {
                var j = jEmbedded.Value.Value <JObject>();
                var e = new GetAddressInfoScriptInfoResponse();
                SetSubInfo(e, j, network);
                Embedded = e;
            }
            IsCompressed  = raw.Property("iscompressed")?.Value.Value <bool>();
            Label         = raw.Property("label")?.Value.Value <string>();
            IsChange      = raw.Property("ischange")?.Value.Value <bool>();
            Timestamp     = raw.Property("timestamp") == null ? (DateTimeOffset?)null : Utils.UnixTimeToDateTime(raw.Property("timestamp").Value.Value <ulong>());
            HDKeyPath     = raw.Property("hdkeypath") == null ? null : KeyPath.Parse(raw.Property("hdkeypath").Value.Value <string>());
            HDSeedID      = raw.Property("hdseedid") == null ? null : uint160.Parse(raw.Property("hdseedid").Value.Value <string>());
            HDMasterKeyID = raw.Property("hdmasterkeyid") == null ? null : uint160.Parse(raw.Property("hdmasterkeyid").Value.Value <string>());
            var jlabels = raw.Property("labels");

            if (jlabels != null)
            {
                var labelObjects = jlabels.Value.Value <JArray>();
                foreach (var jToken in labelObjects)
                {
                    if (jToken is JObject jObject) // Before Bitcoin Core 0.20.0
                    {
#pragma warning disable CS0618                     // Type or member is obsolete.
                        Labels.Add(jToken.ToObject <Dictionary <string, string> >());
#pragma warning restore CS0618                     // Type or member is obsolete
                    }
                }
            }

            return(this);
        }
Пример #2
0
        public static GetAddressInfoResponse FromJsonResponse(JObject raw, Network network)
        {
            var result = new GetAddressInfoResponse();

            SetSubInfo(result, raw, network);
            result.IsMine      = raw.Property("ismine").Value.Value <bool>();
            result.Solvable    = raw.Property("solvable")?.Value.Value <bool>();
            result.Desc        = raw.Property("desc") == null ? null : new ScanTxoutDescriptor(raw.Property("desc").Value.Value <string>());
            result.IsWatchOnly = raw.Property("iswatchonly").Value.Value <bool>();
            result.IsScript    = raw.Property("isscript").Value.Value <bool>();
            result.IsWitness   = raw.Property("iswitness").Value.Value <bool>();
            result.Script      = raw.Property("script")?.Value.Value <string>();
            result.Hex         = raw.Property("hex")?.Value.Value <string>();
            var jEmbedded = raw.Property("embedded");

            if (jEmbedded != null)
            {
                var j = jEmbedded.Value.Value <JObject>();
                var e = new GetAddressInfoScriptInfoResponse();
                SetSubInfo(e, j, network);
                result.Embedded = e;
            }
            result.IsCompressed  = raw.Property("iscompressed")?.Value.Value <bool>();
            result.Label         = raw.Property("label").Value.Value <string>();
            result.IsChange      = raw.Property("ischange")?.Value.Value <bool>();
            result.Timestamp     = raw.Property("timestamp") == null ? (DateTimeOffset?)null : Utils.UnixTimeToDateTime(raw.Property("timestamp").Value.Value <ulong>());
            result.HDKeyPath     = raw.Property("hdkeypath") == null ? null : KeyPath.Parse(raw.Property("hdkeypath").Value.Value <string>());
            result.HDSeedID      = raw.Property("hdseedid") == null ? null : uint160.Parse(raw.Property("hdseedid").Value.Value <string>());
            result.HDMasterKeyID = raw.Property("hdmasterkeyid") == null ? null : uint160.Parse(raw.Property("hdmasterkeyid").Value.Value <string>());
            var jlabels = raw.Property("labels");

            if (jlabels != null)
            {
                var labelObjects = jlabels.Value.Value <JArray>();
                foreach (var jObj in labelObjects)
                {
                    result.Labels.Add(((JObject)jObj).ToObject <Dictionary <string, string> >());
                }
            }

            return(result);
        }
Пример #3
0
        private static void SetSubInfo(GetAddressInfoScriptInfoResponse target, JObject raw, Network network)
        {
            target.IsWitness    = raw.Property("iswitness").Value.Value <bool>();
            target.IsScript     = raw.Property("isscript").Value.Value <bool>();
            target.Address      = BitcoinAddress.Create(raw.Property("address").Value.Value <string>(), network);
            target.ScriptPubKey = new Script(raw.Property("scriptPubKey").Value.Value <string>());
            target.PubKey       = raw.Property("pubkey") == null ? null : new PubKey(raw.Property("pubkey").Value.Value <string>());
            var pubkeys = raw.Property("pubkeys");

            if (pubkeys != null)
            {
                foreach (var pk in pubkeys.Value.Values <string>())
                {
                    target.PubKeys.Add(new PubKey(pk));
                }
            }
            target.SigsRequired   = raw.Property("sigsrequired")?.Value.Value <uint>();
            target.WitnessVersion = raw.Property("witness_version")?.Value.Value <int>();
            target.WitnessProgram = raw.Property("witness_program")?.Value.Value <string>();
        }