Skip to content

Commit

Permalink
Merge pull request #14 from delta-mpc/zk
Browse files Browse the repository at this point in the history
Zk
  • Loading branch information
mh739025250 authored Sep 29, 2022
2 parents 90e15d0 + 8f46d52 commit 5ab5a99
Show file tree
Hide file tree
Showing 10 changed files with 2,129 additions and 1 deletion.
61 changes: 61 additions & 0 deletions contracts/DataHub.sol
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;
}
}
Loading

0 comments on commit 5ab5a99

Please sign in to comment.