This commit is contained in:
+41
-1
@@ -4,9 +4,11 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
modulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
@@ -194,8 +196,10 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
|
||||
// App Wiring Setup
|
||||
|
||||
func init() {
|
||||
appmodule.Register(&modulev1.Module{},
|
||||
appmodule.Register(
|
||||
&modulev1.Module{},
|
||||
appmodule.Provide(ProvideModule),
|
||||
appmodule.Invoke(InvokeSetSendRestrictions),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -254,3 +258,39 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
|
||||
return ModuleOutputs{BankKeeper: bankKeeper, Module: m}
|
||||
}
|
||||
|
||||
func InvokeSetSendRestrictions(
|
||||
config *modulev1.Module,
|
||||
keeper keeper.BaseKeeper,
|
||||
restrictions map[string]types.SendRestrictionFn,
|
||||
) error {
|
||||
if config == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
modules := maps.Keys(restrictions)
|
||||
order := config.RestrictionsOrder
|
||||
if len(order) == 0 {
|
||||
order = modules
|
||||
sort.Strings(order)
|
||||
}
|
||||
|
||||
if len(order) != len(modules) {
|
||||
return fmt.Errorf("len(restrictions order: %v) != len(restriction modules: %v)", order, modules)
|
||||
}
|
||||
|
||||
if len(modules) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, module := range order {
|
||||
restriction, ok := restrictions[module]
|
||||
if !ok {
|
||||
return fmt.Errorf("can't find send restriction for module %s", module)
|
||||
}
|
||||
|
||||
keeper.AppendSendRestriction(restriction)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -54,6 +54,9 @@ func ComposeMintingRestrictions(restrictions ...MintingRestrictionFn) MintingRes
|
||||
// A SendRestrictionFn can restrict sends and/or provide a new receiver address.
|
||||
type SendRestrictionFn func(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) (newToAddr sdk.AccAddress, err error)
|
||||
|
||||
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
|
||||
func (SendRestrictionFn) IsOnePerModuleType() {}
|
||||
|
||||
var _ SendRestrictionFn = NoOpSendRestrictionFn
|
||||
|
||||
// NoOpSendRestrictionFn is a no-op SendRestrictionFn.
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ module cosmossdk.io/x/upgrade
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.7.3
|
||||
cosmossdk.io/api v0.7.4
|
||||
cosmossdk.io/core v0.11.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.4
|
||||
cosmossdk.io/errors v1.0.1
|
||||
|
||||
+2
-2
@@ -184,8 +184,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX
|
||||
cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg=
|
||||
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
|
||||
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
|
||||
cosmossdk.io/api v0.7.3 h1:V815i8YOwOAQa1rLCsSMjVG5Gnzs02JLq+l7ks8s1jk=
|
||||
cosmossdk.io/api v0.7.3/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
|
||||
cosmossdk.io/api v0.7.4 h1:sPo8wKwCty1lht8kgL3J7YL1voJywP3YWuA5JKkBz30=
|
||||
cosmossdk.io/api v0.7.4/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
|
||||
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
|
||||
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
|
||||
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=
|
||||
|
||||
Reference in New Issue
Block a user