コード例 #1
0
        private static async void WithdrawListener(Miner miner, CryptoConnector connector, NodeConfig conf)
        {
            var withdrwawalDictionary = new Dictionary <string, Withdrawal>();

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

                if (chain != null)
                {
                    foreach (var wd in chain.CurrentBlock.Withdrawals)
                    {
                        try
                        {
                            if (!withdrwawalDictionary.ContainsKey(wd.HashStr) && !(await repository.Contains(wd.HashStr)))
                            {
                                await ProcessWithdraw(wd);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error("Failed to withdrawal... \n" + e.ToString());
                        }
                    }
                }
            }
        }
コード例 #2
0
        async static Task Main()
        {
            var CryptoConnector = new CryptoConnector();
            var miner           = new Miner(new PeerListener(), new WalletRepository(),
                                            new BlockRepository(), new BalanceRepository(), new BookRepository(),
                                            new DepositRepository(), new OfferRepository(), new TransactionRepository(),
                                            new WithdrawalRepository(), new TradeRepository(),
                                            CryptoConnector);

            await miner.Start(true);

            WithdrawListener(miner, CryptoConnector);

            var master = Environment.GetEnvironmentVariable("MASTER");

            if (master != null)
            {
                if (master.ToUpper() != "TRUE")
                {
                    try
                    {
                        var seednode = new Peer(new TcpClient("masternode", 5556));
                        miner.Connect(seednode);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("No Master Variable");
                var seednode = new Peer(new TcpClient("localhost", 5556));
                miner.Connect(seednode);

                // try
                // {
                //     var seednode = new Peer(new TcpClient("bizanc.io", 443));
                //     await miner.Connect(seednode);
                // }
                // catch (Exception e)
                // {
                //     Console.WriteLine("Failed to connect seed: \n"+e.ToString());
                // }
            }

            await Task.Delay(Timeout.Infinite);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: phur771/Bizanc.io.Core
        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());
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: phur771/Bizanc.io.Core
        async static Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddCommandLine(args);

#if DEBUG
            builder = builder.AddUserSecrets <Program>();
#else
            builder = builder.AddAzureKeyVault("https://testnetvaultbiz.vault.azure.net/");
#endif
            IConfigurationRoot configuration = builder.Build();

            var conf = new NodeConfig();
            configuration.GetSection("Node").Bind(conf);
            repository = new WithdrawInfoRepository();
            var connector = new CryptoConnector(conf.OracleETHAddres, conf.OracleBTCAddres, conf.ETHEndpoint, conf.BTCEndpoint);
            var miner     = new Miner(new PeerListener(conf.ListenPort), new WalletRepository(),
                                      new BlockRepository(), new BalanceRepository(), new BookRepository(),
                                      new DepositRepository(), new OfferRepository(), new TransactionRepository(),
                                      new WithdrawalRepository(), new TradeRepository(), repository,
                                      connector);

            reader = miner.GetChainStream();

            await miner.Start(true);

            WithdrawListener(miner, connector, configuration.GetValue <string>("BTCSECRET"), configuration.GetValue <string>("ETHSECRET"), conf);

            if (!string.IsNullOrEmpty(conf.SeedAddress) && conf.SeedPort > 0)
            {
                try
                {
                    var seednode = new Peer(new TcpClient(conf.SeedAddress, conf.SeedPort));
                    miner.Connect(seednode);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    throw;
                }
            }
            await Task.Delay(Timeout.Infinite);
        }
コード例 #5
0
        private static async void WithdrawListener(Miner miner, CryptoConnector connector)
        {
            var withdrwawalDictionary = new Dictionary <string, Withdrawal>();
            await Task.Run(async() =>
            {
                while (true)
                {
                    var withdrawals = await miner.ListWithdrawals(100);
                    if (withdrawals.Count > 0)
                    {
                        foreach (var wd in withdrawals)
                        {
                            try
                            {
                                if (!withdrwawalDictionary.ContainsKey(wd.HashStr))
                                {
                                    withdrwawalDictionary.Add(wd.HashStr, wd);
                                    if (wd.Asset == "BTC")
                                    {
                                        connector.WithdrawBtc(wd.TargetWallet, wd.Size);
                                    }
                                    else
                                    {
                                        connector.WithdrawEth(wd.TargetWallet, wd.Size, wd.Asset);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Failed to withdrawal... \n" + e.ToString());
                            }
                        }
                    }

                    Thread.Sleep(1000);
                }
            });
        }
コード例 #6
0
        async static Task Main(string[] args)
        {
            Console.WriteLine("Starting Oracle");
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile("pkcscfg.json", optional: false, reloadOnChange: true)
                          .AddCommandLine(args);


            IConfigurationRoot configuration = builder.Build();

            Log.Debug("Building Config");

            var conf = new NodeConfig();

            configuration.GetSection("Node").Bind(conf);
            var pkcsConf = new PKCS();

            configuration.GetSection("PKCS").Bind(pkcsConf);
            Log.Debug("NodeConfig created");

            repository = new WithdrawInfoRepository();
            var wdRepository = new WithdrawalRepository();
            var connector    = new CryptoConnector(conf.OracleETHAddres, conf.OracleBTCAddres, conf.ETHEndpoint, conf.BTCEndpoint, conf.Network);
            var miner        = new Miner(new PeerListener(conf.ListenPort), new WalletRepository(),
                                         new BlockRepository(), new BalanceRepository(), new BookRepository(),
                                         new DepositRepository(), new OfferRepository(), new TransactionRepository(),
                                         wdRepository, new TradeRepository(), repository,
                                         connector, conf.ListenPort, true, 1000, true);

            ethConnector = new EthereumOracleConnector(conf.ETHEndpoint, conf.OracleETHAddres, pkcsConf.User, pkcsConf.EthKey);
            btcConnector = new BitcoinOracleConnector(conf.Network, conf.BTCEndpoint, pkcsConf.User, pkcsConf.BtcKey);

            if (conf.Reprocess)
            {
                Log.Information("Reprocessing withdraws: ");
                foreach (var wdid in await repository.ListToReprocess())
                {
                    Log.Information("Reprocessing withdraw: " + wdid);
                    var wd = await wdRepository.Get(wdid);

                    await ProcessWithdraw(wd);
                }
            }

            reader = miner.GetChainStream();

            await miner.Start(true);

            WithdrawListener(miner, connector, conf);

            if (!string.IsNullOrEmpty(conf.SeedAddress) && conf.SeedPort > 0)
            {
                try
                {
                    var seednode = new Peer(new TcpClient(conf.SeedAddress, conf.SeedPort));
                    miner.Connect(seednode);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    throw;
                }
            }
            await Task.Delay(Timeout.Infinite);
        }
コード例 #7
0
 public void Deposit()
 {
     var con  = new CryptoConnector();
     var test = con.DepositBtc("mzVr7Pk8gjWQBGqkGdcn5MZRS9ToxPWTXj", "n4nbUmxSRkSPDuRMTeuLV24pPQZdhqfjKN", 0.001m);
 }