genlayer
Version:
GenLayer Command Line Tool
47 lines (37 loc) • 1.39 kB
text/typescript
import {StakingAction, StakingConfig} from "./StakingAction";
import type {Address} from "genlayer-js/types";
import {abi} from "genlayer-js";
export interface SetOperatorOptions extends StakingConfig {
validator: string;
operator: string;
}
export class SetOperatorAction extends StakingAction {
constructor() {
super();
}
async execute(options: SetOperatorOptions): Promise<void> {
this.startSpinner("Setting operator...");
try {
const validatorWallet = options.validator as Address;
const {walletClient, publicClient} = await this.getViemClients(options);
this.setSpinnerText(`Setting operator to ${options.operator}...`);
const hash = await walletClient.writeContract({
address: validatorWallet,
abi: abi.VALIDATOR_WALLET_ABI,
functionName: "setOperator",
args: [options.operator as Address],
});
const receipt = await publicClient.waitForTransactionReceipt({hash});
const output = {
transactionHash: receipt.transactionHash,
validator: validatorWallet,
newOperator: options.operator,
blockNumber: receipt.blockNumber.toString(),
gasUsed: receipt.gasUsed.toString(),
};
this.succeedSpinner("Operator updated!", output);
} catch (error: any) {
this.failSpinner("Failed to set operator", error.message || error);
}
}
}