Skip to content

Commit

Permalink
Improve the WalletRegistry.getWalletPublicKey fn
Browse files Browse the repository at this point in the history
Skip retrying when the contract throws an error saying the wallet with
the given ID has not been registered. There is no need to retry this
request because the contract responds with the exact reason - the wallet
does not exist.
  • Loading branch information
r-czajkowski committed Jul 26, 2024
1 parent f364b70 commit 3c1af2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions typescript/api-reference/classes/EthereumWalletRegistry.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ WalletRegistry.getDkgResultApprovedEvents

#### Defined in

[lib/ethereum/wallet-registry.ts:126](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L126)
[lib/ethereum/wallet-registry.ts:129](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L129)

___

Expand All @@ -207,7 +207,7 @@ WalletRegistry.getDkgResultChallengedEvents

#### Defined in

[lib/ethereum/wallet-registry.ts:151](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L151)
[lib/ethereum/wallet-registry.ts:154](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L154)

___

Expand All @@ -234,7 +234,7 @@ WalletRegistry.getDkgResultSubmittedEvents

#### Defined in

[lib/ethereum/wallet-registry.ts:83](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L83)
[lib/ethereum/wallet-registry.ts:86](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L86)

___

Expand Down
19 changes: 11 additions & 8 deletions typescript/src/lib/ethereum/wallet-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ChainIdentifier,
Chains,
} from "../contracts"
import { backoffRetrier, Hex } from "../utils"
import { backoffRetrier, Hex, skipRetryWhenMatched } from "../utils"
import { Event as EthersEvent } from "@ethersproject/contracts"
import { BigNumber } from "ethers"
import {
Expand Down Expand Up @@ -66,13 +66,16 @@ export class EthereumWalletRegistry
* @see {WalletRegistry#getWalletPublicKey}
*/
async getWalletPublicKey(walletID: Hex): Promise<Hex> {
const publicKey = await backoffRetrier<string>(this._totalRetryAttempts)(
async () => {
return await this._instance.getWalletPublicKey(
walletID.toPrefixedString()
)
}
)
const publicKey = await backoffRetrier<string>(
this._totalRetryAttempts,
undefined,
undefined,
skipRetryWhenMatched(["Wallet with the given ID has not been registered"])
)(async () => {
return await this._instance.getWalletPublicKey(
walletID.toPrefixedString()
)
})
return Hex.from(publicKey.substring(2))
}

Expand Down

0 comments on commit 3c1af2c

Please sign in to comment.