コード例 #1
0
        public static async void TestTransfer(HttpMessage httpMessage)
        {
            if (Wallet.GetWallet().keys.Count < 1000)
            {
                for (int ii = Wallet.GetWallet().keys.Count; ii < 1000; ii++)
                {
                    Wallet.GetWallet().Create("123");
                }
                Wallet.GetWallet().SaveWallet();

                Log.Info("TestTransfer create");

                Session session2 = null;
                for (int ii = 1; ii < 1000; ii++)
                {
                    int random1 = 0;
                    int random2 = ii;
                    int random3 = 100000;

                    BlockSub transfer = new BlockSub();
                    transfer.type       = "transfer";
                    transfer.addressIn  = Wallet.GetWallet().keys[random1].ToAddress();
                    transfer.addressOut = Wallet.GetWallet().keys[random2].ToAddress();
                    transfer.amount     = random3.ToString();
                    transfer.data       = $"";
                    transfer.depend     = "";
                    transfer.nonce      = HttpRpc.GetAccountNotice(transfer.addressIn, false);
                    transfer.timestamp  = TimeHelper.Now();
                    transfer.hash       = transfer.ToHash();
                    transfer.sign       = transfer.ToSign(Wallet.GetWallet().keys[random1]);

                    session2 = await HttpRpc.OnTransferAsync2(transfer, session2);

                    while (session2 == null)
                    {
                        session2 = await HttpRpc.OnTransferAsync2(transfer, session2);
                    }
                    ;
                }
            }
            else
            {
                if (!HttpRpc.GetParam(httpMessage, "3", "Count", out string strCount))
                {
                    httpMessage.result = "command error! \nexample: test 5 Address C:\\Address.csv";
                    return;
                }
                TestTransfersyncCount = int.Parse(strCount);

                var consensus = Entity.Root.GetComponent <Consensus>();
                while (true)
                {
                    Log.Info($"Test2Async {TestTransfersyncCount}");
                    consensus.AddRunAction(TestTransfersync);
                    await Task.Delay(1000);
                }
            }
        }
コード例 #2
0
        public async override void Start()
        {
            timePass1 = new TimePass(0.1f);
            timePass2 = new TimePass(0.1f);

            pool     = Entity.Root.GetComponentInChild <Pool>();
            httpPool = Entity.Root.GetComponentInChild <HttpPool>();
            httpRpc  = Entity.Root.GetComponentInChild <HttpRpc>();
            pool.transferProcess.rulerRpc = rulerRpc;

            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(RunRegisterPool));
            thread.IsBackground = true;//设置为后台线程
            thread.Priority     = System.Threading.ThreadPriority.Normal;
            thread.Start(this);

            await Task.Delay(3000);

            Run();
        }
コード例 #3
0
        public static void Q2P_Transfer_Handle(Session session, int opcode, object msg)
        {
            Q2P_Transfer q2p_Transfer = msg as Q2P_Transfer;
            BlockSub     transfer     = JsonHelper.FromJson <BlockSub>(q2p_Transfer.transfer);

            R2P_Transfer r2p_Transfer = new R2P_Transfer()
            {
                rel = "-10000"
            };

            if (transfer.CheckSign())
            {
                var rel = Entity.Root.GetComponent <Rule>().AddTransfer(transfer);
                if (rel == -1)
                {
                    HttpRpc.OnTransferAsync(transfer);
                }
            }
            session.Reply(q2p_Transfer, r2p_Transfer);
        }
コード例 #4
0
        public static async void TestTransfersync()
        {
            Session session2     = null;
            var     accountCount = Wallet.GetWallet().keys.Count;
            //while (true)
            {
                session2 = null;
                for (int ii = 0; ii < TestTransfersyncCount; ii++)
                {
                    int random1 = RandomHelper.Range(1, accountCount);
                    int random2 = RandomHelper.Range(1, accountCount);
                    while (random1 == random2)
                    {
                        random2 = RandomHelper.Range(1, accountCount);
                    }
                    int random3 = RandomHelper.Range(1, 100);

                    BlockSub transfer = new BlockSub();
                    transfer.type       = "transfer";
                    transfer.addressIn  = Wallet.GetWallet().keys[random1].ToAddress();
                    transfer.addressOut = Wallet.GetWallet().keys[random2].ToAddress();
                    transfer.amount     = random3.ToString();
                    transfer.data       = "";
                    transfer.depend     = "";
                    transfer.nonce      = HttpRpc.GetAccountNotice(transfer.addressIn);
                    transfer.timestamp  = TimeHelper.Now();
                    transfer.hash       = transfer.ToHash();
                    transfer.sign       = transfer.ToSign(Wallet.GetWallet().keys[random1]);

                    session2 = await HttpRpc.OnTransferAsync2(transfer, session2);

                    while (session2 == null)
                    {
                        session2 = await HttpRpc.OnTransferAsync2(transfer, session2);
                    }
                    ;
                }
                //await Task.Delay(1000);
            }
        }
