Define Function Results
You can use the optional results
subsection to detail the results a function can produce.
This setup aligns with the field definitions seen in the Params subsection.
Schema Tool Features
The Schema Tool assists in this setup by:
- Creating a mutable structure that includes proxies for each result variable found in the Results map.
- Enabling users to assign values to result variables via this generated structure during the function call.
note
If the results
subsection is not used, no structure will be created or conveyed 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.