Skip to content

Commit

Permalink
Fix Periodic Vesting Account JSON for Trust Wallet (#630)
Browse files Browse the repository at this point in the history
* massage vesting account json to match cosmos-sdk/Account json for trust
wallet

* remove comment
  • Loading branch information
nddeluca committed Aug 20, 2020
1 parent e144665 commit 60d7f52
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions migrate/rest_v0_3/rest.go
Expand Up @@ -239,6 +239,7 @@ func makeCodecV03() *codec.Codec {
v0_3valvesting.RegisterCodec(v0_3Codec)
return v0_3Codec
}

func rollbackAccountType(newAccount authexported.Account) v18de63auth.Account {
switch acc := newAccount.(type) {

Expand Down
52 changes: 52 additions & 0 deletions migrate/v0_8/sdk/auth/v18de63/vesting_account.go
@@ -1,6 +1,12 @@
package v18de63

import (
"encoding/json"
"strconv"

"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -31,6 +37,52 @@ type PeriodicVestingAccount struct {
VestingPeriods Periods `json:"vesting_periods" yaml:"vesting_periods"` // the vesting schedule
}

type prettyPublicKey struct {
PubKey crypto.PubKey
}

func (p prettyPublicKey) MarshalJSON() ([]byte, error) {
cdc := codec.New()
codec.RegisterCrypto(cdc)
return cdc.MarshalJSON(p.PubKey)
}

type vestingAccountPretty struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
PubKey prettyPublicKey `json:"public_key" yaml:"public_key"`
AccountNumber string `json:"account_number" yaml:"account_number"`
Sequence string `json:"sequence" yaml:"sequence"`
OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"`
DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"`
DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"`
EndTime int64 `json:"end_time" yaml:"end_time"`

// custom fields based on concrete vesting type which can be omitted
StartTime int64 `json:"start_time,omitempty" yaml:"start_time,omitempty"`
VestingPeriods Periods `json:"vesting_periods,omitempty" yaml:"vesting_periods,omitempty"`
}

func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) {
pubKey := prettyPublicKey{PubKey: pva.PubKey}

alias := vestingAccountPretty{
Address: pva.Address,
Coins: pva.Coins,
PubKey: pubKey,
AccountNumber: strconv.FormatUint(pva.AccountNumber, 10),
Sequence: strconv.FormatUint(pva.Sequence, 10),
OriginalVesting: pva.OriginalVesting,
DelegatedFree: pva.DelegatedFree,
DelegatedVesting: pva.DelegatedVesting,
EndTime: pva.EndTime,
StartTime: pva.StartTime,
VestingPeriods: pva.VestingPeriods,
}

return json.Marshal(alias)
}

// DelayedVestingAccount implements the VestingAccount interface. It vests all
// coins after a specific time, but non prior. In other words, it keeps them
// locked until a specified time.
Expand Down

0 comments on commit 60d7f52

Please sign in to comment.