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

Protobuf: x/auth & x/supply #5533

Merged
merged 70 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
adfae21
Migrate types to use proto
alexanderbez Jan 7, 2020
72f70c0
Add newline
alexanderbez Jan 7, 2020
80ab9d6
Fix rand_util
alexanderbez Jan 7, 2020
bf49ef2
Add nolint
alexanderbez Jan 7, 2020
d9c08cf
Implement amino marshal interface for int, uint, and dec
alexanderbez Jan 7, 2020
c5e5c6b
Update encoding doc
alexanderbez Jan 8, 2020
c1b17a5
Update CircleCI config
alexanderbez Jan 8, 2020
28b2da6
Remove tools target from proto job
alexanderbez Jan 8, 2020
f039b99
Rename to CustomProtobufType
alexanderbez Jan 8, 2020
49aa60d
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 8, 2020
cd092c0
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 8, 2020
b3463f7
changed proto docker image
Jan 8, 2020
f05929c
changed proto job to skip the binary installs
Jan 8, 2020
52e0a49
removed extra files and update proto CI
Jan 8, 2020
161f23b
Use third_party over vendor
alexanderbez Jan 9, 2020
5098419
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 9, 2020
7501af3
Merge PR #5505: Convert Int and Dec to string's on Coin and DecCoin p…
aaronc Jan 13, 2020
5c6c08c
Update go.sum
alexanderbez Jan 13, 2020
2e80b77
Fix protoc-gen-gocosmos target by allowing versioning
alexanderbez Jan 13, 2020
9e6a906
Lint
alexanderbez Jan 13, 2020
33400ef
Update go.{mod, sum} and install
alexanderbez Jan 13, 2020
241eafb
wildcard import
alexanderbez Jan 13, 2020
489d5e0
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 13, 2020
01f7766
go mod tidy
alexanderbez Jan 13, 2020
bb4ae4e
Bump cosmos-proto to v0.1.0
alexanderbez Jan 13, 2020
d6182fb
Update go.{mod, sum}
alexanderbez Jan 13, 2020
ba12a87
Update third party proto deps
alexanderbez Jan 15, 2020
153dadd
Define Marshaler and ProtoMarshaler interfaces along with BaseCodec type
alexanderbez Jan 16, 2020
94ca99c
Initial commit/demo
alexanderbez Jan 16, 2020
4113099
Fix MarshalAccount
alexanderbez Jan 17, 2020
7fd26dd
Prep merge from master
alexanderbez Feb 11, 2020
b268466
Merge branch 'master' into bez/5444-auth-proto-enc
alexanderbez Feb 11, 2020
fb6fc91
Update codec pkg
alexanderbez Feb 11, 2020
2d7e8a8
Fix GetAccountWithHeight
alexanderbez Feb 11, 2020
f8c4632
Use codec json over json pkg
alexanderbez Feb 11, 2020
aaeaf2e
Update auth types
alexanderbez Feb 11, 2020
305db41
Update account marshal tests
alexanderbez Feb 11, 2020
31af710
Update vesting types
alexanderbez Feb 11, 2020
c21d5fe
Update module APIs
alexanderbez Feb 11, 2020
769e57f
Update client logic to use pkg-level codec
alexanderbez Feb 11, 2020
c242f1c
Proto
alexanderbez Feb 11, 2020
41773be
Update vesting (remove codec)
alexanderbez Feb 13, 2020
b218b1e
Update auth types
alexanderbez Feb 13, 2020
56f824b
Update proto
alexanderbez Feb 13, 2020
38338fd
Undo account interface naming
alexanderbez Feb 13, 2020
df62b47
Update APIs
alexanderbez Feb 13, 2020
d9dbdd6
Update alias
alexanderbez Feb 13, 2020
6849bcb
Update simapp codec
alexanderbez Feb 13, 2020
e2fccc0
Add missing UnmarshalAccountJSON
alexanderbez Feb 13, 2020
66c8beb
Update simapp
alexanderbez Feb 13, 2020
96e36b4
Migrate x/supply to proto and update Supply interface
alexanderbez Feb 13, 2020
4d49c14
cleanup module codecs
alexanderbez Feb 13, 2020
4b1b6bb
Define SupplyCodec
alexanderbez Feb 13, 2020
f0aab9f
Restructure x/supply
alexanderbez Feb 13, 2020
fd1758f
Supply proto updates
alexanderbez Feb 14, 2020
98de856
Merge branch 'master' into bez/5444-auth-proto-enc
alexanderbez Feb 14, 2020
eebcba3
Refactor Module Manager to use codec
alexanderbez Feb 14, 2020
348a7e1
Update genutil
alexanderbez Feb 14, 2020
c52731d
Fix cal to DefaultGenesis
alexanderbez Feb 14, 2020
0dfd3ef
Lint
alexanderbez Feb 14, 2020
e9d161c
Fix supply tests
alexanderbez Feb 14, 2020
098e3a9
Update changelog
alexanderbez Feb 14, 2020
2c721af
Update changelog
alexanderbez Feb 14, 2020
2482e86
Add error checking
alexanderbez Feb 15, 2020
08502d6
Remove x/auth Account test type and codec
alexanderbez Feb 15, 2020
fe2c0a8
Lint
alexanderbez Feb 18, 2020
85ebbda
Use a single reference to the auth account codec
alexanderbez Feb 18, 2020
9480f1e
Merge branch 'master' into bez/5444-auth-proto-enc
alexanderbez Feb 18, 2020
cb22da9
Rename vesting proto message
alexanderbez Feb 18, 2020
af00a40
Remove vesting codec
alexanderbez Feb 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update vesting types
  • Loading branch information
