-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d17825
commit 843c8fc
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Arg } from "@oclif/core/lib/interfaces"; | ||
import { ethers } from "ethers"; | ||
import { TransactionCommand } from "../../base"; | ||
import { getSigner, parseAddress, pretty, run } from "../../helpers"; | ||
|
||
export default class GrantRole extends TransactionCommand { | ||
static summary = "Grant a role to an account on the Armada Network."; | ||
static examples = [ | ||
"<%= config.bin %> <%= command.id %> RECONCILER_ROLE 0x0000000000000000000000000000000000000000 0xContractAddress", | ||
]; | ||
static usage = "<%= command.id %> ROLE ACCOUNT CONTRACT_ADDRESS"; | ||
static args: Arg[] = [ | ||
{ name: "ROLE", description: "The role to grant.", required: true }, | ||
{ name: "ACCOUNT", description: "The address to grant the role to.", required: true }, | ||
{ name: "CONTRACT_ADDRESS", description: "The address of the contract.", required: true }, | ||
]; | ||
|
||
public async run(): Promise<unknown> { | ||
const { args, flags } = await this.parse(GrantRole); | ||
|
||
const signer = await getSigner(flags.network, flags.rpc, flags.address, flags.signer, flags.key, flags.account); | ||
const abi = ["function grantRole(bytes32 role, address account) external"]; | ||
const contract = new ethers.Contract(args.CONTRACT_ADDRESS, abi, signer); | ||
|
||
const role = ethers.utils.id(args.ROLE); | ||
const account = parseAddress(args.ACCOUNT); | ||
|
||
try { | ||
const tx = await contract.populateTransaction.grantRole(role, account); | ||
const output = await run(tx, signer, [contract]); | ||
this.log(pretty(output)); | ||
return output; | ||
} catch (e) { | ||
this.error(`Error granting role`); | ||
} | ||
} | ||
} |