Ejemplo n.º 1
0
        public void GetPool(HttpMessage httpMessage)
        {
            Dictionary <string, BlockSub> transfers = Entity.Root.GetComponent <Rule>().GetTransfers();

            httpMessage.result = JsonHelper.ToJson(transfers);
        }
Ejemplo n.º 2
0
        public void OnHttpMessage(Session session, int opcode, object msg)
        {
            HttpMessage httpMessage = msg as HttpMessage;

            if (httpMessage == null || httpMessage.request == null || networkHttp == null ||
                httpMessage.request.LocalEndPoint.ToString() != networkHttp.ipEndPoint.ToString())
            {
                return;
            }

            string cmd = httpMessage.map["cmd"].ToLower();

            switch (cmd)
            {
            case "account":
                OnAccount(httpMessage);
                break;

            case "stats":
                OnStats(httpMessage);
                break;

            case "rules":
                OnRules(httpMessage);
                break;

            case "transfer":
                OnTransfer(httpMessage);
                break;

            case "transferstate":
                OnTransferState(httpMessage);
                break;

            case "beruler":
                OnBeRuler(httpMessage);
                break;

            //case "getmnemonicword":
            //    GetMnemonicWord(httpMessage);
            //    break;
            case "command":
                Command(httpMessage);
                break;

            case "gettransfers":
                GetTransfers(httpMessage);
                break;

            case "getaccounts":
                GetAccounts(httpMessage);
                break;

            case "getnearblock":
                GetNearBlock(httpMessage);
                break;

            case "node":
                OnNode(httpMessage);
                break;

            case "getblock":
                GetBlock(httpMessage);
                break;

            case "getproperty":
                OnProperty(httpMessage);
                break;

            case "getliquidity":
                OnLiquidityOf(httpMessage);
                break;

            case "balanceof":
                balanceOf(httpMessage);
                break;

            case "callfun":
                callFun(httpMessage);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
 public async void TestBeRule(HttpMessage httpMessage)
 {
     httpMessage.result = "";
     await Task.Delay(10);
 }
Ejemplo n.º 4
0
        // console 支持
        public void Command(HttpMessage httpMessage)
        {
            httpMessage.result = "command error!";

            string input = httpMessage.map["input"];

            input = input.Replace("%20", " ");
            input = input.Replace("  ", " ");
            input = input.Replace("   ", " ");
            input = input.Replace("  ", " ");

            string[] array = input.Split(' ');

            if (input.IndexOf("-") != -1)
            {
                for (int ii = 1; ii < array.Length; ii++)
                {
                    string[] arrayValue = array[ii].Split(':');
                    if (arrayValue != null && arrayValue.Length >= 1)
                    {
                        httpMessage.map.Remove(arrayValue[0].Replace("-", ""));
                        httpMessage.map.Add(arrayValue[0].Replace("-", ""), arrayValue.Length >= 2 ? arrayValue[1] : "");
                    }
                }
            }
            else
            {
                for (int ii = 1; ii < array.Length; ii++)
                {
                    string arrayValue = array[ii];
                    httpMessage.map.Remove("" + ii);
                    httpMessage.map.Add("" + ii, arrayValue);
                }
            }

            string cmd = array[0].ToLower();

            switch (cmd)
            {
            case "account":
                OnAccount(httpMessage);
                break;

            case "stats":
                OnStats(httpMessage);
                break;

            case "rules":
                OnRules(httpMessage);
                break;

            //case "transfer":
            //    OnTransfer(httpMessage);
            //    break;
            case "transferstate":
                OnTransferState(httpMessage);
                break;

            case "beruler":
                OnBeRuler(httpMessage);
                break;

            //case "getmnemonic":
            //    GetMnemonicWord(httpMessage);
            //    break;
            case "node":
                OnNode(httpMessage);
                break;

            case "miner":
                OnMiner(httpMessage);
                break;

            case "getblock":
                GetBlock(httpMessage);
                break;

            case "test":
                Test(httpMessage);
                break;

            case "delblock":
                DelBlock(httpMessage);
                break;

            case "mergechain":
                MergeChain(httpMessage);
                break;

            case "dbreset":
                onDBReset(httpMessage);
                break;

            case "pool":
                GetPool(httpMessage);
                break;

            case "search":
                OnSearch(httpMessage);
                break;

            case "callFun":
                callFun(httpMessage);
                break;

            case "outleveldb":
                OutLeveldb(httpMessage);
                break;

            case "hello":
            {
                httpMessage.result = "welcome join SmartX";
            }
            break;

            case "help":
            {
                httpMessage.result = "you can use Command menu";
            }
            break;

            default:
                break;
            }

            //httpMessage.result = "ok";
        }
Ejemplo n.º 5
0
        public void Test(HttpMessage httpMessage)
        {
            if (!GetParam(httpMessage, "1", "password", out string password))
            {
                httpMessage.result = "command error! \nexample: test 1 Address C:\\Address.csv";
                return;
            }
            if (!Wallet.GetWallet().IsPassword(password))
            {
                return;
            }

            if (!GetParam(httpMessage, "2", "style", out string style))
            {
                httpMessage.result = "command error! \nexample: test 1 Address C:\\Address.csv";
                return;
            }

            httpMessage.result = "";
            if (style == "1")
            {
                if (!GetParam(httpMessage, "3", "Address", out string Address))
                {
                    httpMessage.result = "command error! \nexample: test 1 Address C:\\Address.csv";
                    return;
                }
                if (!GetParam(httpMessage, "4", "file", out string file))
                {
                    httpMessage.result = "command error! \nexample: test 1 Address C:\\Address.csv";
                    return;
                }

                LevelDBStore.Export2CSV_Transfer($"{file}", Address);
            }
            else
            if (style == "2")
            {
                OneThreadSynchronizationContext.Instance.Post(this.Test2Async, null);
            }
            else
            if (style == "3")
            {
                OneThreadSynchronizationContext.Instance.Post(this.Test3Async, null);
            }
            else
            if (style == "4")
            {
                LevelDBStore.Export2CSV_Accounts($"C:\\Accounts_test4.csv");
            }
            else
            if (style == "5")
            {
                if (!GetParam(httpMessage, "3", "Address", out string Address))
                {
                    httpMessage.result = "command error! \nexample: test 5 Address C:\\Address.csv";
                    return;
                }
                if (!GetParam(httpMessage, "4", "file", out string file))
                {
                    httpMessage.result = "command error! \nexample: test 5 Address C:\\Address.csv";
                    return;
                }
                LevelDBStore.Export2CSV_Account($"{file}", Address);
            }
            else
            if (style == "rule")
            {
                TestBeRule(httpMessage);
            }
        }
Ejemplo n.º 6
0
        // console 支持

        public void OnStats(HttpMessage httpMessage)
        {
            if (!GetParam(httpMessage, "1", "style", out string style))
            {
                style = "";
            }
            Dictionary <string, object> result = new Dictionary <string, object>();
            string  address = Wallet.GetWallet().GetCurWallet().ToAddress();
            Account account = null;

            using (DbSnapshot dbSnapshot = Entity.Root.GetComponent <LevelDBStore>().GetSnapshot(0))
            {
                account = dbSnapshot.Accounts.Get(address);
            }

            var rule   = Entity.Root.GetComponent <Rule>();
            var pool   = Entity.Root.GetComponent <Pool>();
            var amount = account != null ? account.amount : "0";

            long.TryParse(Entity.Root.GetComponent <LevelDBStore>().Get("UndoHeight"), out long UndoHeight);
            long   PoolHeight = rule.height;
            string power1     = rule.calculatePower.GetPower();
            string power2     = Entity.Root.GetComponent <Consensus>().calculatePower.GetPower();

            int NodeCount = Entity.Root.GetComponent <NodeManager>().GetNodeCount();

            if (style == "")
            {
                result.Add("AlppyHeight", UndoHeight);
                result.Add("PoolHeight", PoolHeight);
                result.Add("Calculate Power", $"{power1}of{power2}");
                result.Add("Account", $"{ address},{amount}");
                result.Add("Node", NodeCount);
                result.Add("Rule.Transfer", rule?.GetTransfersCount());
                result.Add("Pool.Transfer", pool?.GetTransfersCount());
                httpMessage.result = JsonHelper.ToJson(result);
                //httpMessage.result = $"      AlppyHeight: {UndoHeight}\n" +
                //                        $"       PoolHeight: {PoolHeight}\n" +
                //                        $"  Calculate Power: {power1} of {power2}\n" +
                //                        $"          Account: {address}, {amount}\n" +
                //                        $"             Node: {NodeCount}\n" +
                //                        $"    Rule.Transfer: {rule?.GetTransfersCount()}\n" +
                //                        $"    Pool.Transfer: {pool?.GetTransfersCount()}";
            }
            else
            if (style == "1")
            {
                result.Add("H", UndoHeight);
                result.Add("P", power2);
                httpMessage.result = JsonHelper.ToJson(result);
                //httpMessage.result = $"H:{UndoHeight} P:{power2}";
            }
            else
            if (style == "2")
            {
                var httpPool = Entity.Root.GetComponent <HttpPool>();
                var miners   = httpPool.GetMinerReward(out long miningHeight);
                result.Add("H", UndoHeight);
                result.Add("P", power2);
                result.Add("P1", power1);
                result.Add("Miner", miners?.Count);
                httpMessage.result = JsonHelper.ToJson(result);
                //httpMessage.result = $"H:{UndoHeight} P:{power2} Miner:{miners?.Count}";
            }
        }
Ejemplo n.º 7
0
        public void OnHttpMessage(Session session, int opcode, object msg)
        {
            HttpMessage httpMessage = msg as HttpMessage;

            if (httpMessage == null || httpMessage.request == null || networkHttp == null ||
                httpMessage.request.LocalEndPoint.ToString() != networkHttp.ipEndPoint.ToString())
            {
                return;
            }

            string cmd = null;

            //httpMessage.map.TryGetValue("v1.0.0/global-info", out cmd);
            httpMessage.map.TryGetValue("cmd", out cmd);
            cmd = cmd.ToLower();

            switch (cmd)
            {
            case "contract":
                OnContractTran(httpMessage);
                break;

            case "checktran":
                checkTran(httpMessage);
                break;

            case "account":
                OnAccount(httpMessage);
                break;

            case "stats":
                OnStats(httpMessage);
                break;

            case "rules":
                OnRules(httpMessage);
                break;

            case "transfer":
                OnTransfer(httpMessage);
                break;

            case "transferstate":
                OnTransferState(httpMessage);
                break;

            case "beruler":
                OnBeRuler(httpMessage);
                break;

            case "gettransfers":
                GetTransfers(httpMessage);
                break;

            case "getnearblock":
                GetNearBlock(httpMessage);
                break;

            case "node":
                OnNode(httpMessage);
                break;

            case "getblock":
                GetBlock(httpMessage);
                break;

            case "balance":
                OnBalance(httpMessage);
                break;

            case "balanceof":
                balanceOf(httpMessage);    //获取代币信息
                break;

            case "callfun":    //创建代币
                callFun(httpMessage);
                break;

            case "global-info":     //信息
                OnGlobal_info(httpMessage);
                break;

            case "latest-block":     //获取交易的列表
                OnLatest_block(httpMessage);
                break;

            case "block-by-hash":     //根据主块查询信息
                OnBlockHash(httpMessage);
                break;

            case "getnonce":     //根据主块查询信息
                OnGetNonce(httpMessage);
                break;

            case "getproperty":     //根据地址查询所拥有的代币
                OnProperty(httpMessage);
                break;

            case "getliquidity":    //获取质押可约
                OnLiquidityOf(httpMessage);
                break;

            case "block-by-tranhash":     //根据交易查询 交易的信息
                OnBlocktranHash(httpMessage);
                break;

            case "transactions":     //根据地址查询该地址的交易记录
                OnTransactions(httpMessage);
                break;

            case "info":      //info
                OnInfo(httpMessage);
                break;

            case "latest-block-height":    //latest-block-height
                OnLatestBlockHeight(httpMessage);
                break;

            case "transfercount":
                OnTransferCount(httpMessage);
                break;

            case "miner":
                OnMiner(httpMessage);
                break;

            case "mempool":
                GetPool(httpMessage);
                break;

            case "search":
                OnSearch(httpMessage);
                break;

            case "getlastblock":
                GetNearBlock(httpMessage);
                break;

            case "adressreg":
                AdressReg(httpMessage);
                break;

            case "outleveldb":
                OutLeveldb(httpMessage);
                break;

            case "hello":
            {
                httpMessage.result = "welcome join SmartX.net";
            }
            break;

            default:
                break;
            }
        }