public object Get(GetPolicyLogs request) { // Return the requested log file entries return(new PolicyLogs() { Logs = new LogParser <PolicyLog>().parseLogs( AppModelConfig.POLICY, AppServices.GetEcosystemAdr(request.ContractAdr).PolicyContractAdr, "LogPolicy", (request.Hash.IsEmpty() == true ? null : new object[] { request.Hash.HexToByteArray() }), (request.Owner.IsEmpty() == true ? null : new object[] { request.Owner }), (request.Info.IsEmpty() == true ? null : new object[1]), request.FromBlock, request.ToBlock, (request.Hash.IsEmpty() == true) && (request.Owner.IsEmpty() == true) && (request.Info.IsEmpty() == true) ) }); }
public object Get(GetPolicyLogs request) { // Retrieve the block parameters (BlockParameter fromBlock, BlockParameter toBlock) = AppServices.getBlockParameterConfiguration(request.FromBlock, request.ToBlock, (request.Hash.IsEmpty() == true) && (request.Owner.IsEmpty() == true) && (request.Info.IsEmpty() == true)); // Create the filter variables for selecting only the requested log entries object[] ft1 = (request.Hash.IsEmpty() == true ? null : new object[] { request.Hash.HexToByteArray() }); object[] ft2 = (request.Owner.IsEmpty() == true ? null : new object[] { request.Owner }); object[] ft3 = (request.Info.IsEmpty() == true ? null : new object[1]); // Adjust the filterinpu for ft3 if a value has been provided if (request.Info.IsEmpty() == false) { if (request.Info.HasHexPrefix() == true) { ft3[0] = request.Info.HexToByteArray(); } else if (uint.TryParse(request.Info, out uint val) == true) { ft3[0] = val.ToString("X64").EnsureHexPrefix().HexToByteArray(); } } // Retrieve the contract info var contract = AppServices.web3.Eth.GetContract(AppModelConfig.POLICY.abi, AppServices.GetEcosystemAdr(request.ContractAdr).PolicyContractAdr); // Create the filter input to extract the requested log entries var filterInput = contract.GetEvent("LogPolicy").CreateFilterInput(filterTopic1: ft1, filterTopic2: ft2, filterTopic3: ft3, fromBlock: fromBlock, toBlock: toBlock); // Extract all the logs as specified by the filter input var res = AppServices.web3.Eth.Filters.GetLogs.SendRequestAsync(filterInput).Result; // Create the return instance var logs = new PolicyLogs() { EventLogs = new List <PolicyEventLog>() }; // Interate through all the returned logs and add them to the logs list for (int i = res.Length - 1; i >= 0; i--) { var log = new PolicyEventLog(); log.BlockNumber = Convert.ToUInt64(res[i].BlockNumber.HexValue, 16); log.Hash = res[i].Topics[1].ToString(); log.Owner = AppModelConfig.getAdrFromString32(res[i].Topics[2].ToString()); log.Timestamp = Convert.ToUInt64(res[i].Data.Substring(2 + 0 * 64, 64), 16); log.State = (PolicyState)Convert.ToInt32(res[i].Data.Substring(2 + 1 * 64, 64), 16); if (AppModelConfig.isEmptyHash(res[i].Topics[3].ToString()) == true) { log.Info = ""; } else if (res[i].Topics[3].ToString().StartsWith("0x000000") == true) { log.Info = Convert.ToInt64(res[i].Topics[3].ToString(), 16).ToString(); } else { log.Info = res[i].Topics[3].ToString(); } logs.EventLogs.Add(log); } // Return the list of Policy logs return(logs); }