From 016a1c8ec9adebc2fbc9dc87fc7c84943001a882 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 22 Apr 2018 23:36:15 -0700 Subject: [PATCH] removed seal --- cmd/gaia/app/app.go | 2 +- examples/basecoin/app/app.go | 2 +- examples/democoin/app/app.go | 2 +- x/auth/mapper.go | 29 ----------------------------- x/auth/mapper_test.go | 14 -------------- x/stake/test_common.go | 2 +- 6 files changed, 4 insertions(+), 47 deletions(-) diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index e780c08bf..fd981a3b5 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -58,7 +58,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp { app.cdc, app.keyMain, // target store &auth.BaseAccount{}, // prototype - ).Seal() + ) // add handlers app.coinKeeper = bank.NewKeeper(app.accountMapper) diff --git a/examples/basecoin/app/app.go b/examples/basecoin/app/app.go index e9f5b6e5a..b02f21669 100644 --- a/examples/basecoin/app/app.go +++ b/examples/basecoin/app/app.go @@ -61,7 +61,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp { cdc, app.capKeyMainStore, // target store &types.AppAccount{}, // prototype - ).Seal() + ) // Add handlers. coinKeeper := bank.NewKeeper(app.accountMapper) diff --git a/examples/democoin/app/app.go b/examples/democoin/app/app.go index 290a04d66..b70f51b5c 100644 --- a/examples/democoin/app/app.go +++ b/examples/democoin/app/app.go @@ -66,7 +66,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp { cdc, app.capKeyMainStore, // target store &types.AppAccount{}, // prototype - ).Seal() + ) // Add handlers. coinKeeper := bank.NewKeeper(app.accountMapper) diff --git a/x/auth/mapper.go b/x/auth/mapper.go index ed69034be..b815fada7 100644 --- a/x/auth/mapper.go +++ b/x/auth/mapper.go @@ -9,7 +9,6 @@ import ( ) var _ sdk.AccountMapper = (*accountMapper)(nil) -var _ sdk.AccountMapper = (*sealedAccountMapper)(nil) // Implements sdk.AccountMapper. // This AccountMapper encodes/decodes accounts using the @@ -37,21 +36,6 @@ func NewAccountMapper(cdc *wire.Codec, key sdk.StoreKey, proto sdk.Account) acco } } -// Returns the go-amino codec. You may need to register interfaces -// and concrete types here, if your app's sdk.Account -// implementation includes interface fields. -// NOTE: It is not secure to expose the codec, so check out -// .Seal(). -func (am accountMapper) WireCodec() *wire.Codec { - return am.cdc -} - -// Returns a "sealed" accountMapper. -// The codec is not accessible from a sealedAccountMapper. -func (am accountMapper) Seal() sealedAccountMapper { - return sealedAccountMapper{am} -} - // Implements sdk.AccountMapper. func (am accountMapper) NewAccountWithAddress(ctx sdk.Context, addr sdk.Address) sdk.Account { acc := am.clonePrototype() @@ -78,19 +62,6 @@ func (am accountMapper) SetAccount(ctx sdk.Context, acc sdk.Account) { store.Set(addr, bz) } -//---------------------------------------- -// sealedAccountMapper - -type sealedAccountMapper struct { - accountMapper -} - -// There's no way for external modules to mutate the -// sam.accountMapper.cdc from here, even with reflection. -func (sam sealedAccountMapper) WireCodec() *wire.Codec { - panic("accountMapper is sealed") -} - //---------------------------------------- // misc. diff --git a/x/auth/mapper_test.go b/x/auth/mapper_test.go index 030207db2..2912ddde8 100644 --- a/x/auth/mapper_test.go +++ b/x/auth/mapper_test.go @@ -57,17 +57,3 @@ func TestAccountMapperGetSet(t *testing.T) { assert.NotNil(t, acc) assert.Equal(t, newSequence, acc.GetSequence()) } - -func TestAccountMapperSealed(t *testing.T) { - _, capKey := setupMultiStore() - cdc := wire.NewCodec() - RegisterBaseAccount(cdc) - - // normal mapper exposes the wire codec - mapper := NewAccountMapper(cdc, capKey, &BaseAccount{}) - assert.NotNil(t, mapper.WireCodec()) - - // seal mapper, should panic when we try to get the codec - mapperSealed := mapper.Seal() - assert.Panics(t, func() { mapperSealed.WireCodec() }) -} diff --git a/x/stake/test_common.go b/x/stake/test_common.go index 9d7b13e7c..4a36feb95 100644 --- a/x/stake/test_common.go +++ b/x/stake/test_common.go @@ -138,7 +138,7 @@ func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context cdc, // amino codec keyMain, // target store &auth.BaseAccount{}, // prototype - ).Seal() + ) ck := bank.NewKeeper(accountMapper) keeper := NewKeeper(cdc, keyStake, ck, DefaultCodespace) keeper.setPool(ctx, initialPool())