Example #1
0
        public void TestGetNodeInfoShouldIncludeAllParameters()
        {
            var restClientMock = new Mock <IRestClient>();

            restClientMock.Setup(r => r.Execute <NodeInfo>(It.IsAny <IRestRequest>())).Returns(
                () =>
            {
                var restResponse = new RestResponse <NodeInfo>
                {
                    StatusCode = HttpStatusCode.OK,
                    Data       =
                        new NodeInfo
                    {
                        AppName                = "IRI",
                        AppVersion             = "1.4.1.1",
                        Duration               = 0,
                        JreAvailableProcessors = 4,
                        JreFreeMemory          = 1433752216,
                        JreMaxMemory           = 4294967296,
                        JreTotalMemory         = 4294967296,
                        LatestMilestone        =
                            "MWBOADDZVATGJWCZSEQSPJSEEMGROZOGEERYBTIBZIKTJTXGNKMKWDFKIJOAKEPEJBGEMZLE9UVCA9999",
                        LatestMilestoneIndex          = 325116,
                        LatestSolidSubtangleMilestone =
                            "MWBOADDZVATGJWCZSEQSPJSEEMGROZOGEERYBTIBZIKTJTXGNKMKWDFKIJOAKEPEJBGEMZLE9UVCA9999",
                        LatestSolidSubtangleMilestoneIndex = 325116,
                        Neighbors             = 6,
                        PacketsQueueSize      = 0,
                        Time                  = 1515707837727,
                        Tips                  = 5946,
                        TransactionsToRequest = 550
                    }
                };
                return(restResponse);
            });

            var repository = new RestIotaRepository(restClientMock.Object);
            var nodeInfo   = repository.GetNodeInfo();

            Assert.AreEqual("IRI", nodeInfo.AppName);
            Assert.AreEqual("1.4.1.1", nodeInfo.AppVersion);
            Assert.AreEqual(0, nodeInfo.Duration);
            Assert.AreEqual(4, nodeInfo.JreAvailableProcessors);
            Assert.AreEqual(1433752216, nodeInfo.JreFreeMemory);
            Assert.AreEqual(4294967296, nodeInfo.JreMaxMemory);
            Assert.AreEqual(4294967296, nodeInfo.JreTotalMemory);
            Assert.AreEqual("MWBOADDZVATGJWCZSEQSPJSEEMGROZOGEERYBTIBZIKTJTXGNKMKWDFKIJOAKEPEJBGEMZLE9UVCA9999", nodeInfo.LatestMilestone);
            Assert.AreEqual(325116, nodeInfo.LatestMilestoneIndex);
            Assert.AreEqual("MWBOADDZVATGJWCZSEQSPJSEEMGROZOGEERYBTIBZIKTJTXGNKMKWDFKIJOAKEPEJBGEMZLE9UVCA9999", nodeInfo.LatestSolidSubtangleMilestone);
            Assert.AreEqual(325116, nodeInfo.LatestSolidSubtangleMilestoneIndex);
            Assert.AreEqual(6, nodeInfo.Neighbors);
            Assert.AreEqual(0, nodeInfo.PacketsQueueSize);
            Assert.AreEqual(1515707837727, nodeInfo.Time);
            Assert.AreEqual(5946, nodeInfo.Tips);
            Assert.AreEqual(550, nodeInfo.TransactionsToRequest);
        }
Example #2
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            var repository   = new RestIotaRepository(new RestClient("https://localhost:14265"));
            var nodeInfo     = repository.GetNodeInfo();
            var neighbours   = repository.GetNeighbors();
            var transactions =
                repository.GetTransactionsByAddresses(
                    new List <string> {
                "GVZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9"
            });
            var balances =
                repository.GetBalances(
                    new List <string>
            {
                "GVZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9",
                "HBBYKAKTILIPVUKFOTSLHGENPTXYBNKXZFQFR9VQFWNBMTQNRVOUKPVPRNBSZVVILMAFBKOTBLGLWLOHQ999999999"
            },
                    100);

            Console.WriteLine("Done");
            Console.ReadKey();
        }
Example #3
0
        /// <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();
        }