Skip to content

Commit

Permalink
fix import/export tokenfactory hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0n00gler committed Jun 20, 2024
1 parent 28b1d2c commit 688e7f1
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 28 deletions.
2 changes: 2 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ message GenesisDenom {
(gogoproto.moretags) = "yaml:\"authority_metadata\"",
(gogoproto.nullable) = false
];

string hook_contract_address = 3 [(gogoproto.nullable) = true];
}
17 changes: 15 additions & 2 deletions x/tokenfactory/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
if err != nil {
panic(err)
}

err = k.createDenomAfterValidation(ctx, creator, genDenom.GetDenom())
if err != nil {
panic(err)
}

err = k.setAuthorityMetadata(ctx, genDenom.GetDenom(), genDenom.GetAuthorityMetadata())
if err != nil {
panic(err)
}

if _, err := sdk.AccAddressFromBech32(genDenom.HookContractAddress); genDenom.HookContractAddress != "" && err != nil {
panic(err)
}

if err := k.setBeforeSendHook(ctx, genDenom.Denom, genDenom.HookContractAddress); err != nil {
panic(err)
}
}
}

Expand All @@ -43,14 +53,17 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
for ; iterator.Valid(); iterator.Next() {
denom := string(iterator.Value())

contractHook := k.GetBeforeSendHook(ctx, denom)

authorityMetadata, err := k.GetAuthorityMetadata(ctx, denom)
if err != nil {
panic(err)
}

genDenoms = append(genDenoms, types.GenesisDenom{
Denom: denom,
AuthorityMetadata: authorityMetadata,
Denom: denom,
AuthorityMetadata: authorityMetadata,
HookContractAddress: contractHook,
})
}

Expand Down
2 changes: 2 additions & 0 deletions x/tokenfactory/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (suite *KeeperTestSuite) TestGenesis() {
AuthorityMetadata: types.DenomAuthorityMetadata{
Admin: "neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2",
},
HookContractAddress: "",
},
{
Denom: "factory/neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2/diff-admin",
Expand All @@ -26,6 +27,7 @@ func (suite *KeeperTestSuite) TestGenesis() {
AuthorityMetadata: types.DenomAuthorityMetadata{
Admin: "neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2",
},
HookContractAddress: "neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2",
},
},
}
Expand Down
109 changes: 83 additions & 26 deletions x/tokenfactory/types/genesis.pb.go

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

0 comments on commit 688e7f1

Please sign in to comment.