-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrc100_static.sol
More file actions
130 lines (125 loc) · 3.83 KB
/
trc100_static.sol
File metadata and controls
130 lines (125 loc) · 3.83 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
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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/*
trc100 静态分片管理模块
*/
contract trc100_static{
address public InitSender;
address public trc100_addr;
address public Coin;
struct MapPos{
uint pos;
bool isVaild;
}
struct Node{
bytes32 markid;
bytes32 cotnent;
}
Node []nodes;
mapping(bytes32 => MapPos) nodePosMap;
constructor(){
InitSender=msg.sender;
trc100_addr=msg.sender;
Coin=msg.sender;
}
function SetTrc100Addr(address addr)public returns(address){
if(msg.sender!=InitSender)return trc100_addr;
trc100_addr=addr;
return addr;
}
function SetCoinbase(address coin)public returns(uint256){
require(InitSender==msg.sender,"SetCoinbase access denied");
Coin=coin;
return 0;
}
//激励合约
function CoinbaseOf()public view returns(bool,address){
if(Coin==InitSender){
return (false,Coin);
}
return (true,Coin);
}
/*
增加准入网络节点ID
*/
function addnode(bytes32 s,bytes32 content)public returns (bool success){
require(InitSender==msg.sender,"addnode access denied");
require(!nodePosMap[s].isVaild,"addnode rec exist");
nodes.push(Node(s,content));
nodePosMap[s].pos=nodes.length-1;
nodePosMap[s].isVaild=true;
return true;
}
function addnodes(bytes32[] memory s,bytes32[] memory content)public returns (bool success){
require(InitSender==msg.sender,"addnodes access denied");
uint i=0;
for(i=0;i<s.length;i++){
if (!nodePosMap[s[i]].isVaild){
nodes.push(Node(s[i],content[i]));
nodePosMap[s[i]].pos=nodes.length-1;
nodePosMap[s[i]].isVaild=true;
}
}
return true;
}
/*
删除准入网络节点ID
*/
function delnode(bytes32 s) public returns (bool success){
require(InitSender==msg.sender,"delnode access denied");
require(nodePosMap[s].isVaild,"rec find fail");
uint pos=nodePosMap[s].pos;
delete nodePosMap[s];
if(pos==(nodes.length-1)){
nodes.pop();
}else{
nodes[pos]=nodes[nodes.length-1];
nodePosMap[nodes[nodes.length-1].markid].pos=pos;
nodes.pop();
}
return true;
}
/*
批删除准入节点ID
*/
function delnodes(bytes32[] memory ss) public returns (bool success){
require(InitSender==msg.sender,"delnodes access denied");
uint i=0;
uint len=ss.length;
uint256 pos=0;
for(i=0;i<len;i++){
if(nodePosMap[ss[i]].isVaild){
pos=nodePosMap[ss[i]].pos;
delete nodePosMap[ss[i]];
if(pos==(nodes.length-1)){
nodes.pop();
}else{
nodes[pos]=nodes[nodes.length-1];
nodePosMap[nodes[nodes.length-1].markid].pos=pos;
nodes.pop();
}
}
}
return true;
}
/*
网络节点ID信息
*/
function nodeinfo(uint256 begin,uint256 _len) public view returns(bool success, bytes32[] memory ss, bytes32[] memory content){
uint l=nodes.length;
uint end=begin+_len;
require(l>=begin,"access denied");
if(end>l){
end=l;
}
bytes32[] memory result_markid=new bytes32[](end-begin);
bytes32[] memory result_content=new bytes32[](end-begin);
uint count=0;
for(uint i=begin;i<end;i++){
result_markid[count]=nodes[i].markid;
result_content[count]=nodes[i].cotnent;
count++;
}
return (true,result_markid,result_content);
}
}