public void ShouldContain(string name) { var methodInfos = DomainExtensions.Methods(typeof(child)); methodInfos.Any(m => m.Name == name).Should().Be(true); }
public void ShouldNotContain(string name, Type type) { var methodInfos = DomainExtensions.Methods(type); methodInfos.Any(m => m.Name == name).Should().Be(false); }
public override IEnumerable <PendingSwap> Update() { // wait another 10s to execute eth interop //Task.Delay(10000).Wait(); try { lock (String.Intern("PendingSetCurrentHeight_" + EthereumWallet.EthereumPlatform)) { var result = new List <PendingSwap>(); // initial start, we have to verify all processed swaps if (initialStart) { Logger.Debug($"Read all ethereum blocks now."); var allInteropBlocks = OracleReader.ReadAllBlocks(EthereumWallet.EthereumPlatform, EthereumWallet.EthereumPlatform); Logger.Debug($"Found {allInteropBlocks.Count} blocks"); foreach (var block in allInteropBlocks) { ProcessBlock(block, ref result); } initialStart = false; // return after the initial start to be able to process all swaps that happend in the mean time. return(result); } var currentHeight = ethAPI.GetBlockHeight(); var _interopBlockHeight = BigInteger.Parse(OracleReader.GetCurrentHeight(EthereumWallet.EthereumPlatform, EthereumWallet.EthereumPlatform)); Logger.Debug($"Swaps: Current Eth chain height: {currentHeight}, interop: {_interopBlockHeight}, delta: {currentHeight - _interopBlockHeight}"); var blocksProcessedInOneBatch = 0; while (blocksProcessedInOneBatch < 50) { if (_resyncBlockIds.Any()) { for (var i = 0; i < _resyncBlockIds.Count; i++) { var blockId = _resyncBlockIds.ElementAt(i); if (blockId > _interopBlockHeight) { this.Logger.Warning($"EthInterop:Update() resync block {blockId} higher than current interop height, can't resync."); _resyncBlockIds.RemoveAt(i); continue; } try { this.Logger.Debug($"EthInterop:Update() resync block {blockId} now."); var block = GetInteropBlock(blockId); ProcessBlock(block, ref result); } catch (Exception e) { this.Logger.Error($"EthInterop:Update() resync block {blockId} failed: " + e); } _resyncBlockIds.RemoveAt(i); } } blocksProcessedInOneBatch++; var blockDifference = currentHeight - _interopBlockHeight; if (blockDifference < confirmations) { // no need to query the node yet break; } //TODO quick sync not done yet, requieres a change to the oracle impl to fetch multiple blocks //var nextHeight = (blockDifference > 50) ? 50 : blockDifference; //TODO //var transfers = new Dictionary<string, Dictionary<string, List<InteropTransfer>>>(); //if (nextHeight > 1) //{ // var blockCrawler = new EthBlockCrawler(logger, contracts.ToArray(), 0/*confirmations*/, ethAPI); //TODO settings confirmations // blockCrawler.Fetch(currentHeight, nextHeight); // transfers = blockCrawler.ExtractInteropTransfers(logger, LocalAddress); // foreach (var entry in transfers) // { // foreach (var txInteropTransfer in entry.Value) // { // foreach (var interopTransfer in txInteropTransfer.Value) // { // result.Add(new PendingSwap( // this.PlatformName // ,Hash.Parse(entry.Key) // ,interopTransfer.sourceAddress // ,interopTransfer.interopAddress) // ); // } // } // } // _interopBlockHeight = nextHeight; // oracleReader.SetCurrentHeight(EthereumWallet.EthereumPlatform, EthereumWallet.EthereumPlatform, _interopBlockHeight.ToString()); //} //else //{ /* Future improvement, implement oracle call to fetch multiple blocks */ var url = DomainExtensions.GetOracleBlockURL( EthereumWallet.EthereumPlatform, EthereumWallet.EthereumPlatform, PBigInteger.FromUnsignedArray(_interopBlockHeight.ToByteArray(), true)); var interopBlock = OracleReader.Read <InteropBlock>(DateTime.Now, url); ProcessBlock(interopBlock, ref result); _interopBlockHeight++; //} } OracleReader.SetCurrentHeight(EthereumWallet.EthereumPlatform, EthereumWallet.EthereumPlatform, _interopBlockHeight.ToString()); var total = result.Count(); if (total > 0) { Logger.Message($"found {total} ethereum swaps"); } else { Logger.Debug($"did not find any ethereum swaps"); } return(result); } } catch (Exception e) { var logMessage = "EthereumInterop.Update() exception caught:\n" + e.Message; var inner = e.InnerException; while (inner != null) { logMessage += "\n---> " + inner.Message + "\n\n" + inner.StackTrace; inner = inner.InnerException; } logMessage += "\n\n" + e.StackTrace; Logger.Error(logMessage); return(new List <PendingSwap>()); } }