Skip to content

Commit

Permalink
Add solium linter (#39)
Browse files Browse the repository at this point in the history
* add solium configuration and list command

* run lint with fix

* fix lint errors and warnings and add pre-commit lint hook

* remove useless npm script

* change max-len rule to error

* change all warning rules to errors
  • Loading branch information
rdinicut committed Sep 26, 2018
1 parent efbab64 commit 35e929d
Show file tree
Hide file tree
Showing 11 changed files with 2,213 additions and 1,122 deletions.
2 changes: 2 additions & 0 deletions .soliumignore
@@ -0,0 +1,2 @@
node_modules
contracts/Migrations.sol
17 changes: 17 additions & 0 deletions .soliumrc.json
@@ -0,0 +1,17 @@
{
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"error-reason": "off",
"indentation": ["error", 2],
"max-len": ["error", 99],
"no-constant": ["error"],
"no-empty-blocks": "off",
"quotes": ["error", "double"],
"uppercase": "off",

"security/enforce-explicit-visibility": ["error"],
"security/no-block-members": ["error"],
"security/no-inline-assembly": ["error"]
}
}
122 changes: 80 additions & 42 deletions contracts/AnchorRegistry.sol
@@ -1,47 +1,85 @@
pragma solidity ^0.4.24
;
import 'openzeppelin-solidity/contracts/ownership/Ownable.sol';

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";


contract AnchorRegistry is Ownable {
event AnchorRegistered(address indexed from, bytes32 indexed identifier, bytes32 indexed rootHash, bytes32 timestamp, uint anchorSchemaVersion);
struct Anchor {
bytes32 identifier;
bytes32 merkleRoot;
bytes32 timestamp;
uint schemaVersion;
}

mapping (bytes32 => Anchor) public anchors;

function registerAnchor (bytes32 identifier, bytes32 merkleRoot, uint anchorSchemaVersion) public {

//not allowing to write to an existing anchor
require(anchors[identifier].identifier == 0x0);

// not allowing empty string
require(identifier != 0x0);
require(merkleRoot != 0x0);

// not allowing "null"
// some clients will translate a *null* to a string containing "null"
// reject this to prevent coding errors on the user side
require(identifier != 0x6e756c6c00000000000000000000000000000000000000000000000000000000);
require(merkleRoot != 0x6e756c6c00000000000000000000000000000000000000000000000000000000);

require(anchorSchemaVersion > 0);

bytes32 timeStamp = bytes32(now);

anchors[identifier] = Anchor(identifier, merkleRoot, timeStamp, anchorSchemaVersion);
emit AnchorRegistered(msg.sender, identifier, merkleRoot, timeStamp, anchorSchemaVersion);
}

function getAnchorById (bytes32 identifier) public view returns(bytes32, bytes32, bytes32, uint) {
return (
anchors[identifier].identifier,
anchors[identifier].merkleRoot,
anchors[identifier].timestamp,
anchors[identifier].schemaVersion
);
}
event AnchorRegistered(
address indexed from,
bytes32 indexed identifier,
bytes32 indexed rootHash,
bytes32 timestamp,
uint anchorSchemaVersion
);

struct Anchor {
bytes32 identifier;
bytes32 merkleRoot;
bytes32 timestamp;
uint schemaVersion;
}

mapping(bytes32 => Anchor) public anchors;

function registerAnchor(
bytes32 identifier,
bytes32 merkleRoot,
uint anchorSchemaVersion
)
public
{
//not allowing to write to an existing anchor
require(anchors[identifier].identifier == 0x0);
// not allowing empty string
require(identifier != 0x0);
require(merkleRoot != 0x0);

// not allowing "null"
// some clients will translate a *null* to a string containing "null"
// reject this to prevent coding errors on the user side
require(
identifier != 0x6e756c6c00000000000000000000000000000000000000000000000000000000
);
require(
merkleRoot != 0x6e756c6c00000000000000000000000000000000000000000000000000000000
);
require(anchorSchemaVersion > 0);
// TODO remove this
/* solium-disable-next-line */
bytes32 timeStamp = bytes32(now);

anchors[identifier] = Anchor(
identifier,
merkleRoot,
timeStamp,
anchorSchemaVersion
);

emit AnchorRegistered(
msg.sender,
identifier,
merkleRoot,
timeStamp,
anchorSchemaVersion
);
}

function getAnchorById(bytes32 identifier)
public
view
returns (
bytes32,
bytes32,
bytes32,
uint
)
{
return (
anchors[identifier].identifier,
anchors[identifier].merkleRoot,
anchors[identifier].timestamp,
anchors[identifier].schemaVersion
);
}
}

0 comments on commit 35e929d

Please sign in to comment.