コード例 #5
0
        public static async void TestPledge(HttpMessage httpMessage)
        {
            if (Wallet.GetWallet().keys.Count < 1000)
            {
                for (int ii = Wallet.GetWallet().keys.Count; ii < 1000; ii++)
                {
                    Wallet.GetWallet().Create("123");
                }
                Wallet.GetWallet().SaveWallet();

                Log.Info("TestPledge create");

                Session session2 = null;
                for (int ii = 1; ii < 1000; ii++)
                {
                    int random1 = 0;
                    int random2 = ii;
                    int random3 = 100000;

                    BlockSub transfer = new BlockSub();
                    transfer.type       = "transfer";
                    transfer.addressIn  = Wallet.GetWallet().keys[random1].ToAddress();
                    transfer.addressOut = Wallet.GetWallet().keys[random2].ToAddress();
                    transfer.amount     = random3.ToString();
                    transfer.data       = $"";
                    transfer.depend     = "";
                    transfer.nonce      = HttpRpc.GetAccountNotice(transfer.addressIn, false);
                    transfer.timestamp  = TimeHelper.Now();
                    transfer.hash       = transfer.ToHash();
                    transfer.sign       = transfer.ToSign(Wallet.GetWallet().keys[random1]);

                    session2 = await HttpRpc.OnTransferAsync2(transfer, session2);

                    while (session2 == null)
                    {
                        session2 = await HttpRpc.OnTransferAsync2(transfer, session2);
                    }
                    ;
                }
            }
            else
            {
                var     consensus    = Entity.Root.GetComponent <Consensus>();
                var     accountCount = Wallet.GetWallet().keys.Count;
                Session session2     = null;
                while (true)
                {
                    Log.Info("TestPledge start");
                    session2 = null;
                    for (int ii = 0; ii < 200; ii++)
                    {
                        int random1 = RandomHelper.Range(1, accountCount);
                        int random2 = RandomHelper.Range(1, accountCount);
                        while (random1 == random2)
                        {
                            random2 = RandomHelper.Range(1, accountCount);
                        }

                        BlockSub transfer = new BlockSub();
                        transfer.type      = "contract";
                        transfer.addressIn = Wallet.GetWallet().keys[random1].ToAddress();
                        transfer.amount    = "";
                        transfer.depend    = "";
                        transfer.nonce     = HttpRpc.GetAccountNotice(transfer.addressIn);
                        transfer.timestamp = TimeHelper.Now();

                        var rules = consensus.GetRule(consensus.transferHeight).Select(x => x.Value.Contract).ToList();
                        rules.Remove("");
                        rules.Remove(null);

                        int callFunIndex = RandomHelper.Range(0, 3);
                        if (callFunIndex == 0)
                        {
                            int random3 = RandomHelper.Range(1, 1000);
                            transfer.data = $"addLiquidity(\"{random3}\",\"{random3}\")";

                            transfer.addressOut = rules[RandomHelper.Range(0, rules.Count) % rules.Count];
                        }
                        else
                        if (callFunIndex == 1)
                        {
                            int random3 = RandomHelper.Range(1, 1000);
                            transfer.data       = $"removeLiquidity(\"{random3}\")";
                            transfer.addressOut = rules[RandomHelper.Range(0, rules.Count) % rules.Count];
                        }
                        else
                        if (callFunIndex == 2)
                        {
                            int random3 = (int)consensus.transferHeight - RandomHelper.Range(1, 10);
                            transfer.data       = $"retrieved(\"{random3}\",\"{random3}\")";
                            transfer.addressOut = rules[RandomHelper.Range(0, rules.Count) % rules.Count];
                        }
                        else
                        if (callFunIndex == 3)
                        {
                            int random3 = (int)consensus.transferHeight - RandomHelper.Range(1, 10);
                            transfer.data       = $"diversionLiquidity(\"{random3}\",\"{rules[RandomHelper.Range(0, rules.Count) % rules.Count]}\")";
                            transfer.addressOut = rules[RandomHelper.Range(0, rules.Count) % rules.Count];
                        }
                        else
                        if (callFunIndex == 4)
                        {
                            int random3 = (int)consensus.transferHeight - RandomHelper.Range(1, 10);
                            transfer.data       = $"cancel(\"{rules[RandomHelper.Range(0, rules.Count) % rules.Count]}\",\"{random3}\")";
                            transfer.addressOut = consensus.PledgeFactory;
                        }

                        transfer.hash = transfer.ToHash();
                        transfer.sign = transfer.ToSign(Wallet.GetWallet().keys[random1]);

                        session2 = await HttpRpc.OnTransferAsync2(transfer, session2);

                        while (session2 == null)
                        {
                            session2 = await HttpRpc.OnTransferAsync2(transfer, session2);
                        }
                        ;
                    }
                    await Task.Delay(1000);
                }
            }
        }