コード例 #1
0
ファイル: AssetIssueCommand.cs プロジェクト: lovecpus/mineral
        /// <summary>
        /// Get infomation asset issue by name
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Asset issue name
        /// </param>
        /// <returns></returns>
        public static bool AssetIssueListByName(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <asset issue name>\n", command)
            };

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

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

            try
            {
                string       name   = parameters[0];
                RpcApiResult result = RpcApi.AssetIssueListByName(name, out AssetIssueList contracts);
                if (result.Result)
                {
                    Console.WriteLine(PrintUtil.PrintAssetIssueList(contracts));
                }

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

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Get total transaction
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// <returns></returns>
        public static bool GetTotalTransaction(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 || parameters.Length != 0)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            try
            {
                RpcApiResult result = RpcApi.GetTotalTransaction(out NumberMessage message);
                if (result.Result)
                {
                    Console.WriteLine("The num of total transaction is " + message.Num);
                }

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

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Get balance in current keystore
        /// </summary>
        /// <param name="parameters">
        /// Parameters Index
        /// </param>
        /// <returns></returns>
        public static bool GetBalance(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);
            }

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                string       address = RpcApi.KeyStore.Address;
                RpcApiResult result  = RpcApi.GetBalance(out long balance);

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

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Extract private key by keystore
        /// </summary>
        /// <param name="parameters">
        /// Parameters Index
        /// </param>
        /// <returns></returns>
        public static bool BackupWallet(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <path>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                string       password = CommandLineUtil.ReadPasswordString("Please input your password.");
                RpcApiResult result   = RpcApi.BackupWallet(password);

                OutputResultMessage(command, result.Result, result.Code, result.Message);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message + "\n\n" + e.StackTrace);
            }
            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Get approved transaction list
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0] : Transaction binary data
        /// <returns></returns>
        public static bool GetTransactionApprovedList(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <transaction>\n", command)
            };

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

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

            try
            {
                Transaction  transaction = Transaction.Parser.ParseFrom(parameters[0].HexToBytes());
                RpcApiResult result      = RpcApi.GetTransactionApprovedList(transaction, out TransactionApprovedList transaction_list);
                if (result.Result)
                {
                    Console.WriteLine(PrintUtil.PrintTransactionApprovedList(transaction_list));
                }

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

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Get block by id
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Block Id
        /// </param>
        /// <returns></returns>
        public static bool GetBlockById(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <block id>\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 = RpcApi.GetBlockById(parameters[0], 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);
        }
コード例 #7
0
        /// <summary>
        /// Get Blocks
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Start block number
        /// [1] : Block limit count
        /// </param>
        /// <returns></returns>
        public static bool GetBlockByLimitNext(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <start number> <end number>\n", command)
            };

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

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

            try
            {
                long start = long.Parse(parameters[0]);
                long end   = long.Parse(parameters[1]);

                RpcApiResult result = RpcApi.GetBlockByLimitNext(start, end, out BlockListExtention blocks);
                if (result.Result)
                {
                    Console.WriteLine(PrintUtil.PrintBlockListExtention(blocks));
                }

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

            return(true);
        }
コード例 #8
0
        /// <summary>
        /// Get transaction count in block
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0] : Block number
        /// <returns></returns>
        public static bool GetTransactionCountByBlockNum(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
            {
                long         block_num = long.Parse(parameters[0]);
                RpcApiResult result    = RpcApi.GetTransactionCountByBlockNum(block_num, out int count);
                if (result.Result)
                {
                    Console.WriteLine("The block contain " + count + "transactions");
                }

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

            return(true);
        }
コード例 #9
0
        /// <summary>
        /// Get information node list
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// </param>
        /// <returns></returns>
        public static bool ListNode(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.ListNode(out NodeList nodes);
                if (result.Result)
                {
                    Console.WriteLine(PrintUtil.PrintNodeList(nodes));
                }

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

            return(true);
        }
コード例 #10
0
        /// <summary>
        /// Logout keystore
        /// </summary>
        /// <param name="parameters">
        /// Parameters Index
        /// </param>
        /// <returns></returns>
        public static bool Logout(string command, string[] parameters)
        {
            RpcApiResult result = RpcApi.Logout();

            OutputResultMessage(command, result.Result, result.Code, result.Message);

            return(true);
        }
コード例 #11
0
        /// <summary>
        /// Create proposal
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0~] : Proposal pair parameter
        /// <returns></returns>
        public static bool CreateProposal(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <id 1> <value 1> <id 2> <value 2> ...\n", command)
            };

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

            if (parameters == null || parameters.Length < 2 || parameters.Length % 2 != 0)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] owner_address             = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                Dictionary <long, long> proposal = new Dictionary <long, long>();

                for (int i = 0; i < parameters.Length; i += 2)
                {
                    long id    = long.Parse(parameters[i]);
                    long value = long.Parse(parameters[i + 1]);
                    proposal.Add(id, value);
                }

                RpcApiResult result = RpcApi.CreateProposalContract(owner_address,
                                                                    proposal,
                                                                    out ProposalCreateContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.ProposalCreateContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #12
0
        /// <summary>
        /// Update setting
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0] : Contract address
        /// [1] : Consume user resource percent
        /// <returns></returns>
        public static bool UpdateSetting(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <address> <consume user resource percent>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] owner_address    = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                byte[] contract_address = Wallet.Base58ToAddress(parameters[0]);
                long   resource_percent = long.Parse(parameters[1]);
                if (resource_percent > 100 || resource_percent < 0)
                {
                    Console.WriteLine("Consume user resource percent must be 0 to 100.");
                    return(true);
                }

                RpcApiResult result = RpcApi.CreateUpdateSettingContract(owner_address,
                                                                         contract_address,
                                                                         resource_percent,
                                                                         out UpdateSettingContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.UpdateSettingContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #13
0
ファイル: AssetIssueCommand.cs プロジェクト: lovecpus/mineral
        /// <summary>
        /// Update asset
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0] : Limit
        /// [1] : Public limit
        /// [2] : Description
        /// [3] : url
        /// <returns></returns>
        public static bool UpdateAsset(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <limit> <public limit> <description> <url>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                long   limit         = long.Parse(parameters[0]);
                long   public_limit  = long.Parse(parameters[1]);
                byte[] owner_address = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                byte[] description   = Encoding.UTF8.GetBytes(parameters[2]);
                byte[] url           = Encoding.UTF8.GetBytes(parameters[3]);

                RpcApiResult result = RpcApi.CreateUpdateAssetContract(owner_address,
                                                                       description,
                                                                       url,
                                                                       limit,
                                                                       public_limit,
                                                                       out UpdateAssetContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.UpdateAssetContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #14
0
ファイル: AssetIssueCommand.cs プロジェクト: lovecpus/mineral
        /// <summary>
        /// Transfer asset
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : To address
        /// [1] : Asset name
        /// [2] : Amount
        /// </param>
        /// <returns></returns>
        public static bool TransferAsset(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <to address> <asset name> <amount>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] to_address    = Encoding.UTF8.GetBytes(parameters[0]);
                byte[] asset_name    = Encoding.UTF8.GetBytes(parameters[1]);
                byte[] owner_address = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                long   amount        = long.Parse(parameters[2]);


                RpcApiResult result = RpcApi.CreateTransferAssetContract(to_address,
                                                                         owner_address,
                                                                         asset_name,
                                                                         amount,
                                                                         out TransferAssetContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.TransferAssetContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #15
0
        /// <summary>
        /// Vote
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0~] : vote pair parameter
        /// </param>
        /// <returns></returns>
        public static bool VoteWitness(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <address 1> <amount 1> <address 2> <amount 2> ...\n", command)
            };

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

            if (parameters == null || parameters.Length < 2 || parameters.Length % 2 != 0)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            try
            {
                byte[] owner_address            = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                Dictionary <byte[], long> votes = new Dictionary <byte[], long>(new ByteArrayEqualComparer());

                for (int i = 0; i < parameters.Length; i += 2)
                {
                    byte[] address = Wallet.Base58ToAddress(parameters[i]);
                    long   amount  = long.Parse(parameters[i + 1]);
                    votes.Add(address, amount);
                }

                RpcApiResult result = RpcApi.CreateVoteWitnessContract(owner_address,
                                                                       votes,
                                                                       out VoteWitnessContract contract);


                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.VoteWitnessContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #16
0
        /// <summary>
        /// Update setting
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0] : Proposal id
        /// <returns></returns>
        public static bool DeleteProposal(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <id>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] owner_address = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                long   id            = long.Parse(parameters[0]);

                RpcApiResult result = RpcApi.CreateProposalDeleteContract(owner_address,
                                                                          id,
                                                                          out ProposalDeleteContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.ProposalDeleteContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #17
0
        /// <summary>
        /// Update account permission
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0] : Owner address
        /// [1] : Permission json
        /// <returns></returns>
        public static bool UpdateAccountPermission(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <owner address> <permission(json format)>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] owner_address = Wallet.Base58ToAddress(parameters[0]);
                string permission    = parameters[2];

                RpcApiResult result = RpcApi.CreateAccountPermissionUpdateContract(owner_address,
                                                                                   permission,
                                                                                   out AccountPermissionUpdateContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.AccountPermissionUpdateContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #18
0
ファイル: AssetIssueCommand.cs プロジェクト: lovecpus/mineral
        /// <summary>
        /// Transfer asset
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// </param>
        /// <returns></returns>
        public static bool UnfreezeAsset(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <to address> <asset name> <amount>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] owner_address = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);

                RpcApiResult result = RpcApi.CreateUnfreezeAssetContract(owner_address,
                                                                         out UnfreezeAssetContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.UnfreezeAssetContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #19
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);
        }
コード例 #20
0
        /// <summary>
        /// Get transaction information by id
        /// </summary>
        /// <param name="parameters"></param>
        /// /// Parameter Index
        /// [0] : Transaction id
        /// <returns></returns>
        public static bool GetTransactionsToThis(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <transaction id>\n", command)
            };

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

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

            try
            {
                byte[] address = Wallet.Base58ToAddress(parameters[0]);
                int    offset  = int.Parse(parameters[1]);
                int    limit   = int.Parse(parameters[2]);

                RpcApiResult result = RpcApi.GetTransactionsToThis(address, offset, limit, out TransactionListExtention transactions);
                if (result.Result)
                {
                    if (transactions != null)
                    {
                        Console.WriteLine(PrintUtil.PrintTransactionExtentionList(new List <TransactionExtention>(transactions.Transaction)));
                    }
                    else
                    {
                        Console.WriteLine("No transaction from " + Wallet.AddressToBase58(address));
                    }
                }

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

            return(true);
        }
コード例 #21
0
        /// <summary>
        /// Create keystore file
        /// </summary>
        /// <param name="parameters">
        /// Parameters Index
        /// </param>
        /// <returns></returns>
        public static bool RegisterWallet(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <path>\n", command)
            };

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

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

            try
            {
                string password = CommandLineUtil.ReadPasswordString("Please input wallet password");
                string confirm  = CommandLineUtil.ReadPasswordString("Please input confirm wallet password");

                if (!password.Equals(confirm))
                {
                    Console.WriteLine("Confirm password does not match");
                    return(true);
                }

                RpcApiResult result = RpcApi.RegisterWallet(password);
                Logout(null, null);

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


            return(true);
        }
コード例 #22
0
        /// <summary>
        /// Get information proposal list
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Offset
        /// [1] : Limit
        /// </param>
        /// <returns></returns>
        public static bool ListProposalPaginated(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 || parameters.Length != 2)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            try
            {
                int offset = int.Parse(parameters[0]);
                int limit  = int.Parse(parameters[1]);

                RpcApiResult result = RpcApi.ListProposalPaginated(offset,
                                                                   limit,
                                                                   out ProposalList proposals);
                if (result.Result)
                {
                    Console.WriteLine(PrintUtil.PrintProposalsList(proposals));
                }

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

            return(true);
        }
コード例 #23
0
ファイル: AssetIssueCommand.cs プロジェクト: lovecpus/mineral
        /// <summary>
        /// Create asset issue
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Name
        /// [1] : Description
        /// [2] : Url
        /// [3] : transaction count
        /// [4] : count
        /// [5] : Precision
        /// [6] : Total supply
        /// [7] : Free net limit
        /// [8] : public free net limit
        /// [9] : Start time
        /// [10] : End time
        /// [11-] : Pair frozen supply
        /// </param>
        /// <returns></returns>
        public static bool CreateAssetIssue(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] " +
                              "<name> <description> <url>" +
                              "<transaction count> <count>" +
                              "<precision>" +
                              "<total supply>" +
                              "<free net limit> <public free net limit>" +
                              "<start time> <end time>" +
                              "<amount 1> <days 1> <amount 2> <days 2> ...\n"
                              , command)
            };

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

            if (parameters == null || parameters.Length < 11 || parameters.Length % 2 == 0)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                int      i                 = 0;
                byte[]   owner_address     = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                string   name              = parameters[i++];
                string   description       = parameters[i++];
                string   url               = parameters[i++];
                long     total_supply      = long.Parse(parameters[i++]);
                int      tx_num            = int.Parse(parameters[i++]);
                int      num               = int.Parse(parameters[i++]);
                int      precision         = int.Parse(parameters[i++]);
                long     free_limit        = long.Parse(parameters[i++]);
                long     public_free_limit = long.Parse(parameters[i++]);
                DateTime start_time        = DateTime.ParseExact(parameters[i++], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                DateTime end_time          = DateTime.ParseExact(parameters[i++], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);

                Dictionary <long, long> frozen_supply = new Dictionary <long, long>();
                for (int j = i; j < parameters.Length; j += 2)
                {
                    frozen_supply.Add(
                        long.Parse(parameters[j + 0]),
                        long.Parse(parameters[j + 1])
                        );
                }

                RpcApiResult result = RpcApi.CreateAssetIssueContract(owner_address,
                                                                      name,
                                                                      description,
                                                                      url,
                                                                      tx_num,
                                                                      num,
                                                                      precision,
                                                                      0,
                                                                      total_supply,
                                                                      free_limit,
                                                                      public_free_limit,
                                                                      start_time.ToTimestamp(),
                                                                      end_time.ToTimestamp(),
                                                                      frozen_supply,
                                                                      out AssetIssueContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.AssetIssueContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #24
0
        /// <summary>
        /// Freeze balance
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Amount
        /// [1] : Duration time (day)
        /// [2] : Energy / Bandwidth        (default 0 : enerygy)
        /// [3] : Address                   (optional)
        /// </param>
        /// <returns></returns>
        public static bool FreezeBalance(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <amount> <duration> || [<energy/bandwidth>] || [<address>]\n", command)
            };

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

            if (parameters == null || parameters.Length < 2 || parameters.Length > 4)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] owner_address = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                byte[] address       = null;
                long   amount        = long.Parse(parameters[0]);
                long   duration      = long.Parse(parameters[1]);
                int    resource_code = 0;

                if (parameters.Length == 3)
                {
                    try
                    {
                        resource_code = int.Parse(parameters[2]);
                    }
                    catch
                    {
                        address = Wallet.Base58ToAddress(parameters[3]);
                    }
                }
                else if (parameters.Length == 4)
                {
                    resource_code = int.Parse(parameters[2]);
                    address       = Wallet.Base58ToAddress(parameters[3]);
                }

                RpcApiResult result = RpcApi.CreateFreezeBalanceContract(owner_address,
                                                                         address,
                                                                         amount,
                                                                         duration,
                                                                         resource_code,
                                                                         out FreezeBalanceContract contract);


                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.FreezeBalanceContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }
