Function Parameters
The optional params
subsection contains field definitions for each of the
parameters that a function takes. The layout of the field definitions is identical to the
state
subsection field definitions with one addition, the field type can be
followed by a question mark to indicate that the parameter is optional.
The Schema Tool will automatically generate an immutable structure with member variables for proxies to each parameter variable in the Params map. It will also generate code to check the presence of each non-optional parameter, and it will also verify the parameter's data type. This checking is done before the function is called. The user will be able to immediately start using the parameter proxy through the structure that 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 immutable Params for
the member
function:
- Go
- Rust
- TypeScript
type ImmutableMemberParams struct {
proxy wasmtypes.Proxy
}
// address of dividend recipient
func (s ImmutableMemberParams) Address() wasmtypes.ScImmutableAddress {
return wasmtypes.NewScImmutableAddress(s.proxy.Root(ParamAddress))
}
// relative division factor
func (s ImmutableMemberParams) Factor() wasmtypes.ScImmutableUint64 {
return wasmtypes.NewScImmutableUint64(s.proxy.Root(ParamFactor))
}
#[derive(Clone)]
pub struct ImmutableMemberParams {
pub(crate) proxy: Proxy,
}
impl ImmutableMemberParams {
// address of dividend recipient
pub fn address(&self) -> ScImmutableAddress {
ScImmutableAddress::new(self.proxy.root(PARAM_ADDRESS))
}
// relative division factor
pub fn factor(&self) -> ScImmutableUint64 {
ScImmutableUint64::new(self.proxy.root(PARAM_FACTOR))
}
}
export class ImmutableMemberParams extends wasmtypes.ScProxy {
// address of dividend recipient
address(): wasmtypes.ScImmutableAddress {
return new wasmtypes.ScImmutableAddress(this.proxy.root(sc.ParamAddress));
}
// relative division factor
factor(): wasmtypes.ScImmutableUint64 {
return new wasmtypes.ScImmutableUint64(this.proxy.root(sc.ParamFactor));
}
}
Note that the Schema Tool will also generate a mutable version of the structure, suitable for providing the parameters when calling this smart contract function from any Call Context.
In the next section, we will look at the results
subsection.