protected override InteropBlock PullPlatformBlock(string platformName, string chainName, Hash hash, NativeBigInt height = new NativeBigInt()) { if (hash == null && height == null) { throw new OracleException($"Fetching block not possible without hash or height"); } InteropBlock block = Read <InteropBlock>(platformName, chainName, hash, StorageConst.Block); if (height == null && block.Hash != null && block.Hash != Hash.Null) { return(block); } Tuple <InteropBlock, InteropTransaction[]> interopTuple; switch (platformName) { case NeoWallet.NeoPlatform: NeoBlock neoBlock; if (height == 0) { neoBlock = _cli.NeoAPI.GetBlock(new UInt256(LuxUtils.ReverseHex(hash.ToString()).HexToBytes())); } else { neoBlock = _cli.NeoAPI.GetBlock(height); } if (neoBlock == null) { throw new OracleException($"Neo block is null"); } var coldStorage = _cli.Settings.Oracle.SwapColdStorageNeo; interopTuple = NeoInterop.MakeInteropBlock(logger, neoBlock, _cli.NeoAPI, _cli.TokenSwapper.SwapAddresses[SwapPlatformChain.Neo], coldStorage); break; case EthereumWallet.EthereumPlatform: { var hashes = _cli.Nexus.GetPlatformTokenHashes(EthereumWallet.EthereumPlatform, _cli.Nexus.RootStorage) .Select(x => x.ToString().Substring(0, 40)).ToArray(); interopTuple = EthereumInterop.MakeInteropBlock(_cli.Nexus, logger, _cli.EthAPI, height, hashes, _cli.Settings.Oracle.EthConfirmations, _cli.TokenSwapper.SwapAddresses[SwapPlatformChain.Ethereum]); break; } case BSCWallet.BSCPlatform: { var hashes = _cli.Nexus.GetPlatformTokenHashes(BSCWallet.BSCPlatform, _cli.Nexus.RootStorage) .Select(x => x.ToString().Substring(0, 40)).ToArray(); interopTuple = BSCInterop.MakeInteropBlock(_cli.Nexus, logger, _cli.BscAPI, height, hashes, _cli.Settings.Oracle.EthConfirmations, _cli.TokenSwapper.SwapAddresses[SwapPlatformChain.BSC]); break; } default: throw new OracleException("Uknown oracle platform: " + platformName); } if (interopTuple.Item1.Hash != Hash.Null) { var initialStore = Persist <InteropBlock>(platformName, chainName, interopTuple.Item1.Hash, StorageConst.Block, interopTuple.Item1); var transactions = interopTuple.Item2; if (!initialStore) { logger.Debug($"Oracle block { interopTuple.Item1.Hash } on platform { platformName } updated!"); } foreach (var tx in transactions) { var txInitialStore = Persist <InteropTransaction>(platformName, chainName, tx.Hash, StorageConst.Transaction, tx); if (!txInitialStore) { logger.Debug($"Oracle block { interopTuple.Item1.Hash } on platform { platformName } updated!"); } } } return(interopTuple.Item1); }
protected override InteropBlock PullPlatformBlock(string platformName, string chainName, Hash hash, NativeBigInt height = new NativeBigInt()) { if (hash == null && height == null) { throw new OracleException($"Fetching block not possible without hash or height"); } InteropBlock block = Read <InteropBlock>(platformName, chainName, hash, StorageConst.Block); if (height == null && block.Hash != null && block.Hash != Hash.Null) { return(block); } Tuple <InteropBlock, InteropTransaction[]> interopTuple; switch (platformName) { case NeoWallet.NeoPlatform: NeoBlock neoBlock; if (height == 0) { neoBlock = _cli.NeoAPI.GetBlock(new UInt256(LuxUtils.ReverseHex(hash.ToString()).HexToBytes())); } else { neoBlock = _cli.NeoAPI.GetBlock(height); } if (neoBlock == null) { throw new OracleException($"Neo block is null"); } interopTuple = NeoInterop.MakeInteropBlock(logger, neoBlock, _cli.NeoAPI, _cli.TokenSwapper.SwapAddresses[platformName]); break; case EthereumWallet.EthereumPlatform: //BlockWithTransactions ethBlock; //if (height == 0) //{ // //TODO MakeInteropBlock for a full block not done yet // //ethBlock = _cli.EthAPI.GetBlock(hash.ToString()); // //interopTuple = EthereumInterop.MakeInteropBlock(logger, ethBlock, _cli.EthAPI, _cli.TokenSwapper.swapAddress); //} //else //{ //} var hashes = _cli.Nexus.GetPlatformTokenHashes(EthereumWallet.EthereumPlatform, _cli.Nexus.RootStorage) .Select(x => x.ToString().Substring(0, 40)).ToArray(); interopTuple = EthereumInterop.MakeInteropBlock(_cli.Nexus, logger, _cli.EthAPI, height, hashes, _cli.Settings.Oracle.EthConfirmations, _cli.TokenSwapper.SwapAddresses[platformName]); break; default: throw new OracleException("Uknown oracle platform: " + platformName); } if (interopTuple.Item1.Hash != Hash.Null) { var persisted = Persist <InteropBlock>(platformName, chainName, interopTuple.Item1.Hash, StorageConst.Block, interopTuple.Item1); if (persisted) { var transactions = interopTuple.Item2; foreach (var tx in transactions) { var txPersisted = Persist <InteropTransaction>(platformName, chainName, tx.Hash, StorageConst.Transaction, tx); } } else { logger.Error($"Persisting oracle block { interopTuple.Item1.Hash } on platform { platformName } failed!"); } } return(interopTuple.Item1); }