-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vesting account handling (#232)
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺ v ✰ Thanks for creating a PR! ✰ v Before smashing the submit button please review the checkboxes. v If a checkbox is n/a - please still include it but + a little note why ☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --> ## Description This PR replaces #158 close #138 ## Checklist - [x] Targeted PR against correct branch. - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [x] Wrote unit tests. - [x] Re-reviewed `Files changed` in the Github PR explorer.
- Loading branch information
1 parent
b81e781
commit f36063f
Showing
5 changed files
with
160 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
CREATE TABLE account | ||
( | ||
address TEXT NOT NULL PRIMARY KEY | ||
); | ||
|
||
/* ---- Moved from bank.sql for vesting account usage ---- */ | ||
CREATE TYPE COIN AS | ||
( | ||
denom TEXT, | ||
amount TEXT | ||
); | ||
|
||
/* ---- AUTH/ VESTING ACCOUNT ---- */ | ||
CREATE TABLE vesting_account | ||
( | ||
id SERIAL PRIMARY KEY NOT NULL, | ||
type TEXT NOT NULL, | ||
address TEXT NOT NULL REFERENCES account (address), | ||
original_vesting COIN[] NOT NULL DEFAULT '{}', | ||
end_time TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
start_time TIMESTAMP WITHOUT TIME ZONE | ||
); | ||
/* ---- start_time can be empty on DelayedVestingAccount ---- */ | ||
|
||
CREATE UNIQUE INDEX vesting_account_address_idx ON vesting_account (address); | ||
|
||
|
||
CREATE TABLE vesting_period | ||
( | ||
vesting_account_id BIGINT NOT NULL REFERENCES vesting_account (id), | ||
period_order BIGINT NOT NULL, | ||
length BIGINT NOT NULL, | ||
amount COIN[] NOT NULL DEFAULT '{}' | ||
); |
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,9 +1,3 @@ | ||
CREATE TYPE COIN AS | ||
( | ||
denom TEXT, | ||
amount TEXT | ||
); | ||
|
||
/* ---- SUPPLY ---- */ | ||
|
||
CREATE TABLE supply | ||
|
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,35 @@ | ||
package auth | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
authttypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" | ||
) | ||
|
||
// GetGenesisVestingAccounts parses the given appState and returns the genesis vesting accounts | ||
func GetGenesisVestingAccounts(appState map[string]json.RawMessage, cdc codec.Marshaler) ([]exported.VestingAccount, error) { | ||
var authState authttypes.GenesisState | ||
if err := cdc.UnmarshalJSON(appState[authttypes.ModuleName], &authState); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Build vestingAccounts Array | ||
vestingAccounts := []exported.VestingAccount{} | ||
for _, account := range authState.Accounts { | ||
var accountI authttypes.AccountI | ||
err := cdc.UnpackAny(account, &accountI) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vestingAccount, ok := accountI.(exported.VestingAccount) | ||
if !ok { | ||
continue | ||
} | ||
vestingAccounts = append(vestingAccounts, vestingAccount) | ||
} | ||
|
||
return vestingAccounts, nil | ||
} |
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