瀏覽代碼

factoryObj单例设计模式

龚成明 3 年之前
父節點
當前提交
315256eed9
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      scripts/core/pullAndPush.ts

+ 9 - 1
scripts/core/pullAndPush.ts

@@ -138,6 +138,14 @@ export class PullAndPush {
     return true
   }
 
+  parseFactory(router: any, factoryAbi: any, factoryAddress: any) {
+    if (router.factoryObj == null) {
+      router.factoryObj = new web3.eth.Contract(factoryAbi, factoryAddress)
+    }
+
+    return router.factoryObj
+  }
+
   async run() {
     logger.debug('Pull v2 start.')
 
@@ -153,7 +161,7 @@ export class PullAndPush {
 
         const v2FactoryAddress = routerObj.factory
         // 获取工厂实例
-        const v2Factory = new web3.eth.Contract(v2FactoryAbi, v2FactoryAddress)
+        const v2Factory = this.parseFactory(routerObj, v2FactoryAbi, v2FactoryAddress)
         // 获取当前pull状态
         let position = this.fromHead ? 0 : await this.handlePosition(routerObj.router, v2FactoryAddress)
         // 获取当前pairsLength