Exemplo n.º 1
0
        /// <summary>
        /// Get Latest block informattion
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// </param>
        /// <returns></returns>
        public static bool GetBlockByLatestNum(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option]\n", command)
            };

            string[] command_option = new string[] { HelpCommandOption.Help };

            if (parameters != null)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            try
            {
                RpcApiResult result = RpcApi.GetBlockByLatestNum(out BlockExtention block);
                if (result.Result)
                {
                    Console.WriteLine(PrintUtil.PrintBlockExtention(block));
                }

                OutputResultMessage(command, result.Result, result.Code, result.Message);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message + "\n\n" + e.StackTrace);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get block information
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Block number (optional)
        /// </param>
        /// <returns></returns>
        public static bool GetBlock(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <block number>\n", command)
            };

            string[] command_option = new string[] { HelpCommandOption.Help };

            if (parameters != null && parameters.Length > 1)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            try
            {
                RpcApiResult   result = null;
                BlockExtention block  = null;
                if (parameters == null)
                {
                    Console.WriteLine("Get current block.");
                    result = RpcApi.GetBlockByLatestNum(out block);
                }
                else
                {
                    if (!long.TryParse(parameters[0], out long block_num))
                    {
                        Console.WriteLine("Invalid block number");
                        return(true);
                    }
                    result = RpcApi.GetBlock(block_num, out block);
                }

                if (result.Result)
                {
                    Console.WriteLine(PrintUtil.PrintBlockExtention(block));
                }

                OutputResultMessage(command, result.Result, result.Code, result.Message);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message + "\n\n" + e.StackTrace);
            }

            return(true);
        }