/// <summary>
        /// instantiation a contract builder with abi json object
        /// </summary>
        /// <param name="abiJson"></param>
        /// <returns></returns>
        public IAbiContractDefinition ContractBuilder(JArray abiJson)
        {
            AbiContractDefinition definition = new AbiContractDefinition();

            JToken constructorJson = Enumerable.Where(abiJson, item => item["type"].ToString() == "constructor").First();

            if (constructorJson != null)
            {
                definition.Constructor = this.ConstructorBuilder(constructorJson);
            }

            IEnumerable <JToken>          functions    = abiJson.Where(item => item["type"].ToString() == "function");
            List <IAbiFunctionDefinition> functionList = new List <IAbiFunctionDefinition>();

            foreach (JToken item in functions)
            {
                functionList.Add(new AbiFunctionBuiler().Builder(item));
            }
            definition.Functions = functionList.ToArray();

            IEnumerable <JToken>       events    = abiJson.Where(item => item["type"].ToString() == "event");
            List <IAbiEventDefinition> eventList = new List <IAbiEventDefinition>();

            foreach (JToken item in events)
            {
                eventList.Add(new AbiEventBuilder().Builder(item));
            }
            definition.Events = eventList.ToArray();

            return(definition);
        }
예제 #2
0
        public void CorrectFunctionCallTest()
        {
            var ehrtTokenContract = new Contract
            {
                Name          = "EHRT Token",
                AbiDefinition = AbiContractDefinition.ContractBuilder(GetEhrtTokenAbi()),
                Address       = "0xf8e1faa0367298b55f57ed17f7a2ff3f5f1d1628"
            };

            var approveCode = ehrtTokenContract.Execute(
                "approve",
                "0xeE25500c0F305cc42BdcB0f95E1d3186874bc19a",
                new EHRT(5000, false).ToHex())
                              .ToHex();

            Assert.Equal("095ea7b3000000000000000000000000ee25500c0f305cc42bdcb0f95e1d3186874bc19a00000000000000000000000000000000000000000000010f0cf064dd59200000", approveCode);
        }