public EthereumSwap( EthereumAccount account, ICurrencies currencies) : base(account.Currency, currencies) { _account = account ?? throw new ArgumentNullException(nameof(account)); }
static void Main(string[] args) { var sqlDb = new SqlConnector(ConfigurationManager.AppSettings["SqlUserID"], ConfigurationManager.AppSettings["SqlPassword"], ConfigurationManager.AppSettings["SqlInitialCatalog"], ConfigurationManager.AppSettings["SqlDataSource"], ConfigurationManager.AppSettings["applicationId"], ConfigurationManager.AppSettings["applicationSecret"]); sqlDb.Initialize().Wait(); var ethereumAccount = new EthereumAccount(sqlDb, ConfigurationManager.AppSettings["EthereumNodeUrl"]); // If Ethereum node url is empty, the program will run with local Ethereum Test RPC // Otherwise, it will run with the real Ethereum TestNet. if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["EthereumNodeUrl"])) { Console.WriteLine("Running with Docker TestRpc"); EthereumTestRpcDemo(ethereumAccount); } else { Console.WriteLine("Running with Ethereum Testnet"); EthereumTestnetDemo(ethereumAccount); } }
private static void EthereumTestRpcDemo(EthereumAccount ethereumAccount) { var senderPrivateKey = "0x4faec59e004fd62384813d760e55d6df65537b4ccf62f268253ad7d4243a7193"; var reciverPrivateKey = "0x03fd5782c37523be6598ca0e5d091756635d144e42d518bb5f8db11cf931b447"; Console.WriteLine($"Please run the docker image with the following command:{Environment.NewLine}" + "docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest " + $"--account=\"{senderPrivateKey}, 300000000000000000000\"" + $" --account=\"{reciverPrivateKey}, 0\""); // Check if Account already stored in KeyStore try { var senderAccount = ethereumAccount.GetPublicAddressAsync(c_senderId).Result; var reciverAccount = ethereumAccount.GetPublicAddressAsync(c_ReciverId).Result; } catch (Exception) { // TODO: Add Check for key not found exception ethereumAccount.CreateAccountAsync(c_senderId, senderPrivateKey).Wait(); ethereumAccount.CreateAccountAsync(c_ReciverId, reciverPrivateKey).Wait(); } finally { SendCoins(ethereumAccount); } }
public async void Sanity_Get_Balance() { var kvInfo = new DatabaseMock("http://dummyKvUri"); var ethereumWallet = new EthereumAccount(kvInfo, "https://rinkeby.infura.io/fIF86MY6m3PHewhhJ0yE"); var transactionHash = await ethereumWallet.GetCurrentBalance(TestConstants.publicKey); Assert.IsType <decimal>(transactionHash); }
public ERC20Swap( ERC20Account account, EthereumAccount ethereumAccount, ISwapClient swapClient, ICurrencies currencies) : base(account, swapClient, currencies) { EthereumAccount = ethereumAccount ?? throw new ArgumentNullException(nameof(account)); }
public Erc20Swap( Erc20Account account, EthereumAccount ethereumAccount, ICurrencies currencies) : base(account.Currency, currencies) { Erc20Account = account ?? throw new ArgumentNullException(nameof(account)); EthereumAccount = ethereumAccount ?? throw new ArgumentNullException(nameof(ethereumAccount)); }
public async void Test_SendTransaction() { var kvInfo = new DatabaseMock("http://dummyKvUri"); var ethereumWallet = new EthereumAccount(kvInfo, "https://rinkeby.infura.io/fIF86MY6m3PHewhhJ0yE"); var transactionHash = await ethereumWallet.SignTransactionAsync("sender", TestConstants.publicKey, 100); var transactionResult = await ethereumWallet.SendRawTransactionAsync(transactionHash); Assert.StartsWith("0x", transactionResult); Assert.Equal(66, transactionResult.Length); }
private static void EthereumTestnetDemo(EthereumAccount ethereumAccount) { try { var senderAccount = ethereumAccount.GetPublicAddressAsync(c_senderId).Result; var reciverAccount = ethereumAccount.GetPublicAddressAsync(c_ReciverId).Result; } catch (Exception) { // TODO: Add Check for key not found exception ethereumAccount.CreateAccountAsync(c_senderId, "0x6d1ae68da64400f4b29baf4bde6fc9796e71480e8f1a502ad6fc2dae92dce268").Wait(); ethereumAccount.CreateAccountAsync(c_ReciverId).Wait(); var senderPublicAddress = ethereumAccount.GetPublicAddressAsync(c_senderId); Console.WriteLine("Accounts were created. " + $"To continue the demo please send ether to address {senderPublicAddress}{Environment.NewLine}" + "You can send ether for: https://www.rinkeby.io/#faucet"); } SendCoins(ethereumAccount); }
static void Main(string[] args) { Console.WriteLine("TransactionEngine - I do as I told"); // Init var unitConverion = new Nethereum.Util.UnitConversion(); var kv = new KeyVault(ConfigurationManager.AppSettings["AzureKeyVaultUri"], ConfigurationManager.AppSettings["applicationId"], ConfigurationManager.AppSettings["applicationSecret"]); var encryptionKeyName = ConfigurationManager.AppSettings["EncryptionKeyName"]; var decryptionKeyName = ConfigurationManager.AppSettings["DecryptionKeyName"]; var signKeyName = ConfigurationManager.AppSettings["SignKeyName"]; var verifyKeyName = ConfigurationManager.AppSettings["VerifyKeyName"]; var encryptionCertPassword = ConfigurationManager.AppSettings["EncryptionCertPassword"]; var decryptionCertPassword = ConfigurationManager.AppSettings["DecryptionCertPassword"]; var signCertPassword = ConfigurationManager.AppSettings["SignCertPassword"]; var verifyCertPassword = ConfigurationManager.AppSettings["VerifyCertPassword"]; var secretsMgmnt = new KeyVaultCryptoActions( new CertificateInfo(encryptionKeyName, encryptionCertPassword), new CertificateInfo(decryptionKeyName, decryptionCertPassword), new CertificateInfo(signKeyName, signCertPassword), new CertificateInfo(verifyKeyName, verifyCertPassword), kv, kv); secretsMgmnt.InitializeAsync().Wait(); //var securedComm = new RabbitMQBusImpl(ConfigurationManager.AppSettings["rabbitMqUri"], secretsMgmnt, true, "securedCommExchange"); var queueClient = new CloudQueueClientWrapper(ConfigurationManager.AppSettings["AzureStorageConnectionString"]); var securedCommForTransactions = new AzureQueue("transactions", queueClient, secretsMgmnt, true); var securedCommForNotifications = new AzureQueue("notifications", queueClient, secretsMgmnt, true); var taskInitTransactions = securedCommForTransactions.InitializeAsync(); var taskInitNotifications = securedCommForNotifications.InitializeAsync(); Task.WhenAll(taskInitTransactions, taskInitNotifications).Wait(); var sqlDb = new SqlConnector(ConfigurationManager.AppSettings["SqlUserID"], ConfigurationManager.AppSettings["SqlPassword"], ConfigurationManager.AppSettings["SqlInitialCatalog"], ConfigurationManager.AppSettings["SqlDataSource"], ConfigurationManager.AppSettings["applicationId"], ConfigurationManager.AppSettings["applicationSecret"]); sqlDb.Initialize().Wait(); var ethereumNodeWrapper = new EthereumAccount(sqlDb, ConfigurationManager.AppSettings["EthereumNodeUrl"]); // Listen on transactions requests, process them and notify the users when done securedCommForTransactions.DequeueAsync( msg => { Console.WriteLine("Got work!"); var data = Communication.Utils.FromByteArray <string>(msg); var msgArray = data.Split(';'); var amount = unitConverion.ToWei(msgArray[0]); var senderName = msgArray[1]; var reciverAddress = msgArray[2]; try { var transactionHash = ethereumNodeWrapper .SignTransactionAsync(senderName, reciverAddress, amount).Result; var transactionResult = ethereumNodeWrapper.SendRawTransactionAsync(transactionHash).Result; } catch (Exception ex) { Console.WriteLine(ex); throw; } // Wait for miner Thread.Sleep(3000); // notify a user about his balance change securedCommForNotifications.EnqueueAsync(Communication.Utils.ToByteArray(reciverAddress)).Wait(); }, (message) => { Console.WriteLine("Verification failure, doing nothing"); }, TimeSpan.FromSeconds(3)).Wait(); }
private static void SendCoins(EthereumAccount ethereumAccount) { Console.WriteLine("Sender - Happy to transfer my crypto coins!"); // Init var senderAddress = ethereumAccount.GetPublicAddressAsync(c_senderId).Result; var reciverAddress = ethereumAccount.GetPublicAddressAsync(c_ReciverId).Result; var balance = ethereumAccount.GetCurrentBalance(senderAddress).Result; PrintCurrentBalance(senderAddress, balance); var encryptionKeyName = ConfigurationManager.AppSettings["EncryptionKeyName"]; var decryptionKeyName = ConfigurationManager.AppSettings["DecryptionKeyName"]; var signKeyName = ConfigurationManager.AppSettings["SignKeyName"]; var verifyKeyName = ConfigurationManager.AppSettings["VerifyKeyName"]; var encryptionCertPassword = ConfigurationManager.AppSettings["EncryptionCertPassword"]; var decryptionCertPassword = ConfigurationManager.AppSettings["DecryptionCertPassword"]; var signCertPassword = ConfigurationManager.AppSettings["SignCertPassword"]; var verifyCertPassword = ConfigurationManager.AppSettings["VerifyCertPassword"]; var kv = new KeyVault(ConfigurationManager.AppSettings["AzureKeyVaultUri"], ConfigurationManager.AppSettings["applicationId"], ConfigurationManager.AppSettings["applicationSecret"]); var secretsMgmnt = new KeyVaultCryptoActions( new CertificateInfo(encryptionKeyName, encryptionCertPassword), new CertificateInfo(decryptionKeyName, decryptionCertPassword), new CertificateInfo(signKeyName, signCertPassword), new CertificateInfo(verifyKeyName, verifyCertPassword), kv, kv); secretsMgmnt.InitializeAsync().Wait(); //var securedComm = new RabbitMQBusImpl(ConfigurationManager.AppSettings["rabbitMqUri"], secretsMgmnt, true, "securedCommExchange"); var queueClient = new CloudQueueClientWrapper(ConfigurationManager.AppSettings["AzureStorageConnectionString"]); var securedComm = new AzureQueue("transactions", queueClient, secretsMgmnt, true); securedComm.InitializeAsync().Wait(); // While there are sufficient funds, transfer some... while (balance >= 0) { var amountToSend = 0.001; // Message structure: {amountToSend};{senderName};{reciverAddress} var message = $"{amountToSend};{c_senderId};{reciverAddress}"; securedComm.EnqueueAsync(Communication.Utils.ToByteArray(message)).Wait(); // Sleep 1 minute Thread.Sleep(60000); var newBalance = ethereumAccount.GetCurrentBalance(senderAddress).Result; PrintCurrentBalance(senderAddress, newBalance); // Wait for mining.. while (newBalance.Equals(balance)) { newBalance = ethereumAccount.GetCurrentBalance(senderAddress).Result; } balance = newBalance; } }
static void Main(string[] args) { // Init var kv = new KeyVault(ConfigurationManager.AppSettings["AzureKeyVaultUri"], ConfigurationManager.AppSettings["applicationId"], ConfigurationManager.AppSettings["applicationSecret"]); var sqlDb = new SqlConnector(ConfigurationManager.AppSettings["SqlUserID"], ConfigurationManager.AppSettings["SqlPassword"], ConfigurationManager.AppSettings["SqlInitialCatalog"], ConfigurationManager.AppSettings["SqlDataSource"], ConfigurationManager.AppSettings["applicationId"], ConfigurationManager.AppSettings["applicationSecret"]); sqlDb.Initialize().Wait(); var ethereumAccount = new EthereumAccount(sqlDb, ConfigurationManager.AppSettings["EthereumNodeUrl"]); Console.WriteLine("Receiver - I just love getting new crypto coins"); var reciverAddress = ethereumAccount.GetPublicAddressAsync(c_ReciverId).Result; PrintCurrentBalance(reciverAddress, ethereumAccount.GetCurrentBalance(reciverAddress).Result); var encryptionKeyName = ConfigurationManager.AppSettings["EncryptionKeyName"]; var decryptionKeyName = ConfigurationManager.AppSettings["DecryptionKeyName"]; var signKeyName = ConfigurationManager.AppSettings["SignKeyName"]; var verifyKeyName = ConfigurationManager.AppSettings["VerifyKeyName"]; var encryptionCertPassword = ConfigurationManager.AppSettings["EncryptionCertPassword"]; var decryptionCertPassword = ConfigurationManager.AppSettings["DecryptionCertPassword"]; var signCertPassword = ConfigurationManager.AppSettings["SignCertPassword"]; var verifyCertPassword = ConfigurationManager.AppSettings["VerifyCertPassword"]; var secretsMgmnt = new KeyVaultCryptoActions( new CertificateInfo(encryptionKeyName, encryptionCertPassword), new CertificateInfo(decryptionKeyName, decryptionCertPassword), new CertificateInfo(signKeyName, signCertPassword), new CertificateInfo(verifyKeyName, verifyCertPassword), kv, kv); secretsMgmnt.InitializeAsync().Wait(); //var securedComm = new RabbitMQBusImpl(ConfigurationManager.AppSettings["rabbitMqUri"], secretsMgmnt, true, "securedCommExchange"); var queueClient = new CloudQueueClientWrapper(ConfigurationManager.AppSettings["AzureStorageConnectionString"]); var securedComm = new AzureQueue("notifications", queueClient, secretsMgmnt, true); securedComm.InitializeAsync().Wait(); // Listen on the notifications queue, check balance when a notification arrives var consumerTag = securedComm.DequeueAsync( msg => { var data = Communication.Utils.FromByteArray <string>(msg); if (data.Equals(reciverAddress, StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Great, Balance change!"); PrintCurrentBalance(reciverAddress, ethereumAccount.GetCurrentBalance(reciverAddress).Result); } else { Console.WriteLine("Not my balance!"); Console.WriteLine(msg); } }, (message) => { Console.WriteLine("Verification failure, doing nothing"); }, TimeSpan.FromSeconds(3)); // wait 30 minutes Thread.Sleep(30 * 1000 * 60); // switch based on the chosen queue //securedComm.CancelListeningOnQueue(consumerTag.Result); securedComm.CancelListeningOnQueue(); }
public HomeController(IQueue queue, EthereumAccount ethereumAccount) { m_queue = (AzureQueue)queue; m_ethereumAccount = ethereumAccount; }