Skip to content

Commit 50c00bf

Browse files
author
irvinli
committed
merge upstream master
2 parents a7e5549 + 7e0d201 commit 50c00bf

34 files changed

+205
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
| 依赖软件 | 说明 |备注|
1313
| --- | --- | --- |
14-
| Solidity | >= 0.6.10 | 需使用0.6.10版本编译|
14+
| Solidity | 0.4.25 | |
1515
| Git | 下载需要使用Git | |
1616

1717
## 文档

contracts/base_type/ArrayDemo.sol

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pragma solidity ^0.4.25;
2+
import "./LibArrayForUint256Utils.sol";
3+
contract ArrayDemo {
4+
5+
uint[] private array;
6+
uint[] private array1;
7+
uint[] private array2;
8+
9+
function f1() public view {
10+
array=new uint[](0);
11+
// array add element 2
12+
LibArrayForUint256Utils.addValue(array,2);
13+
// array: {2}
14+
}
15+
16+
17+
function f2() public view {
18+
array1=new uint[](2);
19+
array2=new uint[](2);
20+
LibArrayForUint256Utils.extend(array1,array2);
21+
// array1 length 4
22+
}
23+
24+
function f3() public view {
25+
array=new uint[](2);
26+
array[0]=2;
27+
array[1]=2;
28+
LibArrayForUint256Utils.distinct(array);
29+
// array: {2}
30+
}
31+
}

contracts/base_type/BasicDemo.sol

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
pragma solidity ^0.4.25;
2+
import "./LibAddress.sol";
3+
import "./LibConverter.sol" ;
4+
import "./LibSafeMathForUint256Utils.sol";
5+
contract BasicDemo {
6+
7+
function safeMathDemo() public view {
8+
uint256 a =25;
9+
uint256 b =20;
10+
// a + b
11+
uint256 c = LibSafeMathForUint256Utils.add(a,b);
12+
// a - b
13+
uint256 d = LibSafeMathForUint256Utils.sub(a,b);
14+
// a * b
15+
uint256 e = LibSafeMathForUint256Utils.mul(a,b);
16+
// a/b
17+
uint256 f = LibSafeMathForUint256Utils.div(a,b);
18+
}
19+
20+
function modPower() public view {
21+
uint256 a=25;
22+
uint256 b=20;
23+
// a % b
24+
uint256 c = LibSafeMathForUint256Utils.mod(a,b);
25+
// a ^ b
26+
uint256 d = LibSafeMathForUint256Utils.power(a,b);
27+
}
28+
29+
function convertDemo() public view{
30+
uint256 a = 25;
31+
bytes memory b = LibConverter.uintToBytes(a);
32+
}
33+
34+
function convertDemo2() public view{
35+
bytes memory a = "25";
36+
int b = LibConverter.bytesToInt(a);
37+
}
38+
39+
function addressDemo() public view{
40+
address addr = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9;
41+
bytes memory bs=LibAddress.addressToBytes(addr);
42+
bs = new bytes(20);
43+
addr = LibAddress.bytesToAddress(bs);
44+
addr = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9;
45+
string memory addrStr = LibAddress.addressToString(addr);
46+
string memory str="0xE0f5206BBD039e7b0592d8918820024e2a7437b9";
47+
addr = LibAddress.stringToAddress(str);
48+
}
49+
}

contracts/base_type/LibAddress.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
library LibAddress{
2020

contracts/base_type/LibArrayForUint256Utils.sol

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
import "./LibSafeMathForUint256Utils.sol";
2020

@@ -94,7 +94,7 @@ library LibArrayForUint256Utils {
9494
array[index] = array[index + 1];
9595
index++;
9696
}
97-
array.pop();
97+
array.length--;
9898
}
9999

