コード例 #1
0
ファイル: Program.cs プロジェクト: dongnhdongnh/pay_core
        private static void RunSend(RepositoryConfiguration repositoryConfig)
        {
            var repoFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig);

            var ethereumBusiness = new EthereumBusiness.EthereumBusiness(repoFactory);
            var connection       = repoFactory.GetDbConnection();

            try
            {
                while (true)
                {
                    Console.WriteLine("Start Send Ethereum....");

                    var rpc = new EthereumRpc(AppSettingHelper.GetEthereumNode());

                    using (var ethereumRepo = repoFactory.GetEthereumWithdrawTransactionRepository(connection))
                    {
                        var resultSend = ethereumBusiness.SendTransactionAsync(ethereumRepo, rpc);
                        Console.WriteLine(JsonHelper.SerializeObject(resultSend.Result));


                        Console.WriteLine("Send Ethereum End...");
                        Thread.Sleep(1000);
                    }
                }
            }
            catch (Exception e)
            {
                connection.Close();
                Console.WriteLine(e.ToString());
            }
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            try
            {
                CacheHelper.DeleteCacheString("cache");

                var repositoryConfig = new RepositoryConfiguration
                {
                    ConnectionString = AppSettingHelper.GetDbConnection()
                };
                string rootAddress  = "0x15118dB6ED8Fa2f461d62F395DC55C51c42f3488";
                string rootPassword = "******";
                EthereumRpc.SetAdminAddressPassword(rootAddress, rootPassword);


                for (var i = 0; i < 1; i++)
                {
                    var ts = new Thread(() => RunSend(repositoryConfig));
                    ts.Start();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: dongnhdongnh/pay_core
        private static void RunScan(RepositoryConfiguration repositoryConfig)
        {
            var repoFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig);

            var ethereumBusiness = new EthereumBusiness.EthereumBusiness(repoFactory);
            var walletBusiness   = new WalletBusiness.WalletBusiness(repoFactory);
            var connection       = repoFactory.GetOldConnection() ?? repoFactory.GetDbConnection();

            try
            {
                while (true)
                {
                    Console.WriteLine("==========Start Scan Ethereum==========");

                    var rpc = new EthereumRpc(AppSettingHelper.GetEthereumNode());

                    using (var ethereumRepo = repoFactory.GetEthereumWithdrawTransactionRepository(connection))
                    {
                        using (var ethereumDepoRepo = repoFactory.GetEthereumDepositeTransactionRepository(connection))
                        {
                            var resultSend =
                                ethereumBusiness
                                .ScanBlockAsync <EthereumWithdrawTransaction, EthereumDepositTransaction,
                                                 EthereumBlockResponse, EthereumTransactionResponse>(CryptoCurrency.ETH, walletBusiness,
                                                                                                     ethereumRepo, ethereumDepoRepo, rpc);
                            Console.WriteLine(JsonHelper.SerializeObject(resultSend.Result));


                            Console.WriteLine("==========Scan Ethereum End==========");
                            Console.WriteLine("==========Wait for next scan==========");
                            Thread.Sleep(5000);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                connection.Close();
                Console.WriteLine(e.ToString());
            }
        }
コード例 #4
0
        public ClientExampleTest(ITestOutputHelper testOutputHelper)
        {
            var    all            = Environment.GetEnvironmentVariables();
            string whisperRpcUrl  = "http://144.76.25.187:8025";                                     //Environment.GetEnvironmentVariable( "WHISPER_RPC_URL");
            string ethereumRpcUrl = "https://ropsten.infura.io/v3/fb49e892176d413d85f993d0352a0971"; //Environment.GetEnvironmentVariable("ETHEREUM_RPC_URL");

            this._fakeEnsProvider  = new FakeEnsProvider();
            this._testOutputHelper = testOutputHelper;
            this._signService      = new WhisperSignService();
            this._whisperRpc       = new WhisperRpc(new Web3(whisperRpcUrl), new WhisperMessageFormatter());

            var ethRpc = new EthereumRpc(new Web3(ethereumRpcUrl));

            NodeClient = new NodeClient()
            {
                EthereumRpc     = ethRpc,
                WhisperRpc      = _whisperRpc,
                TransportClient = new TransportClient(_whisperRpc, _signService, new WhisperMessageFormatter())
            };
            Settings = new VaspTestSettings()
            {
                PersonHandshakePrivateKeyHex      = "0xe7578145d518e5272d660ccfdeceedf2d55b90867f2b7a6e54dc726662aebac2",
                PersonSignaturePrivateKeyHex      = "0x790a3437381e0ca44a71123d56dc64a6209542ddd58e5a56ecdb13134e86f7c6",
                VaspSmartContractAddressPerson    = "0x6befaf0656b953b188a0ee3bf3db03d07dface61",
                VaspSmartContractAddressJuridical = "0x08FDa931D64b17c3aCFfb35C1B3902e0BBB4eE5C",
                JuridicalSignaturePrivateKeyHex   = "0x6854a4e4f8945d9fa215646a820fe9a866b5635ffc7cfdac29711541f7b913f9",
                JuridicalHandshakePrivateKeyHex   = "0x502eb0b1a40d5b788b2395394bc6ae47adae61e9f0a9584c4700132914a8ed04",
                PlaceOfBirth     = new PlaceOfBirth(DateTime.UtcNow, "Town X", Country.List["DE"]),
                NaturalPersonIds = new NaturalPersonId[]
                {
                    new NaturalPersonId("ID", NaturalIdentificationType.PassportNumber, Country.List["DE"]),
                },
                JuridicalIds = new JuridicalPersonId[]
                {
                    new JuridicalPersonId("ID", JuridicalIdentificationType.BankPartyIdentification, Country.List["DE"]),
                },
            };
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: dongnhdongnh/pay_core
        private static void Main(string[] args)
        {
            try
            {
                CacheHelper.DeleteCacheString("cache");

                var repositoryConfig = new RepositoryConfiguration
                {
                    ConnectionString = AppSettingHelper.GetDbConnection()
                };
                string rootAddress  = "0x12890d2cce102216644c59dae5baed380d84830c";
                string rootPassword = "******";
                EthereumRpc.SetAdminAddressPassword(rootAddress, rootPassword);
                for (var i = 0; i < 10; i++)
                {
                    var ts = new Thread(() => RunSend(repositoryConfig));
                    ts.Start();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #6
0
        private static void RunScan(RepositoryConfiguration repositoryConfig)
        {
            var repoFactory = new SmartContractRepositoryMysqlPersistenceFactory(repositoryConfig);

            var ethereumBusiness = new EthereumBusiness.EthereumBusiness(repoFactory);
            var rpc = new EthereumRpc(AppSettingHelper.GetEthereumNode());

            rpc.GetBlockNumber();
            var result = rpc.GetBlockNumber();

            if (result.Status == Status.STATUS_ERROR)
            {
                throw new Exception("Cant GetBlockNumber");
            }
            int blockNumber = 0;

            if (!int.TryParse(result.Data, out blockNumber))
            {
                throw new Exception("Cant parse block number");
            }
            CacheHelper.SetCacheString(String.Format(RedisCacheKey.KEY_SCANBLOCK_LASTSCANBLOCK,
                                                     CryptoCurrency.ETH), blockNumber.ToString());
            //      var walletBusiness = new WalletBusiness.WalletBusiness(repoFactory);
            var connection = repoFactory.GetOldConnection() ?? repoFactory.GetDbConnection();

            try
            {
                while (true)
                {
                    Console.WriteLine("==========Start Scan Ethereum==========");



                    // var rpc = new EthereumRpc(AppSettingHelper.GetEthereumNode());
                    //  var _re = rpc.FindTransactionByHash("0xe62ea756f9dbb5eb2439ea946eab1a3413c5517ebe6eecfb6d067a5d849fcf1f");
                    // foreach(var tran in _re.)
                    //var _input = rpc.DecodeInput("0xa9059cbb0000000000000000000000003a2e25cfb83d633c184f6e4de1066552c5bf45170000000000000000000000000000000000000000000000008ac7230489e80000");
                    using (var ethereumRepo = repoFactory.GetEthereumWithdrawTransactionRepository(connection))
                    {
                        using (var ethereumDepoRepo = repoFactory.GetEthereumDepositeTransactionRepository(connection))
                        {
                            var resultSend =
                                ethereumBusiness
                                .ScanBlockAsync <models.Entities.ETH.EthereumTransaction.EthereumWithdrawTransaction, models.Entities.ETH.EthereumTransaction.EthereumDepositTransaction,
                                                 models.Entities.ETH.EthereumBlockResponse, EthereumTransactionResponse>(CryptoCurrency.ETH,
                                                                                                                         ethereumRepo, ethereumDepoRepo, rpc);
                            Console.WriteLine(JsonHelper.SerializeObject(resultSend.Result));


                            Console.WriteLine("==========Scan Ethereum End==========");
                            Console.WriteLine("==========Wait for next scan==========");
                            Thread.Sleep(50000);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                connection.Close();
                Console.WriteLine(e.ToString());
            }
        }
コード例 #7
0
        /// <summary>
        /// Created Address with optimistic lock
        /// </summary>
        /// <param name="rpcClass"></param>
        /// <param name="walletId"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        public async Task <ReturnObject> CreateAddressAsync()
        {
            try
            {
                using (var dbConnection = _smartcontractRepositoryFactory.GetDbConnection())
                {
                    if (dbConnection.State != ConnectionState.Open)
                    {
                        dbConnection.Open();
                    }

                    var userRepository = _smartcontractRepositoryFactory.GetUserRepository(dbConnection);
                    var userPendding   = userRepository.FindUserAddressNull();


                    if (userPendding?.mem_id == null)
                    {
                        return new ReturnObject
                               {
                                   Status  = Status.STATUS_ERROR,
                                   Message = "User Not Found"
                               }
                    }
                    ;


                    //begin first email
                    var transctionScope = dbConnection.BeginTransaction();
                    try
                    {
                        var lockResult = await userRepository.LockForProcessUser(userPendding);

                        if (lockResult.Status == Status.STATUS_ERROR)
                        {
                            transctionScope.Rollback();
                            return(new ReturnObject
                            {
                                Status = Status.STATUS_SUCCESS,
                                Message = "Cannot Lock For Process"
                            });
                        }

                        transctionScope.Commit();
                    }
                    catch (Exception e)
                    {
                        transctionScope.Rollback();
                        return(new ReturnObject
                        {
                            Status = Status.STATUS_ERROR,
                            Message = e.ToString()
                        });
                    }

                    //update Version to Model
                    userPendding.Version += 1;

                    var transactionSend = dbConnection.BeginTransaction();
                    try
                    {
                        var ethRpc           = new EthereumRpc(AppSettingHelper.GetEthereumNode());
                        var pass             = CommonHelper.RandomString(15);
                        var ethereumBusiness =
                            new EthereumBusiness.EthereumBusiness(_smartcontractRepositoryFactory);
                        var resultEthereum = ethereumBusiness.CreateAddress(ethRpc, userPendding.mem_id, pass);
                        if (resultEthereum.Status == Status.STATUS_ERROR)
                        {
                            transactionSend.Rollback();

                            return(new ReturnObject
                            {
                                Status = Status.STATUS_ERROR,
                                Message = "Cannot create add bitcoin"
                            });
                        }

                        var address = resultEthereum.Data;

                        if (string.IsNullOrEmpty(address))
                        {
                            transactionSend.Rollback();

                            return(new ReturnObject
                            {
                                Status = Status.STATUS_ERROR,
                                Message = "Cannot create address"
                            });
                        }

                        userPendding.IsProcessing = 0;
                        userPendding.mem_address  = address;
                        userPendding.Status       = Status.STATUS_COMPLETED;

                        var updateResult = userRepository.UpdateUser(userPendding);
                        if (updateResult.Status == Status.STATUS_ERROR)
                        {
                            transactionSend.Rollback();

                            return(new ReturnObject
                            {
                                Status = Status.STATUS_ERROR,
                                Message = "Cannot update wallet status"
                            });
                        }

                        transactionSend.Commit();
                        return(new ReturnObject
                        {
                            Status = Status.STATUS_SUCCESS,
                            Message = "Create success"
                        });
                    }
                    catch (Exception e)
                    {
                        // release lock
                        transactionSend.Rollback();
                        var releaseResult = await userRepository.ReleaseLock(userPendding);

                        Console.WriteLine(JsonHelper.SerializeObject(releaseResult));
                        throw;
                    }
                }
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
コード例 #8
0
 public void Setup()
 {
     _etheRpc = new EthereumRpc("http://localhost:9900");
 }
コード例 #9
0
 public void SetUp()
 {
     this._rpc = new EthereumRpc();
 }
コード例 #10
0
        protected override void Load(ContainerBuilder builder)
        {
            var ethereumRpc            = new EthereumRpc(new Web3(_appSettings.EthereumRpcUri));
            var vaspInformationBuilder = new VaspInformationBuilder(ethereumRpc);

            VaspInformation vaspInfo;
            VaspCode        vaspCode;

            if (_appSettings.VaspBic != null)
            {
                (vaspInfo, vaspCode) = vaspInformationBuilder
                                       .CreateForBankAsync(_appSettings.VaspSmartContractAddress, _appSettings.VaspBic)
                                       .GetAwaiter()
                                       .GetResult();
            }
            else if (_appSettings.VaspJuridicalIds != null)
            {
                (vaspInfo, vaspCode) = vaspInformationBuilder
                                       .CreateForJuridicalPersonAsync(_appSettings.VaspSmartContractAddress, _appSettings.VaspJuridicalIds)
                                       .GetAwaiter()
                                       .GetResult();
            }
            else if (_appSettings.VaspNaturalIds != null)
            {
                (vaspInfo, vaspCode) = vaspInformationBuilder
                                       .CreateForNaturalPersonAsync(_appSettings.VaspSmartContractAddress, _appSettings.VaspNaturalIds, _appSettings.VaspPlaceOfBirth)
                                       .GetAwaiter()
                                       .GetResult();
            }
            else
            {
                throw new ArgumentException("Invalid configuration.");
            }

            builder.RegisterInstance(vaspInfo);
            builder.RegisterInstance(vaspCode);
            builder.RegisterInstance(ethereumRpc)
            .As <IEthereumRpc>()
            .SingleInstance();
            builder.RegisterType <WhisperMessageFormatter>()
            .As <IMessageFormatter>()
            .SingleInstance();
            builder.RegisterType <WhisperRpc>()
            .As <IWhisperRpc>()
            .SingleInstance()
            .WithParameter(TypedParameter.From((IWeb3) new Web3(_appSettings.WhisperRpcUri)));
            builder.RegisterType <EnsProvider>()
            .As <IEnsProvider>()
            .SingleInstance();
            builder.RegisterType <WhisperSignService>()
            .As <ISignService>()
            .SingleInstance();
            builder.RegisterType <WhisperTransportClient>()
            .As <ITransportClient>()
            .SingleInstance();
            builder.RegisterType <TransactionDataService>()
            .As <ITransactionDataService>()
            .SingleInstance();

            builder.RegisterType <TransactionsManager>()
            .SingleInstance()
            .As <ITransactionsManager>()
            .AutoActivate()
            .WithParameter("handshakePrivateKeyHex", _appSettings.HandshakePrivateKeyHex)
            .WithParameter("signaturePrivateKeyHex", _appSettings.SignaturePrivateKeyHex);

            builder.RegisterType <VaspCodeManager>()
            .As <IVaspCodeManager>()
            .WithParameter(TypedParameter.From((IEnumerable <string>)_appSettings.AutoConfirmedVaspCodes))
            .SingleInstance();

            builder.RegisterInMemoryRepositories();

            base.Load(builder);
        }
コード例 #11
0
        private ReturnObject ValidateNetworkStatus(string walletNetworkName)
        {
            //            throw new NotImplementedException();

            /*
             * 1. Validate Bitcoin Network Status
             * 2. Validate Ethereum Network Status
             * 3. Validate Vakacoin Network Status
             *
             * Return network error in result.Message
             */

            // 3. Validate Vakacoin Network Status

            try
            {
                ReturnObject getInfoResult;
                switch (walletNetworkName)
                {
                case CryptoCurrency.BTC:
                    var bitcoinRpc = new BitcoinRpc(AppSettingHelper.GetBitcoinNode(),
                                                    AppSettingHelper.GetBitcoinRpcAuthentication());

                    getInfoResult = bitcoinRpc.GetInfo();

                    if (getInfoResult.Status == Status.STATUS_ERROR)
                    {
                        return(new ReturnObject()
                        {
                            Status = Status.STATUS_ERROR,
                            Message = "Bitcoin network error: " + getInfoResult.Message
                        });
                    }

                    break;

                case CryptoCurrency.ETH:
                    var ethRpc      = new EthereumRpc(AppSettingHelper.GetEthereumNode());
                    var blockNumber = ethRpc.GetBlockNumber();

                    if (blockNumber.Status == Status.STATUS_ERROR)
                    {
                        return(new ReturnObject()
                        {
                            Status = Status.STATUS_ERROR,
                            Message = "Ethereum network error: " + blockNumber.Message
                        });
                    }

                    break;

                case CryptoCurrency.VAKA:
                    var vakacoinRpc = new VakacoinRpc(AppSettingHelper.GetVakacoinNode());
                    getInfoResult = vakacoinRpc.GetInfo();

                    if (getInfoResult.Status == Status.STATUS_ERROR)
                    {
                        return(new ReturnObject()
                        {
                            Status = Status.STATUS_ERROR,
                            Message = "Vakacoin network error: " + getInfoResult.Message
                        });
                    }

                    break;

                default:
                    return(new ReturnObject()
                    {
                        Status = Status.STATUS_ERROR,
                        Message = "Undefined network name!"
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(new ReturnObject()
            {
                Status = Status.STATUS_SUCCESS
            });
        }