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); }
/// <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(); }