-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEvidenceContract.sol
137 lines (122 loc) · 3.88 KB
/
EvidenceContract.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
pragma solidity ^0.4.4;
/*
* Copyright© (2018-2020) WeBank Co., Ltd.
*
* This file is part of weidentity-contract.
*
* weidentity-contract is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* weidentity-contract is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with weidentity-contract. If not, see <https://www.gnu.org/licenses/>.
*/
import "./CredentialController.sol";
contract EvidenceContract {
// block number map, hash as key
mapping(string => uint256) changed;
// Attribute keys
string constant private ATTRIB_KEY_SIGNINFO = "info";
string constant private ATTRIB_KEY_EXTRA = "extra";
// Error codes
uint256 constant private RETURN_CODE_SUCCESS = 0;
uint256 constant private RETURN_CODE_FAILURE_NOT_EXIST = 500600;
CredentialController private credentialController;
// Both hash and signer are used as identification key
event EvidenceAttributeChanged(
string hash,
address signer,
string key,
string value,
uint256 updated,
uint256 previousBlock
);
event ErrorLog(
string error
);
function EvidenceContract
(
address CredentialControllerAddress
)
public
{
credentialController=CredentialController(CredentialControllerAddress);
}
function getLatestRelatedBlock(
string hash
)
public
constant
returns (uint256)
{
return changed[hash];
}
/**
* Create evidence. Here, hash value is the key; signInfo is the base64 signature;
* and extra is the compact json of blob: {"credentialId":"aacc1122-324b.."}
* This allows append operation from other signer onto a same hash, so no permission check.
*/
function createEvidence(
string hash,
string sig,
string extra,
uint256 updated,
uint creid,
uint randNum
)
public
returns(uint)
{
//---------updated begin----------
if(credentialController.getRandNumOfCreid(creid)==randNum){
EvidenceAttributeChanged(hash, msg.sender, ATTRIB_KEY_SIGNINFO, sig, updated, changed[hash]);
EvidenceAttributeChanged(hash, msg.sender, ATTRIB_KEY_EXTRA, extra, updated, changed[hash]);
changed[hash] = block.number;
return 1;
}
else{
ErrorLog("create error");
return 0;
}
//---------updated end----------
}
/**
* Aribitrarily append attributes to an existing hash evidence, e.g. revoke status.
*/
function setAttribute(
string hash,
string key,
string value,
uint256 updated
)
public
{
if (!isHashExist(hash)) {
return;
}
if (isEqualString(key, ATTRIB_KEY_SIGNINFO)) {
return;
}
EvidenceAttributeChanged(hash, msg.sender, key, value, updated, changed[hash]);
changed[hash] = block.number;
}
function isHashExist(string hash) public constant returns (bool) {
if (changed[hash] != 0) {
return true;
}
return false;
}
function isEqualString(string a, string b) private constant returns (bool) {
if (bytes(a).length != bytes(b).length) {
return false;
} else {
return keccak256(a) == keccak256(b);
}
}
}