Skip to content

Commit

Permalink
Merge pull request #23 from XinFinOrg/implement-grandmaster-manager
Browse files Browse the repository at this point in the history
Implement grandmaster manager
  • Loading branch information
wjrjerome authored Aug 6, 2023
2 parents 7520f18 + adb236d commit 84c8f50
Show file tree
Hide file tree
Showing 12 changed files with 625 additions and 1,978 deletions.
12 changes: 11 additions & 1 deletion backend/src/controllers/account.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlockService } from '../services/block.service';
import { CHECKPOINT_CONTRACT, PARENTCHAIN_WALLET } from '../config';
import { CHECKPOINT_CONTRACT, PARENTCHAIN_WALLET, SUBNET_URL } from '../config';
import { getService } from '../services';
import { AccountService } from '../services/account.service';
import { NextFunction, Request, Response } from 'express';
Expand Down Expand Up @@ -33,4 +33,14 @@ export class RelayerController {
next(error);
}
};

// TODO: Fetch the chain grandmaster address etc.
public getChainDetails = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
const data = {
rpcUrl: SUBNET_URL,
grandmasterAddress: 'xxx',
minimumDelegation: '10000000000000000000000000',
};
res.status(200).json(data);
};
}
2 changes: 1 addition & 1 deletion backend/src/controllers/blocks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class BlocksController {
}

public loadRecentBlocks = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
const blockNumIndex = req.query.blockNumIndex? Number(req.query.blockNumIndex) : -1;
const blockNumIndex = req.query.blockNumIndex ? Number(req.query.blockNumIndex) : -1;

try {
const [latestMinedBlock, recentBlocks, chainStatus, lastSubnetCommittedBlock, parentchainSubnetBlock] = await Promise.all([
Expand Down
1 change: 1 addition & 0 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Route implements Routes {
this.router.get('/information/masternodes', this.masterNodeController.getMasternodesInfo);
this.router.get('/information/network', this.blocksController.getBlockChainStats);
this.router.get('/information/relayer', this.relayerController.getRelayerRelatedDetails);
this.router.get('/information/chainsetting', this.relayerController.getChainDetails);
this.router.get('/confirmation', this.blocksController.confirmBlock);
}
}
33 changes: 33 additions & 0 deletions backend/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,39 @@ paths:
description: 'Bad Request'
'500':
description: 'Server Error'
/information/chainsetting:
get:
summary: Get the subnet network metadata such as the RPC URL. This is particularly useful for help to validate the setting parameters from XDC pay/wallet in management page
tags:
- management
responses:
'200':
content:
'application/json':
schema:
type: object
properties:
subnet:
type: object
properties:
rpcUrl:
description: Subnet Chain RPC URL
type: string
grandmasterAddress:
description: The grandmaster wallet address for verification
type: string
minimumDelegation:
description: Minimum delegation required when increase the candidates's voting/ranking power
required:
- rpcUrl
- grandmasterAddress
- minimumDelegation
required:
- subnet
'400':
description: 'Bad Request'
'500':
description: 'Server Error'

/confirmation:
get:
Expand Down
29 changes: 15 additions & 14 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,35 @@
},
"dependencies": {
"@radix-ui/react-tooltip": "^1.0.6",
"@types/lodash.debounce": "^4.0.7",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^4.0.0",
"autoprefixer": "^10.4.14",
"axios": "^1.4.0",
"formik": "^2.4.3",
"lodash.debounce": "^4.0.8",
"postcss": "^8.4.24",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.0",
"sass": "^1.63.6",
"tailwind-merge": "^1.13.2",
"tailwindcss": "^3.3.2",
"typescript": "^5.0.2",
"vite": "^4.4.7",
"vite-tsconfig-paths": "^4.2.0",
"web3": "1.6.1",
"web3": "4.0.3",
"yup": "^1.2.0"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/lodash.debounce": "^4.0.7",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@types/web3": "^1.2.2",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@vitejs/plugin-react": "^4.0.0",
"autoprefixer": "^10.4.14",
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4"
"eslint-plugin-react-refresh": "^0.3.4",
"postcss": "^8.4.24",
"sass": "^1.63.6",
"tailwind-merge": "^1.13.2",
"tailwindcss": "^3.3.2",
"typescript": "^5.0.2",
"vite": "^4.4.7",
"vite-plugin-node-polyfills": "^0.9.0",
"vite-tsconfig-paths": "^4.2.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function ManagementMasterCommitteePage() {
<tr key={i} className='border-b border-text-white-400/40 dark:border-text-dark-400/40'>
<Cell>{formatHash(row.address)}</Cell>
<Cell>{row.delegation} xdc</Cell>
<Cell>{row.rank}</Cell>
<Cell>{i}</Cell>
<Cell>{getDisplayStatus(row.status)}</Cell>
<Cell className='flex'>
<Button
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/services/grandmaster-manager/errors.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@

export interface ManagerError {
errorType: ErrorTypes;
errorStatus: number;
errorMessage?: string;
}

export enum ErrorTypes {
// Login section
WALLET_NOT_INSTALLED = "WALLET_NOT_INSTALLED",
CONFLICT_WITH_METAMASK = "CONFLICT_WITH_METAMASK",
WALLET_NOT_LOGIN = "WALLET_NOT_LOGIN",
NOT_GRANDMASTER = "NOT_GRANDMASTER",
// Transaction section
INVALID_TRANSACTION = "INVALID_TRANSACTION",
NOT_ENOUGH_BALANCE = "NOT_ENOUGH_BALANCE",
// Everything else
INTERNAL_ERROR = "INTERNAL_ERROR"
}

export class ManagerError extends Error {
errorType: ErrorTypes;

constructor(message?: string, errorType?: ErrorTypes) {
super(message);
this.errorType = errorType || ErrorTypes.INTERNAL_ERROR
}
}
29 changes: 29 additions & 0 deletions frontend/src/services/grandmaster-manager/extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Web3PluginBase } from 'web3';


export class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'xdcSubnet';
public async getCandidates(epochNum: "latest"): Promise<{
candidates: {
[key: string]: {
capacity: number;
status: 'MASTERNODE' | 'PROPOSED' | 'SLASHED'
}
};
epoch: number;
success: boolean;
} | undefined> {
return await this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'eth_getCandidates',
params: [epochNum],
});
}
}

// Module Augmentation
declare module 'web3' {
interface Web3Context {
xdcSubnet: CustomRpcMethodsPlugin;
}
}
Loading

0 comments on commit 84c8f50

Please sign in to comment.