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:
- Go
- Rust
- TypeScript
type MutableGetFactorResults struct {
proxy wasmtypes.Proxy
}
// relative division factor
func (s MutableGetFactorResults) Factor() wasmtypes.ScMutableUint64 {
return wasmtypes.NewScMutableUint64(s.proxy.Root(ResultFactor))
}
#[derive(Clone)]
pub struct MutableGetFactorResults {
pub(crate) proxy: Proxy,
}
impl MutableGetFactorResults {
// relative division factor
pub fn factor(&self) -> ScMutableUint64 {
ScMutableUint64::new(self.proxy.root(RESULT_FACTOR))
}
}
export class MutableGetFactorResults extends wasmtypes.ScProxy {
// relative division factor
factor(): wasmtypes.ScMutableUint64 {
return new wasmtypes.ScMutableUint64(this.proxy.root(sc.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.