zkopru-network / zkopru

Ethereum L2 scaling solution for private transactions using zk-SNARK and optimistic rollup.
https://zkopru.network
GNU General Public License v3.0
217 stars 28 forks source link

[fix] add async constructor to zk-wallet and zk-wallet-account #389

Closed tkmct closed 2 years ago

tkmct commented 2 years ago

Currently, ZkWalletAccount has unresolved promise inside its constructor and it's cumbersome to manually wait them resolved outside. For example, the code using ZkWalletAccount has to be check the if the promise returned by this.node.tracker.addAccounts(account) resolved or not by checking length of tracker.transferTrackers doing something similar to following code.

const wallet = new ZkWalletAccount(config)
await new Promise((resolve) => {
  // polling to check the transferTrackers length
  setInterval(() => {
    if (wallet.node.tracker.transferTrackers === 1)  {
      clearInterval(); resolve()
    }, 500)
})

// now wallet is initialized properly.

Instead of doing this, implement async constructor and wait it initialized. and this can be used like this

const wallet = await ZkWalletAccount.new(config)