alexanderbez committed Feb 11, 2020
commit 31af7100853afc4174a7ae13dac1d7771a9b72ae
3 changes: 3 additions & 0 deletions x/auth/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var (
MakeSignature = types.MakeSignature
ValidateGenAccounts = types.ValidateGenAccounts
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
NewCodec = types.NewCodec

// variable aliases
ModuleCdc = types.ModuleCdc
Expand Down Expand Up @@ -89,4 +90,6 @@ type (
StdSignature = types.StdSignature
TxBuilder = types.TxBuilder
GenesisAccountIterator = types.GenesisAccountIterator
AuthCodec = types.AuthCodec
Codec = types.Codec
)
8 changes: 4 additions & 4 deletions x/auth/vesting/alias.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/vesting/types/
package vesting

// nolint

import (
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)
Expand All @@ -18,6 +16,7 @@ var (
NewPeriodicVestingAccount = types.NewPeriodicVestingAccount
NewDelayedVestingAccountRaw = types.NewDelayedVestingAccountRaw
NewDelayedVestingAccount = types.NewDelayedVestingAccount
NewCodec = types.NewCodec

// variable aliases
VestingCdc = types.VestingCdc
Expand All @@ -30,4 +29,5 @@ type (
DelayedVestingAccount = types.DelayedVestingAccount
Period = types.Period
Periods = types.Periods
Codec = types.Codec
)
2 changes: 1 addition & 1 deletion x/auth/vesting/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// VestingAccount defines an account type that vests coins via a vesting schedule.
type VestingAccount interface {
authexported.Account
authexported.AccountI

// LockedCoins returns the set of coins that are not spendable (i.e. locked).
//
Expand Down
68 changes: 62 additions & 6 deletions x/auth/vesting/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,68 @@ package types

import (
"github.com/cosmos/cosmos-sdk/codec"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
)

var _ authtypes.AuthCodec = (*Codec)(nil)

type Codec struct {
codec.Marshaler

// Keep reference to the amino codec to allow backwards compatibility along
// with type, and interface registration.
amino *codec.Codec
}

func NewCodec(amino *codec.Codec) *Codec {
return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino}
}

// MarshalAccount marshals an AccountI interface. If the given type implements
// the Marshaler interface, it is treated as a Proto-defined message and
// serialized that way. Otherwise, it falls back on the internal Amino codec.
func (c *Codec) MarshalAccount(accI authexported.AccountI) ([]byte, error) {
acc := &VestingAccount{}
acc.SetAccountI(accI)
return c.Marshaler.MarshalBinaryLengthPrefixed(acc)
}

// UnmarshalAccount returns an AccountI interface from raw encoded account bytes
// of a Proto-based Account type. An error is returned upon decoding failure.
func (c *Codec) UnmarshalAccount(bz []byte) (authexported.AccountI, error) {
acc := &VestingAccount{}
if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, acc); err != nil {
return nil, err
}
return acc.GetAccountI(), nil
}

// MarshalAccountJSON JSON encodes an account object implementing the AccountI
// interface.
func (c *Codec) MarshalAccountJSON(acc authexported.AccountI) ([]byte, error) {
return c.Marshaler.MarshalJSON(acc)
}

// UnmarshalAccountJSON returns an AccountI from JSON encoded bytes.
func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.AccountI, error) {
acc := &VestingAccount{}
if err := c.Marshaler.UnmarshalJSON(bz, acc); err != nil {
return nil, err
}

return acc.GetAccountI(), nil
}

