Address review comments

This commit is contained in:
Bhargava Shastry 2019-12-09 12:38:04 +01:00
parent a7f50c5aca
commit 70840d5411

View File

@ -344,7 +344,7 @@ Array Slices
------------ ------------
Array slices are a view on a contigous portion of an array. Array slices are a view on a contiguous portion of an array.
They are written as ``x[start:end]``, where ``start`` and They are written as ``x[start:end]``, where ``start`` and
``end`` are expressions resulting in a uint256 type (or ``end`` are expressions resulting in a uint256 type (or
implicitly convertible to it). The first element of the implicitly convertible to it). The first element of the
@ -353,14 +353,14 @@ slice is ``x[start]`` and the last element is ``x[end - 1]``.
If ``start`` is greater than ``end`` or if ``end`` is greater If ``start`` is greater than ``end`` or if ``end`` is greater
than the length of the array, an exception is thrown. than the length of the array, an exception is thrown.
Both ``start`` and ``end`` are optional, and they default to Both ``start`` and ``end`` are optional: ``start`` defaults
``0`` and the length of the array, respectively. to ``0`` and ``end`` defaults to the length of the array.
Array slices do not have any members. They are implicitly Array slices do not have any members. They are implicitly
convertible to arrays of their underlying type convertible to arrays of their underlying type
and support index access. Index access is of course and support index access. Index access is not absolute
not absolute in the underlying array, but relative to in the underlying array, but relative to the start of
the start of the slice. the slice.
Array slices do not have a type name which means Array slices do not have a type name which means
no variable can have an array slices as type, no variable can have an array slices as type,
@ -375,10 +375,24 @@ Array slices are useful to ABI-decode secondary data passed in function paramete
pragma solidity >=0.4.99 <0.7.0; pragma solidity >=0.4.99 <0.7.0;
contract C { contract Proxy {
function verifyBet(address recipient, bytes calldata _data) { /// Address of the client contract managed by proxy i.e., this contract
bytes4 sig = _data[:4]; address client;
// TODO continue with example
constructor(address _client) public {
client = _client;
}
/// 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));
if (sig == bytes4(keccak256("setOwner(address)"))) {
address owner = abi.decode(_payload[4:], (address));
require(owner != address(0), "Address of owner cannot be zero.");
}
(bool status,) = client.delegatecall(_payload);
require(status, "Forwarded call failed.");
} }
} }