private void CreateSpider(UInt160 chainHash) { if (!spiders.ContainsKey(chainHash)) { ZoroSystem system = ZoroChainSystem.Singleton.GetZoroSystem(chainHash); if (system != null) { IActorRef logger = system.ActorOf(Spider.Props(this, system.Blockchain, chainHash)); spiders.TryAdd(chainHash, logger); } } TransactionDal tran = new TransactionDal(); try { tran.BeginTransaction(); AppChainListSpider appChainListSpider = new AppChainListSpider(); appChainListSpider.Start(tran.conn); tran.CommitTransaction(); } catch (Exception e) { tran.RollbackTransaction(); throw e; } }
protected override void OnReceive(object message) { TransactionDal tran = null; if (message is Blockchain.ApplicationExecuted log) { tran.BeginTransaction(); foreach (var notify in log.ExecutionResults) { saveNotify.Save(tran.conn, JObject.Parse(notify.ToString())); } tran.CommitTransaction(); tran.DisposeTransaction(); } else if (message is Blockchain.PersistCompleted block) { tran.BeginTransaction(); JObject jObject = block.Block.ToJson(); saveBlock.Save(tran.conn, jObject, block.Block.Index); tran.CommitTransaction(); tran.DisposeTransaction(); } }
private uint GetBlock(uint height) { try { Block block = blockchain.Store.GetBlock(height); JObject json = block.ToJson(); json["confirmations"] = blockchain.Height - block.Index + 1; UInt256 hash = blockchain.Store.GetNextBlockHash(block.Hash); if (hash != null) { json["nextblockhash"] = hash.ToString(); } tran = new TransactionDal(); tran.BeginTransaction(); { this.block.Save(tran.conn, json, height); //每获取一个块做一次高度记录,方便下次启动时做开始高度 listHeight.Save(tran.conn, chainHash.ToString(), height.ToString()); } tran.CommitTransaction(); tran.DisposeTransaction(); return(height + 1); } catch (MySqlException e) { retryNum++; LogConfig.Log($"error occured when call getblock {height} {chainHash}, reason:{e.Message}", LogConfig.LogLevel.Error); tran.RollbackTransaction(); if (retryNum > 1) { throw e; } return(GetBlock(height)); } }