Exemplo n.º 1
0
        private bool PerformWithdrawal(int wallet, decimal amount, string des)
        {
            int blockchain = MainService.GetWalletBlockchainType(wallet);

            if (blockchain != 6)
            {
                Transaction tx = MainService.CreateSignedP2PKHTx(wallet, amount, des, true, false);
                //Then add to database
                if (tx != null)
                {
                    //Now write to the transaction log
                    MainService.AddMyTxToDatabase(tx.GetHash().ToString(), MainService.GetWalletAddress(wallet), des, amount, wallet, 2, -1); //Withdrawal
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                //This is Ethereum transaction out
                Nethereum.Signer.TransactionChainId tx = null;
                if (MainService.Wallet.CoinERC20(wallet) == true)
                {
                    //ERC20 tokens only move amounts around at a specific contract, tokens are stored in the contract but allocated to the address
                    string     token_contract = MainService.GetWalletERC20TokenContract(wallet);
                    BigInteger int_amount     = MainService.ConvertToERC20Int(amount, MainService.GetWalletERC20TokenDecimals(wallet));
                    string     transfer_data  = MainService.GenerateEthereumERC20TransferData(des, int_amount);
                    tx = MainService.CreateSignedEthereumTransaction(wallet, token_contract, amount, false, 0, transfer_data);
                }
                else
                {
                    //This function will estimate the gas used if sending to a contract
                    tx = MainService.CreateSignedEthereumTransaction(wallet, des, amount, false, 0, "");
                }
                //Then add to database
                if (tx != null)
                {
                    //Broadcast this transaction, and write to log regardless of whether it returns a hash or not
                    //Now write to the transaction log
                    bool timeout;
                    MainService.TransactionBroadcast(wallet, tx.Signed_Hex, out timeout);
                    if (timeout == false)
                    {
                        MainService.UpdateWalletStatus(wallet, 2);                                                                  //Set to wait
                        MainService.AddMyTxToDatabase(tx.HashID, MainService.GetWalletAddress(wallet), des, amount, wallet, 2, -1); //Withdrawal
                        return(true);
                    }
                    else
                    {
                        MainService.NebliDexNetLog("Transaction broadcast timed out, not connected to internet");
                    }
                }
                return(false);
            }
        }