mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Updated some examples following the naming convention
According to Solidity naming convention: https://docs.soliditylang.org/en/latest/style-guide.html#naming-conventions There is no need to use underscore except when there is a naming collision. In which case, a trailing underscore is used to avoid the collision. So in this change, I am removing all underscores, except for the ones that could shadow other symbols in their context (none of the changed names is a reserved keyword: https://docs.soliditylang.org/en/latest/cheatsheet.html?highlight=reserved#reserved-keywords )
This commit is contained in:
parent
c69f91917d
commit
e09b0ae15f
@ -64,15 +64,15 @@ to receive their money - contracts cannot activate themselves.
|
|||||||
/// The function auctionEnd has already been called.
|
/// The function auctionEnd has already been called.
|
||||||
error AuctionEndAlreadyCalled();
|
error AuctionEndAlreadyCalled();
|
||||||
|
|
||||||
/// Create a simple auction with `_biddingTime`
|
/// Create a simple auction with `biddingTime`
|
||||||
/// seconds bidding time on behalf of the
|
/// seconds bidding time on behalf of the
|
||||||
/// beneficiary address `_beneficiary`.
|
/// beneficiary address `beneficiaryAddress`.
|
||||||
constructor(
|
constructor(
|
||||||
uint _biddingTime,
|
uint biddingTime,
|
||||||
address payable _beneficiary
|
address payable beneficiaryAddress
|
||||||
) {
|
) {
|
||||||
beneficiary = _beneficiary;
|
beneficiary = beneficiaryAddress;
|
||||||
auctionEndTime = block.timestamp + _biddingTime;
|
auctionEndTime = block.timestamp + biddingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bid on the auction with the value sent
|
/// Bid on the auction with the value sent
|
||||||
@ -232,26 +232,26 @@ invalid bids.
|
|||||||
// functions. `onlyBefore` is applied to `bid` below:
|
// functions. `onlyBefore` is applied to `bid` below:
|
||||||
// The new function body is the modifier's body where
|
// The new function body is the modifier's body where
|
||||||
// `_` is replaced by the old function body.
|
// `_` is replaced by the old function body.
|
||||||
modifier onlyBefore(uint _time) {
|
modifier onlyBefore(uint time) {
|
||||||
if (block.timestamp >= _time) revert TooLate(_time);
|
if (block.timestamp >= time) revert TooLate(time);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
modifier onlyAfter(uint _time) {
|
modifier onlyAfter(uint time) {
|
||||||
if (block.timestamp <= _time) revert TooEarly(_time);
|
if (block.timestamp <= time) revert TooEarly(time);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
uint _biddingTime,
|
uint biddingTime,
|
||||||
uint _revealTime,
|
uint revealTime,
|
||||||
address payable _beneficiary
|
address payable beneficiaryAddress
|
||||||
) {
|
) {
|
||||||
beneficiary = _beneficiary;
|
beneficiary = beneficiaryAddress;
|
||||||
biddingEnd = block.timestamp + _biddingTime;
|
biddingEnd = block.timestamp + biddingTime;
|
||||||
revealEnd = biddingEnd + _revealTime;
|
revealEnd = biddingEnd + revealTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Place a blinded bid with `_blindedBid` =
|
/// Place a blinded bid with `blindedBid` =
|
||||||
/// keccak256(abi.encodePacked(value, fake, secret)).
|
/// keccak256(abi.encodePacked(value, fake, secret)).
|
||||||
/// The sent ether is only refunded if the bid is correctly
|
/// The sent ether is only refunded if the bid is correctly
|
||||||
/// revealed in the revealing phase. The bid is valid if the
|
/// revealed in the revealing phase. The bid is valid if the
|
||||||
@ -260,13 +260,13 @@ invalid bids.
|
|||||||
/// not the exact amount are ways to hide the real bid but
|
/// not the exact amount are ways to hide the real bid but
|
||||||
/// still make the required deposit. The same address can
|
/// still make the required deposit. The same address can
|
||||||
/// place multiple bids.
|
/// place multiple bids.
|
||||||
function bid(bytes32 _blindedBid)
|
function bid(bytes32 blindedBid)
|
||||||
external
|
external
|
||||||
payable
|
payable
|
||||||
onlyBefore(biddingEnd)
|
onlyBefore(biddingEnd)
|
||||||
{
|
{
|
||||||
bids[msg.sender].push(Bid({
|
bids[msg.sender].push(Bid({
|
||||||
blindedBid: _blindedBid,
|
blindedBid: blindedBid,
|
||||||
deposit: msg.value
|
deposit: msg.value
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -275,24 +275,24 @@ invalid bids.
|
|||||||
/// correctly blinded invalid bids and for all bids except for
|
/// correctly blinded invalid bids and for all bids except for
|
||||||
/// the totally highest.
|
/// the totally highest.
|
||||||
function reveal(
|
function reveal(
|
||||||
uint[] calldata _values,
|
uint[] calldata values,
|
||||||
bool[] calldata _fake,
|
bool[] calldata fakes,
|
||||||
bytes32[] calldata _secret
|
bytes32[] calldata secrets
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
onlyAfter(biddingEnd)
|
onlyAfter(biddingEnd)
|
||||||
onlyBefore(revealEnd)
|
onlyBefore(revealEnd)
|
||||||
{
|
{
|
||||||
uint length = bids[msg.sender].length;
|
uint length = bids[msg.sender].length;
|
||||||
require(_values.length == length);
|
require(values.length == length);
|
||||||
require(_fake.length == length);
|
require(fakes.length == length);
|
||||||
require(_secret.length == length);
|
require(secrets.length == length);
|
||||||
|
|
||||||
uint refund;
|
uint refund;
|
||||||
for (uint i = 0; i < length; i++) {
|
for (uint i = 0; i < length; i++) {
|
||||||
Bid storage bidToCheck = bids[msg.sender][i];
|
Bid storage bidToCheck = bids[msg.sender][i];
|
||||||
(uint value, bool fake, bytes32 secret) =
|
(uint value, bool fake, bytes32 secret) =
|
||||||
(_values[i], _fake[i], _secret[i]);
|
(values[i], fakes[i], secrets[i]);
|
||||||
if (bidToCheck.blindedBid != keccak256(abi.encodePacked(value, fake, secret))) {
|
if (bidToCheck.blindedBid != keccak256(abi.encodePacked(value, fake, secret))) {
|
||||||
// Bid was not actually revealed.
|
// Bid was not actually revealed.
|
||||||
// Do not refund deposit.
|
// Do not refund deposit.
|
||||||
|
@ -346,11 +346,11 @@ The full contract
|
|||||||
address payable public recipient; // The account receiving the payments.
|
address payable public recipient; // The account receiving the payments.
|
||||||
uint256 public expiration; // Timeout in case the recipient never closes.
|
uint256 public expiration; // Timeout in case the recipient never closes.
|
||||||
|
|
||||||
constructor (address payable _recipient, uint256 duration)
|
constructor (address payable recipientAddress, uint256 duration)
|
||||||
payable
|
payable
|
||||||
{
|
{
|
||||||
sender = payable(msg.sender);
|
sender = payable(msg.sender);
|
||||||
recipient = _recipient;
|
recipient = recipientAddress;
|
||||||
expiration = block.timestamp + duration;
|
expiration = block.timestamp + duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ you can use state machine-like constructs inside a contract.
|
|||||||
// The state variable has a default value of the first member, `State.created`
|
// The state variable has a default value of the first member, `State.created`
|
||||||
State public state;
|
State public state;
|
||||||
|
|
||||||
modifier condition(bool _condition) {
|
modifier condition(bool condition_) {
|
||||||
require(_condition);
|
require(condition_);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ you can use state machine-like constructs inside a contract.
|
|||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifier inState(State _state) {
|
modifier inState(State state_) {
|
||||||
if (state != _state)
|
if (state != state_)
|
||||||
revert InvalidState();
|
revert InvalidState();
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user