Define Function Parameters
You can use the optional params
subsection to specify the parameters a function accepts.
This section can define both mandatory and optional parameters.
Optional parameters are denoted with a question mark ?
following the field type.
Schema Tool Automation
The Schema Tool streamlines the creation of functions by:
- Generating an immutable structure holding parameter proxies from the Params map.
- Checking the presence and data type of non-optional parameters before the function call.
These functionalities allow users to directly use parameter proxies in the structure passed to the function.
Omitting the params
subsection results in no structure generation or parameter passing 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));
}
}
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.