public void ShouldCheckConsistency()
        {
            GetNodeInfoResponse      gni = _iotaApi.IotaClient.GetNodeInfo();
            CheckConsistencyResponse ccr = _iotaApi.IotaClient.CheckConsistency(gni.LatestSolidSubtangleMilestone);

            Assert.IsNotNull(ccr, "CheckConsistencyResponse should not return null on failure");
            Assert.IsTrue(ccr.State, "Latest milestone should always be consistent");
        }
Exemple #2
0
        public void shouldGetNodeInfo()
        {
            GetNodeInfoResponse nodeInfo = iotaApi.GetNodeInfo();

            Assert.IsNotNull(nodeInfo.AppVersion);
            Assert.IsNotNull(nodeInfo.AppName);
            Assert.IsNotNull(nodeInfo.JreVersion);
            Assert.IsNotNull(nodeInfo.JreAvailableProcessors);
            Assert.IsNotNull(nodeInfo.JreFreeMemory);
            Assert.IsNotNull(nodeInfo.JreMaxMemory);
            Assert.IsNotNull(nodeInfo.JreTotalMemory);
            Assert.IsNotNull(nodeInfo.LatestMilestone);
            Assert.IsNotNull(nodeInfo.LatestMilestoneIndex);
            Assert.IsNotNull(nodeInfo.LatestSolidSubtangleMilestone);
            Assert.IsNotNull(nodeInfo.LatestSolidSubtangleMilestoneIndex);
            Assert.IsNotNull(nodeInfo.Neighbors);
            Assert.IsNotNull(nodeInfo.PacketsQueueSize);
            Assert.IsNotNull(nodeInfo.Time);
            Assert.IsNotNull(nodeInfo.Tips);
            Assert.IsNotNull(nodeInfo.TransactionsToRequest);
        }
Exemple #3
0
        // ReSharper disable once UnusedParameter.Local
        private AbstractResponse Process(string requestString, IPAddress remoteIpAddress)
        {
            try
            {
                Dictionary <string, object> request =
                    JsonConvert.DeserializeObject <Dictionary <string, object> >(requestString);
                if (request == null)
                {
                    return(ExceptionResponse.Create($"Invalid request payload: '{requestString}'"));
                }

                var result = request.TryGetValue("command", out var valueObject);
                if (!result)
                {
                    return(ErrorResponse.Create("COMMAND parameter has not been specified in the request."));
                }

                string command = (string)valueObject;

                //TODO(gjc): add remote limit api

                Log.Debug($"# {Interlocked.Increment(ref _counter)} -> Requesting command '{command}'");

                switch (command)
                {
                case "attachToTangle":
                    Hash trunkTransaction =
                        new Hash(GetParameterAsStringAndValidate(request, "trunkTransaction", HashSize));
                    Hash branchTransaction =
                        new Hash(GetParameterAsStringAndValidate(request, "branchTransaction", HashSize));
                    int           minWeightMagnitude = GetParameterAsInt(request, "minWeightMagnitude");
                    List <string> trytes             = GetParameterAsList(request, "trytes", TrytesSize);

                    List <string> elements = AttachToTangleStatement(trunkTransaction, branchTransaction,
                                                                     minWeightMagnitude, trytes);
                    return(AttachToTangleResponse.Create(elements));

                case "getNodeInfo":

                    return(GetNodeInfoResponse.Create(
                               Program.MainnetName, Program.Version,
                               Environment.ProcessorCount,
                               975883432, "1.8.0_151", 5726797824, 3193962496,
                               new Hash("TWRPOZZSMGMUMG9LLARESH9CYOZYSZXSNXMJZUC9B9YSFR9VEDYMQQAJJHBWCITVJVSKHYSHWMHP99999"),
                               400101,
                               new Hash("TWRPOZZSMGMUMG9LLARESH9CYOZYSZXSNXMJZUC9B9YSFR9VEDYMQQAJJHBWCITVJVSKHYSHWMHP99999"),
                               400101,
                               0, 0,
                               TimeStamp.Now(),
                               5862, 346));

                //String name = instance.configuration.booling(Configuration.DefaultConfSettings.TESTNET) ? IRI.TESTNET_NAME : IRI.MAINNET_NAME;
                //return GetNodeInfoResponse.create(name, IRI.VERSION, Runtime.getRuntime().availableProcessors(),
                //    Runtime.getRuntime().freeMemory(), System.getProperty("java.version"), Runtime.getRuntime().maxMemory(),
                //    Runtime.getRuntime().totalMemory(), instance.milestone.latestMilestone, instance.milestone.latestMilestoneIndex,
                //    instance.milestone.latestSolidSubtangleMilestone, instance.milestone.latestSolidSubtangleMilestoneIndex,
                //    instance.node.howManyNeighbors(), instance.node.queuedTransactionsSize(),
                //    System.currentTimeMillis(), instance.tipsViewModel.size(),
                //    instance.transactionRequester.numberOfTransactionsToRequest());

                case "getNeighbors":
                    return(GetNeighborsStatement());

                default:
                {
                    //TODO(gjc):add ixi process
                    return(ErrorResponse.Create($"Command [{command}] is unknown"));
                }
                }
            }
            catch (ValidationException e)
            {
                Log.Info(e, "API Validation failed");
                return(ErrorResponse.Create(e.Message));
            }
            catch (Exception e)
            {
                Log.Error(e, "API Exception");
                return(ErrorResponse.Create(e.Message));
            }
        }