public void TestGetTransactionsByAddressesShouldIncludeAllParameters() { var restClientMock = new Mock <IRestClient>(); restClientMock.Setup(r => r.Execute <GetTransactionsResponse>(It.IsAny <IRestRequest>())).Returns( () => { var restResponse = new RestResponse <GetTransactionsResponse> { StatusCode = HttpStatusCode.OK, Data = new GetTransactionsResponse { Hashes = new List <string> { "EJEAOOZYSAWFPZQESYDHZCGYNSTWXUMVJOVDWUNZJXDGWCLUFGIMZRMGCAZGKNPLBRLGUNYWKLJTYEAQX" } } }; return(restResponse); }); var repository = new RestIotaRepository(restClientMock.Object); var transactions = repository.FindTransactionsByAddresses( new List <Address> { new Address("RBTC9D9DCDEAUCFDCDADEAMBHAFAHKAJDHAODHADHDAD9KAHAJDADHJSGDJHSDGSDPODHAUDUAHDJAHAB") }); Assert.AreEqual("EJEAOOZYSAWFPZQESYDHZCGYNSTWXUMVJOVDWUNZJXDGWCLUFGIMZRMGCAZGKNPLBRLGUNYWKLJTYEAQX", transactions.Hashes[0].Value); }
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); }
private static void GetFromChain(string address, RestIotaRepository repository) { int depth = 3; int minWeightMagnitude = 9; try { TransactionHashList transactionsByAdress = repository.FindTransactionsByAddresses(new List <Address> { new Address(address) }); List <TransactionTrytes> transactionsTrytesList = repository.GetTrytes(transactionsByAdress.Hashes); Dictionary <int, Transaction> transactionPosition = new Dictionary <int, Transaction>(); int lastIndex = 0; //foreach (Hash hash in transactionsByAdress.Hashes) //{ foreach (TransactionTrytes transactionTrytes in transactionsTrytesList) { Transaction transactionOne = Transaction.FromTrytes(transactionTrytes, transactionsByAdress.Hashes[0]); transactionPosition.Add(transactionOne.CurrentIndex, transactionOne); lastIndex = transactionOne.LastIndex; } //} string combined = string.Empty; for (int i = 0; i < lastIndex; i++) { combined += transactionPosition[i].Fragment.Value; } string fertisch = TrytesToString(combined); Console.WriteLine(fertisch + " positiv"); } catch (Exception exception) { Console.WriteLine(exception); //throw; } //Hash hashAddress = new Hash(transactionsByAdress.Hashes[0].Value); //TransactionHashList bundleTransactions = repository.FindTransactionsByBundles(new List<Hash> {bundle.Hash}); //foreach (Hash transactionsHash in bundleTransactions.Hashes) //{ // Hash hash = new Hash(transactionsHash.Value); // var transactionsTrytes = repository.GetTrytes(bundleTransactions.Hashes); // var transaction = Transaction.FromTrytes(transactionsTrytes[0], hash); //} }
private static void SendToChain(string address, RestIotaRepository repository, string message) { Seed seed = new Seed(address); Transfer transfer = new Transfer { Address = new Address(address), Message = TryteString.FromUtf8String(message), ValueToTransfer = 0 }; Bundle bundle = new Bundle(); bundle.AddTransfer(transfer); int depth = 3; int minWeightMagnitude = 9; try { var sendTransfer = repository.SendTransfer(seed, bundle, SecurityLevel.Medium, depth, minWeightMagnitude); //TransactionHashList bundleTransactions = repository.FindTransactionsByBundles(new List<Hash> {bundle.Hash}); //foreach (Hash transactionsHash in bundleTransactions.Hashes) //{ // Hash hash = new Hash(transactionsHash.Value); // var transactionsTrytes = repository.GetTrytes(bundleTransactions.Hashes); // var transaction = Transaction.FromTrytes(transactionsTrytes[0], hash); //} TransactionHashList transactionsByAdress = repository.FindTransactionsByAddresses(new List <Address> { new Address(address) }); var transactionsTrytesAddress = repository.GetTrytes(transactionsByAdress.Hashes).First(); Hash hashAddress = new Hash(transactionsByAdress.Hashes[0].Value); Transaction transactionOne = Transaction.FromTrytes(transactionsTrytesAddress, hashAddress); TransactionTrytes transactionTrytes = new TransactionTrytes(""); TransactionTrytes test = transactionOne.ToTrytes(); var text = test.Value; } catch (Exception exception) { Console.WriteLine(exception); //throw; } }
public PositionEncrypted GetPosition(string address) { int depth = 3; int minWeightMagnitude = 9; PositionEncrypted positionEncrypted = new PositionEncrypted(); try { TransactionHashList transactionsByAdress = _Repository.FindTransactionsByAddresses(new List <Address> { new Address(address) }); List <TransactionTrytes> transactionsTrytesList = _Repository.GetTrytes(transactionsByAdress.Hashes); Dictionary <int, Transaction> transactionPosition = new Dictionary <int, Transaction>(); int lastIndex = 0; foreach (TransactionTrytes transactionTrytes in transactionsTrytesList) { Transaction transactionOne = Transaction.FromTrytes(transactionTrytes, transactionsByAdress.Hashes[0]); transactionPosition.Add(transactionOne.CurrentIndex, transactionOne); lastIndex = transactionOne.LastIndex; } string combined = string.Empty; for (int i = 0; i <= lastIndex; i++) { combined += transactionPosition[i].Fragment.Value; } string fertisch = TrytesToString(combined); string[] lines = fertisch.Split(new[] { "#" }, StringSplitOptions.None); positionEncrypted = new PositionEncrypted(); positionEncrypted.Lon = new Ciphertext(); positionEncrypted.Lon.Load(new MemoryStream(Convert.FromBase64String(lines[0]))); positionEncrypted.Lat = new Ciphertext(); positionEncrypted.Lat.Load(new MemoryStream(Convert.FromBase64String(lines[1]))); } catch (Exception exception) { Console.WriteLine(exception); //throw; } return(positionEncrypted); }
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 factory = new RestIotaRepositoryFactory(); var repo = factory.CreateAsync(true).Result; var repository = new RestIotaRepository(new RestClient("http://localhost:14265"), new PoWService(new CpuPearlDiver())); var acc = repository.GetAccountData(Seed.Random(), true, SecurityLevel.Medium, 0); var seed = Seed.Random(); var addressGenerator = new AddressGenerator(new Kerl(), new KeyGenerator(new Kerl(), new IssSigningHelper())); var addresses = addressGenerator.GetAddresses(seed, SecurityLevel.Medium, 0, 6); var addressesWithSpentInformation = repository.WereAddressesSpentFrom(addresses); var transactionStackCounter = 10; for (var i = 1; i <= transactionStackCounter; i++) { var stopwatch = new Stopwatch(); stopwatch.Start(); var transfers = new List <Transfer>(); for (var j = 1; j <= i; j++) { transfers.Add(new Transfer { Address = new Address("YTXCUUWTXIXVRQIDSECVFRTKAFOEZITGDPLWYVUVFURMNVDPIRXEIQN9JHNFNVKVJMQVMA9GDZJROTSFZHIVJOVAEC") { Balance = 0 }, Message = TryteString.FromAsciiString("Hello world! With " + i + " transactions."), Tag = new Tag("CSHARP"), Timestamp = Timestamp.UnixSecondsTimestamp }); } var bundle = new Bundle(); transfers.ForEach(bundle.AddTransfer); bundle.Finalize(); bundle.Sign(); var resultTransactions = repository.SendTrytes(bundle.Transactions, 27, 14); Console.WriteLine("Finished sending bundle with {0} transactions. Time elapsed: {1} seconds.", i, stopwatch.ElapsedMilliseconds / 1000); } var accountData = repository.GetAccountData(new Seed("SOMESEEDHERE"), true, SecurityLevel.Medium, 0); var latestInclusion = repository.GetLatestInclusion( new List <Hash> { new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999") }); var inputs = repository.GetInputs(new Seed("SOMESEEDHERE"), 99900000, SecurityLevel.Medium, 0); var newAddresses = repository.GetNewAddresses(Seed.Random(), 0, 5, SecurityLevel.Medium); var transactions = repository.FindTransactionsByAddresses( new List <Address> { new Address("HHZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9") }); var tips = repository.GetTips(); var inclusionsStates = repository.GetInclusionStates( new List <Hash> { new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999") }, tips.Hashes.GetRange(0, 10)); var transactionTrytes = repository.GetTrytes(new List <Hash> { new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999") }); var transactionData = transactionTrytes.Select(t => Transaction.FromTrytes(t)).ToList(); var transactionsToApprove = repository.GetTransactionsToApprove(); var balances = repository.GetBalances( new List <Address> { new Address("GVZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9"), new Address("HBBYKAKTILIPVUKFOTSLHGENPTXYBNKXZFQFR9VQFWNBMTQNRVOUKPVPRNBSZVVILMAFBKOTBLGLWLOHQ999999999") }); var nodeInfo = repository.GetNodeInfo(); var neighbours = repository.GetNeighbors(); Console.WriteLine("Done"); Console.ReadKey(); }