Skip to content

Commit

Permalink
Add from and options to module methods
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Sep 23, 2020
1 parent 565039e commit d091af1
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/CPK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,28 +320,57 @@ class CPK {
if (!this.#contract) {
throw new Error('CPK contract uninitialized')
}
return this.#contract.call('getModules', [])
const modules = await this.#contract.call('getModules', [])
return modules
}

async isSafeModuleEnabled(moduleAddress: Address): Promise<boolean> {
if (!this.#contract) {
throw new Error('CPK contract uninitialized')
}
return this.#contract.call('isModuleEnabled', [moduleAddress])
const modules = await this.#contract.call('getModules', [])
const selectedModules = modules.filter(
(mod: Address) => mod.toLowerCase() === moduleAddress.toLocaleLowerCase()
)
return selectedModules.length > 0
}

async enableSafeModule(moduleAddress: Address): Promise<TransactionResult> {
async enableSafeModule(
moduleAddress: Address,
options?: ExecOptions
): Promise<TransactionResult> {
if (!this.#contract) {
throw new Error('CPK contract uninitialized')
}
return this.#contract.send('enableModule', [moduleAddress])
const ownerAccount = await this.getOwnerAccount()
if (!ownerAccount) {
throw new Error('CPK ownerAccount uninitialized')
}
const sendOptions = normalizeGasLimit({ ...options, from: ownerAccount })
const txResult = await this.#contract.send('enableModule', [moduleAddress], {
...sendOptions,
from: ownerAccount
})
return txResult
}

async disableSafeModule(moduleAddress: Address): Promise<TransactionResult> {
async disableSafeModule(
moduleAddress: Address,
options?: ExecOptions
): Promise<TransactionResult> {
if (!this.#contract) {
throw new Error('CPK contract uninitialized')
}
return this.#contract.send('disableModule', [moduleAddress])
const ownerAccount = await this.getOwnerAccount()
if (!ownerAccount) {
throw new Error('CPK ownerAccount uninitialized')
}
const sendOptions = normalizeGasLimit({ ...options, from: ownerAccount })
const txResult = await this.#contract.send('disableModule', [moduleAddress], {
...sendOptions,
from: ownerAccount
})
return txResult
}

private getSafeExecTxParams(transactions: Transaction[]): StandardTransaction {
Expand Down

0 comments on commit d091af1

Please sign in to comment.