From 843c8fc133092c2de15d1174c66fafc1527b9a77 Mon Sep 17 00:00:00 2001 From: Cheran Date: Mon, 10 Jun 2024 18:35:10 +0530 Subject: [PATCH] Add grant role --- src/commands/admin/grantrole.ts | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/commands/admin/grantrole.ts diff --git a/src/commands/admin/grantrole.ts b/src/commands/admin/grantrole.ts new file mode 100644 index 0000000..a552fae --- /dev/null +++ b/src/commands/admin/grantrole.ts @@ -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 { + 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`); + } + } +}