public async Task <BeforePayoutResult> CanTryPayout([FromQuery, SwaggerParameter("Node ID", Required = true)] string nodeID, [FromQuery] string identity, [FromQuery] int?blockchainID, [FromQuery, SwaggerParameter("The ID of the offer", Required = true)] string offerId, [FromQuery] string holdingAddress, [FromQuery] string holdingStorageAddress, [FromQuery] string litigationStorageAddress, [FromQuery] string selectedAddress) { return(await BlockchainHelper.CanTryPayout(nodeID, offerId, holdingAddress, holdingStorageAddress, litigationStorageAddress, identity, blockchainID, selectedAddress)); }
private void RegisterEmail_Load(object sender, RibbonUIEventArgs e) { blockchainHelper = new BlockchainHelper(); // Ethereum contract details ethContract = new EthereumContract(); ethContract.ContractAddress = Constants.ContractAddress; ethContract.ContractABI = Constants.ContractABI; // Get sender's saved Ethereum account details (If exists) GetSenderInfo(); }
public frmEmailStatus(EthereumContract eContract, string eId) { InitializeComponent(); blockchainHelper = new BlockchainHelper(); ethContract = new EthereumContract(); ethContract.ContractABI = eContract.ContractABI; ethContract.ContractAddress = eContract.ContractAddress; emailId = eId; }
private async void TransferTransactionFromCreatedAccount(string accPrivateKey, string accAddress, string thisMessage) { try { KeyPair thisKeypair = KeyPair.CreateFromPrivateKey(accPrivateKey); var thisNewAccount = new Account(new Address(accAddress, NetworkType.Types.TEST_NET), thisKeypair); await BlockchainHelper.SendFromNewAccount(thisMessage, thisNewAccount); } catch (Exception ex) { } }
private static void Init() { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); Console.WriteLine($"Environment: {environment}"); var builder = new ConfigurationBuilder() .AddJsonFile($"appsettings.{environment}.json", true, true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections ApplicationSettings.ConnectionString = Configuration.GetSection("ApplicationSettings:ConnectionString")?.Value; ApplicationSettings.DatabaseId = Configuration.GetSection("ApplicationSettings:DatabaseId")?.Value; ApplicationSettings.UserCollection = Configuration.GetSection("ApplicationSettings:UserCollection")?.Value; ApplicationSettings.RabbitMQUsername = Configuration.GetSection("ApplicationSettings:RabbitMQUsername")?.Value; ApplicationSettings.RabbitMQPassword = Configuration.GetSection("ApplicationSettings:RabbitMQPassword")?.Value; ApplicationSettings.RabbitMQHostname = Configuration.GetSection("ApplicationSettings:RabbitMQHostname")?.Value; ApplicationSettings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("ApplicationSettings:RabbitMQPort")?.Value); ApplicationSettings.UserRegistrationQueueName = Configuration.GetSection("ApplicationSettings:UserRegistrationQueueName")?.Value; ApplicationSettings.KeyVaultCertificateName = Configuration.GetSection("ApplicationSettings:KeyVaultCertificateName")?.Value; ApplicationSettings.KeyVaultClientId = Configuration.GetSection("ApplicationSettings:KeyVaultClientId")?.Value; ApplicationSettings.KeyVaultClientSecret = Configuration.GetSection("ApplicationSettings:KeyVaultClientSecret")?.Value; ApplicationSettings.KeyVaultIdentifier = Configuration.GetSection("ApplicationSettings:KeyVaultIdentifier")?.Value; ApplicationSettings.KeyVaultEncryptionKey = Configuration.GetSection("ApplicationSettings:KeyVaultEncryptionKey")?.Value; ApplicationSettings.SendGridAPIKey = Configuration.GetSection("ApplicationSettings:SendGridAPIKey")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = ApplicationSettings.ConnectionString, DatabaseId = ApplicationSettings.DatabaseId, UserCollection = ApplicationSettings.UserCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = ApplicationSettings.KeyVaultCertificateName, ClientId = ApplicationSettings.KeyVaultClientId, ClientSecret = ApplicationSettings.KeyVaultClientSecret, KeyVaultIdentifier = ApplicationSettings.KeyVaultIdentifier }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(ApplicationSettings.KeyVaultEncryptionKey).Result; } using (BlockchainHelper blockchainHelper = new BlockchainHelper()) { wordlist = blockchainHelper.ReadMnemonic(); } }
private void ReadEncryptedEmail_Load(object sender, RibbonUIEventArgs e) { blockchainHelper = new BlockchainHelper(); securityHelper = new SecurityHelper(); fileHelper = new FileOperationsHelper(); ethContract = new EthereumContract(); ethContract.ContractAddress = Constants.ContractAddress; ethContract.ContractABI = Constants.ContractABI; // Get recipient's saved Ethereum account details (If exists) GetRecipientInfo(); }
private static void Init() { var builder = new ConfigurationBuilder() .AddJsonFile($"appsettings.json", true, true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections Settings.ConnectionString = Configuration.GetSection("ConnectionString")?.Value; Settings.DatabaseId = Configuration.GetSection("DatabaseId")?.Value; Settings.UserCollection = Configuration.GetSection("UserCollection")?.Value; Settings.RabbitMQUsername = Configuration.GetSection("RabbitMQUsername")?.Value; Settings.RabbitMQPassword = Configuration.GetSection("RabbitMQPassword")?.Value; Settings.RabbitMQHostname = Configuration.GetSection("RabbitMQHostname")?.Value; Settings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("RabbitMQPort")?.Value); Settings.UserRegistrationQueueName = Configuration.GetSection("UserRegistrationQueueName")?.Value; Settings.KeyVaultCertificateName = Configuration.GetSection("KeyVaultCertificateName")?.Value; Settings.KeyVaultClientId = Configuration.GetSection("KeyVaultClientId")?.Value; Settings.KeyVaultClientSecret = Configuration.GetSection("KeyVaultClientSecret")?.Value; Settings.KeyVaultIdentifier = Configuration.GetSection("KeyVaultIdentifier")?.Value; Settings.KeyVaultEncryptionKey = Configuration.GetSection("KeyVaultEncryptionKey")?.Value; Settings.SendGridAPIKey = Configuration.GetSection("SendGridAPIKey")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.ConnectionString, DatabaseId = Settings.DatabaseId, UserCollection = Settings.UserCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = Settings.KeyVaultCertificateName, ClientId = Settings.KeyVaultClientId, ClientSecret = Settings.KeyVaultClientSecret, KeyVaultIdentifier = Settings.KeyVaultIdentifier }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(Settings.KeyVaultEncryptionKey).Result; } using (BlockchainHelper blockchainHelper = new BlockchainHelper()) { wordlist = blockchainHelper.ReadMnemonic(); } }
public void CreateFirstBlockTest() { Example.Blockchain chain = new Example.Blockchain(); BlockchainHelper helper = new BlockchainHelper(); TransactionPart alice = new TransactionPart("Alice", -3); TransactionPart bob = new TransactionPart("Bob", 3); Transaction transaction = new Transaction(alice, bob); Block newBlock = helper.CreateBlock(transaction, chain); Assert.AreEqual(newBlock.Content.BlockNumber, 1); Assert.AreEqual(newBlock.Content.NumberOfTransactions, 2); Assert.AreNotEqual(newBlock.Content.ParentHash, String.Empty); }
public void CheckBlockHashTest() { Example.Blockchain chain = new Example.Blockchain(); BlockchainHelper helper = new BlockchainHelper(); TransactionPart alice = new TransactionPart("Alice", -3); TransactionPart bob = new TransactionPart("Bob", 3); Transaction transaction = new Transaction(alice, bob); Block newBlock = helper.CreateBlock(transaction, chain); Miner miner = new Miner(); bool result = miner.CheckBlockHash(newBlock); Assert.IsTrue(result); }
private static void PlayBlockchain(Random rand) { Console.WriteLine(String.Format("{0}: Start", DateTime.Now)); Console.WriteLine(String.Format("{0}: Creating Blockchain", DateTime.Now)); Example.Blockchain chain = new Example.Blockchain(); BlockchainHelper helper = new BlockchainHelper(); for (int i = 1; i <= 1000; i++) { int sign = 1; if (rand.Next(0, 2) == 0) { sign = -1; } byte[] buff = new byte[2]; rand.NextBytes(buff); // ToDo: Find a better way for random number string number = "0" + Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator) + buff[0] + buff[1]; double amount = Convert.ToDouble(number); double personA = sign * amount; double personB = personA * -1; TransactionPart alice = new TransactionPart(ALICE, (decimal)personA); TransactionPart bob = new TransactionPart(BOB, (decimal)personB); Transaction transaction = new Transaction(alice, bob); Console.WriteLine(String.Format("{0}: Creating transaction {1} - {2}", DateTime.Now, i, transaction.ToString())); Block innerBlock = helper.CreateBlock(transaction, chain); chain.Chain.Add(innerBlock); } Console.WriteLine(String.Format("{0}: Start mining", DateTime.Now)); Miner miner = new Miner(); Dictionary <string, decimal> result = miner.CheckBlockchain(chain); Console.WriteLine(String.Format("{0}: Final result is {1}:{2} and {3}:{4}", DateTime.Now, ALICE, result[ALICE], BOB, result[BOB])); Console.WriteLine("Press any key to start over"); Console.ReadKey(); }
private static void parseFileDataIntoClasses(ref byte[] currentFile, DBConnect mysql) { uint fileCursor = 0; while (seekToNextHeader(ref fileCursor, ref currentFile)) { byte[] blockData = getBlockData(ref fileCursor, ref currentFile); if (blockData == null) { // null means end of file return; } Block completedBlock = parseBlockDataIntoClass(blockData); BlockchainHelper.pushToMySQL(completedBlock, mysql); } }
public Example.Blockchain GetSampleChain() { const int howMany = 25; string parentHash = ""; Example.Blockchain chain = new Example.Blockchain(); BlockchainHelper helper = new BlockchainHelper(); for (int i = 1; i <= howMany; i++) { Transaction tx = CreateSampleTransaction(); Block innerBlock = helper.CreateBlock(tx, chain); chain.Chain.Add(innerBlock); } return(chain); }
public void CheckBlockTest() { Example.Blockchain chain = new Example.Blockchain(); BlockchainHelper helper = new BlockchainHelper(); Dictionary <string, decimal> states = new Dictionary <string, decimal>(); states.Add("Alice", 5); states.Add("Bob", 5); TransactionPart alice = new TransactionPart("Alice", -3); TransactionPart bob = new TransactionPart("Bob", 3); Transaction transaction = new Transaction(alice, bob); Block newBlock = helper.CreateBlock(transaction, chain); Block parentBlock = chain.Chain[0]; Miner miner = new Miner(); List <string> errors; miner.CheckBlock(newBlock, parentBlock, states, out errors); Assert.AreEqual(0, errors.Count); }
private void buttonLabel1_Click(object sender, EventArgs e) { Account account = CreateAccount(); JObject obj = new JObject(); obj.Add("FirstName", txtFirstName.Text); obj.Add("LastName", txtLastName.Text); obj.Add("MiddleName", txtMiddleName.Text); JsonConvert.SerializeObject(obj); BlockchainHelper.CreateTransaction(account, JsonConvert.SerializeObject(obj)); //TransferTransactionFromCreatedAccount(account.PrivateKey, account.Address.Plain, "ok"); foreach (var entry in Fmds) { Fingerprint fp = new Fingerprint(); fp.Index = entry.Key; String tempFingerPrint = Fmd.SerializeXml(entry.Value); //fp.FingerprintData = BitConverter.ToString(entry.Value.Bytes).Replace("-", ""); fp.FingerprintData = tempFingerPrint; fp.Address = account.Address.Plain; //fp.Save(); } Record record = new Record(); //record.Address = account.Address.Plain; // blockchain account address //record.LastName = txtLastName.Text; //record.FirstName = txtFirstName.Text; //record.MiddleName = txtMiddleName.Text; //record.Suffix = txtSuffix.Text; //record.MaidenName = txtMaidenName.Text; //record.Gender = cmbGender.SelectedValue.ToString()[0]; //record.DateOfBirth = pckDateOfBirth.Value.ToString("yyyy-MM-dd"); //record.PlaceOfBirth = txtPlaceOfBirth.Text; //record.SSS = txtSSS.Text; //record.TIN = txtTIN.Text; //record.PhilHealth = txtPhilHealth.Text; //record.Passport = txtPassport.Text; //record.BloodType = int.Parse(cmbBloodType.SelectedItem.Value.ToString()); //record.MaritalStatus = cmbMaritalStatus.SelectedValue.ToString()[0]; //record.Religion = txtReligion.Text; //record.Nationality = txtNationality.Text; //record.MobileNo = txtMobile.Text; //record.LandlineNo = txtPhone.Text; //record.Email = txtEmailAddress.Text; //record.DocumentPresented = cmbDocumentPresented.SelectedValue.ToString(); //record.Save(); MessageBox.Show("Saved"); }
private Account CreateAccount() { return(BlockchainHelper.GenerateAccount("C:/Users/KMC/Desktop/generatedAccount.txt")); }
public static string FeedReef(object[] args) { if (args.Length != 1) { Runtime.Log("* No Args"); return("no args"); } byte[] reef = (byte[])args[0]; // I am the only one who can feed my reef if (!Runtime.CheckWitness(reef)) { Runtime.Log("* Not the Owner"); return("not owner"); } BigInteger currentBlockHeight = BlockchainHelper.GetHeight(); // used in the whole method BigInteger lastFedBH = ReefDao.GetBlockHeightFedReef(reef).AsBigInteger(); if (currentBlockHeight == lastFedBH) { Runtime.Log("* Fishes are not hungry"); return("not hungry"); } byte[] fishesAlive = ReefDao.GetReefFishesAlive(reef); // fishes alive on the reef, used in the whole method BigInteger fishesAliveLength = ListManager.GetLength(fishesAlive, FishManager.GetSize()); // used in the whole method Runtime.Log(" "); Runtime.Log("Fishes Alive:"); Runtime.Log(fishesAliveLength.AsByteArray().AsString()); Runtime.Log("------------"); BigInteger balance = FishCoinDao.BalanceOf(reef) / FishCoinProcess.DecimalsFactor; // if there is not enough food, there is nothing to do, the food will not be consumed if (balance < fishesAliveLength || balance <= 0) { Runtime.Log("* Not enough food"); return("no food"); } // variables used to generate random BigInteger consensusData = BlockchainHelper.GetConsensusData(); BigInteger randomStep = BlockchainHelper.GetRandomStep(); // a stepper to use a new random next time BigInteger aRandom = 0; // the random variable // if there is less than 2 fishes in the reef if (fishesAliveLength < 2) { Runtime.Log("* There is less than 2 fishes alive in the reef"); aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; // 25% probability to arrive a new fish that got interested by the food you give away if (aRandom % 4 == 0) { Runtime.Log("* Immigrant arrived"); byte[] newImmigrant = FishManager.BuildImmigrant(reef, consensusData, randomStep); randomStep = randomStep + 4; // it was used 4 times inside the method fishesAlive = ListManager.Add(fishesAlive, newImmigrant); fishesAliveLength = fishesAliveLength + 1; Notifier.ImmigrantFish(reef, newImmigrant); } else { Runtime.Log("* No Immigrant today"); } } // if there is 2 or more fishes in the reef else { Runtime.Log("* There is 2 or more fishes in the reef"); aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; // 33.3% probability to fishes get laid if (aRandom % 3 == 0) { Runtime.Log("* Fishs in love"); byte[] newBaby = new byte[0]; BigInteger indexFather; BigInteger indexMother; // if there is only 2 fishes they are the only possibility to mate if (fishesAliveLength == 2) { Runtime.Log("* Exactly 2 lovers"); indexFather = 0; indexMother = 1; } else { Runtime.Log("* More than 2 possible lovers"); // get a random fish to be the father aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; indexFather = aRandom % fishesAliveLength; do { // get a random fish to be the mother, but a different fish of the father aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; indexMother = aRandom % fishesAliveLength; Runtime.Log("* Looking for a pretty female"); } while (indexFather == indexMother); } byte[] father = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexFather); byte[] mother = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexMother); Runtime.Log("* Gestation"); newBaby = FishManager.BuildFromParents(consensusData, randomStep, father, mother); randomStep = randomStep + father.Length; // tried random that many times Runtime.Log("* Its a ... Fish!"); fishesAlive = ListManager.Add(fishesAlive, newBaby); fishesAliveLength = fishesAliveLength + 1; BigInteger newBornIndex = fishesAliveLength - 1; Notifier.NewBornFish(reef, newBaby); byte[] fatherFishType = FishManager.GetPropCarnivorous(father); byte[] motherFishType = FishManager.GetPropCarnivorous(mother); // if one of the parents are carnivorous and there is another silly fish ready to be a pray if (fatherFishType[0] == 0 || motherFishType[0] == 0 || fishesAliveLength > 3) { Runtime.Log("* There is pray for the predator"); BigInteger fathersFedWithFishBlockHeight = FishManager.GetFedWithFishBlockHeight(father).AsBigInteger(); BigInteger mothersFedWithFishBlockHeight = FishManager.GetFedWithFishBlockHeight(mother).AsBigInteger(); BigInteger indexPredator = -1; // zero means carnivorous // if has been more than 20 blocks since last time the father eat a fish if (fatherFishType[0] == 0 && currentBlockHeight - fathersFedWithFishBlockHeight > 20) { Runtime.Log("* The father is hungry"); indexPredator = indexFather; } else if (motherFishType[0] == 0 && currentBlockHeight - mothersFedWithFishBlockHeight > 20) { Runtime.Log("* The mother is hungry"); indexPredator = indexMother; } if (indexPredator > -1) { Runtime.Log("* It means that one of them is having a lunch"); byte[] predator = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexPredator); BigInteger indexPrey = 0; do { // get a random fish to be eaten, but a different fish of the father and the mother aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; indexPrey = aRandom % fishesAliveLength; } while (indexPrey == indexMother || indexPrey == indexFather || indexPrey == newBornIndex); // saving the last blockheight when fish was fed with fish predator = FishManager.SetFedWithFishBlockHeight(predator, currentBlockHeight.AsByteArray()); fishesAlive = ListManager.EditAt(fishesAlive, FishManager.GetSize(), indexPredator, predator); // saving the predator dna inside the prey byte[] prey = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexPrey); // removing the prey from alive list (after everything, to not lose the right position after removing) fishesAlive = ListManager.RemoveAt(fishesAlive, FishManager.GetSize(), indexPrey); fishesAliveLength = fishesAliveLength - 1; byte[] fishesDead = ReefDao.GetReefFishesDead(reef); // fishes alive on the reef fishesDead = ListManager.Add(fishesDead, prey); ReefDao.UpdateReefFishesDead(reef, fishesDead); Notifier.FishEaten(reef, prey, predator); } else { Runtime.Log("* The predators are not hungry"); } } else { Runtime.Log("* No deaths today"); } } else { Runtime.Log("* They are not in the mood"); } } Runtime.Log("* Let's go sleep"); fishesAlive = IncrementQuantityOfFeeds(fishesAlive, fishesAliveLength); ReefDao.UpdateReefFishesAlive(reef, fishesAlive); FishCoinDao.SetTotalSupply(balance - fishesAliveLength); ReefDao.UpdateBlockHeightFedReef(reef, currentBlockHeight.AsByteArray()); BlockchainHelper.UpdateRandomStep(randomStep); Runtime.Log("* End :)"); return("success"); }