Beispiel #1
0
        private static async Task <bool> ProcessWithdraw(Withdrawal wd)
        {
            WithdrawInfo result = new WithdrawInfo();

            if (await repository.Contains(wd.HashStr))
            {
                result = await repository.Get(wd.HashStr);
            }
            else
            {
                result.Asset     = wd.Asset;
                result.HashStr   = wd.HashStr;
                result.Timestamp = DateTime.Now;
                await repository.Save(result);
            }

            if (wd.Asset == "BTC")
            {
                result.TxHash = await btcConnector.WithdrawBtc(wd.HashStr, wd.TargetWallet, wd.Size);
            }
            else
            {
                await ethConnector.WithdrawEth(wd.HashStr, wd.TargetWallet, wd.Size, wd.Asset);
            }

            result.Status = WithdrawStatus.Sent;

            withdrwawalDictionary.Add(wd.HashStr, wd);
            await repository.Save(result);

            return(true);
        }
Beispiel #2
0
        private static async void WithdrawListener(Miner miner, CryptoConnector connector, string btcSecret, string ethSecret, NodeConfig conf)
        {
            var withdrwawalDictionary = new Dictionary <string, Withdrawal>();
            var ethConnector          = new EthereumOracleConnector(ethSecret, conf.ETHEndpoint, conf.OracleETHAddres);
            var btcConnector          = new BitcoinOracleConnector(conf.Network, conf.BTCEndpoint, btcSecret);

            while (await reader.WaitToReadAsync())
            {
                var chain = await reader.ReadAsync();

                chain = chain.Get(5);
                if (chain != null)
                {
                    foreach (var wd in chain.CurrentBlock.Withdrawals)
                    {
                        try
                        {
                            if (!withdrwawalDictionary.ContainsKey(wd.HashStr) && !(await repository.Contains(wd.HashStr)))
                            {
                                WithdrawInfo result = null;

                                if (wd.Asset == "BTC")
                                {
                                    result = await btcConnector.WithdrawBtc(wd.HashStr, wd.TargetWallet, wd.Size);
                                }
                                else
                                {
                                    result = await ethConnector.WithdrawEth(wd.HashStr, wd.TargetWallet, wd.Size, wd.Asset);
                                }

                                if (result != null)
                                {
                                    withdrwawalDictionary.Add(wd.HashStr, wd);
                                    result.HashStr = wd.HashStr;
                                    await repository.Save(result);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error("Failed to withdrawal... \n" + e.ToString());
                        }
                    }
                }
            }
        }