fix: corrects _ prefixes

This commit is contained in:
Richie
2022-03-14 08:03:10 -07:00
parent 7f360e61fc
commit beb51068bb
16 changed files with 185 additions and 185 deletions
+5 -5
View File
@@ -41,14 +41,14 @@ Not all types for constants and immutables are implemented at this time. The onl
uint immutable maxBalance;
address immutable owner = msg.sender;
constructor(uint _decimals, address _reference) {
decimals = _decimals;
constructor(uint decimals_, address ref) {
decimals = decimals_;
// Assignments to immutables can even access the environment.
maxBalance = _reference.balance;
maxBalance = ref.balance;
}
function isBalanceTooHigh(address _other) public view returns (bool) {
return _other.balance > maxBalance;
function isBalanceTooHigh(address other) public view returns (bool) {
return other.balance > maxBalance;
}
}
+2 -2
View File
@@ -48,7 +48,7 @@ This means that cyclic creation dependencies are impossible.
// This is the constructor which registers the
// creator and the assigned name.
constructor(bytes32 _name) {
constructor(bytes32 name_) {
// State variables are accessed via their name
// and not via e.g. `this.owner`. Functions can
// be accessed directly or through `this.f`,
@@ -65,7 +65,7 @@ This means that cyclic creation dependencies are impossible.
// no real way to verify that.
// This does not create a new contract.
creator = TokenCreator(msg.sender);
name = _name;
name = name_;
}
function changeName(bytes32 newName) public {
+8 -8
View File
@@ -80,18 +80,18 @@ four indexed arguments rather than three.
contract ClientReceipt {
event Deposit(
address indexed _from,
bytes32 indexed _id,
uint _value
address indexed from,
bytes32 indexed id,
uint value
);
function deposit(bytes32 _id) public payable {
function deposit(bytes32 id) public payable {
// Events are emitted using `emit`, followed by
// the name of the event and the arguments
// (if any) in parentheses. Any such invocation
// (even deeply nested) can be detected from
// the JavaScript API by filtering for `Deposit`.
emit Deposit(msg.sender, _id, msg.value);
emit Deposit(msg.sender, id, msg.value);
}
}
@@ -126,9 +126,9 @@ The output of the above looks like the following (trimmed):
{
"returnValues": {
"_from": "0x1111…FFFFCCCC",
"_id": "0x50…sd5adb20",
"_value": "0x420042"
"from": "0x1111…FFFFCCCC",
"id": "0x50…sd5adb20",
"value": "0x420042"
},
"raw": {
"data": "0x7f…91385",
+2 -2
View File
@@ -72,8 +72,8 @@ if they are marked ``virtual``. For details, please see
registeredAddresses[msg.sender] = true;
}
function changePrice(uint _price) public onlyOwner {
price = _price;
function changePrice(uint price_) public onlyOwner {
price = price_;
}
}
+29 -29
View File
@@ -17,17 +17,17 @@ that call them, similar to internal library functions.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.1 <0.9.0;
function sum(uint[] memory _arr) pure returns (uint s) {
for (uint i = 0; i < _arr.length; i++)
s += _arr[i];
function sum(uint[] memory arr) pure returns (uint s) {
for (uint i = 0; i < arr.length; i++)
s += arr[i];
}
contract ArrayExample {
bool found;
function f(uint[] memory _arr) public {
function f(uint[] memory arr) public {
// This calls the free function internally.
// The compiler will add its code to the contract.
uint s = sum(_arr);
uint s = sum(arr);
require(s >= 10);
found = true;
}
@@ -65,8 +65,8 @@ with two integers, you would use something like the following:
contract Simple {
uint sum;
function taker(uint _a, uint _b) public {
sum = _a + _b;
function taker(uint a, uint b) public {
sum = a + b;
}
}
@@ -99,13 +99,13 @@ two integers passed as function parameters, then you use something like:
pragma solidity >=0.4.16 <0.9.0;
contract Simple {
function arithmetic(uint _a, uint _b)
function arithmetic(uint a, uint b)
public
pure
returns (uint sum, uint product)
{
sum = _a + _b;
product = _a * _b;
sum = a + b;
product = a * b;
}
}
@@ -126,12 +126,12 @@ statement:
pragma solidity >=0.4.16 <0.9.0;
contract Simple {
function arithmetic(uint _a, uint _b)
function arithmetic(uint a, uint b)
public
pure
returns (uint sum, uint product)
{
return (_a + _b, _a * _b);
return (a + b, a * b);
}
}
@@ -362,7 +362,7 @@ Fallback Function
-----------------
A contract can have at most one ``fallback`` function, declared using either ``fallback () external [payable]``
or ``fallback (bytes calldata _input) external [payable] returns (bytes memory _output)``
or ``fallback (bytes calldata input) external [payable] returns (bytes memory output)``
(both without the ``function`` keyword).
This function must have ``external`` visibility. A fallback function can be virtual, can override
and can have modifiers.
@@ -373,8 +373,8 @@ all and there is no :ref:`receive Ether function <receive-ether-function>`.
The fallback function always receives data, but in order to also receive Ether
it must be marked ``payable``.
If the version with parameters is used, ``_input`` will contain the full data sent to the contract
(equal to ``msg.data``) and can return data in ``_output``. The returned data will not be
If the version with parameters is used, ``input`` will contain the full data sent to the contract
(equal to ``msg.data``) and can return data in ``output``. The returned data will not be
ABI-encoded. Instead it will be returned without modifications (not even padding).
In the worst case, if a payable fallback function is also used in
@@ -397,7 +397,7 @@ operations as long as there is enough gas passed on to it.
for the function selector and then
you can use ``abi.decode`` together with the array slice syntax to
decode ABI-encoded data:
``(c, d) = abi.decode(_input[4:], (uint256, uint256));``
``(c, d) = abi.decode(input[4:], (uint256, uint256));``
Note that this should only be used as a last resort and
proper functions should be used instead.
@@ -486,13 +486,13 @@ The following example shows overloading of the function
pragma solidity >=0.4.16 <0.9.0;
contract A {
function f(uint _in) public pure returns (uint out) {
out = _in;
function f(uint value) public pure returns (uint out) {
out = value;
}
function f(uint _in, bool _really) public pure returns (uint out) {
if (_really)
out = _in;
function f(uint value, bool really) public pure returns (uint out) {
if (really)
out = value;
}
}
@@ -506,12 +506,12 @@ externally visible functions differ by their Solidity types but not by their ext
// This will not compile
contract A {
function f(B _in) public pure returns (B out) {
out = _in;
function f(B value) public pure returns (B out) {
out = value;
}
function f(address _in) public pure returns (address out) {
out = _in;
function f(address value) public pure returns (address out) {
out = value;
}
}
@@ -539,12 +539,12 @@ candidate, resolution fails.
pragma solidity >=0.4.16 <0.9.0;
contract A {
function f(uint8 _in) public pure returns (uint8 out) {
out = _in;
function f(uint8 val) public pure returns (uint8 out) {
out = val;
}
function f(uint256 _in) public pure returns (uint256 out) {
out = _in;
function f(uint256 val) public pure returns (uint256 out) {
out = val;
}
}
+5 -5
View File
@@ -421,8 +421,8 @@ equivalent to ``constructor() {}``. For example:
abstract contract A {
uint public a;
constructor(uint _a) {
a = _a;
constructor(uint a_) {
a = a_;
}
}
@@ -459,7 +459,7 @@ derived contracts need to specify all of them. This can be done in two ways:
contract Base {
uint x;
constructor(uint _x) { x = _x; }
constructor(uint x_) { x = x_; }
}
// Either directly specify in the inheritance list...
@@ -469,12 +469,12 @@ derived contracts need to specify all of them. This can be done in two ways:
// or through a "modifier" of the derived constructor.
contract Derived2 is Base {
constructor(uint _y) Base(_y * _y) {}
constructor(uint y) Base(y * y) {}
}
One way is directly in the inheritance list (``is Base(7)``). The other is in
the way a modifier is invoked as part of
the derived constructor (``Base(_y * _y)``). The first way to
the derived constructor (``Base(y * y)``). The first way to
do it is more convenient if the constructor argument is a
constant and defines the behaviour of the contract or
describes it. The second way has to be used if the
+8 -8
View File
@@ -146,16 +146,16 @@ custom types without the overhead of external function calls:
r.limbs[0] = x;
}
function add(bigint memory _a, bigint memory _b) internal pure returns (bigint memory r) {
r.limbs = new uint[](max(_a.limbs.length, _b.limbs.length));
function add(bigint memory a, bigint memory b) internal pure returns (bigint memory r) {
r.limbs = new uint[](max(a.limbs.length, b.limbs.length));
uint carry = 0;
for (uint i = 0; i < r.limbs.length; ++i) {
uint a = limb(_a, i);
uint b = limb(_b, i);
uint limbA = limb(a, i);
uint limbB = limb(b, i);
unchecked {
r.limbs[i] = a + b + carry;
r.limbs[i] = limbA + limbB + carry;
if (a + b < a || (a + b == type(uint).max && carry > 0))
if (limbA + limbB < limbA || (limbA + limbB == type(uint).max && carry > 0))
carry = 1;
else
carry = 0;
@@ -172,8 +172,8 @@ custom types without the overhead of external function calls:
}
}
function limb(bigint memory _a, uint _limb) internal pure returns (uint) {
return _limb < _a.limbs.length ? _a.limbs[_limb] : 0;
function limb(bigint memory a, uint index) internal pure returns (uint) {
return index < a.limbs.length ? a.limbs[index] : 0;
}
function max(uint a, uint b) private pure returns (uint) {
+4 -4
View File
@@ -128,13 +128,13 @@ In this example, we will use a library.
data.push(value);
}
function replace(uint _old, uint _new) public {
function replace(uint from, uint to) public {
// This performs the library function call
uint index = data.indexOf(_old);
uint index = data.indexOf(from);
if (index == type(uint).max)
data.push(_new);
data.push(to);
else
data[index] = _new;
data[index] = to;
}
}