Note on WIDL and Language Ergonomics
While the WIDL compiler can generate bindings for any specification to any of the supported languages, certain choices in the specification will generate code that is more or less ergonomic on different languages.
For example, the following specification will generate bindings whose methods have return values using Rust's standard Result<_,_>
type.
However, as Go does not have a standard equivalent type, the Weilliptic SDK for Go provides its own Result[_]
, which is not very ergonomic.
interface CrossCounter {
query func fetch_counter_from(contract_id: string) -> result<uint,string>;
mutate func increment_counter_of(contract_id: string) -> result<(),string>
}
If the contract is to be implemented in Go, then the following version of the spec would be more fitting.
interface CrossCounter {
query func fetch_counter_from(contract_id: string) -> (uint, string)>;
mutate func increment_counter_of(contract_id: string) -> string
}
The Go Result[_]
type is provided as a convenience, for example for when cross-contract calls are made between contracts developed in different languages.
Other types are provided in the same spirit and the Applet developer should use its discretion to chose whether to use a convenience type or write a spec that is more befitting of the implementation it foresees.
WIDL specifications can and should be enriched with comments that will help disambiguate the types used. For example, the following specification excerpt makes it clear that one and exactly one of the values in the returned tuple should be taken into account, for example to convert it into a Result<_,_>
.
// Returns a tuple (r,e) where r must be ignored if e is not the empty string ""
query func fetch_counter_from(contract_id: string) -> (uint, error)>;