Skip to content

Commit e691afe

Browse files
author
Chris Hatch
committed
add ethlint/solium and fix contract lint problems
1 parent b6462d9 commit e691afe

File tree

7 files changed

+2405
-151
lines changed

7 files changed

+2405
-151
lines changed

.soliumignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
contracts/Migrations.sol

.soliumrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "solium:recommended",
3+
"plugins": ["security"],
4+
"rules": {
5+
"quotes": ["error", "double"],
6+
"indentation": ["error", 4],
7+
"linebreak-style": ["error", "unix"],
8+
"security/no-block-members": "off"
9+
}
10+
}

contracts/HashedTimelock.sol

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity ^0.5.0;
55
*
66
* This contract provides a way to create and keep HTLCs for ETH.
77
*
8-
* See HashedTimelockERC20.sol for a contract that provides the same functions
8+
* See HashedTimelockERC20.sol for a contract that provides the same functions
99
* for ERC20 tokens.
1010
*
1111
* Protocol:
@@ -14,8 +14,8 @@ pragma solidity ^0.5.0;
1414
* a new HTLC and gets back a 32 byte contract id
1515
* 2) withdraw(contractId, preimage) - once the receiver knows the preimage of
1616
* the hashlock hash they can claim the ETH with this function
17-
* 3) refund() - after timelock has expired and if the receiver did not
18-
* withdraw funds the sender / creator of the HTLC can get their ETH
17+
* 3) refund() - after timelock has expired and if the receiver did not
18+
* withdraw funds the sender / creator of the HTLC can get their ETH
1919
* back with this function.
2020
*/
2121
contract HashedTimelock {
@@ -81,14 +81,14 @@ contract HashedTimelock {
8181
mapping (bytes32 => LockContract) contracts;
8282

8383
/**
84-
* @dev Sender sets up a new hash time lock contract depositing the ETH and
84+
* @dev Sender sets up a new hash time lock contract depositing the ETH and
8585
* providing the reciever lock terms.
8686
*
8787
* @param _receiver Receiver of the ETH.
8888
* @param _hashlock A sha-2 sha256 hash hashlock.
89-
* @param _timelock UNIX epoch seconds time that the lock expires at.
89+
* @param _timelock UNIX epoch seconds time that the lock expires at.
9090
* Refunds can be made after this time.
91-
* @return contractId Id of the new HTLC. This is needed for subsequent
91+
* @return contractId Id of the new HTLC. This is needed for subsequent
9292
* calls.
9393
*/
9494
function newContract(address payable _receiver, bytes32 _hashlock, uint _timelock)
@@ -109,10 +109,10 @@ contract HashedTimelock {
109109
);
110110

111111
// Reject if a contract already exists with the same parameters. The
112-
// sender must change one of these parameters to create a new distinct
112+
// sender must change one of these parameters to create a new distinct
113113
// contract.
114114
if (haveContract(contractId))
115-
revert();
115+
revert("Contract already exists");
116116

117117
contracts[contractId] = LockContract(
118118
msg.sender,
@@ -200,8 +200,16 @@ contract HashedTimelock {
200200
if (haveContract(_contractId) == false)
201201
return (address(0), address(0), 0, 0, 0, false, false, 0);
202202
LockContract storage c = contracts[_contractId];
203-
return (c.sender, c.receiver, c.amount, c.hashlock, c.timelock,
204-
c.withdrawn, c.refunded, c.preimage);
203+
return (
204+
c.sender,
205+
c.receiver,
206+
c.amount,
207+
c.hashlock,
208+
c.timelock,
209+
c.withdrawn,
210+
c.refunded,
211+
c.preimage
212+
);
205213
}
206214

207215
/**

contracts/HashedTimelockERC20.sol

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
77
*
88
* This contract provides a way to create and keep HTLCs for ERC20 tokens.
99
*
10-
* See HashedTimelock.sol for a contract that provides the same functions
10+
* See HashedTimelock.sol for a contract that provides the same functions
1111
* for the native ETH token.
1212
*
1313
* Protocol:
1414
*
15-
* 1) newContract(receiver, hashlock, timelock, tokenContract, amount) - a
16-
* sender calls this to create a new HTLC on a given token (tokenContract)
15+
* 1) newContract(receiver, hashlock, timelock, tokenContract, amount) - a
16+
* sender calls this to create a new HTLC on a given token (tokenContract)
1717
* for a given amount. A 32 byte contract id is returned
1818
* 2) withdraw(contractId, preimage) - once the receiver knows the preimage of
1919
* the hashlock hash they can claim the tokens with this function
20-
* 3) refund() - after timelock has expired and if the receiver did not
21-
* withdraw the tokens the sender / creator of the HTLC can get their tokens
20+
* 3) refund() - after timelock has expired and if the receiver did not
21+
* withdraw the tokens the sender / creator of the HTLC can get their tokens
2222
* back with this function.
2323
*/
2424
contract HashedTimelockERC20 {
25-
constructor() public {
26-
}
27-
2825
event HTLCERC20New(
2926
bytes32 indexed contractId,
3027
address indexed sender,
@@ -43,7 +40,9 @@ contract HashedTimelockERC20 {
4340
address tokenContract;
4441
uint256 amount;
4542
bytes32 hashlock;
46-
uint256 timelock; // locked UNTIL this time. Unit depends on consensus algorithm. PoA, PoA and IBFT all use seconds. But Quorum Raft uses nano-seconds
43+
// locked UNTIL this time. Unit depends on consensus algorithm.
44+
// PoA, PoA and IBFT all use seconds. But Quorum Raft uses nano-seconds
45+
uint256 timelock;
4746
bool withdrawn;
4847
bool refunded;
4948
bytes32 preimage;
@@ -96,16 +95,16 @@ contract HashedTimelockERC20 {
9695
* @dev Sender / Payer sets up a new hash time lock contract depositing the
9796
* funds and providing the reciever and terms.
9897
*
99-
* NOTE: _receiver must first call approve() on the token contract.
98+
* NOTE: _receiver must first call approve() on the token contract.
10099
* See allowance check in tokensTransferable modifier.
101100
102101
* @param _receiver Receiver of the tokens.
103102
* @param _hashlock A sha-2 sha256 hash hashlock.
104-
* @param _timelock UNIX epoch seconds time that the lock expires at.
103+
* @param _timelock UNIX epoch seconds time that the lock expires at.
105104
* Refunds can be made after this time.
106105
* @param _tokenContract ERC20 Token contract address.
107106
* @param _amount Amount of the token to lock up.
108-
* @return contractId Id of the new HTLC. This is needed for subsequent
107+
* @return contractId Id of the new HTLC. This is needed for subsequent
109108
* calls.
110109
*/
111110
function newContract(
@@ -135,11 +134,11 @@ contract HashedTimelockERC20 {
135134
// sender must change one of these parameters (ideally providing a
136135
// different _hashlock).
137136
if (haveContract(contractId))
138-
revert();
137+
revert("Contract already exists");
139138

140139
// This contract becomes the temporary owner of the tokens
141140
if (!ERC20(_tokenContract).transferFrom(msg.sender, address(this), _amount))
142-
revert();
141+
revert("transferFrom sender to this failed");
143142

144143
contracts[contractId] = LockContract(
145144
msg.sender,

contracts/HashedTimelockERC721.sol

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol";
77
*
88
* This contract provides a way to create and keep HTLCs for ERC721 tokens.
99
*
10-
* See HashedTimelock.sol for a contract that provides the same functions
10+
* See HashedTimelock.sol for a contract that provides the same functions
1111
* for the native ETH token.
1212
*
1313
* Protocol:
1414
*
15-
* 1) newContract(receiver, hashlock, timelock, tokenContract, tokenId) - a
16-
* sender calls this to create a new HTLC on a given token (tokenContract)
15+
* 1) newContract(receiver, hashlock, timelock, tokenContract, tokenId) - a
16+
* sender calls this to create a new HTLC on a given token (tokenContract)
1717
* for a given token ID. A 32 byte contract id is returned
1818
* 2) withdraw(contractId, preimage) - once the receiver knows the preimage of
1919
* the hashlock hash they can claim the tokens with this function
20-
* 3) refund() - after timelock has expired and if the receiver did not
21-
* withdraw the tokens the sender / creater of the HTLC can get their tokens
20+
* 3) refund() - after timelock has expired and if the receiver did not
21+
* withdraw the tokens the sender / creater of the HTLC can get their tokens
2222
* back with this function.
2323
*/
2424
contract HashedTimelockERC721 {
@@ -41,7 +41,9 @@ contract HashedTimelockERC721 {
4141
address tokenContract;
4242
uint256 tokenId;
4343
bytes32 hashlock;
44-
uint256 timelock; // locked UNTIL this time. Unit depends on consensus algorithm. PoA, PoA and IBFT all use seconds. But Quorum Raft uses nano-seconds
44+
// locked UNTIL this time. Unit depends on consensus algorithm.
45+
// PoA, PoA and IBFT all use seconds. But Quorum Raft uses nano-seconds
46+
uint256 timelock;
4547
bool withdrawn;
4648
bool refunded;
4749
bytes32 preimage;
@@ -52,7 +54,7 @@ contract HashedTimelockERC721 {
5254
// so that it is able to honor the claim request later
5355
require(
5456
ERC721(_token).getApproved(_tokenId) == address(this),
55-
"The HTLC contract must have been designated an approved spender for the tokenId"
57+
"The HTLC must have been designated an approved spender for the tokenId"
5658
);
5759
_;
5860
}
@@ -95,16 +97,16 @@ contract HashedTimelockERC721 {
9597
* @dev Sender / Payer sets up a new hash time lock contract depositing the
9698
* funds and providing the reciever and terms.
9799
*
98-
* NOTE: _receiver must first call approve() on the token contract.
100+
* NOTE: _receiver must first call approve() on the token contract.
99101
* See isApprovedOrOwner check in tokensTransferable modifier.
100102
101103
* @param _receiver Receiver of the tokens.
102104
* @param _hashlock A sha-2 sha256 hash hashlock.
103-
* @param _timelock UNIX epoch seconds time that the lock expires at.
105+
* @param _timelock UNIX epoch seconds time that the lock expires at.
104106
* Refunds can be made after this time.
105107
* @param _tokenContract ERC20 Token contract address.
106108
* @param _tokenId Id of the token to lock up.
107-
* @return contractId Id of the new HTLC. This is needed for subsequent
109+
* @return contractId Id of the new HTLC. This is needed for subsequent
108110
* calls.
109111
*/
110112
function newContract(
@@ -134,7 +136,7 @@ contract HashedTimelockERC721 {
134136
// sender must change one of these parameters (ideally providing a
135137
// different _hashlock).
136138
if (haveContract(contractId))
137-
revert();
139+
revert("Contract already exists");
138140

139141
// This contract becomes the temporary owner of the token
140142
ERC721(_tokenContract).transferFrom(msg.sender, address(this), _tokenId);

0 commit comments

Comments
 (0)