public object Get(GetBondLogs 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(); else ft3[0] = AppModelConfig.convertToHex64(request.Info).HexToByteArray(); } // Retrieve the contract info var contract = AppServices.web3.Eth.GetContract(AppModelConfig.BOND.abi, AppServices.GetEcosystemAdr(request.ContractAdr).BondContractAdr); // Create the filter input to extract the requested log entries var filterInput = contract.GetEvent("LogBond").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 BondLogs() { EventLogs = new List<BondEventLog>() }; // 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 BondEventLog(); 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 = (BondState)Convert.ToInt32(res[i].Data.Substring(2 + 1 * 64,64), 16); if (AppModelConfig.isEmptyHash(log.Hash)) log.Info = AppModelConfig.FromHexString(res[i].Topics[3].ToString()); else if ((log.State == BondState.SecuredReferenceBond) || (log.State == BondState.LockedReferenceBond)) log.Info = res[i].Topics[3].ToString().EnsureHexPrefix(); else log.Info = Convert.ToInt64(res[i].Topics[3].ToString(), 16).ToString(); logs.EventLogs.Add(log); } // Return the list of bond logs return logs; }
public object Get(GetBondLogs request) { // Return the requested log file entries return(new BondLogs() { Logs = new LogParser <BondLog>().parseLogs( AppModelConfig.BOND, AppServices.GetEcosystemAdr(request.ContractAdr).BondContractAdr, "LogBond", (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) ) }); }