Skip to content

Commit

Permalink
<feat>(contract): add 0.4.25 and 0.5.2 example contracts. (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay authored Aug 30, 2024
1 parent 0a86152 commit 69c107d
Show file tree
Hide file tree
Showing 16 changed files with 397 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/main/java/console/contract/ConsoleContractImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package console.contract;

import static console.contract.utils.ContractCompiler.mergeAbi;
import static console.contract.utils.ContractCompiler.mergeSource;
import static org.fisco.solc.compiler.SolidityCompiler.Options.ABI;
import static org.fisco.solc.compiler.SolidityCompiler.Options.BIN;
Expand Down Expand Up @@ -1115,9 +1114,10 @@ private String getSolidityAbi(String contractFileName) throws Exception {
throw new CompileSolidityException(
" Compile " + solFile.getName() + " error: " + res.getErrors());
}

String contractName = solFile.getName().split("\\.")[0];
CompilationResult result = CompilationResult.parse(res.getOutput());
return mergeAbi(result);
CompilationResult.ContractMetadata contractMetadata = result.getContract(contractName);
return contractMetadata.abi;
}

private String getWasmAbi(String groupId, String pwd, String contractFileName)
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/contract/solidity/0.4.25/BaseEvent.sol
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);

}
}
22 changes: 22 additions & 0 deletions src/main/resources/contract/solidity/0.4.25/Cast.sol
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);
}
40 changes: 40 additions & 0 deletions src/main/resources/contract/solidity/0.4.25/CastTest.sol
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);
}
}
14 changes: 14 additions & 0 deletions src/main/resources/contract/solidity/0.4.25/Crypto.sol
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){}
}
35 changes: 35 additions & 0 deletions src/main/resources/contract/solidity/0.4.25/EchoEvent.sol
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 src/main/resources/contract/solidity/0.4.25/HelloWorld.sol
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;
}
}
41 changes: 41 additions & 0 deletions src/main/resources/contract/solidity/0.4.25/ShaTest.sol
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;
}
}
20 changes: 20 additions & 0 deletions src/main/resources/contract/solidity/0.5.2/BaseEvent.sol
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);

}
}
23 changes: 23 additions & 0 deletions src/main/resources/contract/solidity/0.5.2/Cast.sol
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);
}
40 changes: 40 additions & 0 deletions src/main/resources/contract/solidity/0.5.2/CastTest.sol
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);
}
}
14 changes: 14 additions & 0 deletions src/main/resources/contract/solidity/0.5.2/Crypto.sol
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){}
}
35 changes: 35 additions & 0 deletions src/main/resources/contract/solidity/0.5.2/EchoEvent.sol
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);
}
}
17 changes: 17 additions & 0 deletions src/main/resources/contract/solidity/0.5.2/HelloWorld.sol
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;
}
}
Loading

0 comments on commit 69c107d

Please sign in to comment.