removed seal
This commit is contained in:
parent
d613c2b9e6
commit
016a1c8ec9
|
@ -58,7 +58,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
|
||||||
app.cdc,
|
app.cdc,
|
||||||
app.keyMain, // target store
|
app.keyMain, // target store
|
||||||
&auth.BaseAccount{}, // prototype
|
&auth.BaseAccount{}, // prototype
|
||||||
).Seal()
|
)
|
||||||
|
|
||||||
// add handlers
|
// add handlers
|
||||||
app.coinKeeper = bank.NewKeeper(app.accountMapper)
|
app.coinKeeper = bank.NewKeeper(app.accountMapper)
|
||||||
|
|
|
@ -61,7 +61,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {
|
||||||
cdc,
|
cdc,
|
||||||
app.capKeyMainStore, // target store
|
app.capKeyMainStore, // target store
|
||||||
&types.AppAccount{}, // prototype
|
&types.AppAccount{}, // prototype
|
||||||
).Seal()
|
)
|
||||||
|
|
||||||
// Add handlers.
|
// Add handlers.
|
||||||
coinKeeper := bank.NewKeeper(app.accountMapper)
|
coinKeeper := bank.NewKeeper(app.accountMapper)
|
||||||
|
|
|
@ -66,7 +66,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
|
||||||
cdc,
|
cdc,
|
||||||
app.capKeyMainStore, // target store
|
app.capKeyMainStore, // target store
|
||||||
&types.AppAccount{}, // prototype
|
&types.AppAccount{}, // prototype
|
||||||
).Seal()
|
)
|
||||||
|
|
||||||
// Add handlers.
|
// Add handlers.
|
||||||
coinKeeper := bank.NewKeeper(app.accountMapper)
|
coinKeeper := bank.NewKeeper(app.accountMapper)
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sdk.AccountMapper = (*accountMapper)(nil)
|
var _ sdk.AccountMapper = (*accountMapper)(nil)
|
||||||
var _ sdk.AccountMapper = (*sealedAccountMapper)(nil)
|
|
||||||
|
|
||||||
// Implements sdk.AccountMapper.
|
// Implements sdk.AccountMapper.
|
||||||
// This AccountMapper encodes/decodes accounts using the
|
// 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.
|
// Implements sdk.AccountMapper.
|
||||||
func (am accountMapper) NewAccountWithAddress(ctx sdk.Context, addr sdk.Address) sdk.Account {
|
func (am accountMapper) NewAccountWithAddress(ctx sdk.Context, addr sdk.Address) sdk.Account {
|
||||||
acc := am.clonePrototype()
|
acc := am.clonePrototype()
|
||||||
|
@ -78,19 +62,6 @@ func (am accountMapper) SetAccount(ctx sdk.Context, acc sdk.Account) {
|
||||||
store.Set(addr, bz)
|
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.
|
// misc.
|
||||||
|
|
||||||
|
|
|
@ -57,17 +57,3 @@ func TestAccountMapperGetSet(t *testing.T) {
|
||||||
assert.NotNil(t, acc)
|
assert.NotNil(t, acc)
|
||||||
assert.Equal(t, newSequence, acc.GetSequence())
|
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() })
|
|
||||||
}
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context
|
||||||
cdc, // amino codec
|
cdc, // amino codec
|
||||||
keyMain, // target store
|
keyMain, // target store
|
||||||
&auth.BaseAccount{}, // prototype
|
&auth.BaseAccount{}, // prototype
|
||||||
).Seal()
|
)
|
||||||
ck := bank.NewKeeper(accountMapper)
|
ck := bank.NewKeeper(accountMapper)
|
||||||
keeper := NewKeeper(cdc, keyStake, ck, DefaultCodespace)
|
keeper := NewKeeper(cdc, keyStake, ck, DefaultCodespace)
|
||||||
keeper.setPool(ctx, initialPool())
|
keeper.setPool(ctx, initialPool())
|
||||||
|
|
Loading…
Reference in New Issue