Skip to content

Commit e81f451

Browse files
committed
add-list-remove operator
1 parent d2fc071 commit e81f451

File tree

9 files changed

+132
-11
lines changed

9 files changed

+132
-11
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as Vorpal from "vorpal";
2+
import { addOperatorToReferee, getSignerFromPrivateKey } from "@xai-vanguard-node/core";
3+
4+
/**
5+
* Function to add an operator to the Referee contract.
6+
* @param cli - Vorpal instance
7+
*/
8+
export function addOperator(cli: Vorpal) {
9+
cli
10+
.command('add-operator', 'Adds an operator to the Referee contract.')
11+
.action(async function (this: Vorpal.CommandInstance) {
12+
const {operatorAddress} = await this.prompt({
13+
type: 'input',
14+
name: 'operatorAddress',
15+
message: 'Operator address to be added:'
16+
});
17+
18+
const {privateKey} = await this.prompt({
19+
type: 'password',
20+
name: 'privateKey',
21+
message: 'Private key of the current address that you want to add the operator to:',
22+
mask: '*',
23+
});
24+
25+
if (!operatorAddress || !privateKey) {
26+
this.log('Both operator address and private key are required.');
27+
return;
28+
}
29+
30+
this.log(`Adding operator ${operatorAddress} to the Referee contract...`);
31+
32+
// Create a signer with the private key
33+
const { signer } = getSignerFromPrivateKey(privateKey);
34+
35+
// Call the addOperatorToReferee function to add the operator to the Referee contract
36+
await addOperatorToReferee(operatorAddress, true, signer);
37+
38+
this.log(`Operator ${operatorAddress} has been added to the Referee contract.`);
39+
});
40+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as Vorpal from "vorpal";
2+
import { listOperatorsForAddress } from "@xai-vanguard-node/core";
3+
4+
/**
5+
* Function to list all operators for a particular address in the Referee contract.
6+
* @param cli - Vorpal instance
7+
*/
8+
export function listOperators(cli: Vorpal) {
9+
cli
10+
.command('list-operators', 'Lists all operators for a particular address in the Referee contract.')
11+
.action(async function (this: Vorpal.CommandInstance) {
12+
const {address} = await this.prompt({
13+
type: 'input',
14+
name: 'address',
15+
message: 'Please enter the address to list operators for:'
16+
});
17+
this.log(`Fetching all operators for address ${address}...`);
18+
const operators = await listOperatorsForAddress(address);
19+
this.log(`Operators retrieved. Here are the details:`);
20+
operators.forEach((operator: string, index: number) => {
21+
this.log(`Operator ${index + 1}: ${operator}`);
22+
});
23+
});
24+
}
25+
26+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as Vorpal from "vorpal";
2+
import { removeOperatorFromReferee, getSignerFromPrivateKey } from "@xai-vanguard-node/core";
3+
4+
/**
5+
* Function to remove an operator from the Referee contract.
6+
* @param cli - Vorpal instance
7+
*/
8+
export function removeOperator(cli: Vorpal) {
9+
cli
10+
.command('remove-operator', 'Removes an operator from the Referee contract.')
11+
.action(async function (this: Vorpal.CommandInstance) {
12+
const {operatorAddress} = await this.prompt({
13+
type: 'input',
14+
name: 'operatorAddress',
15+
message: 'Operator address to be removed:'
16+
});
17+
18+
const {privateKey} = await this.prompt({
19+
type: 'password',
20+
name: 'privateKey',
21+
message: 'Private key of the current address that you want to remove the operator from:',
22+
mask: '*',
23+
});
24+
25+
if (!operatorAddress || !privateKey) {
26+
this.log('Both operator address and private key are required.');
27+
return;
28+
}
29+
30+
this.log(`Removing operator ${operatorAddress} from the Referee contract...`);
31+
32+
// Create a signer with the private key
33+
const { signer } = getSignerFromPrivateKey(privateKey);
34+
35+
// Call the removeOperatorFromReferee function to remove the operator from the Referee contract
36+
await removeOperatorFromReferee(operatorAddress, signer);
37+
38+
this.log(`Operator ${operatorAddress} has been removed from the Referee contract.`);
39+
});
40+
}

apps/cli/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ import { removeAdmin } from './commands/access-control/remove-admin';
1515
import { removeChallenger } from './commands/access-control/remove-challenger';
1616
import { setChallengerPublicKey } from './commands/set-challenger-public-key';
1717
import { toggleAssertionCheckingCommand } from './commands/toggle-assertion-checking';
18+
import { addOperator } from './commands/operator-control/add-operator';
19+
import { removeOperator } from './commands/operator-control/remove-operator';
20+
import { listOperators } from './commands/operator-control/list-operators';
1821

1922
const cli = new Vorpal();
2023

2124
// entrypoints to each of the commands
2225
addAdmin(cli);
2326
addChallenger(cli);
27+
addOperator(cli);
2428
bootChallenger(cli);
2529
createBlsKeyPair(cli);
2630
createMnemonic(cli);
@@ -31,8 +35,10 @@ getPrivateKeyFromMnemonic(cli);
3135
getPublicKeyFromPrivateKey(cli);
3236
getRefereeContractAddress(cli);
3337
manuallyChallengeAssertion(cli);
38+
listOperators(cli);
3439
removeAdmin(cli);
3540
removeChallenger(cli);
41+
removeOperator(cli);
3642
setChallengerPublicKey(cli);
3743
toggleAssertionCheckingCommand(cli);
3844

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"scripts": {
77
"lint": "pnpm recursive run lint",
88
"clean": "pnpm recursive run clean",
9-
"build": "pnpm recursive run build"
9+
"build": "pnpm recursive run build",
10+
"cli": "pnpm -r -filter @xai-vanguard-node/core run build && pnpm -r -filter @xai-vanguard-node/vanguard-node-cli run compile && pnpm -r -filter @xai-vanguard-node/vanguard-node-cli run start",
11+
"deploy-smart-contracts": "pnpm -r -filter @xai-vanguard-node/core run build && pnpm -r -filter @xai-vanguard-node/smart-contracts run deploy"
1012
},
1113
"keywords": [],
1214
"author": "",

packages/core/src/challenger/listenForAssertions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function listenForAssertions(callback: (nodeNum: any, blockHash: any, sen
2121

2222
// listen for the NodeConfirmed event
2323
rollupContract.on("NodeConfirmed", (nodeNum, blockHash, sendRoot, event) => {
24-
24+
2525
// if the nodeNum has not been seen before, call the callback and add it to the map
2626
if (!nodeNumMap[nodeNum]) {
2727
nodeNumMap[nodeNum] = true;

packages/core/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const config = {
22
"arbitrumBlockExplorer": "https://arbiscan.io",
33
"arbitrumGoerliBlockExplorer": "https://goerli.arbiscan.io",
44
"defaultRpcUrl": "https://goerli-rollup.arbitrum.io/rpc",
5-
"nodeLicenseAddress": "0x235F7B573882dBe4a5d1E90a92edee77f840A0AF",
6-
"refereeAddress": "0xe59D23656381EA058Ad6587d0Dcb7C93e603161D",
5+
"nodeLicenseAddress": "0x21aff6e15A09265D9906C45bFC480C37F3BBbAA8",
6+
"refereeAddress": "0xC42eb633460fe2006eD1d4E56aD3152D35F81612",
77
"rollupAddress": "0x082742561295f6e1b43c4f5d1e2d52d7FfE082f1"
88
};

packages/smart-contracts/scripts/deploy.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ async function main() {
2929
await extractAbi("Referee", referee);
3030
console.log("Referee Abi exported");
3131

32-
// Update the referee contract address in the config
33-
writeToConfig({ refereeAddress });
34-
console.log("Referee contract address updated in the config");
35-
3632
// Add admins to the contract
3733
const adminRole = await referee.DEFAULT_ADMIN_ROLE();
3834
for (const address of options.admins) {
@@ -56,9 +52,9 @@ async function main() {
5652
await extractAbi("NodeLicense", nodeLicense);
5753
console.log("NodeLicense Abi exported");
5854

59-
// Update the NodeLicense contract address in the config
60-
writeToConfig({ nodeLicenseAddress });
61-
console.log("NodeLicense contract address updated in the config");
55+
// Update the referee and NodeLicense contract addresses in the config
56+
writeToConfig({ refereeAddress, nodeLicenseAddress });
57+
console.log("Referee and NodeLicense contract addresses updated in the config");
6258

6359
// Verify the contracts
6460
await Promise.all([
@@ -76,3 +72,4 @@ main().catch((error) => {
7672
});
7773

7874

75+

packages/smart-contracts/utils/writeToConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import fs from 'fs';
22
import path from 'path';
33
import { config } from '@xai-vanguard-node/core';
44

5+
let isConfigWritten = false;
6+
57
/**
68
* Updates the configuration file with the provided config object.
79
* @param newConfig - The new configuration object to be merged with the existing one.
10+
* @throws {Error} If the function is called more than once during the runtime.
811
*/
912
export function writeToConfig(newConfig: object): void {
13+
if (isConfigWritten) {
14+
throw new Error('writeToConfig can only be called once per runtime.');
15+
}
1016

1117
// Merge the existing and new config objects
1218
const updatedConfig = { ...config, ...newConfig } as Record<string, any>;
@@ -17,12 +23,16 @@ export function writeToConfig(newConfig: object): void {
1723
return result;
1824
}, {});
1925

26+
2027
// Convert the sorted config object to a string
2128
const updatedConfigStr = `export const config = ${JSON.stringify(sortedConfig, null, 2)};`;
29+
console.log("new config", updatedConfigStr);
2230

2331
// Determine the path to the config file dynamically
2432
const configFilePath = path.resolve(__dirname, '../../core/src/config.ts');
2533

2634
// Write the updated config string to the config file
2735
fs.writeFileSync(configFilePath, updatedConfigStr, 'utf8');
36+
37+
isConfigWritten = true;
2838
}

0 commit comments

Comments
 (0)