コード例 #25
0
        /// <summary>
        /// Send balance
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : To address
        /// [1] : Balance amount
        /// </param>
        /// <returns></returns>
        public static bool SendCoin(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <to address> <amount>\n", command)
            };

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

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

            if (!RpcApi.IsLogin)
            {
                return(true);
            }

            try
            {
                byte[] owner_address = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                byte[] to_address    = Wallet.Base58ToAddress(parameters[0]);
                long   amount        = long.Parse(parameters[1]);

                RpcApiResult result = RpcApi.CreateTransaferContract(owner_address,
                                                                     to_address,
                                                                     amount,
                                                                     out TransferContract contract);

                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.TransferContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

                if (result.Result)
                {
                    Console.WriteLine(
                        string.Format("Send {0} drop to {1} + successful. ", long.Parse(parameters[1]), parameters[0]));
                }
                else
                {
                    Console.WriteLine(
                        string.Format("Send {0} drop to {1} + failed. ", long.Parse(parameters[1]), parameters[0]));
                }

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

            return(true);
        }
コード例 #26
0
        /// <summary>
        /// UnFreeze balance
        /// </summary>
        /// <param name="parameters">
        /// Parameter Index
        /// [0] : Energy / Bandwidth        (default 0 : enerygy)
        /// [1] : Address                   (optional)
        /// </param>
        /// <returns></returns>
        public static bool UnFreezeBalance(string command, string[] parameters)
        {
            string[] usage = new string[] {
                string.Format("{0} [command option] <address>\n", command)
            };

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

            if (parameters == null || parameters.Length < 1 || parameters.Length > 2)
            {
                OutputHelpMessage(usage, null, command_option, null);
                return(true);
            }

            try
            {
                byte[] owner_address = Wallet.Base58ToAddress(RpcApi.KeyStore.Address);
                byte[] address       = null;
                int    resource_code = 0;

                if (parameters.Length == 1)
                {
                    try
                    {
                        resource_code = int.Parse(parameters[0]);
                    }
                    catch (System.Exception)
                    {
                        address = Wallet.Base58ToAddress(parameters[0]);
                    }
                }
                else if (parameters.Length == 2)
                {
                    resource_code = int.Parse(parameters[0]);
                    address       = Wallet.Base58ToAddress(parameters[1]);
                }


                RpcApiResult result = RpcApi.CreateUnfreezeBalanceContract(owner_address,
                                                                           address,
                                                                           resource_code,
                                                                           out UnfreezeBalanceContract contract);


                TransactionExtention transaction_extention = null;
                if (result.Result)
                {
                    result = RpcApi.CreateTransaction(contract,
                                                      ContractType.UnfreezeBalanceContract,
                                                      out transaction_extention);
                }

                if (result.Result)
                {
                    result = RpcApi.ProcessTransactionExtention(transaction_extention);
                }

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

            return(true);
        }