private Hash SettleSwapToExternal(Hash sourceHash, string destPlatform) { var swap = OracleReader.ReadTransaction(DomainSettings.PlatformName, DomainSettings.RootChainName, sourceHash); var transfers = swap.Transfers.Where(x => x.destinationAddress.IsInterop).ToArray(); // TODO not support yet if (transfers.Length != 1) { Logger.Warning($"Not implemented: Swap support for multiple transfers in a single transaction"); return(Hash.Null); } var transfer = transfers[0]; var token = Nexus.GetTokenInfo(Nexus.RootStorage, transfer.Symbol); lock (StateModificationLock) { var destHash = GetSettleHash(DomainSettings.PlatformName, sourceHash); Logger.Debug("settleHash in settleswap: " + destHash); if (destHash != Hash.Null) { return(destHash); } if (!_swappers.ContainsKey(destPlatform)) { return(Hash.Null); // just in case, should never happen } var chainSwapper = _swappers[destPlatform]; destHash = chainSwapper.SettleSwap(sourceHash, transfer.destinationAddress, token, transfer.Value); // if the asset transfer was sucessfull, we prepare a fee settlement on the mainnet if (destHash != Hash.Null) { var pendingList = new StorageList(PendingTag, this.Storage); var settle = new PendingFee() { sourceHash = sourceHash, destinationHash = destHash, settleHash = Hash.Null, time = DateTime.UtcNow, status = SwapStatus.Settle }; pendingList.Add <PendingFee>(settle); } return(destHash); } }
private void ProcessBlock(InteropBlock block, ref List <PendingSwap> result) { foreach (var txHash in block.Transactions) { var interopTx = OracleReader.ReadTransaction(BSCWallet.BSCPlatform, "bsc", txHash); foreach (var interopTransfer in interopTx.Transfers) { result.Add( new PendingSwap( this.PlatformName , txHash , interopTransfer.sourceAddress , interopTransfer.interopAddress) ); } } }
private void ProcessBlock(InteropBlock block, List <PendingSwap> result) { foreach (var txHash in block.Transactions) { var interopTx = OracleReader.ReadTransaction("neo", "neo", txHash); if (interopTx.Transfers.Length == 0) { continue; } if (interopTx.Transfers.Length == 0) { continue; } InteropTransfer transfer; if (interopTx.Transfers.Length != 1) { var sources = interopTx.Transfers.Select(x => x.sourceAddress).Distinct(); if (sources.Count() > 1) { throw new OracleException("neo transfers with multiple source addresses not supported yet"); } var dests = interopTx.Transfers.Select(x => x.destinationAddress).Distinct(); if (dests.Count() > 1) { throw new OracleException("neo transfers with multiple destination addresses not supported yet"); } var interops = interopTx.Transfers.Select(x => x.interopAddress).Distinct(); if (interops.Count() > 1) { throw new OracleException("neo transfers with multiple interop addresses not supported yet"); } var symbols = interopTx.Transfers.Select(x => x.Symbol).Distinct(); if (symbols.Count() > 1) { throw new OracleException("neo transfers with multiple tokens not supported yet"); } PBigInteger sum = 0; foreach (var temp in interopTx.Transfers) { sum += temp.Value; } var first = interopTx.Transfers.First(); if (first.Data != null && first.Data.Length > 0) { throw new OracleException("neo transfers with custom data are not supported yet"); } transfer = new InteropTransfer(first.sourceChain, first.sourceAddress, first.destinationChain, first.destinationAddress, first.interopAddress, first.Symbol, sum); } else { transfer = interopTx.Transfers.First(); } if (transfer.sourceAddress == transfer.destinationAddress) // ignore this tx, this is a utxo consolidation { continue; } result.Add( new PendingSwap( this.PlatformName , txHash , transfer.sourceAddress , transfer.interopAddress) ); } }