Merge pull request #9167 from ethereum/fixDocExDecode

Fix documentation example.
This commit is contained in:
chriseth 2020-06-10 14:07:23 +02:00 committed by GitHub
commit 4cf4068020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -430,7 +430,13 @@ Array slices are useful to ABI-decode secondary data passed in function paramete
/// Forward call to "setOwner(address)" that is implemented by client
/// after doing basic validation on the address argument.
function forward(bytes calldata _payload) external {
bytes4 sig = abi.decode(_payload[:4], (bytes4));
// Since ABI decoding requires padded data, we cannot
// use abi.decode(_payload[:4], (bytes4)).
bytes4 sig =
_payload[0] |
(bytes4(_payload[1]) >> 8) |
(bytes4(_payload[2]) >> 16) |
(bytes4(_payload[3]) >> 24);
if (sig == bytes4(keccak256("setOwner(address)"))) {
address owner = abi.decode(_payload[4:], (address));
require(owner != address(0), "Address of owner cannot be zero.");