Beispiel #1
0
        public static void Q2P_BeLinkHash_Handle(Session session, int opcode, object msg)
        {
            Q2P_BeLinkHash q2q_McBlockHash = msg as Q2P_BeLinkHash;
            R2P_BeLinkHash r2p_McBlockHash = new R2P_BeLinkHash();

            var consensus = Entity.Root.GetComponent <Consensus>();
            var blockMgr  = Entity.Root.GetComponent <BlockMgr>();

            Block        mcbkl  = blockMgr.GetBlock(q2q_McBlockHash.hash);
            double       t_1max = consensus.GetRuleCount(mcbkl.height + 1);
            List <Block> blks   = blockMgr.GetBlock(mcbkl.height + 1);

            blks = BlockChainHelper.GetRuleBlk(consensus, blks, mcbkl.hash);


            string[] hashs = blks.Select(a => a.hash).ToArray();
            r2p_McBlockHash.hashs = JsonHelper.ToJson(hashs);

            session.Reply(q2q_McBlockHash, r2p_McBlockHash);
        }
Beispiel #2
0
        public async Task <List <string> > QueryBeLinkHash(string hash, string ipEndPoint = null)
        {
            Q2P_BeLinkHash q2p_BeLinkHash = new Q2P_BeLinkHash();

            q2p_BeLinkHash.ActorId = nodeManager.GetMyNodeId();
            q2p_BeLinkHash.hash    = hash;

            Session session = null;

            if (ipEndPoint != null && ipEndPoint != "")
            {
                session = await networkInner.Get(NetworkHelper.ToIPEndPoint(ipEndPoint));
            }
            if (session != null && !session.IsConnect())
            {
                session = null;
            }

            if (session == null)
            {
                NodeManager.NodeData node = nodeManager.GetRandomNode();
                if (node != null)
                {
                    session = await networkInner.Get(NetworkHelper.ToIPEndPoint(node.ipEndPoint));
                }
            }

            if (session != null)
            {
                R2P_BeLinkHash r2p_BeLinkHash = (R2P_BeLinkHash)await session.Query(q2p_BeLinkHash);

                if (r2p_BeLinkHash != null && r2p_BeLinkHash.hashs != null && r2p_BeLinkHash.hashs != "")
                {
                    return(JsonHelper.FromJson <List <string> >(r2p_BeLinkHash.hashs));
                }
            }

            return(null);
        }