-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from XinFinOrg/implement-grandmaster-manager
Implement grandmaster manager
- Loading branch information
Showing
12 changed files
with
625 additions
and
1,978 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
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
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
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
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
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
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 |
---|---|---|
@@ -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 | ||
} | ||
} |
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,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; | ||
} | ||
} |
Oops, something went wrong.