-
Notifications
You must be signed in to change notification settings - Fork 418
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
Add StoreAndInstantiateContract gov proposal #1074
Changes from 2 commits
31942cb
cf09ba6
0ce88a4
f4ac252
9b52bd9
5caaab9
4c6afb3
9cbf64d
cf81eb8
400eff8
d094d07
0ab5e31
73079d7
5c39dae
3d3635b
f3dc602
fbfdda2
8768a6a
cdaaff4
04827da
dfdccd3
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 |
---|---|---|
|
@@ -23,6 +23,18 @@ type decoratedKeeper interface { | |
authZ AuthorizationPolicy, | ||
) (sdk.AccAddress, []byte, error) | ||
|
||
createAndInstantiate( | ||
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 optimize for this worflow. Let's stick with the existing create and instantiate methods when used as a library |
||
ctx sdk.Context, | ||
creator, admin sdk.AccAddress, | ||
wasmCode []byte, | ||
instantiateAccess *types.AccessConfig, | ||
initMsg []byte, | ||
label string, | ||
deposit sdk.Coins, | ||
addressGenerator AddressGenerator, | ||
authZ AuthorizationPolicy, | ||
) (sdk.AccAddress, []byte, error) | ||
|
||
migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte, authZ AuthorizationPolicy) ([]byte, error) | ||
setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ AuthorizationPolicy) error | ||
pinCode(ctx sdk.Context, codeID uint64) error | ||
|
@@ -128,3 +140,15 @@ func (p PermissionedKeeper) SetContractInfoExtension(ctx sdk.Context, contract s | |
func (p PermissionedKeeper) SetAccessConfig(ctx sdk.Context, codeID uint64, caller sdk.AccAddress, newConfig types.AccessConfig) error { | ||
return p.nested.setAccessConfig(ctx, codeID, caller, newConfig, p.authZPolicy) | ||
} | ||
|
||
func (p PermissionedKeeper) CreateAndInstantiate( | ||
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. Please remove. No need to expose this |
||
ctx sdk.Context, | ||
creator, admin sdk.AccAddress, | ||
wasmCode []byte, | ||
instantiateAccess *types.AccessConfig, | ||
initMsg []byte, | ||
label string, | ||
deposit sdk.Coins, | ||
) (sdk.AccAddress, []byte, error) { | ||
return p.nested.createAndInstantiate(ctx, creator, admin, wasmCode, instantiateAccess, initMsg, label, deposit, p.nested.ClassicAddressGenerator(), p.authZPolicy) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ func NewWasmProposalHandlerX(k types.ContractOpsKeeper, enabledProposalTypes []t | |
return handleUnpinCodesProposal(ctx, k, *c) | ||
case *types.UpdateInstantiateConfigProposal: | ||
return handleUpdateInstantiateConfigProposal(ctx, k, *c) | ||
case *types.StoreAndInstantiateContractProposal: | ||
return handleStoreAndInstantiateContractProposal(ctx, k, *c) | ||
default: | ||
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized wasm proposal content type: %T", c) | ||
} | ||
|
@@ -103,6 +105,44 @@ func handleInstantiateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p typ | |
return nil | ||
} | ||
|
||
func handleStoreAndInstantiateContractProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.StoreAndInstantiateContractProposal) error { | ||
if err := p.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "run as address") | ||
} | ||
var adminAddr sdk.AccAddress | ||
if p.Admin != "" { | ||
if adminAddr, err = sdk.AccAddressFromBech32(p.Admin); err != nil { | ||
return sdkerrors.Wrap(err, "admin") | ||
} | ||
} | ||
|
||
codeID, _, err := k.Create(ctx, runAsAddr, p.WASMByteCode, p.InstantiatePermission) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !p.UnpinCode { | ||
if err := k.PinCode(ctx, codeID); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
_, data, err := k.Instantiate(ctx, codeID, runAsAddr, adminAddr, p.Msg, p.Label, p.Funds) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctx.EventManager().EmitEvent(sdk.NewEvent( | ||
types.EventTypeGovContractResult, | ||
sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), | ||
)) | ||
return nil | ||
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. looks good |
||
} | ||
|
||
func handleMigrateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.MigrateContractProposal) error { | ||
if err := p.ValidateBasic(); err != nil { | ||
return err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,16 @@ type ContractOpsKeeper interface { | |
fixMsg bool, | ||
) (sdk.AccAddress, []byte, error) | ||
|
||
CreateAndInstantiate( | ||
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 export this. |
||
ctx sdk.Context, | ||
creator, admin sdk.AccAddress, | ||
wasmCode []byte, | ||
instantiateAccess *AccessConfig, | ||
initMsg []byte, | ||
label string, | ||
deposit sdk.Coins, | ||
) (sdk.AccAddress, []byte, error) | ||
|
||
// Execute executes the contract instance | ||
Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) | ||
|
||
|
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.
👍 This looks complete