Skip to main content

Function Results

The optional results subsection contains field definitions for each of the results a function produces. The layout of the field definitions is identical to that of the Params field definitions.

The Schema Tool will automatically generate a mutable structure with member variables for proxies to each result variable in the Results map. The user will be able to set the result variables through this structure, which is passed to the function.

When this subsection is empty, or completely omitted, no structure will be generated or passed to the function.

For example, here is the structure generated for the mutable results for the getFactor function:

type MutableGetFactorResults struct {
proxy wasmtypes.Proxy
}

// relative division factor
func (s MutableGetFactorResults) Factor() wasmtypes.ScMutableUint64 {
return wasmtypes.NewScMutableUint64(s.proxy.Root(ResultFactor))
}

Note that the Schema Tool will also generate an immutable version of the structure, suitable for accessing the results after by the caller of this smart contract function.

In the next section we will look at how so-called thunk functions encapsulate access and parameter checking and set up the type-safe function-specific contexts.