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);
        }
Esempio n. 2
0
        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();
        }