コード例 #1
0
        public void TestGetNeighborsShouldIncludeAllParameters()
        {
            var restClientMock = new Mock <IRestClient>();

            restClientMock.Setup(r => r.Execute <NeighborList>(It.IsAny <IRestRequest>())).Returns(
                () =>
            {
                var restResponse = new RestResponse <NeighborList>
                {
                    StatusCode = HttpStatusCode.OK,
                    Data       =
                        new NeighborList
                    {
                        Duration  = 1,
                        Neighbors =
                            new List <Neighbor>
                        {
                            new Neighbor
                            {
                                Address                 = "/8.8.8.8:14265",
                                ConnectionType          = "Remote",
                                NumberOfAllTransactions =
                                    45,
                                NumberOfInvalidTransactions
                                    = 0,
                                NumberOfNewTransactions = 5,
                                NumberOfRandomTransactionRequests
                                    = 3,
                                NumberOfSentTransactions =
                                    40
                            }
                        }
                    }
                };
                return(restResponse);
            });

            var repository = new RestIotaRepository(restClientMock.Object);
            var neighbors  = repository.GetNeighbors();

            Assert.AreEqual(1, neighbors.Duration);
            Assert.AreEqual("/8.8.8.8:14265", neighbors.Neighbors[0].Address);
            Assert.AreEqual("Remote", neighbors.Neighbors[0].ConnectionType);
            Assert.AreEqual(45, neighbors.Neighbors[0].NumberOfAllTransactions);
            Assert.AreEqual(0, neighbors.Neighbors[0].NumberOfInvalidTransactions);
            Assert.AreEqual(5, neighbors.Neighbors[0].NumberOfNewTransactions);
            Assert.AreEqual(3, neighbors.Neighbors[0].NumberOfRandomTransactionRequests);
            Assert.AreEqual(40, neighbors.Neighbors[0].NumberOfSentTransactions);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: SeeSharp7/tangle-.net
        /// <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();
        }
コード例 #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();
        }