protected override InteropTransaction PullPlatformTransaction(string platformName, string chainName, Hash hash) { logger.Debug($"{platformName} pull tx: {hash}"); InteropTransaction tx = Read <InteropTransaction>(platformName, chainName, hash, StorageConst.Transaction); if (tx != null && tx.Hash != null) { logger.Debug($"Found tx {hash} in oracle storage"); return(tx); } switch (platformName) { case NeoWallet.NeoPlatform: NeoTx neoTx; UInt256 uHash = new UInt256(LuxUtils.ReverseHex(hash.ToString()).HexToBytes()); neoTx = _cli.NeoAPI.GetTransaction(uHash); var coldStorage = _cli.Settings.Oracle.SwapColdStorageNeo; tx = NeoInterop.MakeInteropTx(logger, neoTx, _cli.NeoAPI, _cli.TokenSwapper.SwapAddresses[SwapPlatformChain.Neo], coldStorage); break; case EthereumWallet.EthereumPlatform: { var txRcpt = _cli.EthAPI.GetTransactionReceipt(hash.ToString()); tx = EthereumInterop.MakeInteropTx(_cli.Nexus, logger, txRcpt, _cli.EthAPI, _cli.TokenSwapper.SwapAddresses[SwapPlatformChain.Ethereum]); break; } case BSCWallet.BSCPlatform: { var txRcpt = _cli.BscAPI.GetTransactionReceipt(hash.ToString()); tx = BSCInterop.MakeInteropTx(_cli.Nexus, logger, txRcpt, _cli.BscAPI, _cli.TokenSwapper.SwapAddresses[SwapPlatformChain.BSC]); break; } default: throw new OracleException("Uknown oracle platform: " + platformName); } if (!Persist <InteropTransaction>(platformName, chainName, tx.Hash, StorageConst.Transaction, tx)) { logger.Error($"Oracle transaction { hash } on platform { platformName } updated!"); } return(tx); }
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); }