Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
11 changed files
with
2,213 additions
and
1,122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
contracts/Migrations.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
); | ||
} | ||
} |
Oops, something went wrong.