// ----------------------------------------------------------------------------

// VestingCdc is the global vesting-specific codec for x/auth module.
//
// NOTE: This codec is deprecated, where a codec via NewCodec without an Amino
// codec should be used.
var VestingCdc = NewCodec(codec.New())

// RegisterCodec registers concrete types on the codec
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*exported.VestingAccount)(nil), nil)
Expand All @@ -14,11 +73,8 @@ func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil)
}

// VestingCdc module wide codec
var VestingCdc *codec.Codec

func init() {
VestingCdc = codec.New()
RegisterCodec(VestingCdc)
VestingCdc.Seal()
RegisterCodec(VestingCdc.amino)
codec.RegisterCrypto(VestingCdc.amino)
VestingCdc.amino.Seal()
}
4 changes: 2 additions & 2 deletions x/auth/vesting/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
func TestValidateGenesisInvalidAccounts(t *testing.T) {
acc1 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr1))
acc1Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150))
baseVestingAcc := NewBaseVestingAccount(&acc1, acc1Balance, 1548775410)
baseVestingAcc := NewBaseVestingAccount(acc1, acc1Balance, 1548775410)

// invalid delegated vesting
baseVestingAcc.DelegatedVesting = acc1Balance.Add(acc1Balance...)
Expand All @@ -32,7 +32,7 @@ func TestValidateGenesisInvalidAccounts(t *testing.T) {

genAccs := make([]exported.GenesisAccount, 2)
genAccs[0] = baseVestingAcc
genAccs[1] = &acc2
genAccs[1] = acc2

require.Error(t, authtypes.ValidateGenAccounts(genAccs))
baseVestingAcc.DelegatedVesting = acc1Balance
Expand Down
13 changes: 4 additions & 9 deletions x/auth/vesting/types/period.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
"gopkg.in/yaml.v2"
)

// Period defines a length of time and amount of coins that will vest
type Period struct {
Length int64 `json:"length" yaml:"length"` // length of the period, in seconds
Amount sdk.Coins `json:"amount" yaml:"amount"` // amount of coins vesting during this period
}

// Periods stores all vesting periods passed as part of a PeriodicVestingAccount
type Periods []Period

// String Period implements stringer interface
func (p Period) String() string {
return fmt.Sprintf(`Length: %d
Amount: %s`, p.Length, p.Amount)
out, _ := yaml.Marshal(p)
return string(out)
}

// String Periods implements stringer interface
Expand All @@ -28,6 +22,7 @@ func (vp Periods) String() string {
for _, period := range vp {
periodsListString = append(periodsListString, period.String())
}

return strings.TrimSpace(fmt.Sprintf(`Vesting Periods:
%s`, strings.Join(periodsListString, ", ")))
}
Loading