I have the following code snippet for checking a transfer was successful. This function is taken from an already live project, though that project is using pragam 4.2.0
. I am using pragma 6.12.0
, so I am assuming that it is some kind of versioning issue with Yul but I am struggling to find the correct information.
The code:
function checkSuccess(
)
private
pure
returns (bool)
{
uint256 returnValue = 0;
assembly {
// check number of bytes returned from last function call
switch returndatasize
// no bytes returned: assume success
case 0x0 {
returnValue := 1
}
// 32 bytes returned: check if non-zero
case 0x20 {
// copy 32 bytes into scratch space
returndatacopy(0x0, 0x0, 0x20)
// load those bytes into returnValue
returnValue := mload(0x0)
}
// not sure what was returned: don't mark as success
default { }
}
return returnValue != 0;
}
I get the following error when compiling:
ParserError: Expected '(' but got reserved keyword 'case'
case 0x0 {
^--^
Anyone with more expertise with inline assembly who could shed some light on this is a +1 from me!
Thanks, Jim