-
Notifications
You must be signed in to change notification settings - Fork 8
/
blkcc smart contract for notary v1 .sol
66 lines (50 loc) · 1.56 KB
/
blkcc smart contract for notary v1 .sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// backup copy to: https://ropsten.etherscan.io/address/0x3e36fc445441cdea7f380aec633e6bb0d35a87ff#code
pragma solidity ^0.4.24;
contract record256 {
mapping(uint => uint) public blockTs;
mapping(uint => uint) public blockNr;
uint public totalRecords;
event REC(uint h);
event DUP(uint h);
constructor() public {}
// check records
function checkRecords(uint[] zz) public view returns (uint r) {
require(zz.length < 256);
uint b = 1;
for (uint i; i < zz.length; i++) {
if (blockTs[zz[i]] > 0) r += b ;
b = b << 1;
}
}
// add a single record
function addRecordStrict(uint z) public {
require (z != 0 && blockTs[z] == 0);
_addRec(z);
}
function addRecord(uint z) public {
if (z == 0 || blockTs[z] != 0) {
emit DUP(z);
} else {
_addRec(z);
}
}
function _addRec(uint z) private {
blockTs[z] = now;
blockNr[z] = block.number;
totalRecords += 1;
emit REC(z);
}
// add multiple records
function addMultipleRecords(uint[] zz) public returns (uint) {
uint totalRecordsIni = totalRecords;
for (uint i; i < zz.length; i++) {
addRecord(zz[i]);
}
return totalRecords - totalRecordsIni;
}
function addMultipleRecordsStrict(uint[] zz) public {
for (uint i; i < zz.length; i++) {
addRecordStrict(zz[i]);
}
}
}