예제 #1
0
        public static ContractParametersContext FromJson(JObject json)
        {
            IVerifiable verifiable = typeof(ContractParametersContext).GetTypeInfo().Assembly.CreateInstance(json["type"].AsString()) as IVerifiable;

            if (verifiable == null)
            {
                throw new FormatException();
            }
            using (MemoryStream ms = new MemoryStream(json["hex"].AsString().HexToBytes(), false))
                using (BinaryReader reader = new BinaryReader(ms, Encoding.UTF8))
                {
                    verifiable.DeserializeUnsigned(reader);
                }
            UInt160    chainHash  = UInt160.Parse(json["chainhash"].AsString());
            Blockchain blockchain = Blockchain.GetBlockchain(chainHash);

            if (blockchain == null)
            {
                throw new FormatException();
            }
            ContractParametersContext context = new ContractParametersContext(verifiable, blockchain);

            foreach (var property in json["items"].Properties)
            {
                context.ContextItems.Add(UInt160.Parse(property.Key), ContextItem.FromJson(property.Value));
            }
            return(context);
        }
예제 #2
0
        public static ContractParametersContext FromJson(JObject json)
        {
            var type = typeof(ContractParametersContext).GetTypeInfo().Assembly.GetType(json["type"].AsString());

            if (!typeof(IVerifiable).IsAssignableFrom(type))
            {
                throw new FormatException();
            }

            var verifiable = (IVerifiable)Activator.CreateInstance(type);

            using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(json["hex"].AsString()), false))
                using (BinaryReader reader = new BinaryReader(ms, Encoding.UTF8))
                {
                    verifiable.DeserializeUnsigned(reader);
                }
            ContractParametersContext context = new ContractParametersContext(verifiable);

            foreach (var property in json["items"].Properties)
            {
                context.ContextItems.Add(UInt160.Parse(property.Key), ContextItem.FromJson(property.Value));
            }
            return(context);
        }