Ejemplo n.º 1
0
        /// <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);
        }