Merge pull request #897 from cosmos/sunny/remove_accountmapper_seal

Remove Account Mapper Seal
This commit is contained in:
Christopher Goes 2018-04-24 12:27:01 +02:00 committed by GitHub
commit 4ac80c3204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 5 additions and 47 deletions

View File

@ -23,6 +23,7 @@ BREAKING CHANGES
* Many changes to names throughout
* Type as a prefix naming convention applied (ex. BondMsg -> MsgBond)
* Removed redundancy in names (ex. stake.StakeKeeper -> stake.Keeper)
* Removed SealedAccountMapper
BUG FIXES
* Gaia now uses stake, ported from github.com/cosmos/gaia

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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.

View File

@ -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() })
}

View File

@ -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())