public ContractABI DeserialiseABI(string abi) { var expandoObjectConverter = new ExpandoObjectConverter(); var dictionaryList = JsonConvert.DeserializeObject <List <IDictionary <string, object> > >(abi, expandoObjectConverter); var functionAbiList = new List <FunctionABI>(); var eventAbiList = new List <EventABI>(); var errorAbiList = new List <ErrorABI>(); var constructorAbi = new ConstructorABI(); var contractAbi = new ContractABI(); foreach (IDictionary <string, object> dictionary in dictionaryList) { if ((string)dictionary["type"] == "function") { functionAbiList.Add(this.BuildFunction(dictionary, contractAbi)); } if ((string)dictionary["type"] == "event") { eventAbiList.Add(this.BuildEvent(dictionary, contractAbi)); } if ((string)dictionary["type"] == "error") { errorAbiList.Add(this.BuildError(dictionary, contractAbi)); } if ((string)dictionary["type"] == "constructor") { constructorAbi = this.BuildConstructor(dictionary); } } contractAbi.Functions = functionAbiList.ToArray(); contractAbi.Constructor = constructorAbi; contractAbi.Events = eventAbiList.ToArray(); contractAbi.Errors = errorAbiList.ToArray(); var structs = _structDeserialiser.GetStructsFromAbi(abi); contractAbi.Structs = structs; _structDeserialiser.SetTupleTypeSameAsNameIfRequired(contractAbi); return(contractAbi); }
public ContractABI DeserialiseABI(string abi) { var abiDeserialiser = new ABIDeserialiser(); var baseContractABI = abiDeserialiser.DeserialiseContract(abi); var contractABI = new ContractABI { Constructor = GetConstructor(baseContractABI), Functions = baseContractABI.Functions.Select(f => { return(new FunctionABI(f.Name, f.Constant, f.Serpent) { InputParameters = f.InputParameters.Select(p => new ParameterABI(p.Type, p.Name, p.Order)) .ToArray(), OutputParameters = f.OutputParameters.Select(p => new ParameterABI(p.Type, p.Name, p.Order)) .ToArray() }); }).ToArray(), Events = baseContractABI.Events.Select(e => { return(new EventABI(e.Name) { InputParameters = e.InputParameters.Select(p => new ParameterABI(p.Type, p.Name, p.Order) { Indexed = p.Indexed }) .ToArray() }); }).ToArray() }; var structDeserialiser = new StructABIDeserialiser(); var structs = structDeserialiser.GetStructsFromAbi(abi); contractABI.Structs = structs; structDeserialiser.SetTupleTypeSameAsName(contractABI); return(contractABI); }