Improving function call return types
With the inclusion of core#855 return values of function calls with a singular value is more intuitive and easier to work with.
Consider the following example of reading the balance of an ERC20:
sol! {
#[sol(rpc)]
contract ERC20 {
// Note: Only a single value is being returned
function balanceOf(address) returns (uint256);
}
}Before
Calling the balanceOf fn would return a struct balanceOfReturn which encapsulated the actual balance value.
// .. snip ..
let balance_return: balanceOfReturn = erc20.balanceOf(owner).await?;
let actual_balance = balance_return._0;After
Calling the balanceOf fn would now yield the balance directly instead of a struct wrapping it.
// .. snip ..
let balance: U256 = erc20.balanceOf(owner).await?;It is important to note that this change only applies to function calls that have a singular return value.
Function calls that return multiple values have their return types unchanged, i.e they still return a struct with values inside it.
sol! {
function multiValues() returns (uint256 a, address b, bytes c);
}
// The above function call will have the following return type.
pub struct multiValuesReturn {
pub a: U256,
pub b: Address,
pub c: Bytes,
}