public List <ChatEntry> GetChat(Connections conn) { List <ChatEntry> chatEntrys = new List <ChatEntry>(); User User_A = _context.User.Single(m => m.Name.Equals(conn.UserA_.Name)); User User_B = _context.User.Single(m => m.Name.Equals(conn.UserB_.Name)); User local = HttpContext.Session.GetObjectFromJson <User>("User"); var repository = new RestIotaRepository(new RestClient("https://field.carriota.com:443"), new PoWService(new CpuPowDiver())); //set refresh bools if (conn.UserA_.Name.Equals(local.Name)) { conn.Refresh_A = false; } else { conn.Refresh_B = false; } //updating entry _context.Connections.Update(conn); _context.SaveChanges(); //setting addresses to check for new messages List <Address> addresses = new List <Address>() { new Address(conn.AddressA), new Address(conn.AddressB) }; //doing now tangle stuff var hashList = repository.FindTransactionsByAddresses(addresses); List <Bundle> bundles = repository.GetBundles(hashList.Hashes, true); foreach (Bundle b in bundles) { string entryName = ""; if (b.Transactions[0].Address.ToString() == conn.AddressA) { entryName = conn.UserB_.Name; } else { entryName = conn.UserA_.Name; } ChatEntry entry = new ChatEntry(b, entryName, conn.EncryptionKey); chatEntrys.Add(entry); } List <ChatEntry> sortedList = chatEntrys.OrderBy(o => o.TimeStamp).ToList(); return(sortedList); }
public List <T> GetAllFromAddress <T>(string address) where T : IDownloadable { //create object list var list = new List <T>(); var addressList = new List <TangleNet::Address> { new TangleNet::Address(address) }; var bundleHashList = _repository.FindTransactionsByAddresses(addressList); for (var i = 0; i < bundleHashList.Hashes.Count; i++) { var hash = bundleHashList.Hashes[i].Value; if (_simpleCache.ContainsKey(hash)) { var obj = _simpleCache[hash]; if (obj is T) { list.Add((T)_simpleCache[hash]); bundleHashList.Hashes.RemoveAt(i); i--; Console.WriteLine("We loaded something from cache"); } } } var bundles = _repository.GetBundles(bundleHashList.Hashes, false); foreach (TangleNet::Bundle bundle in bundles) { string json = bundle.AggregateFragments().ToUtf8String(); var newTrans = Utils.FromJSON <T>(json); if (newTrans.HasValue) { list.Add(newTrans.Value); bundle.Transactions.ForEach(x => _simpleCache[x.Hash.Value] = newTrans.Value); } } return(list); }
/// <summary> /// The main. /// </summary> /// <param name="args"> /// The args. /// </param> private static void Main(string[] args) { var repository = new RestIotaRepository( new FallbackIotaClient( new List <string> { "https://peanut.iotasalad.org:14265", "http://node04.iotatoken.nl:14265", "http://node05.iotatoken.nl:16265", "https://nodes.thetangle.org:443", "http://iota1.heidger.eu:14265", "https://nodes.iota.cafe:443", "https://potato.iotasalad.org:14265", "https://durian.iotasalad.org:14265", "https://turnip.iotasalad.org:14265", "https://nodes.iota.fm:443", "https://tuna.iotasalad.org:14265", "https://iotanode2.jlld.at:443", "https://node.iota.moe:443", "https://wallet1.iota.town:443", "https://wallet2.iota.town:443", "http://node03.iotatoken.nl:15265", "https://node.iota-tangle.io:14265", "https://pow4.iota.community:443", "https://dyn.tangle-nodes.com:443", "https://pow5.iota.community:443", }, 5000), new PoWSrvService()); var response = repository.GetBundles( new List <Hash> { new Hash("HRXMDIQMRFDFQFP9ZKHAGRRBWSDHCKJCTGZMHPIFUY9EVNGDXRCOUWTHFMLXRDYVMBZLEVFPZSKFA9999") }, true); var confirmedBundle = response.FirstOrDefault(b => b.IsConfirmed); confirmedBundle.Transactions.ForEach( t => { Console.WriteLine(t.Hash.Value); }); var notReattached = repository.GetBundles( new List <Hash> { new Hash("DNICBWUUIWYSTOVNTSOLZOHEAGWQPVMJSJDMCNFTR9MJNVVTDWOWSHFDVNZHKCDPVLEXSCILPXTNZ9999") }, true); var single = repository.GetBundles( new List <Hash> { new Hash("WXHKZQMPIOMUOWGLHLE9ZGAPOBZOBXKTLXAGOIJMQPCIZEZENFRTBIRWZ99KWC9UUKBRHDQUFFJEZ9999") }, true); var all = repository.GetBundlesAsync( new List <Hash> { new Hash("HRXMDIQMRFDFQFP9ZKHAGRRBWSDHCKJCTGZMHPIFUY9EVNGDXRCOUWTHFMLXRDYVMBZLEVFPZSKFA9999"), new Hash("DNICBWUUIWYSTOVNTSOLZOHEAGWQPVMJSJDMCNFTR9MJNVVTDWOWSHFDVNZHKCDPVLEXSCILPXTNZ9999"), new Hash("WXHKZQMPIOMUOWGLHLE9ZGAPOBZOBXKTLXAGOIJMQPCIZEZENFRTBIRWZ99KWC9UUKBRHDQUFFJEZ9999") }, true).Result; Console.WriteLine("Done"); Console.ReadKey(); }