Skip to content

Commit

Permalink
Directly extract required capabilities from report
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Dec 10, 2024
1 parent 5f9f00d commit edc67b3
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,17 @@ func (k Keeper) create(ctx context.Context, creator sdk.AccAddress, wasmCode []b
if err != nil {
return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error())
}
// simulation gets default value for report
var report *wasmvmtypes.AnalysisReport = &wasmvmtypes.AnalysisReport{}
// simulation gets default value for capabilities
var requiredCapabilities string
if !isSimulation {
report, err = k.wasmVM.AnalyzeCode(checksum)
}
if err != nil {
return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error())
report, err := k.wasmVM.AnalyzeCode(checksum)
if err != nil {
return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error())
}
requiredCapabilities = report.RequiredCapabilities
}
codeID = k.mustAutoIncrementID(sdkCtx, types.KeySequenceCodeID)
k.Logger(sdkCtx).Debug("storing new contract", "capabilities", report.RequiredCapabilities, "code_id", codeID)
k.Logger(sdkCtx).Debug("storing new contract", "capabilities", requiredCapabilities, "code_id", codeID)
codeInfo := types.NewCodeInfo(checksum, creator, *instantiateAccess)
k.mustStoreCodeInfo(sdkCtx, codeID, codeInfo)

Expand All @@ -201,7 +202,7 @@ func (k Keeper) create(ctx context.Context, creator sdk.AccAddress, wasmCode []b
sdk.NewAttribute(types.AttributeKeyChecksum, hex.EncodeToString(checksum)),
sdk.NewAttribute(types.AttributeKeyCodeID, strconv.FormatUint(codeID, 10)), // last element to be compatible with scripts
)
for _, f := range strings.Split(report.RequiredCapabilities, ",") {
for _, f := range strings.Split(requiredCapabilities, ",") {
evt.AppendAttributes(sdk.NewAttribute(types.AttributeKeyRequiredCapability, strings.TrimSpace(f)))
}
sdkCtx.EventManager().EmitEvent(evt)
Expand Down

0 comments on commit edc67b3

Please sign in to comment.