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 that of
the state field definitions with one addition, the field type can be
followed by a question mark which indicates that that 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 {
id int32
}
func (s ImmutableMemberParams) Address() wasmlib.ScImmutableAddress {
return wasmlib.NewScImmutableAddress(s.id, idxMap[IdxParamAddress])
}
func (s ImmutableMemberParams) Factor() wasmlib.ScImmutableInt64 {
return wasmlib.NewScImmutableInt64(s.id, idxMap[IdxParamFactor])
}
#[derive(Clone, Copy)]
pub struct ImmutableMemberParams {
pub(crate) id: i32,
}
impl ImmutableMemberParams {
pub fn address(&self) -> ScImmutableAddress {
ScImmutableAddress::new(self.id, idx_map(IDX_PARAM_ADDRESS))
}
pub fn factor(&self) -> ScImmutableInt64 {
ScImmutableInt64::new(self.id, idx_map(IDX_PARAM_FACTOR))
}
}
export class ImmutableMemberParams extends wasmlib.ScMapID {
address(): wasmlib.ScImmutableAddress {
return new wasmlib.ScImmutableAddress(this.mapID, sc.idxMap[sc.IdxParamAddress]);
}
factor(): wasmlib.ScImmutableInt64 {
return new wasmlib.ScImmutableInt64(this.mapID, sc.idxMap[sc.IdxParamFactor]);
}
}
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.
In the next section, we will look at the results
.