-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extra support for more getters for the Validator class #344
Changes from 1 commit
b30e18b
66e08cc
abc5ac2
698d8ca
63032fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import { Coinbase } from "./coinbase"; | ||
import { Validator as ValidatorModel, ValidatorStatus as APIValidatorStatus } from "../client/api"; | ||
import { | ||
Balance, | ||
Validator as ValidatorModel, | ||
ValidatorStatus as APIValidatorStatus, | ||
} from "../client/api"; | ||
import { ValidatorStatus } from "./types"; | ||
import { BalanceMap } from "./balance_map"; | ||
|
||
/** | ||
* A representation of a validator onchain. | ||
|
@@ -151,11 +156,119 @@ | |
} | ||
} | ||
/** | ||
* Returns the string representation of the Validator. | ||
* Returns the network ID. | ||
* | ||
* @returns The string representation of the Validator. | ||
* @returns The network ID. | ||
*/ | ||
public getNetworkId(): string { | ||
return this.model.network_id; | ||
} | ||
|
||
/** | ||
* Returns the asset ID. | ||
* | ||
* @returns The asset ID. | ||
*/ | ||
public getAssetId(): string { | ||
return this.model.asset_id; | ||
} | ||
|
||
/** | ||
* Returns the activation epoch of the validator. | ||
* | ||
* @returns The activation epoch as a string. | ||
*/ | ||
public getActivationEpoch(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the problem with this is - these are very ethereum specific. In future if we say support sol validators, do we still want user to do Do we want to support a helper function of this format instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be more in favor of revisiting this when we cross that bridge. i.e. I don't see us exposing Solana validator staking anytime soon. |
||
return this.model.details?.activationEpoch || ""; | ||
} | ||
|
||
/** | ||
* Returns the balance of the validator. | ||
* | ||
* @returns The balance object. | ||
*/ | ||
public getBalance(): Balance | undefined { | ||
return this.model.details?.balance; | ||
} | ||
|
||
/** | ||
* Returns the effective balance of the validator. | ||
* | ||
* @returns The effective balance object. | ||
*/ | ||
public getEffectiveBalance(): Balance | undefined { | ||
return this.model.details?.effective_balance; | ||
} | ||
|
||
/** | ||
* Returns the exit epoch of the validator. | ||
* | ||
* @returns The exit epoch as a string. | ||
*/ | ||
public getExitEpoch(): string { | ||
return this.model.details?.exitEpoch || ""; | ||
} | ||
|
||
/** | ||
* Returns the index of the validator. | ||
* | ||
* @returns The validator index as a string. | ||
*/ | ||
public getIndex(): string { | ||
return this.model.details?.index || ""; | ||
} | ||
|
||
/** | ||
* Returns the public key of the validator. | ||
* | ||
* @returns The validator's public key as a string. | ||
*/ | ||
public getPublicKey(): string { | ||
return this.model.details?.public_key || ""; | ||
} | ||
|
||
/** | ||
* Returns whether the validator has been slashed. | ||
* | ||
* @returns True if the validator has been slashed, false otherwise. | ||
*/ | ||
public isSlashed(): boolean { | ||
return this.model.details?.slashed || false; | ||
} | ||
|
||
/** | ||
* Returns the withdrawable epoch of the validator. | ||
* | ||
* @returns The withdrawable epoch as a string. | ||
*/ | ||
public getWithdrawableEpoch(): string { | ||
return this.model.details?.withdrawableEpoch || ""; | ||
} | ||
|
||
/** | ||
* Returns the withdrawal address of the validator. | ||
* | ||
* @returns The withdrawal address as a string. | ||
*/ | ||
public getWithdrawalAddress(): string { | ||
return this.model.details?.withdrawal_address || ""; | ||
} | ||
|
||
/** | ||
* Returns the string representation of the Validator including all its details. | ||
* | ||
* @returns The string representation of the Validator including all its details. | ||
*/ | ||
public toString(): string { | ||
return `Id: ${this.getValidatorId()} Status: ${this.getStatus()}`; | ||
return `Validator { Id: ${this.getValidatorId()}, Status: ${this.getStatus()}, Exit Epoch: ${this.getExitEpoch()}, Network ID: ${this.getNetworkId()}, Asset ID: ${this.getAssetId()}, Index: ${this.getIndex()}, Public Key: ${this.getPublicKey()}, Slashed: ${this.isSlashed()}, Withdrawable Epoch: ${this.getWithdrawableEpoch()}, Withdrawal Address: ${this.getWithdrawalAddress()}, Effective Balance: { Amount: ${this.getEffectiveBalance()?.amount}, AssetID: { ${this.getEffectiveBalance()?.asset.asset_id}, Decimals: ${this.getEffectiveBalance()?.asset.decimals}, NetworkID: ${this.getEffectiveBalance()?.asset.network_id} } }, Balance: { Amount ${this.getBalance()?.amount}, Asset: { AssetID: ${this.getBalance()?.asset.asset_id}, Decimals: ${this.getBalance()?.asset.decimals}, NetworkID: ${this.getBalance()?.asset.network_id} } }, Activation Epoch: ${this.getActivationEpoch()} }`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think toString should still be the simpler one. Primarily used of logging etc. This will be too much to log. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I see. Truly wasn't sure what to do here. I'm fine with simplifying this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just id and status like before and updating the comment acccordingly. |
||
} | ||
|
||
/** | ||
* Returns the JSON representation of the Validator. | ||
* | ||
* @returns The JSON representation of the Validator. | ||
*/ | ||
public toJSON(): string { | ||
return JSON.stringify(this.model); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe some unit tests for these getters ?