Пример #1
0
        public Module_RPC(AllPet.Common.ILogger logger, Newtonsoft.Json.Linq.JObject configJson) : base(true)
        {
            this.logger = logger;
            this.config = new Config_Module(configJson);
            this.server = new http.server.httpserver();

            this.recvRPC = new System.Collections.Concurrent.ConcurrentDictionary <int, MessagePackObject?>();
            this.RPCID   = 0;
        }
Пример #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();
        }