-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from delta-mpc/zk
Zk
- Loading branch information
Showing
10 changed files
with
2,129 additions
and
1 deletion.
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,61 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract DataHub { | ||
address private owner; | ||
event OwnerSet(address indexed oldOwner, address indexed newOwner); | ||
|
||
struct DataRecord { | ||
bytes32 commitment; | ||
uint32 version; | ||
} | ||
mapping(address => mapping(string => DataRecord)) datahub; | ||
|
||
event DataRegistered( | ||
address indexed owner, | ||
string name, | ||
bytes32 commitment, | ||
uint32 version | ||
); | ||
|
||
constructor() { | ||
owner = msg.sender; | ||
emit OwnerSet(address(0), owner); | ||
} | ||
|
||
function register(string calldata name, bytes32 commitment) public { | ||
datahub[msg.sender][name].commitment = commitment; | ||
datahub[msg.sender][name].version += 1; | ||
|
||
emit DataRegistered( | ||
msg.sender, | ||
name, | ||
commitment, | ||
datahub[msg.sender][name].version | ||
); | ||
} | ||
|
||
modifier dataExists(address addr, string calldata name) { | ||
require(datahub[addr][name].version > 0); | ||
_; | ||
} | ||
|
||
function getDataCommitment(address addr, string calldata name) | ||
public | ||
view | ||
dataExists(addr, name) | ||
returns (bytes32 commitment) | ||
{ | ||
commitment = datahub[addr][name].commitment; | ||
} | ||
|
||
function getDataVersion(address addr, string calldata name) | ||
public | ||
view | ||
dataExists(addr, name) | ||
returns (uint32 version) | ||
{ | ||
version = datahub[addr][name].version; | ||
} | ||
} |
Oops, something went wrong.