100100
function removeByValue(uint256[] storage array, uint256 value) internal{
@@ -127,20 +127,21 @@ library LibArrayForUint256Utils {
127127
bool contains;
128128
uint index;
129129
for (uint i = 0; i < array.length; i++) {
130-
bool contains = false;
131-
uint256 index = 0;
132-
for(uint j = i+1;j < array.length; j++){
130+
contains = false;
131+
index = 0;
132+
uint j = i+1;
133+
for(;j < array.length; j++){
133134
if(array[j] == array[i]){
134135
contains =true;
135136
index = i;
136137
break;
137138
}
138139
}
139140
if (contains) {
140-
for (uint j = index; j < array.length - 1; j++){
141+
for (j = index; j < array.length - 1; j++){
141142
array[j] = array[j + 1];
142143
}
143-
array.pop();
144+
array.length--;
144145
i--;
145146
}
146147
}

contracts/base_type/LibConverter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity >=0.4.24 <0.6.11;
1+
pragma solidity ^0.4.25;
22

33
library LibConverter {
44
function toUint128(uint256 value) internal pure returns (uint128) {

contracts/base_type/LibSafeMathForUint256Utils.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
library LibSafeMathForUint256Utils {
2020

contracts/base_type/LibString.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
library LibString{
2020

@@ -285,8 +285,9 @@ library LibString{
285285

286286
uint offset = 0;
287287
uint splitsCount = 1;
288+
int limit = -1;
288289
while (offset < srcBytes.length - 1) {
289-
int limit = indexOf(src, separator, offset);
290+
limit = indexOf(src, separator, offset);
290291
if (limit == -1)
291292
break;
292293
else {
@@ -301,7 +302,7 @@ library LibString{
301302
splitsCount = 0;
302303
while (offset < srcBytes.length - 1) {
303304

304-
int limit = indexOf(src, separator, offset);
305+
limit = indexOf(src, separator, offset);
305306
if (limit == - 1) {
306307
limit = int(srcBytes.length);
307308
}

contracts/base_type/StringDemo.sol

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pragma solidity ^0.4.25;
2+
import "./LibString.sol";
3+
4+
contract StringDemo {
5+
6+
function demo1() public{
7+
string memory str = "你好";
8+
uint256 lenOfChars = LibString.lenOfChars(str);
9+
uint256 lenOfBytes = LibString.lenOfBytes(str);
10+
require(lenOfChars == 2);
11+
require(lenOfBytes == 6);
12+
}
13+
14+
function demo2() public view returns(string memory) {
15+
string memory c = LibString.toUppercase("abcd");// Expected to be ABCD
16+
return c;
17+
}
18+
19+
function demo3() public view {
20+
bool r = LibString.equal("abcd","abcd");//Expected to be true
21+
require(r);
22+
}
23+
}

contracts/business_template/Evidence/Authentication.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
contract Authentication{
2020
address public _owner;

contracts/business_template/Evidence/EvidenceController.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
* */
1717

18-
pragma solidity >=0.4.24 <0.6.11;
18+
pragma solidity ^0.4.25;
1919

2020
import "./RequestRepository.sol";
2121
import "./EvidenceRepository.sol";

contracts/business_template/Evidence/EvidenceRepository.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818
import "./Authentication.sol";
1919

2020
contract EvidenceRepository is Authentication {

contracts/business_template/Evidence/RequestRepository.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
import "./Authentication.sol";
2020

contracts/business_template/RewardPoint/Admin.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
import "./BasicAuth.sol";
2020
import "./RewardPointController.sol";

contracts/business_template/RewardPoint/BasicAuth.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
contract BasicAuth {
2020
address public _owner;

contracts/business_template/RewardPoint/IssuerRole.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
import "./LibRoles.sol";
2020

contracts/business_template/RewardPoint/LibRoles.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
library LibRoles {
2020
struct Role {

contracts/business_template/RewardPoint/LibSafeMath.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919

2020
library LibSafeMath {

contracts/business_template/RewardPoint/RewardPointController.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
import "./RewardPointData.sol";
2020
import "./BasicAuth.sol";

contracts/business_template/RewardPoint/RewardPointData.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
import "./BasicAuth.sol";
2020
import "./IssuerRole.sol";
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pragma solidity ^0.4.25;
2+
3+
import "./LibAddressSet.sol";
4+
5+
contract AddressSetDemo {
6+
using LibAddressSet for LibAddressSet.AddressSet;
7+
LibAddressSet.AddressSet private addressSet;
8+
9+
event Log(uint256 size);
10+
11+
function testAddress() public {
12+
//添加元素;
13+
addressSet.add(address(1));
14+
// {1}
15+
// 查询set容器数量
16+
uint256 size = addressSet.getSize();
17+
require(size == 1);
18+
// 获取指定index的元素
19+
address addr = addressSet.get(0);
20+
require(addr == (address(1));
21+
// 返回set中所有的元素
22+
addressSet.getAll();
23+
// {0x1}
24+
// 判断元素是否存在
25+
bool contains = addressSet.contains(address(1));
26+
require(contains== true);
27+
// 删除元素
28+
addressSet.remove(address(1));
29+
}
30+
}

contracts/data_structure/LibAddressSet.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919

2020
library LibAddressSet {
@@ -41,8 +41,8 @@ library LibAddressSet {
4141
uint256 lastindexMapping = self.values.length - 1;
4242
address lastValue = self.values[lastindexMapping];
4343
self.values[toDeleteindexMapping] = lastValue;
44-
self.indexMapping[lastValue] = toDeleteindexMapping + 1;
45-
self.values.pop();
44+
self.indexMapping[lastValue] = toDeleteindexMapping + 1;
45+
self.values.length--;
4646
}
4747

4848
function getSize(AddressSet storage self) internal view returns (uint256) {

contracts/data_structure/LibBytesMap.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919
library LibBytesMap{
2020

contracts/data_structure/LibDeque.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
* */
1717

18-
pragma solidity >=0.4.24 <0.6.11;
18+
pragma solidity ^0.4.25;
1919

2020
/**
2121
* Doubly ended queue

contracts/data_structure/LibLinkedList.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
* */
1616

17-
pragma solidity >=0.4.24 <0.6.11;
17+
pragma solidity ^0.4.25;
1818

1919

2020
library LibLinkedList {

0 commit comments

Comments
 (0)