Example #1
0
        public ContractABI DeserialiseContract(string abi)
        {
            var            convertor   = new ExpandoObjectConverter();
            var            contract    = JsonConvert.DeserializeObject <List <ExpandoObject> >(abi, convertor);
            var            functions   = new List <FunctionABI>();
            var            events      = new List <EventABI>();
            ConstructorABI constructor = null;

            foreach (IDictionary <string, object> element in contract)
            {
                if ((string)element["type"] == "function")
                {
                    functions.Add(BuildFunction(element));
                }
                if ((string)element["type"] == "event")
                {
                    events.Add(BuildEvent(element));
                }
                if ((string)element["type"] == "constructor")
                {
                    constructor = BuildConstructor(element);
                }
            }

            var contractABI = new ContractABI();

            contractABI.Functions   = functions.ToArray();
            contractABI.Constructor = constructor;
            contractABI.Events      = events.ToArray();

            return(contractABI);
        }
Example #2
0
        public ContractABI DeserialiseContract(string abi)
        {
            var convertor = new ExpandoObjectConverter();
            var contract = JsonConvert.DeserializeObject<List<ExpandoObject>>(abi, convertor);
            var functions = new List<FunctionABI>();
            var events = new List<EventABI>();
            ConstructorABI constructor = null;

            foreach (IDictionary<string, object> element in contract)
            {
                if ((string) element["type"] == "function")
                    functions.Add(BuildFunction(element));
                if ((string) element["type"] == "event")
                    events.Add(BuildEvent(element));
                if ((string) element["type"] == "constructor")
                    constructor = BuildConstructor(element);
            }

            var contractABI = new ContractABI();
            contractABI.Functions = functions.ToArray();
            contractABI.Constructor = constructor;
            contractABI.Events = events.ToArray();

            return contractABI;
        }
 public string EventsGen(ContractABI contract)
 {
     var builder = new StringBuilder();
     foreach (var eventAbi in contract.Events)
     {
         builder.AppendLine(EventGet(eventAbi.Name));
     }
     return builder.ToString();
 }
 public string FunctionsGen(ContractABI contract)
 {
     var builder = new StringBuilder();
     foreach (var function in contract.Functions)
     {
         builder.AppendLine(FunctionGen(function));
     }
     return builder.ToString();
 }