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 65 commits
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
21 changes: 19 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ flushed to disk or kept as a snapshot. Note, `KeepRecent` is automatically infer
and provided directly the IAVL store.
* (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move x/auth/client/utils/ types and functions to x/auth/client/.
* (modules) [\#5572](https://github.com/cosmos/cosmos-sdk/pull/5572) Move account balance logic and APIs from `x/auth` to `x/bank`.
* (types) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Refactored `AppModuleBasic` and `AppModuleGenesis`
to now accept a `codec.JSONMarshaler` for modular serialization of genesis state.

### Bug Fixes

Expand All @@ -72,15 +74,15 @@ and provided directly the IAVL store.
* Callers to `NewBaseVestingAccount` are responsible for verifying account balance in relation to
the original vesting amount.
* The `SendKeeper` and `ViewKeeper` interfaces in `x/bank` have been modified to account for changes.
* (staking) [\#5600](https://github.com/cosmos/cosmos-sdk/pull/5600) Migrate the `x/staking` module to use Protocol Buffer for state
* (x/staking) [\#5600](https://github.com/cosmos/cosmos-sdk/pull/5600) Migrate the `x/staking` module to use Protocol Buffers for state
serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino
for JSON encoding.
* `BondStatus` is now of type `int32` instead of `byte`.
* Types of `int16` in the `Params` type are now of type `int32`.
* Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`.
* The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type
provided is specified by `ModuleCdc`.
* (distr) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffer for state
* (x/distribution) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffers for state
serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino
for JSON encoding.
* `ValidatorHistoricalRewards.ReferenceCount` is now of types `uint32` instead of `uint16`.
Expand All @@ -89,6 +91,21 @@ for JSON encoding.
* `ValidatorAccumulatedCommission` is now a struct with `commission`.
* The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type
provided is specified by `ModuleCdc`.
* (x/auth) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Migrate the `x/auth` module to use Protocol Buffers for state
serialization instead of Amino.
* The `BaseAccount.PubKey` field is now represented as a Bech32 string instead of a `crypto.Pubkey`.
* `NewBaseAccountWithAddress` now returns a reference to a `BaseAccount`.
* The `x/auth` module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by
requiring a concrete codec to know how to serialize accounts.
* The `AccountRetriever` type now accepts a `Codec` in its constructor in order to know how to
serialize accounts.
* (x/supply) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Migrate the `x/supply` module to use Protocol Buffers for state
serialization instead of Amino.
* The `internal` sub-package has been removed in order to expose the types proto file.
* The `x/supply` module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by
requiring a concrete codec to know how to serialize `SupplyI` types.
* The `SupplyI` interface has been modified to no longer return `SupplyI` on methods. Instead the
concrete type's receiver should modify the type.

### Improvements

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/pelletier/go-toml v1.6.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.6
github.com/regen-network/cosmos-proto v0.1.0
github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2
github.com/spf13/afero v1.2.1 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129/go.mod h1:sBzyDLLjw3
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
Expand Down Expand Up @@ -196,8 +195,8 @@ github.com/rakyll/statik v0.1.6 h1:uICcfUXpgqtw2VopbIncslhAmE5hwc4g20TEyEENBNs=
github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165 h1:nkcn14uNmFEuGCb2mBZbBb24RdNRL08b/wb+xBOYpuk=
github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/regen-network/cosmos-proto v0.1.0 h1:gsV+YO2kMvY430zQn8ioPXRxEJgb/ms0iMPeWo3VEyY=
github.com/regen-network/cosmos-proto v0.1.0/go.mod h1:+r7jN10xXCypD4yBgzKOa+vgLz0riqYMHeDcKekxPvA=
github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2 h1:jQK1YoH972Aptd22YKgtNu5jM2X2xMGkyIENOAc71to=
github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2/go.mod h1:+r7jN10xXCypD4yBgzKOa+vgLz0riqYMHeDcKekxPvA=
github.com/regen-network/protobuf v1.3.2-alpha.regen.1 h1:YdeZbBS0lG1D13COb7b57+nM/RGgIs8WF9DwitU6EBM=
github.com/regen-network/protobuf v1.3.2-alpha.regen.1/go.mod h1:lye6mqhOn/GCw1zRl3uPD5VP8rC+LPMyTyPAyQV872U=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand Down Expand Up @@ -253,7 +252,6 @@ github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN
github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tendermint/iavl v0.13.0 h1:r2sINvNFlJsLlLhGoqlqPlREWYkuK26BvMfkBt+XQnA=
github.com/tendermint/iavl v0.13.0/go.mod h1:7nSUPdrsHEZ2nNZa+9gaIrcJciWd1jCQZXtcyARU82k=
github.com/tendermint/tendermint v0.33.0 h1:TW1g9sQs3YSqKM8o1+opL3/VmBy4Ke/VKV9MxYpqNbI=
github.com/tendermint/tendermint v0.33.0/go.mod h1:s5UoymnPIY+GcA3mMte4P9gpMP8vS7UH7HBXikT1pHI=
github.com/tendermint/tendermint v0.33.1 h1:8f68LUBz8yhISZvaLFP4siXXrLWsWeoYfelbdNtmvm4=
github.com/tendermint/tendermint v0.33.1/go.mod h1:fBOKyrlXOETqQ+heL8x/TZgSdmItON54csyabvktBp0=
Expand Down Expand Up @@ -341,7 +339,6 @@ google.golang.org/genproto v0.0.0-20200108215221-bd8f9a0ef82f/go.mod h1:n3cpQtvx
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
Expand Down
20 changes: 10 additions & 10 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -78,7 +79,6 @@ var (
}
)

// Verify app interface at compile time
var _ App = (*SimApp)(nil)

// SimApp extends an ABCI application, but with most of its parameters exported.
Expand Down Expand Up @@ -124,10 +124,10 @@ func NewSimApp(
invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp),
) *SimApp {

appCodec := NewAppCodec()

// TODO: Remove cdc in favor of appCodec once all modules are migrated.
cdc := MakeCodec()
cdc := simappcodec.MakeCodec(ModuleBasics)

appCodec := simappcodec.NewAppCodec(cdc)

bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
Expand All @@ -150,7 +150,7 @@ func NewSimApp(
}

// init params keeper and subspaces
app.ParamsKeeper = params.NewKeeper(appCodec.Params, keys[params.StoreKey], tkeys[params.TStoreKey])
app.ParamsKeeper = params.NewKeeper(appCodec, keys[params.StoreKey], tkeys[params.TStoreKey])
app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace)
app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace)
app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace)
Expand All @@ -163,23 +163,23 @@ func NewSimApp(

// add keepers
app.AccountKeeper = auth.NewAccountKeeper(
app.cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount,
appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount,
)
app.BankKeeper = bank.NewBaseKeeper(
app.cdc, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(),
)
app.SupplyKeeper = supply.NewKeeper(
app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
appCodec, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
)
stakingKeeper := staking.NewKeeper(
appCodec.Staking, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
appCodec, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
)
app.MintKeeper = mint.NewKeeper(
app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName,
)
app.DistrKeeper = distr.NewKeeper(
appCodec.Distribution, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper,
appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(),
)
app.SlashingKeeper = slashing.NewKeeper(
Expand Down Expand Up @@ -305,7 +305,7 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re
func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState)
return app.mm.InitGenesis(ctx, genesisState)
return app.mm.InitGenesis(ctx, app.cdc, genesisState)
}

// LoadHeight loads a particular height
Expand Down
46 changes: 0 additions & 46 deletions simapp/codec.go

This file was deleted.

128 changes: 128 additions & 0 deletions simapp/codec/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package codec

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

var (
_ auth.Codec = (*Codec)(nil)
_ supply.Codec = (*Codec)(nil)
)

// AppCodec defines the application-level codec. This codec contains all the
// required module-specific codecs that are to be provided upon initialization.
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 NewAppCodec(amino *codec.Codec) *Codec {
return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino}
}

// MarshalAccount marshals an Account 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.Account) ([]byte, error) {
acc := &Account{}
if err := acc.SetAccount(accI); err != nil {
return nil, err
}

return c.Marshaler.MarshalBinaryLengthPrefixed(acc)
}

// UnmarshalAccount returns an Account 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.Account, error) {
acc := &Account{}
if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, acc); err != nil {
return nil, err
}

return acc.GetAccount(), nil
}

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

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

return acc.GetAccount(), nil
}

// MarshalSupply marshals a SupplyI 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) MarshalSupply(supplyI exported.SupplyI) ([]byte, error) {
supply := &Supply{}
if err := supply.SetSupplyI(supplyI); err != nil {
return nil, err
}

return c.Marshaler.MarshalBinaryLengthPrefixed(supply)
}

// UnmarshalSupply returns a SupplyI interface from raw encoded account bytes
// of a Proto-based SupplyI type. An error is returned upon decoding failure.
func (c *Codec) UnmarshalSupply(bz []byte) (exported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, supply); err != nil {
return nil, err
}

return supply.GetSupplyI(), nil
}

// MarshalSupplyJSON JSON encodes a supply object implementing the SupplyI
// interface.
func (c *Codec) MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error) {
return c.Marshaler.MarshalJSON(supply)
}

// UnmarshalSupplyJSON returns a SupplyI from JSON encoded bytes.
func (c *Codec) UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalJSON(bz, supply); err != nil {
return nil, err
}

return supply.GetSupplyI(), nil
}

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

// MakeCodec creates and returns a reference to an Amino codec that has all the
// necessary types and interfaces registered. This codec is provided to all the
// modules the application depends on.
//
// NOTE: This codec will be deprecated in favor of AppCodec once all modules are
// migrated.
func MakeCodec(bm module.BasicManager) *codec.Codec {
cdc := codec.New()

bm.RegisterCodec(cdc)
vesting.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)

return cdc
}
Loading