Skip to content
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

Merged
merged 5 commits into from
Dec 17, 2024

Conversation

marcin-cb
Copy link
Contributor

@marcin-cb marcin-cb commented Dec 17, 2024

What changed? Why?

Adding support for more getters to expose the data behind the Validator object.

Example

validator.toJSON()

'{"asset_id":"ETH","details":{"activationEpoch":"67501","balance":{"amount":"32000113927000000000","asset":{"asset_id":"eth","decimals":18,"network_id":"ethereum-holesky"}},"effective_balance":{"amount":"32000000000000000000","asset":{"asset_id":"eth","decimals":18,"network_id":"ethereum-holesky"}},"exitEpoch":"18446744073709551615","index":"1768213","public_key":"0x921018e49cf63a8573ea2e0c665d025325361b417233d6727907b205cf2c420e153060297b60dcbf6d42871cf8610d2f","slashed":false,"withdrawableEpoch":"18446744073709551615","withdrawal_address":"0x0100000000000000000000008d082f80606b8f93827a8a8e8c1c48950be60a33"},"network_id":"ethereum-holesky","status":"active","validator_id":"0x921018e49cf63a8573ea2e0c665d025325361b417233d6727907b205cf2c420e153060297b60dcbf6d42871cf8610d2f"}'

Qualified Impact

@marcin-cb marcin-cb requested a review from drohit-cb December 17, 2024 18:20
*/
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()} }`;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Are you suggesting just printing out the top level data values? or what subset specifically would be important?

Copy link
Contributor

@drohit-cb drohit-cb Dec 17, 2024

Choose a reason for hiding this comment

The 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 activation epoch as a string.
*/
public getActivationEpoch(): string {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 validator. getActivationEpoch() ?

Do we want to support a helper function of this format instead validator. getEthereumDetails().getActivationEpoch() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -1,6 +1,11 @@
import { Coinbase } from "./coinbase";
import { Validator as ValidatorModel, ValidatorStatus as APIValidatorStatus } from "../client/api";
import {
Copy link
Contributor

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 ?

@marcin-cb marcin-cb requested a review from drohit-cb December 17, 2024 19:27
@marcin-cb marcin-cb merged commit 5dae1b3 into v0.13.0 Dec 17, 2024
4 checks passed
@marcin-cb marcin-cb deleted the marcin/validator-details branch December 17, 2024 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants