-
Notifications
You must be signed in to change notification settings - Fork 0
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
custom-diff: x/bank #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ message GenesisState { | |
|
||
// denom_metadata defines the metadata of the differents coins. | ||
repeated Metadata denom_metadata = 4 [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; | ||
|
||
// blocked_addrs is an array containing the blocked addresses | ||
repeated string blocked_addrs = 5 [(gogoproto.moretags) = "yaml:\"blocked_addrs\"", (gogoproto.nullable) = false]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest another name: |
||
} | ||
|
||
// Balance defines an account address and balance pair used in the bank module's | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,10 @@ type SendKeeper interface { | |
IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool | ||
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error | ||
|
||
BlockedAddr(addr sdk.AccAddress) bool | ||
BlockedAddr(ctx sdk.Context, addr sdk.AccAddress) bool | ||
GetAllBlockedAddrs(ctx sdk.Context) (blockedAddrs []string) | ||
AddBlockedAddr(ctx sdk.Context, addr sdk.AccAddress) | ||
RemoveBlockedAddr(ctx sdk.Context, addr sdk.AccAddress) | ||
} | ||
|
||
var _ SendKeeper = (*BaseSendKeeper)(nil) | ||
|
@@ -285,6 +288,30 @@ func (k BaseSendKeeper) IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool { | |
|
||
// BlockedAddr checks if a given address is restricted from | ||
// receiving funds. | ||
func (k BaseSendKeeper) BlockedAddr(addr sdk.AccAddress) bool { | ||
return k.blockedAddrs[addr.String()] | ||
func (k BaseSendKeeper) BlockedAddr(ctx sdk.Context, addr sdk.AccAddress) bool { | ||
return k.blockedAddrs[addr.String()] || ctx.KVStore(k.storeKey).Has(types.BlockedAddrKey(addr)) | ||
} | ||
|
||
// GetAllBlockedAddrs returns a list of blocked addresses. | ||
func (k BaseSendKeeper) GetAllBlockedAddrs(ctx sdk.Context) (blockedAddrs []string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think returning |
||
store := ctx.KVStore(k.storeKey) | ||
iter := sdk.KVStorePrefixIterator(store, types.BlockedAddrsPrefix) | ||
defer iter.Close() | ||
for ; iter.Valid(); iter.Next() { | ||
blockedAddrs = append(blockedAddrs, types.ParseBlockedAddrKey(iter.Key()).String()) | ||
} | ||
return | ||
} | ||
|
||
// AddBlockedAddr add a given address to blocked address map to be restricted from receiving funds. | ||
func (k BaseSendKeeper) AddBlockedAddr(ctx sdk.Context, addr sdk.AccAddress) { | ||
ctx.KVStore(k.storeKey).Set(types.BlockedAddrKey(addr), []byte{}) | ||
} | ||
|
||
// RemoveBlockedAddr delete a given address to blocked address map. | ||
func (k BaseSendKeeper) RemoveBlockedAddr(ctx sdk.Context, addr sdk.AccAddress) { | ||
store := ctx.KVStore(k.storeKey) | ||
if store.Has(types.BlockedAddrKey(addr)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to check if the key presents, since |
||
store.Delete(types.BlockedAddrKey(addr)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,22 +58,28 @@ func (gs GenesisState) Validate() error { | |
} | ||
} | ||
|
||
for _, addr := range gs.BlockedAddrs { | ||
if _, err := sdk.AccAddressFromBech32(addr); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// NewGenesisState creates a new genesis state. | ||
func NewGenesisState(params Params, balances []Balance, supply sdk.Coins, denomMetaData []Metadata) *GenesisState { | ||
func NewGenesisState(params Params, balances []Balance, supply sdk.Coins, denomMetaData []Metadata, blockedAddrs []string) *GenesisState { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about accepting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BankKeeper and others are receiving BlockedAddr as string, so string was used to follow this format as much as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the original version used |
||
return &GenesisState{ | ||
Params: params, | ||
Balances: balances, | ||
Supply: supply, | ||
DenomMetadata: denomMetaData, | ||
BlockedAddrs: blockedAddrs, | ||
} | ||
} | ||
|
||
// DefaultGenesisState returns a default bank module genesis state. | ||
func DefaultGenesisState() *GenesisState { | ||
return NewGenesisState(DefaultParams(), []Balance{}, sdk.Coins{}, []Metadata{}) | ||
return NewGenesisState(DefaultParams(), []Balance{}, sdk.Coins{}, []Metadata{}, []string{}) | ||
} | ||
|
||
// GetGenesisStateFromAppState returns x/bank GenesisState given raw application | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.