Browse Source

factoryObj单例设计模式

龚成明 3 years ago
parent
commit
315256eed9
1 changed files with 9 additions and 1 deletions
  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