-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate_log.sol
More file actions
77 lines (65 loc) · 2.88 KB
/
Update_log.sol
File metadata and controls
77 lines (65 loc) · 2.88 KB
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
pragma solidity ^0.5.8;
// 各ベンダーが利用するアップデートログ を保持するコントラクト
contract Update_log {
// モデル名と開発者のマッピング
mapping(string=>address) public vender;
// モデル名でファームウェアを管理(リストの最新が最新のファームウェア)
mapping(string=>int256[]) public version;
// モデルのダウンロード元URL
mapping(string=>mapping(int256=>string)) public dl_link;
// モデル名・バージョンで検証用ハッシュ値取得 実装未定
// mapping(string=>mapping(int256=>string[])) public firmware;
address public owner;
constructor() public{
owner = msg.sender;
}
event Up_newver(address indexed from, string indexed model, int256 indexed ver);
// ハッシュ関数(文字列 -> ハッシュ値)
function getHash(string memory _var) public pure returns (bytes32){
byte b = 0x00;
uint8 i = 0;
return keccak256(abi.encodePacked(b, i, _var));
}
// モデル名(_model)を元に最新のファームウェア(_program)情報を保存
function up_newver(string memory _model,int256 _ver)public{
if(vender[_model] == address(0)){
vender[_model] = msg.sender;
}else if(vender[_model] != msg.sender){
revert("不正な更新情報です");
}
version[_model].push(_ver);
emit Up_newver(msg.sender, _model, _ver);
//firmware[_model][_ver].push(getHash(_program));
}
// モデル名(_model)を元に最新のファームウェア(_program)情報を保存
function up_newver2(string memory _model,int256 _ver, string memory _url)public{
if(vender[_model] == address(0)){
vender[_model] = msg.sender;
}else if(vender[_model] != msg.sender){
revert("不正な更新情報です");
}
version[_model].push(_ver);
dl_link[_model][_ver] = _url;
emit Up_newver(msg.sender, _model, _ver);
//firmware[_model][_ver].push(getHash(_program));
}
// 最新のファームウェア情報を取得
function getInfo(string memory _model) public view returns (int256){
if(vender[_model] == address(0)){
revert("該当するモデルはありません");
}
return version[_model][version[_model].length - 1];
}
// 最新のファームウェア情報を比較
function compInfo(string memory _model, int256 _ver) public view returns (int256, string memory){
if(vender[_model] == address(0)){
revert("該当するモデルはありません");
}
int256 ver = version[_model][version[_model].length - 1];
if(_ver == ver){
return (0, "");
}else{
return (ver - _ver, dl_link[_model][_ver]);
}
}
}