Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 private static void BindingSetAuthInfo(RpcProtectionLevel level, RpcAuthentication[] authTypes,
                                        RpcHandle handle, string serverPrincipalName, NetworkCredential credentails)
 {
     if (credentails == null)
     {
         foreach (RpcAuthentication atype in authTypes)
         {
             RpcError result = RpcApi.RpcBindingSetAuthInfo2(handle.Handle, serverPrincipalName, level, atype, IntPtr.Zero, 0);
             if (result != RpcError.RPC_S_OK)
             {
                 Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message);
             }
         }
     }
     else
     {
         SEC_WINNT_AUTH_IDENTITY pSecInfo = new SEC_WINNT_AUTH_IDENTITY(credentails);
         foreach (RpcAuthentication atype in authTypes)
         {
             RpcError result = RpcApi.RpcBindingSetAuthInfo(handle.Handle, serverPrincipalName, level, atype, ref pSecInfo, 0);
             if (result != RpcError.RPC_S_OK)
             {
                 Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message);
             }
         }
     }
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private static void ServerRegisterInterface(RpcHandle handle, Guid iid, Delegate[] funcs, int maxCalls, int maxRequestBytes, bool allowAnonTcp)
        {
            const int RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH = 0x0010;
            int       flags  = 0;
            IntPtr    fnAuth = IntPtr.Zero;

            if (allowAnonTcp)
            {
                flags  = RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH;
                fnAuth = hAuthCall.Handle;
            }

            Ptr <RPC_SERVER_INTERFACE> sIf = MIDL_SERVER_INFO.Create(handle, iid, RpcApi.TYPE_FORMAT, RpcApi.FUNC_FORMAT, RpcApi.ASYNC_FUNC_OFFSETS, funcs);

            if (!allowAnonTcp && maxRequestBytes < 0)
            {
                RpcException.Assert(RpcApi.RpcServerRegisterIf(sIf.Handle, IntPtr.Zero, IntPtr.Zero));
            }
            else
            {
                RpcException.Assert(RpcApi.RpcServerRegisterIf2(sIf.Handle, IntPtr.Zero, IntPtr.Zero, flags,
                                                                maxCalls <= 0 ? MAX_CALL_LIMIT : maxCalls,
                                                                maxRequestBytes <= 0 ? 80 * 1024 : maxRequestBytes, fnAuth));
            }

            handle.Handle = sIf.Handle;
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 protected override void DisposeHandle(ref IntPtr handle)
 {
     if (handle != IntPtr.Zero)
     {
         RpcException.Assert(RpcApi.RpcBindingFree(ref Handle));
         handle = IntPtr.Zero;
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
0
 protected override void DisposeHandle(ref IntPtr handle)
 {
     if (handle != IntPtr.Zero)
     {
         RpcApi.RpcServerUnregisterIf(handle, IntPtr.Zero, 1);
         handle = IntPtr.Zero;
     }
 }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        /// <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);
        }
Ejemplo n.º 15
0
        /// <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);
        }
Ejemplo n.º 16
0
        public RpcError abortCall(uint exceptionCode)
        {
            if (AsyncContextStatus.InProgress != status)
            {
                throw new InvalidOperationException(String.Format("Invalid operation, the current state = {0}.", status));
            }
            RpcError result = RpcApi.RpcAsyncAbortCall(asyncState, exceptionCode);

            status = AsyncContextStatus.Aborted;
            return(result);
        }
Ejemplo n.º 17
0
        private static void ServerListen(int maxCalls)
        {
            Log.Verbose("Begin Server Listening");
            RpcError result = RpcApi.RpcServerListen(1, maxCalls, 1);

            if (result == RpcError.RPC_S_ALREADY_LISTENING)
            {
                result = RpcError.RPC_S_OK;
            }
            RpcException.Assert(result);
            Log.Verbose("Server Ready");
        }
Ejemplo n.º 18
0
        private static bool ServerRegisterAuthInfo(RpcAuthentication auth, string serverPrincName)
        {
            Log.Verbose("ServerRegisterAuthInfo({0})", auth);
            RpcError response = RpcApi.RpcServerRegisterAuthInfo(serverPrincName, (uint)auth, IntPtr.Zero, IntPtr.Zero);

            if (response != RpcError.RPC_S_OK)
            {
                Log.Warning("ServerRegisterAuthInfo - unable to register authentication type {0}", auth);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 19
0
        private static bool ServerUseProtseqEp(RpcProtseq protocol, int maxCalls, String endpoint)
        {
            Log.Verbose("ServerUseProtseqEp({0})", protocol);
            RpcError err = RpcApi.RpcServerUseProtseqEp(protocol.ToString(), maxCalls, endpoint, IntPtr.Zero);

            if (err != RpcError.RPC_S_DUPLICATE_ENDPOINT)
            {
                RpcException.Assert(err);
            }

            return(err == RpcError.RPC_S_OK);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        private static void ServerStopListening()
        {
            Log.Verbose("Stop Server Listening");
            RpcError result = RpcApi.RpcMgmtStopServerListening(IntPtr.Zero);

            if (result != RpcError.RPC_S_OK)
            {
                Log.Warning("RpcMgmtStopServerListening result = {0}", result);
            }
            result = RpcApi.RpcMgmtWaitServerListen();
            if (result != RpcError.RPC_S_OK)
            {
                Log.Warning("RpcMgmtWaitServerListen result = {0}", result);
            }
        }
Ejemplo n.º 24
0
        /// <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);
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
        protected override void putOutput(byte[] value)
        {
            if (null == value)
            {
                throw new ArgumentException("output data coulnd not be null.");
            }
            if (0 == value.Length)
            {
                throw new ArgumentException("output data coulnd not be empty.");
            }

            var buffer = RpcApi.Alloc((uint)value.Length);

            Marshal.Copy(value, 0, buffer, value.Length);
            Marshal.WriteIntPtr(_output, buffer);
            Marshal.WriteInt32(_cbOutput, value.Length);
        }
Ejemplo n.º 27
0
        private static String StringBindingCompose(RpcProtseq ProtSeq, String NetworkAddr, String Endpoint,
                                                   String Options)
        {
            IntPtr   lpBindingString;
            RpcError result = RpcApi.RpcStringBindingCompose(null, ProtSeq.ToString(), NetworkAddr, Endpoint, Options,
                                                             out lpBindingString);

            RpcException.Assert(result);

            try
            {
                return(Marshal.PtrToStringUni(lpBindingString));
            }
            finally
            {
                RpcException.Assert(RpcApi.RpcStringFree(ref lpBindingString));
            }
        }
Ejemplo n.º 28
0
        private void RpcEntryPoint2(IntPtr pAsyncState, IntPtr clientHandle, uint szInput, IntPtr input, out uint szOutput, out IntPtr output)
        {
            Console.WriteLine("RpcEntryPoint2");

            output   = IntPtr.Zero;
            szOutput = 0;

            try
            {
                byte[] bytesIn = new byte[szInput];
                Marshal.Copy(input, bytesIn, 0, bytesIn.Length);

                byte[] bytesOut;
                using (RpcClientInfo client = new RpcClientInfo(clientHandle))
                {
                    bytesOut = ExecuteAsync(client, pAsyncState, bytesIn);
                }
                if (bytesOut == null)
                {
                    var result = (IntPtr)RpcError.RPC_S_NOT_LISTENING;
                    RpcApi.RpcAsyncCompleteCall(pAsyncState, ref result);
                    return;
                }

                szOutput = (uint)bytesOut.Length;
                output   = RpcApi.Alloc(szOutput);
                Marshal.Copy(bytesOut, 0, output, bytesOut.Length);

                var result2 = (IntPtr)RpcError.RPC_S_OK;
                RpcApi.RpcAsyncCompleteCall(pAsyncState, ref result2);
                return;
            }
            catch (Exception ex)
            {
                RpcApi.Free(output);
                output   = IntPtr.Zero;
                szOutput = 0;

                Log.Error(ex);
                var result = (IntPtr)RpcError.RPC_S_OK;
                RpcApi.RpcAsyncCompleteCall(pAsyncState, ref result);
                return;
            }
        }
Ejemplo n.º 29
0
        public RpcError completeCall(byte[] value, uint exceptionCode)
        {
            if (AsyncContextStatus.InProgress != status)
            {
                throw new InvalidOperationException(String.Format("Invalid operation, the current state = {0}.", status));
            }

            if (null != value)
            {
                // write output payload
                putOutput(value);
            }

            var      rt     = (IntPtr)exceptionCode;
            RpcError result = RpcApi.RpcAsyncCompleteCall(asyncState, ref rt);

            status = AsyncContextStatus.Completed;
            return(result);
        }
Ejemplo n.º 30
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);
        }