Skip to content

Commit 69c107d

Browse files
authored
<feat>(contract): add 0.4.25 and 0.5.2 example contracts. (#856)
1 parent 0a86152 commit 69c107d

File tree

16 files changed

+397
-34
lines changed

16 files changed

+397
-34
lines changed

src/main/java/console/contract/ConsoleContractImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package console.contract;
22

3-
import static console.contract.utils.ContractCompiler.mergeAbi;
43
import static console.contract.utils.ContractCompiler.mergeSource;
54
import static org.fisco.solc.compiler.SolidityCompiler.Options.ABI;
65
import static org.fisco.solc.compiler.SolidityCompiler.Options.BIN;
@@ -1115,9 +1114,10 @@ private String getSolidityAbi(String contractFileName) throws Exception {
11151114
throw new CompileSolidityException(
11161115
" Compile " + solFile.getName() + " error: " + res.getErrors());
11171116
}
1118-
1117+
String contractName = solFile.getName().split("\\.")[0];
11191118
CompilationResult result = CompilationResult.parse(res.getOutput());
1120-
return mergeAbi(result);
1119+
CompilationResult.ContractMetadata contractMetadata = result.getContract(contractName);
1120+
return contractMetadata.abi;
11211121
}
11221122

11231123
private String getWasmAbi(String groupId, String pwd, String contractFileName)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.4.25;
3+
4+
contract BaseEvent {
5+
6+
//---------------------------------------------------------------------------------------------------------------
7+
event Transfer(string indexed from_account, string indexed to_account, uint256 indexed amount);
8+
event TransferAccount(string indexed from_account,string indexed to_account);
9+
event TransferAmount(uint256 indexed amount);
10+
11+
function transfer(string memory from_account, string memory to_account, uint256 amount) public {
12+
13+
emit Transfer(from_account, to_account, amount);
14+
15+
emit TransferAccount(from_account, to_account);
16+
17+
emit TransferAmount(amount);
18+
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.4.25;
3+
4+
pragma experimental ABIEncoderV2;
5+
6+
contract Cast {
7+
function stringToS256(string memory) public view returns (int256);
8+
9+
function stringToS64(string memory) public view returns (int64);
10+
11+
function stringToU256(string memory) public view returns (uint256);
12+
13+
function stringToAddr(string memory) public view returns (address);
14+
15+
function stringToBytes32(string memory) public view returns (bytes32);
16+
17+
function s256ToString(int256) public view returns (string memory);
18+
function s64ToString(int64) public view returns (string memory);
19+
function u256ToString(uint256) public view returns (string memory);
20+
function addrToString(address) public view returns (string memory);
21+
function bytes32ToString(bytes32) public view returns (string memory);
22+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.4.25;
3+
4+
import "./Cast.sol";
5+
6+
contract CastTest {
7+
Cast constant cast = Cast(address(0x100f));
8+
9+
function stringToS256(string memory _s) public view returns (int256){
10+
return cast.stringToS256(_s);
11+
}
12+
13+
function stringToS64(string memory _s) public view returns (int64){
14+
return cast.stringToS64(_s);
15+
}
16+
function stringToU256(string memory _s) public view returns (uint256){
17+
return cast.stringToU256(_s);
18+
}
19+
function stringToAddr(string memory _s) public view returns (address){
20+
return cast.stringToAddr(_s);
21+
}
22+
function stringToBytes32(string memory _s) public view returns (bytes32){
23+
return cast.stringToBytes32(_s);
24+
}
25+
function s256ToString(int256 _i) public view returns (string memory){
26+
return cast.s256ToString(_i);
27+
}
28+
function s64ToString(int64 _i) public view returns (string memory){
29+
return cast.s64ToString(_i);
30+
}
31+
function u256ToString(uint256 _u) public view returns (string memory){
32+
return cast.u256ToString(_u);
33+
}
34+
function addrToString(address _a) public view returns (string memory){
35+
return cast.addrToString(_a);
36+
}
37+
function bytes32ToString(bytes32 _b) public view returns (string memory){
38+
return cast.bytes32ToString(_b);
39+
}
40+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pragma solidity ^0.4.25;
2+
3+
pragma experimental ABIEncoderV2;
4+
5+
contract Crypto
6+
{
7+
function sm3(bytes memory data) public view returns (bytes32){}
8+
9+
function keccak256Hash(bytes memory data) public view returns (bytes32){}
10+
11+
function sm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns (bool, address){}
12+
13+
function curve25519VRFVerify(bytes memory message, bytes memory publicKey, bytes memory proof) public view returns (bool, uint256){}
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.4.25;
3+
4+
import "./BaseEvent.sol";
5+
6+
contract EchoEvent {
7+
8+
event Echo(uint256 indexed u);
9+
event Echo(int256 indexed i);
10+
event Echo(string indexed s);
11+
event Echo(uint256 indexed u, int256 indexed i, string indexed s);
12+
13+
function echo(uint256 u, int256 i, string memory s) public returns(uint256, int256, string memory) {
14+
15+
emit Echo(u);
16+
emit Echo(i);
17+
emit Echo(s);
18+
emit Echo(u, i ,s);
19+
20+
return (u, i , s);
21+
}
22+
23+
event Echo(bytes32 indexed bsn);
24+
event Echo(bytes indexed bs);
25+
event Echo(bytes32 indexed bsn, bytes indexed bs);
26+
27+
function echo(bytes32 bsn, bytes memory bs) public returns(bytes32, bytes memory) {
28+
29+
emit Echo(bsn);
30+
emit Echo(bs);
31+
emit Echo(bsn, bs);
32+
33+
return (bsn, bs);
34+
}
35+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.4.25;
2+
3+
contract HelloWorld {
4+
string name;
5+
6+
constructor() public {
7+
name = "Hello, World!";
8+
}
9+
10+
function get() public view returns (string memory) {
11+
return name;
12+
}
13+
14+
function set(string memory n) public {
15+
name = n;
16+
}
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.4.25;
3+
4+
pragma experimental ABIEncoderV2;
5+
6+
import "./Crypto.sol";
7+
8+
contract ShaTest{
9+
bytes _data = "Hello, ShaTest";
10+
Crypto crypto;
11+
12+
constructor() public {
13+
address cryptoAddr = address(0x100a);
14+
crypto = Crypto(cryptoAddr);
15+
}
16+
17+
function getSha256(bytes memory _memory) public returns(bytes32 result)
18+
{
19+
return sha256(_memory);
20+
}
21+
22+
function getKeccak256(bytes memory _memory) public returns(bytes32 result)
23+
{
24+
return keccak256(_memory);
25+
}
26+
27+
function calculateSM3(bytes memory _memory) public returns(bytes32 result)
28+
{
29+
return crypto.sm3(_memory);
30+
}
31+
32+
function calculateKeccak256(bytes memory _memory) public returns(bytes32 result)
33+
{
34+
return crypto.keccak256Hash(_memory);
35+
}
36+
37+
function getData() public view returns(bytes memory)
38+
{
39+
return _data;
40+
}
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.5.2;
3+
4+
contract BaseEvent {
5+
6+
//---------------------------------------------------------------------------------------------------------------
7+
event Transfer(string indexed from_account, string indexed to_account, uint256 indexed amount);
8+
event TransferAccount(string indexed from_account,string indexed to_account);
9+
event TransferAmount(uint256 indexed amount);
10+
11+
function transfer(string memory from_account, string memory to_account, uint256 amount) public {
12+
13+
emit Transfer(from_account, to_account, amount);
14+
15+
emit TransferAccount(from_account, to_account);
16+
17+
emit TransferAmount(amount);
18+
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.5.2;
3+
4+
5+
pragma experimental ABIEncoderV2;
6+
7+
contract Cast {
8+
function stringToS256(string memory) public view returns (int256);
9+
10+
function stringToS64(string memory) public view returns (int64);
11+
12+
function stringToU256(string memory) public view returns (uint256);
13+
14+
function stringToAddr(string memory) public view returns (address);
15+
16+
function stringToBytes32(string memory) public view returns (bytes32);
17+
18+
function s256ToString(int256) public view returns (string memory);
19+
function s64ToString(int64) public view returns (string memory);
20+
function u256ToString(uint256) public view returns (string memory);
21+
function addrToString(address) public view returns (string memory);
22+
function bytes32ToString(bytes32) public view returns (string memory);
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.5.2;
3+
4+
import "./Cast.sol";
5+
6+
contract CastTest {
7+
Cast constant cast = Cast(address(0x100f));
8+
9+
function stringToS256(string memory _s) public view returns (int256){
10+
return cast.stringToS256(_s);
11+
}
12+
13+
function stringToS64(string memory _s) public view returns (int64){
14+
return cast.stringToS64(_s);
15+
}
16+
function stringToU256(string memory _s) public view returns (uint256){
17+
return cast.stringToU256(_s);
18+
}
19+
function stringToAddr(string memory _s) public view returns (address){
20+
return cast.stringToAddr(_s);
21+
}
22+
function stringToBytes32(string memory _s) public view returns (bytes32){
23+
return cast.stringToBytes32(_s);
24+
}
25+
function s256ToString(int256 _i) public view returns (string memory){
26+
return cast.s256ToString(_i);
27+
}
28+
function s64ToString(int64 _i) public view returns (string memory){
29+
return cast.s64ToString(_i);
30+
}
31+
function u256ToString(uint256 _u) public view returns (string memory){
32+
return cast.u256ToString(_u);
33+
}
34+
function addrToString(address _a) public view returns (string memory){
35+
return cast.addrToString(_a);
36+
}
37+
function bytes32ToString(bytes32 _b) public view returns (string memory){
38+
return cast.bytes32ToString(_b);
39+
}
40+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pragma solidity ^0.5.2;
2+
3+
pragma experimental ABIEncoderV2;
4+
5+
contract Crypto
6+
{
7+
function sm3(bytes memory data) public view returns (bytes32){}
8+
9+
function keccak256Hash(bytes memory data) public view returns (bytes32){}
10+
11+
function sm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns (bool, address){}
12+
13+
function curve25519VRFVerify(bytes memory message, bytes memory publicKey, bytes memory proof) public view returns (bool, uint256){}
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.5.2;
3+
4+
import "./BaseEvent.sol";
5+
6+
contract EchoEvent {
7+
8+
event Echo(uint256 indexed u);
9+
event Echo(int256 indexed i);
10+
event Echo(string indexed s);
11+
event Echo(uint256 indexed u, int256 indexed i, string indexed s);
12+
13+
function echo(uint256 u, int256 i, string memory s) public returns(uint256, int256, string memory) {
14+
15+
emit Echo(u);
16+
emit Echo(i);
17+
emit Echo(s);
18+
emit Echo(u, i ,s);
19+
20+
return (u, i , s);
21+
}
22+
23+
event Echo(bytes32 indexed bsn);
24+
event Echo(bytes indexed bs);
25+
event Echo(bytes32 indexed bsn, bytes indexed bs);
26+
27+
function echo(bytes32 bsn, bytes memory bs) public returns(bytes32, bytes memory) {
28+
29+
emit Echo(bsn);
30+
emit Echo(bs);
31+
emit Echo(bsn, bs);
32+
33+
return (bsn, bs);
34+
}
35+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.5.2;
2+
3+
contract HelloWorld {
4+
string name;
5+
6+
constructor() public {
7+
name = "Hello, World!";
8+
}
9+
10+
function get() public view returns (string memory) {
11+
return name;
12+
}
13+
14+
function set(string memory n) public {
15+
name = n;
16+
}
17+
}

0 commit comments

Comments
 (0)