-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle storing contract with gov module
- Loading branch information
hard-nett
committed
Oct 31, 2023
1 parent
2a2bff4
commit 9b973c9
Showing
7 changed files
with
95 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package v4 | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
||
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" | ||
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" | ||
"github.com/terpnetwork/terp-core/v2/app/keepers" | ||
) | ||
|
||
//go:embed headstash_contract.wasm | ||
|
||
var embedFs embed.FS | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
func setupHeadstashContract(ctx sdk.Context, keepers *keepers.AppKeepers) error { | ||
logger := ctx.Logger() | ||
// set the gov module address | ||
govModule := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName) | ||
// define the headstash patch contract | ||
code, err := embedFs.ReadFile("headstash_contract.wasm") | ||
if err != nil { | ||
return err | ||
} | ||
// define instantiate permissions | ||
instantiateConfig := wasmtypes.AccessConfig{Permission: wasmtypes.AccessTypeNobody} | ||
contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(keepers.WasmKeeper) | ||
// store wasm contract | ||
codeID, _, err := contractKeeper.Create(ctx, govModule, code, &instantiateConfig) | ||
if err != nil { | ||
return err | ||
} | ||
// define instantiate msg | ||
initMsgBz := []byte(fmt.Sprintf(`{ | ||
"owner": "%s", | ||
"claim_msg_plaintext": "%s" | ||
}`, | ||
govModule, "{address}")) | ||
// instantiate contract | ||
addr, _, err := contractKeeper.Instantiate(ctx, codeID, govModule, govModule, initMsgBz, "headstash patch contract", nil) | ||
if err != nil { | ||
return err | ||
} | ||
// format contract bytes to bech32 addr | ||
addrStr, err := sdk.Bech32ifyAddressBytes("terp", addr) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if err != nil { | ||
return err | ||
} | ||
// print results | ||
logger.Info(fmt.Sprintf("instatiated headstash patch contract: %s", addrStr)) | ||
This comment has been minimized.
Sorry, something went wrong.
alpe
|
||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Good use of embed so that the contract is included into the binary