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 async Task <ActionResult> GetBalanceAsync(HomeViewModel model)
        {
            var balance = await m_ethereumAccount.GetCurrentBalance(model.WalletAddress, model.SenderId);

            ViewBag.model = new HomeViewModel()
            {
                Balance       = balance,
                WalletAddress = model.WalletAddress,
                SenderId      = model.SenderId
            };

            return(View("Index"));
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        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();
        }