Skip to content

Commit

Permalink
Use staking hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ulbqb committed Mar 7, 2024
1 parent 7aaa26e commit 14631f6
Show file tree
Hide file tree
Showing 24 changed files with 204 additions and 2,274 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lbm.stakingplus.v1;

import "cosmos_proto/cosmos.proto";

option go_package = "github.com/Finschia/finschia-sdk/x/stakingplus";
option go_package = "github.com/Finschia/finschia-sdk/x/foundation";

// CreateValidatorAuthorization allows the grantee to create a new validator.
message CreateValidatorAuthorization {
Expand Down
4 changes: 2 additions & 2 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
_ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

collectionmodulev1 "github.com/Finschia/finschia-sdk/api/lbm/collection/module/v1"
foundationmodulev1 "github.com/Finschia/finschia-sdk/api/lbm/foundation/module/v1"
"github.com/Finschia/finschia-sdk/x/collection"
_ "github.com/Finschia/finschia-sdk/x/collection/module" // import for side-effects
"github.com/Finschia/finschia-sdk/x/foundation"
_ "github.com/Finschia/finschia-sdk/x/foundation/module" // import for side-effects
_ "github.com/Finschia/finschia-sdk/x/stakingplus/module" // import for side-effects
_ "github.com/Finschia/finschia-sdk/x/foundation/module" // import for side-effects
)

var (
Expand Down
6 changes: 3 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"

collectionmodule "github.com/Finschia/finschia-sdk/x/collection/module"
foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module"
stakingplusmodule "github.com/Finschia/finschia-sdk/x/stakingplus/module"
)

func TestSimAppExportAndBlockedAddrs(t *testing.T) {
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestRunMigrations(t *testing.T) {
"bank": 1,
"auth": auth.AppModule{}.ConsensusVersion(),
"authz": authzmodule.AppModule{}.ConsensusVersion(),
"staking": stakingplusmodule.AppModule{}.ConsensusVersion(),
"staking": staking.AppModule{}.ConsensusVersion(),
"mint": mint.AppModule{}.ConsensusVersion(),
"distribution": distribution.AppModule{}.ConsensusVersion(),
"slashing": slashing.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"bank": bank.AppModule{}.ConsensusVersion(),
"auth": auth.AppModule{}.ConsensusVersion(),
"authz": authzmodule.AppModule{}.ConsensusVersion(),
"staking": stakingplusmodule.AppModule{}.ConsensusVersion(),
"staking": staking.AppModule{}.ConsensusVersion(),
"mint": mint.AppModule{}.ConsensusVersion(),
"distribution": distribution.AppModule{}.ConsensusVersion(),
"slashing": slashing.AppModule{}.ConsensusVersion(),
Expand Down
2 changes: 0 additions & 2 deletions simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/Finschia/finschia-sdk/x/collection v0.0.0-00010101000000-000000000000
github.com/Finschia/finschia-sdk/x/foundation v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v0.38.3
github.com/Finschia/finschia-sdk/x/stakingplus v0.0.0-00010101000000-000000000000
github.com/cosmos/cosmos-db v1.0.0
// this version is not used as it is always replaced by the latest Cosmos SDK version
github.com/cosmos/cosmos-sdk v0.50.3
Expand Down Expand Up @@ -220,7 +219,6 @@ replace (
github.com/Finschia/finschia-sdk/api => ../api
github.com/Finschia/finschia-sdk/x/collection => ../x/collection
github.com/Finschia/finschia-sdk/x/foundation => ../x/foundation
github.com/Finschia/finschia-sdk/x/stakingplus => ../x/stakingplus
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/stakingplus/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/Finschia/finschia-sdk/x/foundation"
"github.com/Finschia/finschia-sdk/x/stakingplus"
)

type E2ETestSuite struct {
Expand Down Expand Up @@ -96,7 +95,7 @@ func (s *E2ETestSuite) SetupSuite() {
for _, grantee := range []sdk.AccAddress{s.grantee, val1} {
ga := foundation.GrantAuthorization{
Grantee: s.bytesToString(grantee),
}.WithAuthorization(&stakingplus.CreateValidatorAuthorization{
}.WithAuthorization(&foundation.CreateValidatorAuthorization{
ValidatorAddress: s.bytesToValString(grantee),
})
s.Require().NotNil(ga)
Expand Down
2 changes: 0 additions & 2 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
require (
github.com/Finschia/finschia-sdk/simapp v0.0.0-00010101000000-000000000000
github.com/Finschia/finschia-sdk/x/foundation v0.0.0-00010101000000-000000000000
github.com/Finschia/finschia-sdk/x/stakingplus v0.0.0-00010101000000-000000000000
github.com/cosmos/go-bip39 v1.0.0
)

Expand Down Expand Up @@ -231,6 +230,5 @@ replace (
github.com/cosmos/cosmos-sdk => github.com/Finschia/cosmos-sdk v0.0.0-20231211060251-d8fb76d4c267

github.com/Finschia/finschia-sdk/x/foundation => ./../x/foundation
github.com/Finschia/finschia-sdk/x/stakingplus => ./../x/stakingplus
github.com/Finschia/finschia-sdk/x/collection => ./../x/collection
)
1 change: 1 addition & 0 deletions x/foundation/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*Authorization)(nil),
&ReceiveFromTreasuryAuthorization{},
&CreateValidatorAuthorization{},
)

registry.RegisterImplementations(
Expand Down
4 changes: 4 additions & 0 deletions x/foundation/keeper/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *foundation.GenesisState {
return k.impl.ExportGenesis(ctx)
}

func (k Keeper) Hooks() internal.Hooks {
return k.impl.Hooks()
}

func NewMsgServer(k Keeper) foundation.MsgServer {
return internal.NewMsgServer(k.impl)
}
Expand Down
76 changes: 76 additions & 0 deletions x/foundation/keeper/internal/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package internal

import (
"context"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var _ stakingtypes.StakingHooks = Hooks{}

// Wrapper struct
type Hooks struct {
k Keeper
}

// Create new foundation hooks
func (k Keeper) Hooks() Hooks { return Hooks{k} }

func (h Hooks) AfterDelegationModified(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) AfterUnbondingInitiated(ctx context.Context, id uint64) error {
return nil
}

func (h Hooks) AfterValidatorBeginUnbonding(ctx context.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) AfterValidatorBonded(ctx context.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) AfterValidatorCreated(goCtx context.Context, valAddr sdk.ValAddress) error {
ctx := sdk.UnwrapSDKContext(goCtx)

grantee := sdk.AccAddress(valAddr)

msg := stakingtypes.MsgCreateValidator{
ValidatorAddress: valAddr.String(),
}

if err := h.k.Accept(ctx, grantee, &msg); err != nil {
return err
}

return nil
}

func (h Hooks) AfterValidatorRemoved(ctx context.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) BeforeDelegationCreated(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) BeforeDelegationRemoved(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) BeforeDelegationSharesModified(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) BeforeValidatorModified(ctx context.Context, valAddr sdk.ValAddress) error {
return nil
}

func (h Hooks) BeforeValidatorSlashed(ctx context.Context, valAddr sdk.ValAddress, fraction math.LegacyDec) error {
return nil
}
Loading

0 comments on commit 14631f6

Please sign in to comment.