Beispiel #1
0
        /// <summary>
        /// 根据data得到挑选 dataserver
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        IModulePipeline getServer(byte[] data)
        {
            int hash = Helper_NEO.CalcHash256(data).GetHashCode() % serverPath.Count;
            var path = serverPath[hash];

            return(this.DataServerDic[path]);
        }
Beispiel #2
0
        public Module_Node(AllPet.Common.ILogger logger, Newtonsoft.Json.Linq.JObject configJson) : base(true)
        {
            this.guid      = Helper_NEO.CalcHash256(Guid.NewGuid().ToByteArray());
            this.logger    = logger;
            this.config    = new Config_Module(configJson);
            this.chainHash = Helper_NEO.CalcHash256(this.config.ChainInfo.ToInitScript());
            //this.config = new Config_ChainInit(configJson);
            this.linkNodes   = new System.Collections.Concurrent.ConcurrentDictionary <ulong, LinkObj>();
            this.provedNodes = new System.Collections.Concurrent.ConcurrentDictionary <ulong, LinkObj>();
            this.linkIDs     = new System.Collections.Concurrent.ConcurrentDictionary <string, ulong>();
            this.listCanlink = new Struct.ThreadSafeQueueWithKey <CanLinkObj>();

            try
            {
                if (configJson.ContainsKey("Key_Nep2") && configJson.ContainsKey("Key_Password"))
                {
                    var nep2     = configJson["Key_Nep2"].AsString();
                    var password = configJson["Key_Password"].AsString();
                    this.prikey = Helper_NEO.GetPrivateKeyFromNEP2(nep2, password);
                    this.pubkey = Helper_NEO.GetPublicKey_FromPrivateKey(prikey);
                    //区分记账人
                    var address = Helper_NEO.GetAddress_FromPublicKey(pubkey); //证明人的地址
                                                                               //如果证明人的地址和初始记账人的地址相同即为记账人
                    if (this.config.ChainInfo.InitOwner.Contains(address))
                    {
                        this.isProved = true;
                        this.pLevel   = 0;//记账节点
                    }
                }
                //return;
                blockChain = new BlockChain();
                blockChain.InitChain(this.config.SimpleDbPath, this.config.ChainInfo);
                this.blockIndex = blockChain.GetBlockCount();

                //记账节点才需要出块
                if (this.isProved)
                {
                    this.blockTimer           = new System.Timers.Timer();
                    this.blockTimer.Interval  = blockTime * 1000; //毫秒
                    this.blockTimer.Enabled   = true;
                    this.blockTimer.AutoReset = true;             //一直执行true
                    this.blockTimer.Elapsed  += new System.Timers.ElapsedEventHandler(MakeBlock);
                    this.blockTimer.Start();
                }
            }
            catch (Exception err)
            {
                logger.Error("Error in Get Prikey:" + err.ToString());
                throw new Exception("error in get prikey.", err);
            }

            this.txpool = new Node.TXPool();
            ResetCanlinkList();
        }
        public void AddTx(Transaction trans)
        {
            //第一步,验证交易合法性,合法就收

            //第二步,验证Hash是否已经存在
            var txid = Helper_NEO.CalcHash256(trans.message);

            if (TXData.ContainsKey(txid))
            {
                //txpoolcount++;
                return;
            }
            //第三步,放进去并调整MaxTransactionID
            TXData.TryAdd(txid, trans);
            map_tx2index.TryAdd(MaxTransactionID, txid);
            MaxTransactionID++;
        }