-
Notifications
You must be signed in to change notification settings - Fork 247
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
feat: add vesting account handling #232
Conversation
…om/forbole/bdjuno into v2/aaron/update_rewards_commission
types/auth.go
Outdated
// --------------- For Vesting Account --------------- | ||
|
||
// Account represents a chain account | ||
type VestingAccount struct { |
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.
As above, why are these re-declared since they are already available inside the SDK?
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.
Hi @RiccardoM , I added the types on the side because I couldn't really get the account type with Codec.. so I did with brute force to parse them into json. Do you know a way how I can parse/unpack the accounts?
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.
@huichiaotsou In order to understand how to unpack accounts, it's worth to understand how they are handled from Cosmos and why they are packed in a strange way. The best way to do this is though a series of considerations:
- All the data returned from a gRPC call is serialized using Protobuf
- In order to represent a generic account, inside the Cosmos SDK there are multiple Go interfaces used. The most common are:
AccountI
, to represent a generic accountVestingAccount
to represent a generic vesting account
- Protobuf does not support Go interfaces by default. For this reason, the Cosmos team has decided to use the
Any
type to serialize them.
So, in order to read the details of a vesting account you need to do the following:
- Unpack that account from
Any
into anAccountI
interface:
var accountI authtypes.AccountI
err := cdc.UnpackAny(account, &accountI)
if err != nil {
return err
}
- Check if that
accountI
is also implementing theVestingAccountI
interface:
vestingAccount, ok := accountI.(exported.VestingAccount)
if !ok {
// The account is not a VestingAccount. Do as you wish (skip the for loop, return an error, ...)
}
From there, you can use vestingAccount
however you wish since it will be of type VestingAccount
.
Side note
Since they can be of various types (ContinousVestingAccount
, DelayedVestingAccount
and PeriodicVestingAccount
), the best way to store VestingAccount
instances is to simply serialize them as JSON and store them inside a table. However, this might make it really hard to get some useful insights that we might want to display on BigDipper (such as total vested/unvested tokens, next unvesting period, etc).
For this reason, I would like to ask @ryuash and @calvinkei how they are going to use the vesting data in order to decide how to store them accordingly.
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.
By default Big Dipper 2.0 will not be using this data in favor of Forbole X.
Inside the Forbole X wallet details page I would assume it would show xx tokens are locked until xx (maybe a countdown type of animation)
Maybe @calvinkei can clarify
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.
@ryuash Wouldn't it be interesting for BigDipper to show a global amount of locked/unlocked tokens? Asking @kwunyeung also.
That might be interesting for users, no? To know when the next large unlock will happen or other interesting things
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.
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.
Hahs, if we do some feature like that then we definitely cannot throw a JSONB in to psql.
I would need to get all possible vesting periods in the genesis file and query by xx time.
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.
@huichiaotsou In order to preserve forward-compatibility with new features that might come up I would suggest then adding a better handling for different vesting account types. We can do so by doing this:
// inside handler
db.StoreVestingAccount(vestingAccount)
// -------------------------
func (db *Database) StoreVestingAccount(vestingAccount exported.VestingAccount) error {
if continousVestingAccount, ok := vestingAccount.(*vestingtypes.ContinousVestingAccount); ok {
return db.storeContinousVestingAccount(continousVestingAccount)
}
if delayedVestingAccount, ok := vestingAccount.(*vestingtypes.DelayedVestingAccount); ok {
return db.storeDelayedVestingAccount(continousVestingAccount)
}
if periodicVestingAccount, ok := vestingAccount.(*vestingtypes.PeriodicVestingAccount); ok {
return db.storePeriodicVestingAccount(continousVestingAccount)
}
return fmt.Errorf("invalid vesting account type: %T", vestingAccount")
This way we can handling the storing of different types properly, with various periods etc
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.
@RiccardoM I'm also interested in showing vesting amount on BD but I do agree with @ryuash that it could be in favour of Forbole X at some point if BD not showing them by default. I think we can have this feature showing on X first. I also wanna see if there will be any feedback or request on getting this feature on BD.
Agree not storing the vesting periods in JSONB
as the structure is very clear that each record has an array of coins and a vested date. It's not any arbitrary json content where we may search in certain keys inside the json.
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.
Tested, LGTM
…ngPeriods to SaveVestingAccounts
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.
utACK. Can I have a tACK from @MonikaCat please?
tACK, LGTM |
Description
This PR replaces #158
close #138
Checklist
Files changed
in the Github PR explorer.