-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<feat>(contract): add 0.4.25 and 0.5.2 example contracts. (#856)
- Loading branch information
Showing
16 changed files
with
397 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.4.25; | ||
|
||
contract BaseEvent { | ||
|
||
//--------------------------------------------------------------------------------------------------------------- | ||
event Transfer(string indexed from_account, string indexed to_account, uint256 indexed amount); | ||
event TransferAccount(string indexed from_account,string indexed to_account); | ||
event TransferAmount(uint256 indexed amount); | ||
|
||
function transfer(string memory from_account, string memory to_account, uint256 amount) public { | ||
|
||
emit Transfer(from_account, to_account, amount); | ||
|
||
emit TransferAccount(from_account, to_account); | ||
|
||
emit TransferAmount(amount); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.4.25; | ||
|
||
pragma experimental ABIEncoderV2; | ||
|
||
contract Cast { | ||
function stringToS256(string memory) public view returns (int256); | ||
|
||
function stringToS64(string memory) public view returns (int64); | ||
|
||
function stringToU256(string memory) public view returns (uint256); | ||
|
||
function stringToAddr(string memory) public view returns (address); | ||
|
||
function stringToBytes32(string memory) public view returns (bytes32); | ||
|
||
function s256ToString(int256) public view returns (string memory); | ||
function s64ToString(int64) public view returns (string memory); | ||
function u256ToString(uint256) public view returns (string memory); | ||
function addrToString(address) public view returns (string memory); | ||
function bytes32ToString(bytes32) public view returns (string memory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.4.25; | ||
|
||
import "./Cast.sol"; | ||
|
||
contract CastTest { | ||
Cast constant cast = Cast(address(0x100f)); | ||
|
||
function stringToS256(string memory _s) public view returns (int256){ | ||
return cast.stringToS256(_s); | ||
} | ||
|
||
function stringToS64(string memory _s) public view returns (int64){ | ||
return cast.stringToS64(_s); | ||
} | ||
function stringToU256(string memory _s) public view returns (uint256){ | ||
return cast.stringToU256(_s); | ||
} | ||
function stringToAddr(string memory _s) public view returns (address){ | ||
return cast.stringToAddr(_s); | ||
} | ||
function stringToBytes32(string memory _s) public view returns (bytes32){ | ||
return cast.stringToBytes32(_s); | ||
} | ||
function s256ToString(int256 _i) public view returns (string memory){ | ||
return cast.s256ToString(_i); | ||
} | ||
function s64ToString(int64 _i) public view returns (string memory){ | ||
return cast.s64ToString(_i); | ||
} | ||
function u256ToString(uint256 _u) public view returns (string memory){ | ||
return cast.u256ToString(_u); | ||
} | ||
function addrToString(address _a) public view returns (string memory){ | ||
return cast.addrToString(_a); | ||
} | ||
function bytes32ToString(bytes32 _b) public view returns (string memory){ | ||
return cast.bytes32ToString(_b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pragma solidity ^0.4.25; | ||
|
||
pragma experimental ABIEncoderV2; | ||
|
||
contract Crypto | ||
{ | ||
function sm3(bytes memory data) public view returns (bytes32){} | ||
|
||
function keccak256Hash(bytes memory data) public view returns (bytes32){} | ||
|
||
function sm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns (bool, address){} | ||
|
||
function curve25519VRFVerify(bytes memory message, bytes memory publicKey, bytes memory proof) public view returns (bool, uint256){} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.4.25; | ||
|
||
import "./BaseEvent.sol"; | ||
|
||
contract EchoEvent { | ||
|
||
event Echo(uint256 indexed u); | ||
event Echo(int256 indexed i); | ||
event Echo(string indexed s); | ||
event Echo(uint256 indexed u, int256 indexed i, string indexed s); | ||
|
||
function echo(uint256 u, int256 i, string memory s) public returns(uint256, int256, string memory) { | ||
|
||
emit Echo(u); | ||
emit Echo(i); | ||
emit Echo(s); | ||
emit Echo(u, i ,s); | ||
|
||
return (u, i , s); | ||
} | ||
|
||
event Echo(bytes32 indexed bsn); | ||
event Echo(bytes indexed bs); | ||
event Echo(bytes32 indexed bsn, bytes indexed bs); | ||
|
||
function echo(bytes32 bsn, bytes memory bs) public returns(bytes32, bytes memory) { | ||
|
||
emit Echo(bsn); | ||
emit Echo(bs); | ||
emit Echo(bsn, bs); | ||
|
||
return (bsn, bs); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/resources/contract/solidity/0.4.25/HelloWorld.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pragma solidity ^0.4.25; | ||
|
||
contract HelloWorld { | ||
string name; | ||
|
||
constructor() public { | ||
name = "Hello, World!"; | ||
} | ||
|
||
function get() public view returns (string memory) { | ||
return name; | ||
} | ||
|
||
function set(string memory n) public { | ||
name = n; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.4.25; | ||
|
||
pragma experimental ABIEncoderV2; | ||
|
||
import "./Crypto.sol"; | ||
|
||
contract ShaTest{ | ||
bytes _data = "Hello, ShaTest"; | ||
Crypto crypto; | ||
|
||
constructor() public { | ||
address cryptoAddr = address(0x100a); | ||
crypto = Crypto(cryptoAddr); | ||
} | ||
|
||
function getSha256(bytes memory _memory) public returns(bytes32 result) | ||
{ | ||
return sha256(_memory); | ||
} | ||
|
||
function getKeccak256(bytes memory _memory) public returns(bytes32 result) | ||
{ | ||
return keccak256(_memory); | ||
} | ||
|
||
function calculateSM3(bytes memory _memory) public returns(bytes32 result) | ||
{ | ||
return crypto.sm3(_memory); | ||
} | ||
|
||
function calculateKeccak256(bytes memory _memory) public returns(bytes32 result) | ||
{ | ||
return crypto.keccak256Hash(_memory); | ||
} | ||
|
||
function getData() public view returns(bytes memory) | ||
{ | ||
return _data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.5.2; | ||
|
||
contract BaseEvent { | ||
|
||
//--------------------------------------------------------------------------------------------------------------- | ||
event Transfer(string indexed from_account, string indexed to_account, uint256 indexed amount); | ||
event TransferAccount(string indexed from_account,string indexed to_account); | ||
event TransferAmount(uint256 indexed amount); | ||
|
||
function transfer(string memory from_account, string memory to_account, uint256 amount) public { | ||
|
||
emit Transfer(from_account, to_account, amount); | ||
|
||
emit TransferAccount(from_account, to_account); | ||
|
||
emit TransferAmount(amount); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.5.2; | ||
|
||
|
||
pragma experimental ABIEncoderV2; | ||
|
||
contract Cast { | ||
function stringToS256(string memory) public view returns (int256); | ||
|
||
function stringToS64(string memory) public view returns (int64); | ||
|
||
function stringToU256(string memory) public view returns (uint256); | ||
|
||
function stringToAddr(string memory) public view returns (address); | ||
|
||
function stringToBytes32(string memory) public view returns (bytes32); | ||
|
||
function s256ToString(int256) public view returns (string memory); | ||
function s64ToString(int64) public view returns (string memory); | ||
function u256ToString(uint256) public view returns (string memory); | ||
function addrToString(address) public view returns (string memory); | ||
function bytes32ToString(bytes32) public view returns (string memory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.5.2; | ||
|
||
import "./Cast.sol"; | ||
|
||
contract CastTest { | ||
Cast constant cast = Cast(address(0x100f)); | ||
|
||
function stringToS256(string memory _s) public view returns (int256){ | ||
return cast.stringToS256(_s); | ||
} | ||
|
||
function stringToS64(string memory _s) public view returns (int64){ | ||
return cast.stringToS64(_s); | ||
} | ||
function stringToU256(string memory _s) public view returns (uint256){ | ||
return cast.stringToU256(_s); | ||
} | ||
function stringToAddr(string memory _s) public view returns (address){ | ||
return cast.stringToAddr(_s); | ||
} | ||
function stringToBytes32(string memory _s) public view returns (bytes32){ | ||
return cast.stringToBytes32(_s); | ||
} | ||
function s256ToString(int256 _i) public view returns (string memory){ | ||
return cast.s256ToString(_i); | ||
} | ||
function s64ToString(int64 _i) public view returns (string memory){ | ||
return cast.s64ToString(_i); | ||
} | ||
function u256ToString(uint256 _u) public view returns (string memory){ | ||
return cast.u256ToString(_u); | ||
} | ||
function addrToString(address _a) public view returns (string memory){ | ||
return cast.addrToString(_a); | ||
} | ||
function bytes32ToString(bytes32 _b) public view returns (string memory){ | ||
return cast.bytes32ToString(_b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pragma solidity ^0.5.2; | ||
|
||
pragma experimental ABIEncoderV2; | ||
|
||
contract Crypto | ||
{ | ||
function sm3(bytes memory data) public view returns (bytes32){} | ||
|
||
function keccak256Hash(bytes memory data) public view returns (bytes32){} | ||
|
||
function sm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns (bool, address){} | ||
|
||
function curve25519VRFVerify(bytes memory message, bytes memory publicKey, bytes memory proof) public view returns (bool, uint256){} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.5.2; | ||
|
||
import "./BaseEvent.sol"; | ||
|
||
contract EchoEvent { | ||
|
||
event Echo(uint256 indexed u); | ||
event Echo(int256 indexed i); | ||
event Echo(string indexed s); | ||
event Echo(uint256 indexed u, int256 indexed i, string indexed s); | ||
|
||
function echo(uint256 u, int256 i, string memory s) public returns(uint256, int256, string memory) { | ||
|
||
emit Echo(u); | ||
emit Echo(i); | ||
emit Echo(s); | ||
emit Echo(u, i ,s); | ||
|
||
return (u, i , s); | ||
} | ||
|
||
event Echo(bytes32 indexed bsn); | ||
event Echo(bytes indexed bs); | ||
event Echo(bytes32 indexed bsn, bytes indexed bs); | ||
|
||
function echo(bytes32 bsn, bytes memory bs) public returns(bytes32, bytes memory) { | ||
|
||
emit Echo(bsn); | ||
emit Echo(bs); | ||
emit Echo(bsn, bs); | ||
|
||
return (bsn, bs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pragma solidity ^0.5.2; | ||
|
||
contract HelloWorld { | ||
string name; | ||
|
||
constructor() public { | ||
name = "Hello, World!"; | ||
} | ||
|
||
function get() public view returns (string memory) { | ||
return name; | ||
} | ||
|
||
function set(string memory n) public { | ||
name = n; | ||
} | ||
} |
Oops, something went wrong.