Example #1
0
        // NOTE no locks happen here because this callback is called from within a lock
        internal override Hash SettleSwap(Hash sourceHash, Address destination, IToken token, Numerics.BigInteger amount)
        {
            // check if tx was sent but not minded yet
            string tx = null;

            var inProgressMap = new StorageMap(TokenSwapper.InProgressTag, Swapper.Storage);

            if (inProgressMap.ContainsKey <Hash>(sourceHash))
            {
                tx = inProgressMap.Get <Hash, string>(sourceHash);

                if (!string.IsNullOrEmpty(tx))
                {
                    return(VerifyBscTx(sourceHash, tx));
                }
            }

            var total = Numerics.UnitConversion.ToDecimal(amount, token.Decimals);

            var bscKeys = EthereumKey.FromWIF(this.WIF);

            var destAddress = BSCWallet.DecodeAddress(destination);

            try
            {
                Logger.Debug($"BSCSWAP: Trying transfer of {total} {token.Symbol} from {bscKeys.Address} to {destAddress}");
                var transferResult = ethAPI.TryTransferAsset(BSCWallet.BSCPlatform, token.Symbol, destAddress, total, token.Decimals, out tx);

                if (transferResult == EthTransferResult.Success)
                {
                    // persist resulting tx hash as in progress
                    inProgressMap.Set <Hash, string>(sourceHash, tx);
                    Logger.Debug("broadcasted eth tx: " + tx);
                }
                else
                {
                    Logger.Error($"BSCSWAP: Transfer of {total} {token.Symbol} from {bscKeys.Address} to {destAddress} failed, no tx generated");
                }
            }
            catch (Exception e)
            {
                Logger.Error($"Exception during transfer: {e}");
                // we don't know if the transfer happend or not, therefore can't delete from inProgressMap yet.
                return(Hash.Null);
            }

            return(VerifyBscTx(sourceHash, tx));
        }
Example #2
0
        // NOTE no locks happen here because this callback is called from within a lock
        internal override Hash SettleSwap(Hash sourceHash, Address destination, IToken token, Numerics.BigInteger amount)
        {
            Hash   txHash = Hash.Null;
            string txStr  = null;

            var inProgressMap = new StorageMap(TokenSwapper.InProgressTag, Swapper.Storage);
            var rpcMap        = new StorageMap(TokenSwapper.UsedRpcTag, Swapper.Storage);

            if (inProgressMap.ContainsKey <Hash>(sourceHash))
            {
                txStr = inProgressMap.Get <Hash, string>(sourceHash);

                if (!string.IsNullOrEmpty(txStr))
                {
                    return(VerifyNeoTx(sourceHash, txStr));
                }
            }

            var total = Numerics.UnitConversion.ToDecimal(amount, token.Decimals);

            var neoKeys = NeoKeys.FromWIF(this.WIF);

            var destAddress = NeoWallet.DecodeAddress(destination);

            Logger.Debug($"NEOSWAP: Trying transfer of {total} {token.Symbol} from {neoKeys.Address} to {destAddress}");

            var nonce = sourceHash.ToByteArray();

            Neo.Core.Transaction tx = null;
            string usedRpc          = null;

            try
            {
                if (token.Symbol == "NEO" || token.Symbol == "GAS")
                {
                    tx = neoAPI.SendAsset(neoKeys, destAddress, token.Symbol, total, out usedRpc);
                }
                else
                {
                    var nep5 = neoAPI.GetToken(token.Symbol);
                    tx = nep5.Transfer(neoKeys, destAddress, total, nonce, x => usedRpc = x);
                }

                // persist resulting tx hash as in progress
                inProgressMap.Set <Hash, string>(sourceHash, tx.Hash.ToString());
                rpcMap.Set <Hash, string>(sourceHash, usedRpc);

                Logger.Debug("broadcasted neo tx: " + tx);
            }
            catch (Exception e)
            {
                Logger.Error("Error during transfering {token.Symbol}: " + e);
                return(Hash.Null);
            }

            if (tx == null)
            {
                Logger.Error($"NeoAPI error {neoAPI.LastError} or possible failed neo swap sourceHash: {sourceHash} no transfer happend.");
                return(Hash.Null);
            }

            var strHash = tx.Hash.ToString();

            return(VerifyNeoTx(sourceHash, strHash));
        }
Example #3
0
 protected override InteropNFT PullPlatformNFT(string platformName, string symbol, Numerics.BigInteger tokenID)
 {
     throw new NotImplementedException();
 }