├── .ci ├── check_rare_string.sh ├── ci_check.sh └── ci_check_commit.sh ├── .circleci └── config.yml ├── .gitattributes ├── .github └── workflows │ ├── codeql.yml │ └── workflow.yml ├── .gitignore ├── CONTRIBUTING.md ├── Changelog.md ├── LICENSE ├── README.md ├── build.gradle ├── doc ├── CONTRIBUTING_CN.md ├── README_EN.md └── images │ └── WeChatQR.jpeg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── release_note.txt ├── settings.gradle ├── src ├── integration-test │ ├── java │ │ └── console │ │ │ ├── ConsoleClientTest.java │ │ │ ├── PrecompiledTest.java │ │ │ ├── TestBase.java │ │ │ └── WelcomeInfoTest.java │ └── resources │ │ ├── clog.ini │ │ └── config-example.toml └── main │ ├── java │ └── console │ │ ├── Console.java │ │ ├── ConsoleInitializer.java │ │ ├── NonInteractiveConsole.java │ │ ├── auth │ │ ├── AuthFace.java │ │ └── AuthImpl.java │ │ ├── client │ │ ├── ConsoleClientFace.java │ │ ├── ConsoleClientImpl.java │ │ └── model │ │ │ └── TotalTransactionCountResult.java │ │ ├── collaboration │ │ ├── CollaborationFace.java │ │ └── CollaborationImpl.java │ │ ├── command │ │ ├── JlineUtils.java │ │ ├── SupportedCommand.java │ │ ├── category │ │ │ ├── AccountOpCommand.java │ │ │ ├── AuthOpCommand.java │ │ │ ├── BalanceOpCommand.java │ │ │ ├── BasicCommand.java │ │ │ ├── BfsCommand.java │ │ │ ├── CollaborationOpCommand.java │ │ │ ├── ConsensusOpCommand.java │ │ │ ├── ContractOpCommand.java │ │ │ ├── CrudCommand.java │ │ │ ├── GroupCommand.java │ │ │ ├── ShardingCommand.java │ │ │ └── StatusQueryCommand.java │ │ ├── completer │ │ │ ├── AccountCompleter.java │ │ │ ├── AccountFileFormatCompleter.java │ │ │ ├── ConsoleFilesCompleter.java │ │ │ ├── ContractAddressCompleter.java │ │ │ ├── ContractMethodCompleter.java │ │ │ ├── CurrentPathCompleter.java │ │ │ └── StringsCompleterIgnoreCase.java │ │ └── model │ │ │ ├── BasicCategoryCommand.java │ │ │ ├── CommandInfo.java │ │ │ ├── CommandType.java │ │ │ ├── HelpInfo.java │ │ │ └── WelcomeInfo.java │ │ ├── common │ │ ├── Common.java │ │ ├── ConsoleUtils.java │ │ ├── ConsoleVersion.java │ │ └── StatusCodeLink.java │ │ ├── contract │ │ ├── ConsoleContractFace.java │ │ ├── ConsoleContractImpl.java │ │ ├── exceptions │ │ │ └── CompileContractException.java │ │ ├── model │ │ │ └── AbiAndBin.java │ │ └── utils │ │ │ └── ContractCompiler.java │ │ ├── exception │ │ ├── CompileSolidityException.java │ │ └── ConsoleMessageException.java │ │ └── precompiled │ │ ├── PrecompiledFace.java │ │ ├── PrecompiledImpl.java │ │ └── model │ │ ├── CRUDParseUtils.java │ │ └── Table.java │ └── resources │ ├── contract │ ├── liquid │ │ ├── asset │ │ │ ├── .gitignore │ │ │ ├── .liquid │ │ │ │ └── abi_gen │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ └── main.rs │ │ │ ├── Cargo.toml │ │ │ ├── asset.abi │ │ │ ├── asset.wasm │ │ │ ├── asset_gm.wasm │ │ │ └── src │ │ │ │ └── lib.rs │ │ ├── hello_world │ │ │ ├── .gitignore │ │ │ ├── .liquid │ │ │ │ └── abi_gen │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ └── main.rs │ │ │ ├── Cargo.toml │ │ │ ├── hello_world.abi │ │ │ ├── hello_world.wasm │ │ │ ├── hello_world_gm.wasm │ │ │ └── src │ │ │ │ └── lib.rs │ │ ├── kv_table_test │ │ │ ├── .gitignore │ │ │ ├── .liquid │ │ │ │ └── abi_gen │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ └── main.rs │ │ │ ├── Cargo.toml │ │ │ ├── kv_table_test.abi │ │ │ ├── kv_table_test.wasm │ │ │ ├── kv_table_test_gm.wasm │ │ │ └── src │ │ │ │ └── lib.rs │ │ ├── parallel_ok │ │ │ ├── .gitignore │ │ │ ├── .liquid │ │ │ │ └── abi_gen │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ └── main.rs │ │ │ ├── Cargo.toml │ │ │ ├── parallel_ok.abi │ │ │ ├── parallel_ok.wasm │ │ │ ├── parallel_ok_gm.wasm │ │ │ └── src │ │ │ │ └── lib.rs │ │ └── table_test │ │ │ ├── .gitignore │ │ │ ├── .liquid │ │ │ └── abi_gen │ │ │ │ ├── Cargo.toml │ │ │ │ └── main.rs │ │ │ ├── Cargo.toml │ │ │ ├── src │ │ │ └── lib.rs │ │ │ ├── table_test.abi │ │ │ ├── table_test.wasm │ │ │ └── table_test_gm.wasm │ └── solidity │ │ ├── 0.4.25 │ │ ├── BaseEvent.sol │ │ ├── Cast.sol │ │ ├── CastTest.sol │ │ ├── Crypto.sol │ │ ├── EchoEvent.sol │ │ ├── HelloWorld.sol │ │ └── ShaTest.sol │ │ ├── 0.5.2 │ │ ├── BaseEvent.sol │ │ ├── Cast.sol │ │ ├── CastTest.sol │ │ ├── Crypto.sol │ │ ├── EchoEvent.sol │ │ ├── HelloWorld.sol │ │ └── ShaTest.sol │ │ ├── 0.8.26 │ │ ├── BlobHashExample.sol │ │ ├── ContractA.sol │ │ ├── ContractB.sol │ │ ├── DoubleBufferContract.sol │ │ ├── MainContract.sol │ │ ├── Mcopy.sol │ │ ├── StorageContract.sol │ │ ├── StorageSlot.sol │ │ ├── TestDoubleBufferContract.sol │ │ └── blobBaseFee.sol │ │ ├── Asset.sol │ │ ├── BaseEvent.sol │ │ ├── Cast.sol │ │ ├── CastTest.sol │ │ ├── Crypto.sol │ │ ├── DelegateCallTest.sol │ │ ├── EchoEvent.sol │ │ ├── EntryWrapper.sol │ │ ├── EventSubDemo.sol │ │ ├── HelloWorld.sol │ │ ├── KVTableTest.sol │ │ ├── ShaTest.sol │ │ ├── Table.sol │ │ ├── TableTest.sol │ │ ├── TableTestV320.sol │ │ └── TableV320.sol │ └── log4j2.xml └── tools ├── console.sh ├── contract2java.sh ├── download_console.sh ├── get_account.sh ├── get_gm_account.sh └── start.sh /.ci/check_rare_string.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | concatenatedString=$1 4 | 5 | function LOG_ERROR() 6 | { 7 | local content=${1} 8 | echo -e "\033[31m"${content}"\033[0m" 9 | } 10 | 11 | function LOG_INFO() 12 | { 13 | local content=${1} 14 | echo -e "\033[32m"${content}"\033[0m" 15 | } 16 | 17 | get_md5sum_cmd() { 18 | local md5sum_cmd="md5sum" 19 | if [ "$(uname)" == "Darwin" ]; then 20 | md5sum_cmd="md5" 21 | fi 22 | echo "$md5sum_cmd" 23 | } 24 | 25 | function checkConcatenatedRareString() { 26 | local contract_address=${1} 27 | md5sum_cmd=$(get_md5sum_cmd) 28 | 29 | md5_concatenatedString=$(echo -n "$concatenatedString" | $md5sum_cmd | awk '{print $1}') 30 | 31 | local set_output=$(./dist/console.sh call HelloWorld "${contract_address}" set "${concatenatedString}") 32 | eventLogsFromSet=$(echo "set_output" | grep -o 'Event: {}' | sed 's/Event: {\(.*\)}/\1/') 33 | if [ ! -z "$eventLogsFromSet" ]; then 34 | echo "eventLogsFromSet=${eventLogsFromSet}" 35 | md5_eventLogsFromSet=$(echo -n "$eventLogsFromSet" | $md5sum_cmd | awk '{print $1}') 36 | if [ "$md5_concatenatedString" != "$md5_eventLogsFromSet" ]; then 37 | LOG_ERROR "error: check failed, the md5 values of rareString and eventLogsFromSet are not equal, fail concatenatedString: ${concatenatedString}" 38 | exit 1 39 | fi 40 | fi 41 | 42 | # compare rare string and stringFromGet 43 | get_output=$(./dist/console.sh call HelloWorld "${contract_address}" get) 44 | stringFromGet=$(echo "$get_output" | grep "Return values" | sed 's/Return values:\(.*\)/\1/' | tr -d '()') 45 | md5_stringFromGet=$(echo -n "$stringFromGet" | $md5sum_cmd | awk '{print $1}') 46 | if [ "$md5_concatenatedString" != "$md5_stringFromGet" ]; then 47 | LOG_ERROR "error: check failed, the md5 values of rareString and stringFromGet are not equal, fail concatenatedString: ${concatenatedString}" 48 | exit 1 49 | else 50 | LOG_INFO "check success, concatenatedString: ${concatenatedString}" 51 | fi 52 | } 53 | 54 | main() { 55 | LOG_INFO "check rare string start, concatenatedString: ${concatenatedString}" 56 | 57 | # deploy HelloWorld contract 58 | console_output=$(./dist/console.sh deploy HelloWorld) 59 | contract_address=$(echo "$console_output" | grep -oE 'contract address: 0x[0-9a-fA-F]+' | sed 's/contract address: //') 60 | if [ -z "$contract_address" ]; then 61 | LOG_ERROR "deploy HelloWorld contract failed, contract_address: ${contract_address}" 62 | exit 1 63 | fi 64 | 65 | checkConcatenatedRareString $contract_address 66 | LOG_INFO "check rare string finished!" 67 | } 68 | 69 | main "$@" 70 | -------------------------------------------------------------------------------- /.ci/ci_check_commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | scan_code_script="python ~/cobra/cobra.py -t " 6 | ignore_files=(.ci ConsoleClientImpl.java ConsoleInitializer.java ConsoleUtils.java) 7 | 8 | LOG_ERROR() { 9 | content=${1} 10 | echo -e "\033[31m${content}\033[0m" 11 | } 12 | 13 | LOG_INFO() { 14 | content=${1} 15 | echo -e "\033[32m${content}\033[0m" 16 | } 17 | 18 | execute_cmd() { 19 | command="${1}" 20 | eval ${command} 21 | ret=$? 22 | if [ $ret -ne 0 ];then 23 | LOG_ERROR "FAILED of command: ${command}" 24 | exit 1 25 | else 26 | LOG_INFO "SUCCESS of command: ${command}" 27 | fi 28 | } 29 | 30 | should_ignore() 31 | { 32 | local file=${1} 33 | for ignore in ${ignore_files[*]}; do 34 | if echo ${file} | grep ${ignore} &>/dev/null; then 35 | echo "ignore ${file} ${ignore}" 36 | return 0 37 | fi 38 | done 39 | return 1 40 | } 41 | 42 | scan_code() 43 | { 44 | # Redirect output to stderr. 45 | exec 1>&2 46 | for file in $(git diff-index --name-status HEAD^ | awk '{print $2}'); do 47 | if should_ignore ${file}; then continue; fi 48 | if [ ! -f ${file} ];then continue; fi 49 | LOG_INFO "check file ${file}" 50 | execute_cmd "${scan_code_script} $file -f json -o /tmp/report.json" 51 | trigger_rules=$(jq -r '.' /tmp/report.json | grep 'trigger_rules' | awk '{print $2}' | sed 's/,//g') 52 | echo "trigger_rules is ${trigger_rules}" 53 | rm /tmp/report.json 54 | if [ ${trigger_rules} -ne 0 ]; then 55 | echo "######### ERROR: Scan code failed, please adjust them before commit" 56 | exit 1 57 | fi 58 | done 59 | } 60 | 61 | install_cobra() { 62 | git clone https://github.com/WhaleShark-Team/cobra.git ~/cobra 63 | pip install -r ~/cobra/requirements.txt 64 | cp ~/cobra/config.template ~/cobra/config 65 | } 66 | 67 | install_cobra 68 | scan_code 69 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | jobs: 3 | build: 4 | working_directory: /console 5 | docker: 6 | - image: centos:7 7 | environment: 8 | PATH=$PATH:/usr/bin 9 | steps: 10 | - run: 11 | name: Setup dependencies 12 | command: | 13 | cd /etc/yum.repos.d/ 14 | sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* 15 | sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* 16 | yum update -y 17 | yum install -y git openssl-devel openssl java java-devel 18 | - checkout 19 | - run: 20 | name: Compile 21 | command: | 22 | bash gradlew build 23 | - run: 24 | name: Integration Test 25 | command: | 26 | bash .ci/ci_check.sh 27 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | lib/web3sdk.jar filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [ 'master*', 'dev*', 'release-*' ] 6 | pull_request: 7 | # The branches below must be a subset of the branches above 8 | branches: [ 'master', 'dev*', 'release-*' ] 9 | schedule: 10 | - cron: '57 14 * * 0' 11 | 12 | jobs: 13 | analyze: 14 | name: Analyze 15 | runs-on: ubuntu-latest 16 | permissions: 17 | actions: read 18 | contents: read 19 | security-events: write 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | language: [ 'java' ] 25 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 26 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@v3 31 | 32 | # Initializes the CodeQL tools for scanning. 33 | - name: Initialize CodeQL 34 | uses: github/codeql-action/init@v2 35 | with: 36 | languages: ${{ matrix.language }} 37 | # If you wish to specify custom queries, you can do so here or in a config file. 38 | # By default, queries listed here will override any specified in a config file. 39 | # Prefix the list here with "+" to use these queries and those in the config file. 40 | 41 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 42 | queries: +security-and-quality 43 | 44 | 45 | # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). 46 | # If this step fails, then you should remove it and run the build manually (see below) 47 | - name: Autobuild 48 | uses: github/codeql-action/autobuild@v2 49 | 50 | # ℹ️ Command-line programs to run using the OS shell. 51 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 52 | 53 | # If the Autobuild fails above, remove it and uncomment the following three lines. 54 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 55 | 56 | # - run: | 57 | # echo "Run, Build Application using script" 58 | # ./location_of_script_within_repo/buildscript.sh 59 | 60 | - name: Perform CodeQL Analysis 61 | uses: github/codeql-action/analyze@v2 62 | with: 63 | category: "/language:${{matrix.language}}" 64 | -------------------------------------------------------------------------------- /.github/workflows/workflow.yml: -------------------------------------------------------------------------------- 1 | name: Console GitHub Actions 2 | on: 3 | pull_request: 4 | release: 5 | types: [published, created, edited] 6 | env: 7 | CCACHE_DIR: ${{ github.workspace }}/ccache 8 | 9 | jobs: 10 | build: 11 | name: build 12 | runs-on: ${{ matrix.os }} 13 | continue-on-error: true 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | os: [ubuntu-20.04, ubuntu-22.04, windows-2019, macos-12] 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 5 22 | - name: install Ubuntu dependencies 23 | if: runner.os == 'Linux' 24 | run: sudo apt update && sudo apt install -y git curl libssl-dev build-essential openssl 25 | - name: install macOS dependencies 26 | if: runner.os == 'macOS' 27 | run: brew install openssl@1.1 28 | - name: Set up JDK 1.8 29 | uses: actions/setup-java@v3 30 | with: 31 | distribution: 'zulu' 32 | java-version: '8.0.382' 33 | - name: run build test 34 | if: runner.os == 'Windows' 35 | run: ./gradlew.bat build 36 | - name: run integration testing 37 | if: runner.os != 'Windows' 38 | run: /bin/bash -x .ci/ci_check.sh 39 | 40 | build-centos: 41 | name: build-centos 42 | runs-on: ${{ matrix.os }} 43 | continue-on-error: true 44 | strategy: 45 | fail-fast: false 46 | matrix: 47 | os: [ ubuntu-20.04 ] 48 | container: docker.io/centos:latest 49 | steps: 50 | - uses: actions/checkout@v2 51 | with: 52 | fetch-depth: 5 53 | - name: install CentOS dependencies 54 | run: | 55 | cd /etc/yum.repos.d/ 56 | sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* 57 | sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* 58 | yum update -y 59 | yum install -y which git openssl-devel openssl wget 60 | - name: Set up JDK 1.8 61 | uses: actions/setup-java@v3 62 | with: 63 | distribution: 'zulu' 64 | java-version: '8.0.382' 65 | - name: run integration testing 66 | run: /bin/bash -x .ci/ci_check.sh 67 | - name: upload coverage 68 | run: curl -LO https://codecov.io/bash && /bin/bash ./bash 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | *.class 4 | 5 | 6 | # Package Files # 7 | *.war 8 | *.ear 9 | *.bin 10 | 11 | ### Gradle template 12 | .gradle 13 | /build 14 | gradle.properties 15 | 16 | 17 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 18 | !gradle-wrapper.jar 19 | 20 | # Cache of project 21 | .gradletasknamecache 22 | 23 | # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 24 | # gradle/wrapper/gradle-wrapper.properties 25 | 26 | .idea 27 | *.iml 28 | 29 | # OS X 30 | .DS_Store 31 | 32 | /target 33 | /out 34 | /log 35 | /dist 36 | .project 37 | .settings/** 38 | .classpath 39 | bin/** 40 | # integration test 41 | /src/integration-test/resources/* 42 | /contracts** 43 | /account 44 | /build_chain.sh 45 | /deploylog.txt 46 | /bin/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | English / [中文](doc/CONTRIBUTING_CN.md) 2 | 3 | # Contributing and Review Guidelines 4 | 5 | All contributions are welcome! 6 | 7 | ## Branching 8 | 9 | Our branching method is [git-flow](https://jeffkreeftmeijer.com/git-flow/) 10 | 11 | - **master**: Latest stable branch 12 | - **dev**: Stable branch waiting for release(merge to master) 13 | - **feature-xxxx**: A developing branch of a new feature named xxxx 14 | - **bugfix-xxxx**: A branch to fix the bug named xxxx 15 | 16 | ## How to 17 | 18 | ### Issue 19 | 20 | Go to [issues page](https://github.com/FISCO-BCOS/console/issues) 21 | 22 | ### Fix bugs 23 | 24 | 1. **Fork** this repo 25 | 2. **Create** a new branch named **bugfix-xxxx** forked from your repo's **master** branch 26 | 3. **Fix** the bug 27 | 4. **Test** the fixed code 28 | 5. Make **pull request** back to this repo's **dev** branch 29 | 6. Wait the community to review the code 30 | 7. Merged(**Bug fixed**) 31 | 32 | ### Develop a new feature 33 | 34 | 1. **Fork** this repo 35 | 2. **Create** a new branch named **feature-xxxx** forked from your repo's **dev** branch 36 | 3. **Coding** in feature-xxxx 37 | 4. **Pull** this repo's dev branch to your feature-xxxx constantly 38 | 5. **Test** your code 39 | 6. Make **pull request** back to this repo's dev branch 40 | 7. Wait the community to review the code 41 | 8. Merged !!!! 42 | 43 | ## Code formatting 44 | 45 | The code formatting tool are described by the [google-java-format-gradle-plugin](https://github.com/sherter/google-java-format-gradle-plugin). 46 | 47 | Execute the task `googleJavaFormat` to format all *.java files in the project 48 | ``` 49 | ./gradlew goJF 50 | ``` 51 | Execute the task `verifyGoogleJavaFormat` to verify that all *.java files are formatted properly 52 | ``` 53 | ./gradlew verGJF 54 | ``` 55 | 56 | ## Continous integration 57 | 58 | **Continous integration platform** 59 | 60 | * travis-ci: [![Build Status](https://travis-ci.org/FISCO-BCOS/console.svg?branch=master)](https://travis-ci.org/FISCO-BCOS/console) 61 | 62 | 63 | **Code quality** 64 | 65 | * Codacy: [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a2a6c2eb499e42739d066ff775d1b288)](https://www.codacy.com/app/fisco/console?utm_source=github.com&utm_medium=referral&utm_content=FISCO-BCOS/console&utm_campaign=Badge_Grade) 66 | 67 | 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://github.com/FISCO-BCOS/FISCO-BCOS/raw/master/docs/images/FISCO_BCOS_Logo.svg?sanitize=true) 2 | 3 | 中文 / [English](doc/README_EN.md) 4 | 5 | # 控制台 6 | 7 | [![contributors](https://img.shields.io/github/contributors/FISCO-BCOS/console)](https://github.com/FISCO-BCOS/console/graphs/contributors) 8 | [![GitHub activity](https://img.shields.io/github/commit-activity/m/FISCO-BCOS/console)](https://github.com/FISCO-BCOS/console/pulse) 9 | [![GitHub All Releases](https://img.shields.io/github/downloads/FISCO-BCOS/console/total.svg)](https://github.com/FISCO-BCOS/console) 10 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 11 | --- 12 | 13 | 控制台是FISCO BCOS的重要交互式客户端工具。控制台拥有丰富的命令,包括查询区块链状态、管理区块链节点、部署并调用合约等。 14 | 15 | ## 版本及兼容性说明 16 | 17 | **v3.x版本控制台仅适用于FISCO BCOS v3.x,不兼容FISCO BCOS v2.x**。 18 | 19 | ### **v2.x控制台** 20 | 21 | - [部署文档](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/installation.html) 22 | 23 | - **代码**: [GitHub](https://github.com/FISCO-BCOS/console/tree/master-2.0), [Gitee](https://gitee.com/FISCO-BCOS/console/tree/master-2.0/) 24 | 25 | - **FISCO BCOS v2.x**: [GitHub](https://github.com/FISCO-BCOS/FISCO-BCOS/tree/master-2.0), [Gitee](https://gitee.com/FISCO-BCOS/FISCO-BCOS/tree/master-2.0/) 26 | 27 | ### **v3.x控制台** 28 | 29 | - [部署文档](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/quick_start/air_installation.html) 30 | 31 | - **代码**: [GitHub](https://github.com/FISCO-BCOS/console/tree/master), [Gitee](https://gitee.com/FISCO-BCOS/console/tree/master) 32 | 33 | - **FISCO BCOS v3.x**: [GitHub](https://github.com/FISCO-BCOS/FISCO-BCOS/tree/master), [Gitee](https://gitee.com/FISCO-BCOS/FISCO-BCOS/tree/master) 34 | 35 | 36 | ## 关键特性 37 | 38 | - 提供大量的区块链状态查询命令。 39 | - 提供简单易用的部署和调用合约命令。 40 | - 提供一些可以管理区块链节点的命令。 41 | - 提供一个合约编译工具,用户可以方便快捷的将Solidity合约文件编译为Java合约文件。 42 | - 提供一个合约转换工具,用户可将编译好的Liquid合约的物料包,例如WASM文件和ABI文件,转换成Java合约文件。 43 | 44 | ## 使用 45 | - 可以直接下载控制台压缩包,然后解压控制台压缩包使用控制台。具体参考 [控制台手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/operation_and_maintenance/console/index.html)。 46 | 47 | ## 源码安装 48 | ``` 49 | $ git clone https://github.com/FISCO-BCOS/console.git 50 | $ cd console 51 | $ bash gradlew build 52 | ``` 53 | 如果安装成功,将在当前目录生成一个`dist`目录。 54 | 55 | ## 配置 56 | 控制台具体配置参考[这里](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/console/console_config.html)。 57 | 58 | ## 贡献代码 59 | 欢迎参与FISCO BCOS的社区建设: 60 | - 点亮我们的小星星(点击项目左上方Star按钮)。 61 | - 提交代码(Pull requests),参考我们的[代码贡献流程](CONTRIBUTING_CN.md)。 62 | - [提问和提交BUG](https://github.com/FISCO-BCOS/console/issues)。 63 | 64 | ## 加入我们的社区 65 | 66 | FISCO BCOS开源社区是国内活跃的开源社区,社区长期为机构和个人开发者提供各类支持与帮助。已有来自各行业的数千名技术爱好者在研究和使用FISCO BCOS。如您对FISCO BCOS开源技术及应用感兴趣,欢迎加入社区获得更多支持与帮助。 67 | 68 | 69 | ![](https://media.githubusercontent.com/media/FISCO-BCOS/LargeFiles/master/images/QR_image.png) 70 | 71 | 72 | ## License 73 | 74 | ![license](https://img.shields.io/badge/license-Apache%20v2-blue.svg) 75 | 76 | FISCO-BCOS/Console的开源协议为[Apache License 2.0](http://www.apache.org/licenses/). 详情参考[LICENSE](LICENSE)。 -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.github.sherter.google-java-format' version '0.8' 3 | id 'java-library' 4 | id 'java' 5 | } 6 | apply plugin: 'maven-publish' 7 | apply plugin: 'java' 8 | apply plugin: 'eclipse' 9 | 10 | 11 | sourceCompatibility = 1.8 12 | targetCompatibility = 1.8 13 | 14 | [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8' 15 | 16 | repositories { 17 | mavenCentral() 18 | maven { url "https://maven.aliyun.com/nexus/content/groups/public/" } 19 | maven { url "https://oss.sonatype.org/service/local/staging/deploy/maven2" } 20 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 21 | } 22 | 23 | googleJavaFormat { 24 | options style: 'AOSP' 25 | source = sourceSets*.allJava 26 | include '**/*.java' 27 | } 28 | 29 | def log4j_version = '2.22.1' 30 | List logger = [ 31 | "org.apache.logging.log4j:log4j-api:$log4j_version", 32 | "org.apache.logging.log4j:log4j-core:$log4j_version", 33 | "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version", 34 | "org.apache.logging.log4j:log4j-web:$log4j_version" 35 | ] 36 | 37 | // In this section you declare the dependencies for your production and test code 38 | dependencies { 39 | implementation logger 40 | //implementation 'org.fisco-bcos:solcJ:0.4.25.1' 41 | //implementation 'org.fisco-bcos:solcJ:0.6.10.1' 42 | //implementation 'org.fisco-bcos:solcJ:0.5.2.1' 43 | implementation 'org.fisco-bcos:solcJ:1.0.0' 44 | 45 | implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.8.0') { 46 | exclude group: "org.slf4j" 47 | } 48 | 49 | implementation('org.fisco-bcos:evm-static-analysis:1.0.0') { 50 | exclude group: "org.slf4j" 51 | } 52 | implementation('commons-cli:commons-cli:1.5.0') 53 | implementation('org.jline:jline:3.21.0') 54 | implementation('io.bretty:console-table-builder:1.2') 55 | implementation('com.github.jsqlparser:jsqlparser:2.0') 56 | implementation('org.fisco-bcos.code-generator:bcos-code-generator:1.6.0') { 57 | exclude group: "org.fisco-bcos.java-sdk" 58 | exclude group: "org.slf4j" 59 | } 60 | implementation ('com.fasterxml.jackson.core:jackson-databind:2.14.3'){ 61 | force true 62 | } 63 | testImplementation('com.github.stefanbirkner:system-rules:1.19.0') 64 | testImplementation('junit:junit:4.13.2') 65 | } 66 | 67 | configurations.all { 68 | resolutionStrategy.cacheChangingModulesFor 0, 'seconds' 69 | exclude group: 'ch.qos.logback', module: 'logback-classic' 70 | exclude group: 'io.zipkin.brave', module: 'brave-tests' 71 | } 72 | 73 | 74 | sourceSets { 75 | main { 76 | java { 77 | srcDir 'src/main/java' 78 | } 79 | resources { 80 | srcDir 'src/main/resources' 81 | } 82 | } 83 | integrationTest { 84 | java { 85 | compileClasspath += main.output + test.output 86 | runtimeClasspath += main.output + test.output 87 | srcDir file('src/integration-test/java') 88 | } 89 | resources.srcDir file('src/integration-test/resources') 90 | } 91 | } 92 | configurations { 93 | integrationTestCompile.extendsFrom testImplementation 94 | integrationTestRuntime.extendsFrom testRuntime 95 | } 96 | 97 | task integrationTest(type: Test) { 98 | testClassesDirs = sourceSets.integrationTest.output.classesDirs 99 | classpath = sourceSets.integrationTest.runtimeClasspath 100 | } 101 | 102 | jar { 103 | destinationDir file('dist/apps') 104 | archiveFileName=project.name + '.jar' 105 | exclude '**/*.xml' 106 | exclude '**/*.properties' 107 | exclude '**/*.crt' 108 | exclude '**/*.key' 109 | 110 | doLast { 111 | copy { 112 | from configurations.runtimeClasspath 113 | into 'dist/lib' 114 | } 115 | copy { 116 | from file('src/integration-test/resources/clog.ini') 117 | from file('src/integration-test/resources/config-example.toml') 118 | from file('src/integration-test/resources/group-generate-config.toml') 119 | from file('src/main/resources/log4j2.xml') 120 | into 'dist/conf' 121 | } 122 | copy { 123 | from file('tools/start.sh') 124 | from file('tools/get_account.sh') 125 | from file('tools/get_gm_account.sh') 126 | from file('tools/contract2java.sh') 127 | from file('tools/console.sh') 128 | into 'dist/' 129 | } 130 | copy { 131 | from file('src/main/resources/contract/') 132 | into 'dist/contracts/' 133 | } 134 | new File('dist/contracts/console').mkdirs() 135 | new File('dist/contracts/sdk').mkdirs() 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /doc/CONTRIBUTING_CN.md: -------------------------------------------------------------------------------- 1 | [English](../CONTRIBUTING.md) / 中文 2 | 3 | # 贡献代码 4 | 5 | 非常感谢能有心为FISCO-BCOS社区贡献代码! 6 | 7 | ## 分支策略 8 | 9 | 项目采用[git-flow](https://jeffkreeftmeijer.com/git-flow/)的分支策略。 10 | 11 | * master:最新的稳定分支 12 | * dev:待发布的稳定分支 13 | * feature-xxxx:一个正在开发xxxx特性分支 14 | * bugfix-xxxx:一个正在修bug xxxx的分支 15 | 16 | ## 贡献方法 17 | 18 | ### Issue 19 | 20 | 可直接去[issues page](https://github.com/FISCO-BCOS/console/issues)提issue。 21 | 22 | ### 修复bug 23 | 24 | 1. Fork本仓库到个人仓库 25 | 2. 从个人仓库的master分支拉出一个bugfix-xxxx分支 26 | 3. 在bugfix-xxxx上修复bug 27 | 4. 测试修复的bug 28 | 5. PR(Pull Request)到本仓库的dev分支 29 | 6. 等待社区review这个PR 30 | 7. PR合入,bug修复完成! 31 | 32 | ### 开发新特性 33 | 34 | 1. Fork本仓库到个人仓库 35 | 2. 从个人仓库的dev分支拉出一个feature-xxxx分支 36 | 3. 在feature-xxxx上进行特性开发 37 | 4. 不定期的从本仓库的dev分支pull最新的改动到feature-xxxx分支 38 | 5. 测试新特性 39 | 6. PR(Pull Request)到本参考的dev分支 40 | 7. 等待社区review这个PR 41 | 8. PR合入,特性开发完成! 42 | 43 | ## 代码格式化 44 | 45 | 代码格式化gradle插件[google-java-format-gradle-plugin](https://github.com/sherter/google-java-format-gradle-plugin). 46 | 47 | 执行任务 `googleJavaFormat`格式化java文件。 48 | ``` 49 | ./gradlew goJF 50 | ``` 51 | 执行任务 `verifyGoogleJavaFormat`验证java文件是否格式化完成 52 | ``` 53 | ./gradlew verGJF 54 | ``` 55 | 56 | ## 持续集成(CI) 57 | 58 | 持续集成框架 59 | 60 | * travis-ci: [![Build Status](https://travis-ci.org/FISCO-BCOS/console.svg?branch=master)](https://travis-ci.org/FISCO-BCOS/console) 61 | 62 | 63 | 代码质量 64 | 65 | * Codacy: [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a2a6c2eb499e42739d066ff775d1b288)](https://www.codacy.com/app/fisco/console?utm_source=github.com&utm_medium=referral&utm_content=FISCO-BCOS/console&utm_campaign=Badge_Grade) 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /doc/README_EN.md: -------------------------------------------------------------------------------- 1 | ![](https://github.com/FISCO-BCOS/FISCO-BCOS/raw/master/docs/images/FISCO_BCOS_Logo.svg?sanitize=true) 2 | 3 | English / [中文](../README.md) 4 | 5 | # console 6 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 7 | [![Build Status](https://travis-ci.org/FISCO-BCOS/console.svg?branch=master)](https://travis-ci.org/FISCO-BCOS/console) 8 | [![GitHub All Releases](https://img.shields.io/github/downloads/FISCO-BCOS/console/total.svg)](https://github.com/FISCO-BCOS/console) 9 | --- 10 | 11 | **The console is an important interactive client tool for FISCO BCOS. The console has wealth of commands, including querying blockchain status, managing blockchain nodes, deploying and invoking contracts, etc.** 12 | 13 | ## Version and Compatibility Notes 14 | 15 | **v3.x version console only works with FISCO BCOS v3.x, not compatible with FISCO BCOS v2.x**. 16 | 17 | ### **v2.x** 18 | 19 | - [Deployment documentation](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/installation.html) 20 | 21 | - **Code**: [GitHub](https://github.com/FISCO-BCOS/console/tree/master-2.0), [Gitee](https://gitee.com/FISCO-BCOS/console/tree/master-2.0/) 22 | 23 | - **FISCO BCOS v2.x**: [GitHub](https://github.com/FISCO-BCOS/FISCO-BCOS/tree/master-2.0), [Gitee](https://gitee.com/FISCO-BCOS/FISCO-BCOS/tree/master-2.0/) 24 | 25 | ### **v3.x** 26 | 27 | - [Deployment documentation](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/quick_start/air_installation.html) 28 | 29 | - **Code**: [GitHub](https://github.com/FISCO-BCOS/console/tree/master), [Gitee](https://gitee.com/FISCO-BCOS/console/tree/master) 30 | 31 | - **FISCO BCOS v3.x**: [GitHub](https://github.com/FISCO-BCOS/FISCO-BCOS/tree/master), [Gitee](https://gitee.com/FISCO-BCOS/FISCO-BCOS/tree/master) 32 | 33 | 34 | ## Features 35 | 36 | - Provide a lot of query commands for blockchain. 37 | - Provide the easiest way to deploy and invoke contracts. 38 | - Provide some commands which can manage blockchain node. 39 | - Provide a contract compilation tool that allows users to easily and quickly compile Solidity contract files into Java contract files. 40 | - Provide an easy way to transfer compiled Liquid contract material, such as WASM and ABI, into Java contract files. 41 | 42 | ## Usage 43 | 44 | - You can download a tar file and decompress it to enjoy console. See [console manual](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/console/index.html) for more details. 45 | 46 | ## Source Installation 47 | ``` 48 | $ git clone https://github.com/FISCO-BCOS/console.git 49 | $ cd console 50 | $ bash gradlew build 51 | ``` 52 | 53 | If you install successfully, it produces the `dist` directory. 54 | 55 | ## Configuration 56 | Please see the [documentation](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/console/console_config.html) about configuration for the console. Have fun :) 57 | 58 | ## Code Contribution 59 | - Star our GitHub. 60 | - Pull requests. See [CONTRIBUTING](CONTRIBUTING.md). 61 | - [Ask questions](https://github.com/FISCO-BCOS/console/issues). 62 | 63 | 64 | ## Join Our Community 65 | 66 | The FISCO BCOS community is one of the most active open-source blockchain communities in China. It provides long-term technical support for both institutional and individual developers and users of FISCO BCOS. Thousands of technical enthusiasts from numerous industry sectors have joined this community, studying and using FISCO BCOS platform. If you are also interested, you are most welcome to join us for more support and fun. 67 | 68 | ![](https://media.githubusercontent.com/media/FISCO-BCOS/LargeFiles/master/images/QR_image_en.png) 69 | 70 | ## License 71 | ![license](https://img.shields.io/badge/license-Apache%20v2-blue.svg) 72 | 73 | 74 | All contributions are made under the [Apache License 2.0](http://www.apache.org/licenses/). See [LICENSE](../LICENSE). 75 | -------------------------------------------------------------------------------- /doc/images/WeChatQR.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/doc/images/WeChatQR.jpeg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | #distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /release_note.txt: -------------------------------------------------------------------------------- 1 | v3.8.0 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user guide at https://docs.gradle.org/4.5/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'console' 11 | -------------------------------------------------------------------------------- /src/integration-test/java/console/TestBase.java: -------------------------------------------------------------------------------- 1 | package console; 2 | 3 | import console.auth.AuthFace; 4 | import console.client.ConsoleClientFace; 5 | import console.contract.ConsoleContractFace; 6 | import console.precompiled.PrecompiledFace; 7 | import org.fisco.bcos.sdk.v3.model.EnumNodeVersion; 8 | import org.junit.AfterClass; 9 | import org.junit.BeforeClass; 10 | 11 | public class TestBase { 12 | 13 | protected static ConsoleClientFace consoleClientFace; 14 | protected static PrecompiledFace precompiledFace; 15 | protected static ConsoleContractFace consoleContractFace; 16 | protected static ConsoleInitializer consoleInitializer; 17 | protected static boolean isWasm; 18 | protected static boolean isAuthCheck; 19 | protected static EnumNodeVersion chainVersion; 20 | protected static AuthFace authFace; 21 | 22 | @BeforeClass 23 | public static void setUpBeforeClass() throws Exception { 24 | consoleInitializer = new ConsoleInitializer(); 25 | consoleInitializer.init(new String[0]); 26 | isWasm = consoleInitializer.getClient().isWASM(); 27 | isAuthCheck = consoleInitializer.getClient().isEnableCommittee(); 28 | authFace = consoleInitializer.getAuthFace(); 29 | consoleClientFace = consoleInitializer.getConsoleClientFace(); 30 | precompiledFace = consoleInitializer.getPrecompiledFace(); 31 | consoleContractFace = consoleInitializer.getConsoleContractFace(); 32 | long compatibilityVersion = consoleInitializer.getClient().getGroupInfo().getResult().getNodeList().get(0).getProtocol().getCompatibilityVersion(); 33 | chainVersion = EnumNodeVersion.valueOf((int) compatibilityVersion); 34 | } 35 | 36 | @AfterClass 37 | public static void setUpAfterClass() throws Exception {} 38 | } 39 | -------------------------------------------------------------------------------- /src/integration-test/java/console/WelcomeInfoTest.java: -------------------------------------------------------------------------------- 1 | package console; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | 5 | import console.command.model.WelcomeInfo; 6 | import org.junit.Rule; 7 | import org.junit.Test; 8 | import org.junit.contrib.java.lang.system.SystemOutRule; 9 | 10 | public class WelcomeInfoTest extends TestBase { 11 | 12 | @Rule public final SystemOutRule log = new SystemOutRule().enableLog(); 13 | 14 | @Test 15 | public void welcome() { 16 | WelcomeInfo.welcome(); 17 | assertFalse(log.getLog().isEmpty()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/integration-test/resources/clog.ini: -------------------------------------------------------------------------------- 1 | [log] 2 | enable=true 3 | log_path=./log 4 | ; network statistics interval, unit is second, default is 60s 5 | stat_flush_interval=60 6 | ; info debug trace 7 | level=debug 8 | ; MB 9 | max_log_file_size=200 10 | -------------------------------------------------------------------------------- /src/integration-test/resources/config-example.toml: -------------------------------------------------------------------------------- 1 | [cryptoMaterial] 2 | 3 | certPath = "conf" # The certification path 4 | disableSsl = "false" # Communication with nodes without SSL 5 | useSMCrypto = "false" # RPC SM crypto type 6 | 7 | # The following configurations take the certPath by default if commented 8 | # caCert = "conf/ca.crt" # CA cert file path 9 | # sslCert = "conf/sdk.crt" # SSL cert file path 10 | # sslKey = "conf/sdk.key" # SSL key file path 11 | 12 | # The following configurations take the sm certPath by default if commented 13 | # caCert = "conf/sm_ca.crt" # SM CA cert file path 14 | # sslCert = "conf/sm_sdk.crt" # SM SSL cert file path 15 | # sslKey = "conf/sm_sdk.key" # SM SSL key file path 16 | # enSslCert = "conf/sm_ensdk.crt" # SM encryption cert file path 17 | # enSslKey = "conf/sm_ensdk.key" # SM ssl cert file path 18 | 19 | [network] 20 | messageTimeout = "10000" 21 | defaultGroup="group0" # Console default group to connect 22 | peers=["127.0.0.1:20200", "127.0.0.1:20201"] # The peer list to connect 23 | 24 | [account] 25 | keyStoreDir = "account" # The directory to load/store the account file, default is "account" 26 | # accountFilePath = "" # The account file path (default load from the path specified by the keyStoreDir) 27 | accountFileFormat = "pem" # The storage format of account file (Default is "pem", "p12" as an option) 28 | 29 | # accountAddress = "" # The transactions sending account address 30 | # Default is a randomly generated account 31 | # The randomly generated account is stored in the path specified by the keyStoreDir 32 | 33 | # password = "" # The password used to load the account file 34 | 35 | [threadPool] 36 | # threadPoolSize = "16" # The size of the thread pool to process message callback 37 | # Default is the number of cpu cores 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/console/auth/AuthFace.java: -------------------------------------------------------------------------------- 1 | package console.auth; 2 | 3 | import console.ConsoleInitializer; 4 | 5 | public interface AuthFace { 6 | 7 | void createUpdateGovernorProposal(String[] params) throws Exception; 8 | 9 | void createSetRateProposal(String[] params) throws Exception; 10 | 11 | void createSetDeployAuthTypeProposal(String[] params) throws Exception; 12 | 13 | void createOpenDeployAuthProposal(String[] params) throws Exception; 14 | 15 | void createCloseDeployAuthProposal(String[] params) throws Exception; 16 | 17 | void createResetAdminProposal(String[] params) throws Exception; 18 | 19 | void createSetConsensusWeightProposal(String[] params) throws Exception; 20 | 21 | void createAddSealerProposal(String[] params) throws Exception; 22 | 23 | void createAddObserverProposal(String[] params) throws Exception; 24 | 25 | void createRemoveNodeProposal(String[] params) throws Exception; 26 | 27 | void createSetSysConfigProposal(ConsoleInitializer consoleInitializer, String[] params) 28 | throws Exception; 29 | 30 | void createUpgradeVoteComputerProposal(String[] params) throws Exception; 31 | 32 | void revokeProposal(String[] params) throws Exception; 33 | 34 | void voteProposal(String[] params) throws Exception; 35 | 36 | void getProposalInfoList(String[] params) throws Exception; 37 | 38 | void getCommitteeInfo(String[] params) throws Exception; 39 | 40 | void getContractAdmin(String[] params) throws Exception; 41 | 42 | void getDeployStrategy(String[] params) throws Exception; 43 | 44 | void checkDeployAuth(ConsoleInitializer consoleInitializer, String[] params) throws Exception; 45 | 46 | void setMethodAuthType(ConsoleInitializer consoleInitializer, String[] params) throws Exception; 47 | 48 | void openMethodAuth(ConsoleInitializer consoleInitializer, String[] params) throws Exception; 49 | 50 | void closeMethodAuth(ConsoleInitializer consoleInitializer, String[] params) throws Exception; 51 | 52 | void checkMethodAuth(ConsoleInitializer consoleInitializer, String[] params) throws Exception; 53 | 54 | void getMethodAuth(ConsoleInitializer consoleInitializer, String[] params) throws Exception; 55 | 56 | void getLatestProposal(String[] params) throws Exception; 57 | 58 | void freezeContract(String[] params) throws Exception; 59 | 60 | void unfreezeContract(String[] params) throws Exception; 61 | 62 | void abolishContract(String[] params) throws Exception; 63 | 64 | void getContractStatus(String[] params) throws Exception; 65 | 66 | void freezeAccount(String[] params) throws Exception; 67 | 68 | void unfreezeAccount(String[] params) throws Exception; 69 | 70 | void abolishAccount(String[] params) throws Exception; 71 | 72 | void getAccountStatus(String[] params) throws Exception; 73 | 74 | void initAuth(String[] params) throws Exception; 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/console/client/ConsoleClientFace.java: -------------------------------------------------------------------------------- 1 | package console.client; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import console.ConsoleInitializer; 5 | import java.io.IOException; 6 | import org.fisco.bcos.sdk.v3.client.Client; 7 | 8 | public interface ConsoleClientFace { 9 | void updateClient(Client client); 10 | 11 | void getBlockNumber(String[] params) throws IOException; 12 | 13 | void getPbftView(String[] params) throws IOException; 14 | 15 | void getObserverList(String[] params) throws IOException; 16 | 17 | void getSealerList(String[] params) throws IOException; 18 | 19 | void getCandidateSealerList(String[] params) throws IOException; 20 | 21 | void getSyncStatus(String[] params) throws IOException; 22 | 23 | void getConsensusStatus(String[] params) throws IOException; 24 | 25 | void getPeers(String[] params) throws IOException; 26 | 27 | void getBlockByHash(String[] params) throws IOException; 28 | 29 | void getBlockByNumber(String[] params) throws IOException; 30 | 31 | void getLatestBlock(String[] params) throws IOException; 32 | 33 | void getBlockHeaderByHash(String[] params) throws IOException; 34 | 35 | void getBlockHashByNumber(String[] params) throws IOException; 36 | 37 | void getBlockHeaderByNumber(String[] params) throws IOException; 38 | 39 | void getTransactionByHash(String[] params); 40 | 41 | void getTransactionReceipt(String[] params) throws Exception; 42 | 43 | void getTransactionByHashWithProof(String[] params) throws Exception; 44 | 45 | void getTransactionReceiptByHashWithProof(String[] params) throws Exception; 46 | 47 | void getPendingTxSize(String[] params) throws IOException; 48 | 49 | void getCode(String[] params, boolean isWasm, String pwd) throws IOException; 50 | 51 | void getTotalTransactionCount(String[] params) throws IOException; 52 | 53 | void getSystemConfigByKey(String[] params) throws Exception; 54 | 55 | void listConfigs(String[] params) throws Exception; 56 | 57 | void newAccount(String[] params); 58 | 59 | void listAccount(String[] params); 60 | 61 | void getGroupPeers(String[] params); 62 | 63 | void getGroupList(String[] params); 64 | 65 | void getGroupInfo(String[] params) throws IOException; 66 | 67 | void getGroupInfoList(String[] params) throws JsonProcessingException; 68 | 69 | void getGroupNodeInfo(String[] params) throws JsonProcessingException; 70 | 71 | void setNodeName(ConsoleInitializer consoleInitializer, String[] params) throws IOException; 72 | 73 | void clearNodeName(ConsoleInitializer consoleInitializer); 74 | 75 | void getNodeName(ConsoleInitializer consoleInitializer); 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/console/client/model/TotalTransactionCountResult.java: -------------------------------------------------------------------------------- 1 | package console.client.model; 2 | 3 | import java.math.BigInteger; 4 | 5 | public class TotalTransactionCountResult { 6 | 7 | private BigInteger blockNumber; 8 | private BigInteger txSum; 9 | private BigInteger failedTxSum = BigInteger.ZERO; 10 | 11 | public TotalTransactionCountResult() {} 12 | 13 | public BigInteger getBlockNumber() { 14 | return blockNumber; 15 | } 16 | 17 | public void setBlockNumber(BigInteger blockNumber) { 18 | this.blockNumber = blockNumber; 19 | } 20 | 21 | public BigInteger getTxSum() { 22 | return txSum; 23 | } 24 | 25 | public void setTxSum(BigInteger txSum) { 26 | this.txSum = txSum; 27 | } 28 | 29 | public BigInteger getFailedTxSum() { 30 | return failedTxSum; 31 | } 32 | 33 | public void setFailedTxSum(BigInteger failedTxSum) { 34 | this.failedTxSum = failedTxSum; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "InnerTotalTransactionCountResult [blockNumber=" 40 | + blockNumber 41 | + ", txSum=" 42 | + txSum 43 | + ", failedTxSum=" 44 | + failedTxSum 45 | + "]"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/console/collaboration/CollaborationFace.java: -------------------------------------------------------------------------------- 1 | package console.collaboration; 2 | 3 | public interface CollaborationFace { 4 | 5 | void initialize(String[] params) throws Exception; 6 | 7 | void sign(String[] params) throws Exception; 8 | 9 | void exercise(String[] params) throws Exception; 10 | 11 | void fetch(String[] params) throws Exception; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/console/command/category/AccountOpCommand.java: -------------------------------------------------------------------------------- 1 | package console.command.category; 2 | 3 | import console.command.model.BasicCategoryCommand; 4 | import console.command.model.CommandInfo; 5 | import console.command.model.CommandType; 6 | import console.command.model.HelpInfo; 7 | import java.lang.reflect.Field; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.stream.Collectors; 12 | 13 | public class AccountOpCommand extends BasicCategoryCommand { 14 | protected static final Map commandToCommandInfo = new HashMap<>(); 15 | 16 | public AccountOpCommand() { 17 | super(CommandType.ACCOUNT_OP); 18 | } 19 | 20 | @Override 21 | public CommandInfo getCommandInfo(String command) { 22 | if (commandToCommandInfo.containsKey(command)) { 23 | return commandToCommandInfo.get(command); 24 | } 25 | return null; 26 | } 27 | 28 | @Override 29 | public List getAllCommand(boolean isWasm, boolean isAuthOpen) { 30 | return commandToCommandInfo 31 | .keySet() 32 | .stream() 33 | .filter( 34 | key -> 35 | !(isWasm && !commandToCommandInfo.get(key).isWasmSupport() 36 | || (!isAuthOpen 37 | && commandToCommandInfo.get(key).isNeedAuthOpen()))) 38 | .collect(Collectors.toList()); 39 | } 40 | 41 | @Override 42 | public Map getAllCommandInfo(boolean isWasm) { 43 | return commandToCommandInfo; 44 | } 45 | 46 | public static final CommandInfo NEW_ACCOUNT = 47 | new CommandInfo( 48 | "newAccount", 49 | "Create account", 50 | HelpInfo::newAccountHelp, 51 | (consoleInitializer, params, pwd) -> 52 | consoleInitializer.getConsoleClientFace().newAccount(params), 53 | 0, 54 | 2); 55 | 56 | public static final CommandInfo LOAD_ACCOUNT = 57 | new CommandInfo( 58 | "loadAccount", 59 | "Load account for the transaction signature", 60 | HelpInfo::loadAccountHelp, 61 | (consoleInitializer, params, pwd) -> consoleInitializer.loadAccount(params), 62 | 1, 63 | 2, 64 | false); 65 | 66 | public static final CommandInfo LIST_ACCOUNT = 67 | new CommandInfo( 68 | "listAccount", 69 | "List the current saved account list", 70 | () -> { 71 | System.out.println("List all the accounts"); 72 | System.out.println("Usage: \nlistAccount"); 73 | }, 74 | (consoleInitializer, params, pwd) -> 75 | consoleInitializer.getConsoleClientFace().listAccount(params), 76 | 0, 77 | 0); 78 | 79 | public static final CommandInfo GET_CURRENT_ACCOUNT = 80 | new CommandInfo( 81 | "getCurrentAccount", 82 | "Get the current account info", 83 | (consoleInitializer, params, pwd) -> 84 | System.out.println( 85 | consoleInitializer 86 | .getClient() 87 | .getCryptoSuite() 88 | .getCryptoKeyPair() 89 | .getAddress())); 90 | 91 | static { 92 | Field[] fields = AccountOpCommand.class.getDeclaredFields(); 93 | for (Field field : fields) { 94 | if (field.getType().equals(CommandInfo.class)) { 95 | try { 96 | CommandInfo constantCommandInfo = (CommandInfo) field.get(null); 97 | commandToCommandInfo.put(constantCommandInfo.getCommand(), constantCommandInfo); 98 | if (constantCommandInfo.getOptionCommand() != null) { 99 | List subCommandList = constantCommandInfo.getOptionCommand(); 100 | for (String s : subCommandList) { 101 | commandToCommandInfo.put(s, constantCommandInfo); 102 | } 103 | } 104 | } catch (IllegalAccessException e) { 105 | e.printStackTrace(); 106 | } 107 | } 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/console/command/category/BasicCommand.java: -------------------------------------------------------------------------------- 1 | package console.command.category; 2 | 3 | import console.command.model.BasicCategoryCommand; 4 | import console.command.model.CommandInfo; 5 | import console.command.model.CommandType; 6 | import console.command.model.HelpInfo; 7 | import java.lang.reflect.Field; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | import java.util.stream.Collectors; 15 | 16 | public class BasicCommand extends BasicCategoryCommand { 17 | protected static final Map commandToCommandInfo = new HashMap<>(); 18 | 19 | public BasicCommand() { 20 | super(CommandType.BASIC_CMD); 21 | } 22 | 23 | @Override 24 | public CommandInfo getCommandInfo(String command) { 25 | if (commandToCommandInfo.containsKey(command)) { 26 | return commandToCommandInfo.get(command); 27 | } 28 | return null; 29 | } 30 | 31 | @Override 32 | public List getAllCommand(boolean isWasm, boolean isAuthOpen) { 33 | return commandToCommandInfo 34 | .keySet() 35 | .stream() 36 | .filter( 37 | key -> 38 | !(isWasm && !commandToCommandInfo.get(key).isWasmSupport() 39 | || (!isAuthOpen 40 | && commandToCommandInfo.get(key).isNeedAuthOpen()))) 41 | .collect(Collectors.toList()); 42 | } 43 | 44 | @Override 45 | public Map getAllCommandInfo(boolean isWasm) { 46 | return commandToCommandInfo; 47 | } 48 | 49 | public static final CommandInfo SWITCH = 50 | new CommandInfo( 51 | "switch", 52 | "Switch to a specific group by name", 53 | new ArrayList<>(Collections.singletonList("s")), 54 | HelpInfo::switchEndPointHelp, 55 | (consoleInitializer, params, pwd) -> consoleInitializer.switchGroup(params), 56 | 1, 57 | 1, 58 | false); 59 | 60 | public static final CommandInfo QUIT = 61 | new CommandInfo( 62 | "quit", 63 | "Quit console", 64 | new ArrayList<>(Arrays.asList("quit", "q", "exit")), 65 | (consoleInitializer, params, pwd) -> System.exit(0), 66 | false); 67 | 68 | public static final CommandInfo SET_NODE_NAME = 69 | new CommandInfo( 70 | "setNodeName", 71 | "Set default node name to send request.", 72 | HelpInfo::setNodeNameHelp, 73 | (consoleInitializer, params, pwd) -> 74 | consoleInitializer 75 | .getConsoleClientFace() 76 | .setNodeName(consoleInitializer, params), 77 | 1, 78 | 1); 79 | 80 | public static final CommandInfo GET_NODE_NAME = 81 | new CommandInfo( 82 | "getNodeName", 83 | "Get default node name in this client.", 84 | HelpInfo::getNodeNameHelp, 85 | (consoleInitializer, params, pwd) -> 86 | consoleInitializer 87 | .getConsoleClientFace() 88 | .getNodeName(consoleInitializer), 89 | 0, 90 | 0); 91 | 92 | public static final CommandInfo CLEAR_NODE_NAME = 93 | new CommandInfo( 94 | "clearNodeName", 95 | "Clear default node name to empty.", 96 | HelpInfo::clearNodeNameHelp, 97 | (consoleInitializer, params, pwd) -> 98 | consoleInitializer 99 | .getConsoleClientFace() 100 | .clearNodeName(consoleInitializer), 101 | 0, 102 | 0); 103 | 104 | static { 105 | Field[] fields = BasicCommand.class.getDeclaredFields(); 106 | for (Field field : fields) { 107 | if (field.getType().equals(CommandInfo.class)) { 108 | try { 109 | CommandInfo constantCommandInfo = (CommandInfo) field.get(null); 110 | commandToCommandInfo.put(constantCommandInfo.getCommand(), constantCommandInfo); 111 | if (constantCommandInfo.getOptionCommand() != null) { 112 | List subCommandList = constantCommandInfo.getOptionCommand(); 113 | for (String s : subCommandList) { 114 | commandToCommandInfo.put(s, constantCommandInfo); 115 | } 116 | } 117 | } catch (IllegalAccessException e) { 118 | e.printStackTrace(); 119 | } 120 | } 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/console/command/category/CollaborationOpCommand.java: -------------------------------------------------------------------------------- 1 | package console.command.category; 2 | 3 | import console.command.model.BasicCategoryCommand; 4 | import console.command.model.CommandInfo; 5 | import console.command.model.CommandType; 6 | import console.command.model.HelpInfo; 7 | import java.lang.reflect.Field; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public class CollaborationOpCommand extends BasicCategoryCommand { 15 | protected static final Map commandToCommandInfo = new HashMap<>(); 16 | 17 | public CollaborationOpCommand() { 18 | super(CommandType.COLLABORATE_OP); 19 | } 20 | 21 | @Override 22 | public CommandInfo getCommandInfo(String command) { 23 | if (commandToCommandInfo.containsKey(command)) { 24 | return commandToCommandInfo.get(command); 25 | } 26 | return null; 27 | } 28 | 29 | @Override 30 | public List getAllCommand(boolean isWasm, boolean isAuthOpen) { 31 | if (isWasm) return new ArrayList<>(commandToCommandInfo.keySet()); 32 | return new ArrayList<>(); 33 | } 34 | 35 | @Override 36 | public Map getAllCommandInfo(boolean isWasm) { 37 | return commandToCommandInfo; 38 | } 39 | 40 | public static final CommandInfo INITIALIZE = 41 | new CommandInfo( 42 | "initialize", 43 | "Initialize a collaboration", 44 | HelpInfo::initializeHelp, 45 | (consoleInitializer, params, pwd) -> { 46 | consoleInitializer.getCollaborationFace().initialize(params); 47 | }); 48 | 49 | public static final CommandInfo SIGN = 50 | new CommandInfo( 51 | "sign", 52 | "Sign a contract", 53 | HelpInfo::signHelp, 54 | (consoleInitializer, params, pwd) -> { 55 | consoleInitializer.getCollaborationFace().sign(params); 56 | }); 57 | 58 | public static final CommandInfo EXERCISE = 59 | new CommandInfo( 60 | "execute", 61 | "Exercise an right of a contract", 62 | HelpInfo::exerciseHelp, 63 | (consoleInitializer, params, pwd) -> { 64 | consoleInitializer.getCollaborationFace().exercise(params); 65 | }); 66 | 67 | public static final CommandInfo FETCH = 68 | new CommandInfo( 69 | "fetch", 70 | "Fetch a contract", 71 | HelpInfo::fetchHelp, 72 | (consoleInitializer, params, pwd) -> { 73 | consoleInitializer.getCollaborationFace().fetch(params); 74 | }); 75 | 76 | static { 77 | Field[] fields = CollaborationOpCommand.class.getDeclaredFields(); 78 | for (Field field : fields) { 79 | if (field.getType().equals(CommandInfo.class)) { 80 | try { 81 | CommandInfo constantCommandInfo = (CommandInfo) field.get(null); 82 | commandToCommandInfo.put(constantCommandInfo.getCommand(), constantCommandInfo); 83 | if (constantCommandInfo.getOptionCommand() != null) { 84 | List subCommandList = constantCommandInfo.getOptionCommand(); 85 | for (String s : subCommandList) { 86 | commandToCommandInfo.put(s, constantCommandInfo); 87 | } 88 | } 89 | } catch (IllegalAccessException e) { 90 | e.printStackTrace(); 91 | } 92 | } 93 | } 94 | } 95 | 96 | // TODO: Liquid collaboration service is not supported in FISCO BCOS 3.0.0 rc4 97 | public static final List COLLABORATION_COMMANDS = 98 | new ArrayList<>( 99 | Arrays.asList( 100 | INITIALIZE.getCommand(), 101 | SIGN.getCommand(), 102 | EXERCISE.getCommand(), 103 | FETCH.getCommand())); 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/console/command/category/CrudCommand.java: -------------------------------------------------------------------------------- 1 | package console.command.category; 2 | 3 | import console.command.model.BasicCategoryCommand; 4 | import console.command.model.CommandInfo; 5 | import console.command.model.CommandType; 6 | import console.command.model.HelpInfo; 7 | import java.lang.reflect.Field; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.stream.Collectors; 14 | 15 | public class CrudCommand extends BasicCategoryCommand { 16 | protected static final Map commandToCommandInfo = new HashMap<>(); 17 | 18 | public CrudCommand() { 19 | super(CommandType.CRUD_OP); 20 | } 21 | 22 | @Override 23 | public CommandInfo getCommandInfo(String command) { 24 | if (commandToCommandInfo.containsKey(command)) { 25 | return commandToCommandInfo.get(command); 26 | } 27 | return null; 28 | } 29 | 30 | @Override 31 | public List getAllCommand(boolean isWasm, boolean isAuthOpen) { 32 | return commandToCommandInfo 33 | .keySet() 34 | .stream() 35 | .filter( 36 | key -> 37 | !(isWasm && !commandToCommandInfo.get(key).isWasmSupport() 38 | || (!isAuthOpen 39 | && commandToCommandInfo.get(key).isNeedAuthOpen()))) 40 | .collect(Collectors.toList()); 41 | } 42 | 43 | @Override 44 | public Map getAllCommandInfo(boolean isWasm) { 45 | return commandToCommandInfo; 46 | } 47 | 48 | public static final CommandInfo DESC = 49 | new CommandInfo( 50 | "desc", 51 | "Description table information", 52 | HelpInfo::showDescHelp, 53 | (consoleInitializer, params, pwd) -> 54 | consoleInitializer.getPrecompiledFace().desc(params), 55 | 1, 56 | 1); 57 | public static final CommandInfo CREATE = 58 | new CommandInfo( 59 | "create", 60 | "Create table by sql", 61 | (consoleInitializer, params, pwd) -> 62 | consoleInitializer.getPrecompiledFace().createTable(params[0])); 63 | 64 | public static final CommandInfo ALTER = 65 | new CommandInfo( 66 | "alter", 67 | "Alter table columns by sql", 68 | (consoleInitializer, params, pwd) -> 69 | consoleInitializer.getPrecompiledFace().alterTable(params[0])); 70 | 71 | public static final CommandInfo SELECT = 72 | new CommandInfo( 73 | "select", 74 | "Select records by sql", 75 | (consoleInitializer, params, pwd) -> 76 | consoleInitializer.getPrecompiledFace().select(params[0])); 77 | public static final CommandInfo INSERT = 78 | new CommandInfo( 79 | "insert", 80 | "Insert records by sql", 81 | (consoleInitializer, params, pwd) -> 82 | consoleInitializer.getPrecompiledFace().insert(params[0])); 83 | public static final CommandInfo UPDATE = 84 | new CommandInfo( 85 | "update", 86 | "Update records by sql", 87 | (consoleInitializer, params, pwd) -> 88 | consoleInitializer.getPrecompiledFace().update(params[0])); 89 | public static final CommandInfo DELETE = 90 | new CommandInfo( 91 | "delete", 92 | "Remove records by sql", 93 | (consoleInitializer, params, pwd) -> 94 | consoleInitializer.getPrecompiledFace().remove(params[0])); 95 | 96 | static { 97 | Field[] fields = CrudCommand.class.getDeclaredFields(); 98 | for (Field field : fields) { 99 | if (field.getType().equals(CommandInfo.class)) { 100 | try { 101 | CommandInfo constantCommandInfo = (CommandInfo) field.get(null); 102 | commandToCommandInfo.put(constantCommandInfo.getCommand(), constantCommandInfo); 103 | if (constantCommandInfo.getOptionCommand() != null) { 104 | List subCommandList = constantCommandInfo.getOptionCommand(); 105 | for (String s : subCommandList) { 106 | commandToCommandInfo.put(s, constantCommandInfo); 107 | } 108 | } 109 | } catch (IllegalAccessException e) { 110 | e.printStackTrace(); 111 | } 112 | } 113 | } 114 | } 115 | 116 | public static final List CRUD_COMMANDS = 117 | new ArrayList<>( 118 | Arrays.asList( 119 | CrudCommand.CREATE.getCommand(), 120 | CrudCommand.ALTER.getCommand(), 121 | CrudCommand.INSERT.getCommand(), 122 | CrudCommand.SELECT.getCommand(), 123 | CrudCommand.UPDATE.getCommand(), 124 | CrudCommand.DELETE.getCommand())); 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/console/command/category/GroupCommand.java: -------------------------------------------------------------------------------- 1 | package console.command.category; 2 | 3 | import console.command.model.BasicCategoryCommand; 4 | import console.command.model.CommandInfo; 5 | import console.command.model.CommandType; 6 | import console.command.model.HelpInfo; 7 | import java.lang.reflect.Field; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.stream.Collectors; 12 | 13 | public class GroupCommand extends BasicCategoryCommand { 14 | protected static final Map commandToCommandInfo = new HashMap<>(); 15 | 16 | public GroupCommand() { 17 | super(CommandType.GROUP_QUERY); 18 | } 19 | 20 | @Override 21 | public CommandInfo getCommandInfo(String command) { 22 | if (commandToCommandInfo.containsKey(command)) { 23 | return commandToCommandInfo.get(command); 24 | } 25 | return null; 26 | } 27 | 28 | @Override 29 | public List getAllCommand(boolean isWasm, boolean isAuthOpen) { 30 | return commandToCommandInfo 31 | .keySet() 32 | .stream() 33 | .filter( 34 | key -> 35 | !(isWasm && !commandToCommandInfo.get(key).isWasmSupport() 36 | || (!isAuthOpen 37 | && commandToCommandInfo.get(key).isNeedAuthOpen()))) 38 | .collect(Collectors.toList()); 39 | } 40 | 41 | @Override 42 | public Map getAllCommandInfo(boolean isWasm) { 43 | return commandToCommandInfo; 44 | } 45 | 46 | public static final CommandInfo GET_GROUP_PEERS = 47 | new CommandInfo( 48 | "getGroupPeers", 49 | "List all group peers", 50 | HelpInfo::getGroupPeersHelp, 51 | (consoleInitializer, params, pwd) -> 52 | consoleInitializer.getConsoleClientFace().getGroupPeers(params), 53 | 0, 54 | 0); 55 | 56 | public static final CommandInfo GET_GROUP_NODE_INFO = 57 | new CommandInfo( 58 | "getGroupNodeInfo", 59 | "Get group node info", 60 | () -> { 61 | System.out.println("Get group node info"); 62 | System.out.println("Usage: \ngetGroupNodeInfo [nodeName]"); 63 | }, 64 | (consoleInitializer, params, pwd) -> 65 | consoleInitializer.getConsoleClientFace().getGroupNodeInfo(params), 66 | 1, 67 | 1); 68 | 69 | public static final CommandInfo GET_GROUP_INFO = 70 | new CommandInfo( 71 | "getGroupInfo", 72 | "Query the current group information.", 73 | HelpInfo::getGroupInfoHelp, 74 | (consoleInitializer, params, pwd) -> 75 | consoleInitializer.getConsoleClientFace().getGroupInfo(params), 76 | 0, 77 | 0); 78 | 79 | public static final CommandInfo GET_GROUP_LIST = 80 | new CommandInfo( 81 | "getGroupList", 82 | "List all group list", 83 | HelpInfo::getGroupListHelp, 84 | (consoleInitializer, params, pwd) -> 85 | consoleInitializer.getConsoleClientFace().getGroupList(params), 86 | 0, 87 | 0); 88 | 89 | public static final CommandInfo GET_GROUP_INFO_LIST = 90 | new CommandInfo( 91 | "getGroupInfoList", 92 | "Get all groups info", 93 | () -> { 94 | System.out.println("Get all group info"); 95 | System.out.println("Usage: \ngetGroupInfoList"); 96 | }, 97 | (consoleInitializer, params, pwd) -> 98 | consoleInitializer.getConsoleClientFace().getGroupInfoList(params), 99 | 0, 100 | 0); 101 | 102 | static { 103 | Field[] fields = GroupCommand.class.getDeclaredFields(); 104 | for (Field field : fields) { 105 | if (field.getType().equals(CommandInfo.class)) { 106 | try { 107 | CommandInfo constantCommandInfo = (CommandInfo) field.get(null); 108 | commandToCommandInfo.put(constantCommandInfo.getCommand(), constantCommandInfo); 109 | if (constantCommandInfo.getOptionCommand() != null) { 110 | List subCommandList = constantCommandInfo.getOptionCommand(); 111 | for (String s : subCommandList) { 112 | commandToCommandInfo.put(s, constantCommandInfo); 113 | } 114 | } 115 | } catch (IllegalAccessException e) { 116 | e.printStackTrace(); 117 | } 118 | } 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/console/command/category/ShardingCommand.java: -------------------------------------------------------------------------------- 1 | package console.command.category; 2 | 3 | import console.command.model.BasicCategoryCommand; 4 | import console.command.model.CommandInfo; 5 | import console.command.model.CommandType; 6 | import console.command.model.HelpInfo; 7 | import java.lang.reflect.Field; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.stream.Collectors; 12 | 13 | public class ShardingCommand extends BasicCategoryCommand { 14 | protected static final Map commandToCommandInfo = new HashMap<>(); 15 | 16 | public ShardingCommand() { 17 | super(CommandType.SHARDING_OP); 18 | } 19 | 20 | @Override 21 | public CommandInfo getCommandInfo(String command) { 22 | if (commandToCommandInfo.containsKey(command)) { 23 | return commandToCommandInfo.get(command); 24 | } 25 | return null; 26 | } 27 | 28 | @Override 29 | public List getAllCommand(boolean isWasm, boolean isAuthOpen) { 30 | return commandToCommandInfo 31 | .keySet() 32 | .stream() 33 | .filter( 34 | key -> 35 | !(isWasm && !commandToCommandInfo.get(key).isWasmSupport() 36 | || (!isAuthOpen 37 | && commandToCommandInfo.get(key).isNeedAuthOpen()))) 38 | .collect(Collectors.toList()); 39 | } 40 | 41 | @Override 42 | public Map getAllCommandInfo(boolean isWasm) { 43 | return commandToCommandInfo; 44 | } 45 | 46 | public static final CommandInfo GET_CONTRACT_SHARD = 47 | new CommandInfo( 48 | "getContractShard", 49 | "Get a contract's belonging shard.", 50 | HelpInfo::getContractShardHelp, 51 | (consoleInitializer, params, pwd) -> 52 | consoleInitializer.getPrecompiledFace().getContractShard(params), 53 | 1, 54 | 1, 55 | false, 56 | false); 57 | 58 | public static final CommandInfo MAKE_SHARD = 59 | new CommandInfo( 60 | "makeShard", 61 | "Make a shard.", 62 | HelpInfo::makeShardHelp, 63 | (consoleInitializer, params, pwd) -> 64 | consoleInitializer.getPrecompiledFace().makeShard(params), 65 | 1, 66 | 1, 67 | false, 68 | false); 69 | 70 | public static final CommandInfo LINK_SHARD = 71 | new CommandInfo( 72 | "linkShard", 73 | "Add a contract to a shard.", 74 | HelpInfo::linkShardHelp, 75 | (consoleInitializer, params, pwd) -> 76 | consoleInitializer.getPrecompiledFace().linkShard(params), 77 | 2, 78 | 2, 79 | false, 80 | false); 81 | 82 | static { 83 | Field[] fields = ShardingCommand.class.getDeclaredFields(); 84 | for (Field field : fields) { 85 | if (field.getType().equals(CommandInfo.class)) { 86 | try { 87 | CommandInfo constantCommandInfo = (CommandInfo) field.get(null); 88 | commandToCommandInfo.put(constantCommandInfo.getCommand(), constantCommandInfo); 89 | if (constantCommandInfo.getOptionCommand() != null) { 90 | List subCommandList = constantCommandInfo.getOptionCommand(); 91 | for (String s : subCommandList) { 92 | commandToCommandInfo.put(s, constantCommandInfo); 93 | } 94 | } 95 | } catch (IllegalAccessException e) { 96 | e.printStackTrace(); 97 | } 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/console/command/completer/AccountCompleter.java: -------------------------------------------------------------------------------- 1 | package console.command.completer; 2 | 3 | import console.client.ConsoleClientImpl; 4 | import java.io.File; 5 | import java.util.List; 6 | import org.fisco.bcos.sdk.v3.client.Client; 7 | import org.fisco.bcos.sdk.v3.utils.AddressUtils; 8 | import org.jline.reader.Candidate; 9 | import org.jline.reader.LineReader; 10 | import org.jline.reader.ParsedLine; 11 | import org.jline.utils.AttributedString; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | public class AccountCompleter extends StringsCompleterIgnoreCase { 16 | private static final Logger logger = LoggerFactory.getLogger(AccountCompleter.class); 17 | private Client client; 18 | public static int defaultRecordNum = 20; 19 | private boolean showAccountPath = true; 20 | 21 | public AccountCompleter(Client client) { 22 | this.client = client; 23 | } 24 | 25 | public AccountCompleter(Client client, boolean showAccountPath) { 26 | this(client); 27 | this.showAccountPath = showAccountPath; 28 | } 29 | 30 | @Override 31 | public void complete(LineReader reader, ParsedLine commandLine, List candidates) { 32 | List accountList = ConsoleClientImpl.listAccount(client); 33 | String accountFileDir = ConsoleClientImpl.getAccountDir(client); 34 | int recordNum = 0; 35 | // list the account 36 | String prefix = "[ Account."; 37 | for (String account : accountList) { 38 | if (!AddressUtils.isValidAddress(account)) { 39 | continue; 40 | } 41 | candidates.add( 42 | new Candidate( 43 | AttributedString.stripAnsi(account), 44 | account, 45 | prefix + String.valueOf(recordNum) + " ]", 46 | null, 47 | null, 48 | null, 49 | true)); 50 | recordNum++; 51 | // list with the account path 52 | String accountPath = accountFileDir + File.separator + account + ".pem"; 53 | if (!new File(accountPath).exists()) { 54 | accountPath = accountFileDir + File.separator + account + ".p12"; 55 | } 56 | if (!new File(accountPath).exists()) { 57 | continue; 58 | } 59 | if (!showAccountPath) { 60 | continue; 61 | } 62 | candidates.add( 63 | new Candidate( 64 | AttributedString.stripAnsi(accountPath), 65 | accountPath, 66 | prefix + String.valueOf(recordNum) + " ]", 67 | null, 68 | null, 69 | null, 70 | true)); 71 | if (recordNum == defaultRecordNum) { 72 | break; 73 | } 74 | } 75 | 76 | super.complete(reader, commandLine, candidates); 77 | } 78 | 79 | public Client getClient() { 80 | return client; 81 | } 82 | 83 | public void setClient(Client client) { 84 | this.client = client; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/console/command/completer/AccountFileFormatCompleter.java: -------------------------------------------------------------------------------- 1 | package console.command.completer; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import org.jline.reader.Candidate; 6 | import org.jline.reader.LineReader; 7 | import org.jline.reader.ParsedLine; 8 | import org.jline.utils.AttributedString; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | public class AccountFileFormatCompleter extends StringsCompleterIgnoreCase { 13 | private static final Logger logger = LoggerFactory.getLogger(AccountFileFormatCompleter.class); 14 | 15 | @Override 16 | public void complete(LineReader reader, ParsedLine commandLine, List candidates) { 17 | List accountFileFormat = Arrays.asList("pem", "p12"); 18 | for (String format : accountFileFormat) { 19 | candidates.add( 20 | new Candidate( 21 | AttributedString.stripAnsi(format), 22 | format, 23 | null, 24 | null, 25 | null, 26 | null, 27 | true)); 28 | } 29 | super.complete(reader, commandLine, candidates); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/console/command/completer/ContractAddressCompleter.java: -------------------------------------------------------------------------------- 1 | package console.command.completer; 2 | 3 | import console.common.ConsoleUtils; 4 | import console.contract.utils.ContractCompiler; 5 | import java.io.File; 6 | import java.util.List; 7 | import org.fisco.bcos.sdk.v3.client.Client; 8 | import org.fisco.bcos.sdk.v3.utils.AddressUtils; 9 | import org.jline.reader.Candidate; 10 | import org.jline.reader.LineReader; 11 | import org.jline.reader.ParsedLine; 12 | import org.jline.utils.AttributedString; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | public class ContractAddressCompleter extends StringsCompleterIgnoreCase { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(ContractAddressCompleter.class); 19 | 20 | private Client client; 21 | private static int defaultRecordNum = 20; 22 | 23 | public ContractAddressCompleter(Client client) { 24 | this.client = client; 25 | } 26 | 27 | @Override 28 | public void complete(LineReader reader, ParsedLine commandLine, List candidates) { 29 | try { 30 | String buffer = reader.getBuffer().toString().trim(); 31 | String[] ss = buffer.split(" "); 32 | if (ss.length >= 2) { 33 | String contractName = ConsoleUtils.getContractName(ConsoleUtils.resolvePath(ss[1])); 34 | File contractDir = 35 | new File( 36 | ContractCompiler.COMPILED_PATH 37 | + File.separator 38 | + client.getGroup() 39 | + File.separator 40 | + contractName); 41 | if (!contractDir.exists()) { 42 | return; 43 | } 44 | File[] contractAddressFiles = contractDir.listFiles(); 45 | if (contractAddressFiles == null || contractAddressFiles.length == 0) { 46 | return; 47 | } 48 | String contractPrefix = "[ " + contractName + "."; 49 | candidates.add( 50 | new Candidate( 51 | AttributedString.stripAnsi("latest"), 52 | "latest", 53 | contractPrefix + "0 ]", 54 | null, 55 | null, 56 | null, 57 | true)); 58 | ConsoleUtils.sortFiles(contractAddressFiles); 59 | int recordNum = 0; 60 | 61 | for (File contractAddressFile : contractAddressFiles) { 62 | if (!AddressUtils.isValidAddress(contractAddressFile.getName())) { 63 | continue; 64 | } 65 | candidates.add( 66 | new Candidate( 67 | AttributedString.stripAnsi(contractAddressFile.getName()), 68 | contractAddressFile.getName(), 69 | contractPrefix + String.valueOf(recordNum + 1) + " ]", 70 | null, 71 | null, 72 | null, 73 | true)); 74 | recordNum++; 75 | if (recordNum == defaultRecordNum) { 76 | break; 77 | } 78 | } 79 | } 80 | super.complete(reader, commandLine, candidates); 81 | } catch (Exception e) { 82 | logger.debug("ContractAddressCompleter exception, error: {}", e.getMessage(), e); 83 | } 84 | } 85 | 86 | public Client getClient() { 87 | return client; 88 | } 89 | 90 | public void setClient(Client client) { 91 | this.client = client; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/console/command/completer/ContractMethodCompleter.java: -------------------------------------------------------------------------------- 1 | package console.command.completer; 2 | 3 | import console.contract.model.AbiAndBin; 4 | import console.contract.utils.ContractCompiler; 5 | import java.util.List; 6 | import org.fisco.bcos.codegen.v3.utils.CodeGenUtils; 7 | import org.fisco.bcos.sdk.v3.client.Client; 8 | import org.fisco.bcos.sdk.v3.codec.wrapper.ABIDefinition; 9 | import org.jline.reader.Candidate; 10 | import org.jline.reader.LineReader; 11 | import org.jline.reader.ParsedLine; 12 | import org.jline.utils.AttributedString; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | public class ContractMethodCompleter extends StringsCompleterIgnoreCase { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(ContractMethodCompleter.class); 19 | private Client client; 20 | 21 | public ContractMethodCompleter(Client client) { 22 | this.client = client; 23 | } 24 | 25 | @Override 26 | public void complete(LineReader reader, ParsedLine commandLine, List candidates) { 27 | 28 | String buffer = reader.getBuffer().toString().trim(); 29 | String[] ss = buffer.split(" "); 30 | 31 | if (ss.length >= 3) { 32 | String contractNameOrPath = ss[1]; 33 | String contractAddress = ss[2]; 34 | try { 35 | AbiAndBin abiAndBin = 36 | ContractCompiler.loadAbi( 37 | client.getGroup(), contractNameOrPath, contractAddress, true); 38 | List abiDefinitions = 39 | CodeGenUtils.loadContractAbiDefinition(abiAndBin.getAbi()); 40 | for (ABIDefinition definition : abiDefinitions) { 41 | String functionName = definition.getName(); 42 | if (functionName == null) continue; 43 | candidates.add( 44 | new Candidate( 45 | AttributedString.stripAnsi(functionName), 46 | functionName, 47 | null, 48 | null, 49 | null, 50 | null, 51 | true)); 52 | } 53 | } catch (Exception e) { 54 | logger.trace("e: ", e); 55 | } 56 | } 57 | super.complete(reader, commandLine, candidates); 58 | } 59 | 60 | public Client getClient() { 61 | return client; 62 | } 63 | 64 | public void setClient(Client client) { 65 | this.client = client; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/console/command/completer/CurrentPathCompleter.java: -------------------------------------------------------------------------------- 1 | package console.command.completer; 2 | 3 | import console.common.Common; 4 | import console.common.ConsoleUtils; 5 | import java.util.List; 6 | import org.fisco.bcos.sdk.v3.client.Client; 7 | import org.fisco.bcos.sdk.v3.contract.precompiled.bfs.BFSPrecompiled.BfsInfo; 8 | import org.fisco.bcos.sdk.v3.contract.precompiled.bfs.BFSService; 9 | import org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair; 10 | import org.jline.reader.Candidate; 11 | import org.jline.reader.LineReader; 12 | import org.jline.reader.ParsedLine; 13 | import org.jline.terminal.Terminal; 14 | import org.jline.utils.AttributedString; 15 | import org.jline.utils.AttributedStringBuilder; 16 | import org.jline.utils.AttributedStyle; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | public class CurrentPathCompleter extends StringsCompleterIgnoreCase { 21 | private static final Logger logger = LoggerFactory.getLogger(CurrentPathCompleter.class); 22 | 23 | private String pwd = "/apps"; 24 | private Client client; 25 | private BFSService bfsService; 26 | 27 | public CurrentPathCompleter(Client client) { 28 | this.client = client; 29 | CryptoKeyPair cryptoKeyPair = client.getCryptoSuite().getCryptoKeyPair(); 30 | this.bfsService = new BFSService(this.client, cryptoKeyPair); 31 | } 32 | 33 | public void setPwd(String absolutePath) { 34 | this.pwd = absolutePath; 35 | } 36 | 37 | protected String getDisplay(Terminal terminal, BfsInfo fileInfo) { 38 | String name = fileInfo.getFileName(); 39 | if (fileInfo.getFileType().equals(Common.BFS_TYPE_DIR)) { 40 | AttributedStringBuilder sb = new AttributedStringBuilder(); 41 | sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name); 42 | sb.append("/"); 43 | name = sb.toAnsi(terminal); 44 | } 45 | return name; 46 | } 47 | 48 | @Override 49 | public void complete(LineReader reader, ParsedLine commandLine, List candidates) { 50 | try { 51 | String buffer = commandLine.word().substring(0, commandLine.wordCursor()); 52 | String curBuf; 53 | int lastSep = buffer.lastIndexOf('/'); 54 | if (lastSep >= 0) { 55 | curBuf = buffer.substring(0, lastSep + 1); 56 | } else { 57 | curBuf = ""; 58 | } 59 | 60 | String fixedPath = pwd; 61 | 62 | if (!curBuf.isEmpty()) { 63 | fixedPath = ConsoleUtils.fixedBfsParam(curBuf, pwd); 64 | } 65 | 66 | List listResult = bfsService.list(fixedPath); 67 | for (BfsInfo bfsInfo : listResult) { 68 | String relativePath = curBuf + bfsInfo.getFileName(); 69 | if (bfsInfo.getFileType().equals(Common.BFS_TYPE_DIR)) { 70 | candidates.add( 71 | new Candidate( 72 | AttributedString.stripAnsi(relativePath + "/"), 73 | getDisplay(reader.getTerminal(), bfsInfo), 74 | null, 75 | null, 76 | null, 77 | null, 78 | false)); 79 | } else { 80 | candidates.add( 81 | new Candidate( 82 | AttributedString.stripAnsi(relativePath), 83 | getDisplay(reader.getTerminal(), bfsInfo), 84 | null, 85 | null, 86 | null, 87 | null, 88 | true)); 89 | } 90 | } 91 | super.complete(reader, commandLine, candidates); 92 | } catch (Exception e) { 93 | logger.debug("CurrentPathCompleter exception, error: {}", e.getMessage(), e); 94 | } 95 | } 96 | 97 | public void setClient(Client client) { 98 | this.client = client; 99 | this.bfsService = new BFSService(client, client.getCryptoSuite().getCryptoKeyPair()); 100 | this.pwd = "/apps"; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/console/command/completer/StringsCompleterIgnoreCase.java: -------------------------------------------------------------------------------- 1 | package console.command.completer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collection; 6 | import java.util.List; 7 | import org.jline.reader.Buffer; 8 | import org.jline.reader.Candidate; 9 | import org.jline.reader.Completer; 10 | import org.jline.reader.LineReader; 11 | import org.jline.reader.ParsedLine; 12 | import org.jline.utils.AttributedString; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | public class StringsCompleterIgnoreCase implements Completer { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(StringsCompleterIgnoreCase.class); 19 | 20 | protected final Collection candidates = new ArrayList<>(); 21 | 22 | public StringsCompleterIgnoreCase() {} 23 | 24 | public StringsCompleterIgnoreCase(String... strings) { 25 | this(Arrays.asList(strings)); 26 | } 27 | 28 | public StringsCompleterIgnoreCase(Iterable strings) { 29 | assert strings != null; 30 | for (String string : strings) { 31 | candidates.add( 32 | new Candidate( 33 | AttributedString.stripAnsi(string), 34 | string, 35 | null, 36 | null, 37 | null, 38 | null, 39 | true)); 40 | } 41 | } 42 | 43 | @Override 44 | public void complete( 45 | LineReader reader, final ParsedLine commandLine, final List candidates) { 46 | if (commandLine == null || candidates == null) { 47 | return; 48 | } 49 | 50 | Buffer buffer = reader.getBuffer(); 51 | String start = (buffer == null) ? "" : buffer.toString(); 52 | int index = start.lastIndexOf(" "); 53 | String tmp = start.substring(index + 1).toLowerCase(); 54 | 55 | for (Candidate candidate : this.candidates) { 56 | String candidateStr = candidate.value().toLowerCase(); 57 | if (candidateStr.startsWith(tmp)) { 58 | candidates.add(candidate); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/console/command/model/BasicCategoryCommand.java: -------------------------------------------------------------------------------- 1 | package console.command.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public abstract class BasicCategoryCommand { 9 | private CommandType commandType; 10 | 11 | protected BasicCategoryCommand(CommandType commandType) { 12 | this.commandType = commandType; 13 | } 14 | 15 | public abstract CommandInfo getCommandInfo(String command); 16 | 17 | public abstract List getAllCommand(boolean isWasm, boolean isAuthOpen); 18 | 19 | public abstract Map getAllCommandInfo(boolean isWasm); 20 | 21 | public void printDescInfo(boolean isWasm, boolean isAuthOpen) { 22 | List allCommand = getAllCommand(isWasm, isAuthOpen); 23 | List outputCmd = new ArrayList<>(); 24 | if (allCommand == null || allCommand.isEmpty()) return; 25 | Collections.sort(allCommand); 26 | System.out.printf( 27 | "---------------------------%s----------------------------%n", 28 | getCommandType().toString()); 29 | for (String key : allCommand) { 30 | CommandInfo commandInfo = getCommandInfo(key); 31 | if (outputCmd.contains(commandInfo.getCommand())) continue; 32 | outputCmd.add(commandInfo.getCommand()); 33 | commandInfo.printDescInfo(); 34 | } 35 | } 36 | 37 | public CommandType getCommandType() { 38 | return commandType; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/console/command/model/CommandType.java: -------------------------------------------------------------------------------- 1 | package console.command.model; 2 | 3 | public enum CommandType { 4 | BASIC_CMD, 5 | CONTRACT_OP, 6 | STATUS_QUERY, 7 | CONSENSUS_OP, 8 | CRUD_OP, 9 | BFS_OP, 10 | GROUP_QUERY, 11 | AUTH_OP, 12 | ACCOUNT_OP, 13 | COLLABORATE_OP, 14 | SHARDING_OP, 15 | BALANCE_PRECOMPILED_OP; 16 | 17 | @Override 18 | public String toString() { 19 | switch (this) { 20 | case BASIC_CMD: 21 | return "Basic Command"; 22 | case CONTRACT_OP: 23 | return "Contract Operation"; 24 | case STATUS_QUERY: 25 | return "Blockchain Status Query"; 26 | case CONSENSUS_OP: 27 | return "Consensus Operation"; 28 | case CRUD_OP: 29 | return "CRUD Contract Operation"; 30 | case BFS_OP: 31 | return "BFS Operation"; 32 | case GROUP_QUERY: 33 | return "Group Info Query"; 34 | case AUTH_OP: 35 | return "Authority Operation"; 36 | case ACCOUNT_OP: 37 | return "Account Operation"; 38 | case COLLABORATE_OP: 39 | return "Wasm Collaboration Operation"; 40 | case SHARDING_OP: 41 | return "Sharding Operation"; 42 | case BALANCE_PRECOMPILED_OP: 43 | return "Balance Precompiled Operation"; 44 | default: 45 | return "Unknown Command"; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/console/command/model/WelcomeInfo.java: -------------------------------------------------------------------------------- 1 | package console.command.model; 2 | 3 | import console.common.ConsoleUtils; 4 | import console.common.ConsoleVersion; 5 | 6 | public class WelcomeInfo { 7 | 8 | public static void welcome() { 9 | ConsoleUtils.doubleLine(); 10 | System.out.println("Welcome to FISCO BCOS console(" + ConsoleVersion.Version + ")!"); 11 | System.out.println("Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console."); 12 | String logo = 13 | " ________ ______ ______ ______ ______ _______ ______ ______ ______ \n" 14 | + "| | \\/ \\ / \\ / \\ | \\ / \\ / \\ / \\ \n" 15 | + "| $$$$$$$$\\$$$$$| $$$$$$| $$$$$$| $$$$$$\\ | $$$$$$$| $$$$$$| $$$$$$| $$$$$$\\\n" 16 | + "| $$__ | $$ | $$___\\$| $$ \\$| $$ | $$ | $$__/ $| $$ \\$| $$ | $| $$___\\$$\n" 17 | + "| $$ \\ | $$ \\$$ \\| $$ | $$ | $$ | $$ $| $$ | $$ | $$\\$$ \\ \n" 18 | + "| $$$$$ | $$ _\\$$$$$$| $$ __| $$ | $$ | $$$$$$$| $$ __| $$ | $$_\\$$$$$$\\\n" 19 | + "| $$ _| $$_| \\__| $| $$__/ | $$__/ $$ | $$__/ $| $$__/ | $$__/ $| \\__| $$\n" 20 | + "| $$ | $$ \\\\$$ $$\\$$ $$\\$$ $$ | $$ $$\\$$ $$\\$$ $$\\$$ $$\n" 21 | + " \\$$ \\$$$$$$ \\$$$$$$ \\$$$$$$ \\$$$$$$ \\$$$$$$$ \\$$$$$$ \\$$$$$$ \\$$$$$$"; 22 | System.out.println(logo); 23 | System.out.println(); 24 | ConsoleUtils.doubleLine(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/console/common/Common.java: -------------------------------------------------------------------------------- 1 | package console.common; 2 | 3 | import java.math.BigInteger; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigFeature; 8 | import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigService; 9 | 10 | public class Common { 11 | 12 | private Common() {} 13 | 14 | public static final String CONTRACT_LOG_FILE_NAME = "deploylog.txt"; 15 | 16 | // SystemConfig key 17 | public static final String TX_COUNT_LIMIT = "tx_count_limit"; 18 | public static final String TX_GAS_LIMIT = "tx_gas_limit"; 19 | public static final String TX_GAS_PRICE = "tx_gas_price"; 20 | public static final String CONSENSUS_LEADER_PERIOD = "consensus_leader_period"; 21 | public static final String COMPATIBILITY_VERSION = "compatibility_version"; 22 | public static final String AUTH_CHECK_STATUS = "auth_check_status"; 23 | 24 | public static final List SUPPORTED_SYSTEM_KEYS = 25 | new ArrayList<>( 26 | Arrays.asList( 27 | SystemConfigService.TX_COUNT_LIMIT, 28 | SystemConfigService.TX_GAS_LIMIT, 29 | SystemConfigService.TX_GAS_PRICE, 30 | SystemConfigService.CONSENSUS_PERIOD, 31 | SystemConfigService.COMPATIBILITY_VERSION, 32 | SystemConfigService.AUTH_STATUS)); 33 | 34 | static { 35 | for (SystemConfigFeature.Features feature : SystemConfigFeature.Features.values()) { 36 | SUPPORTED_SYSTEM_KEYS.add(feature.toString()); 37 | } 38 | } 39 | 40 | public static final int INVALID_RETURN_NUMBER = -100; 41 | public static final long INVALID_LONG_VALUE = Long.MAX_VALUE; 42 | 43 | public static final int QUERY_LOG_COUNT = 20; 44 | public static final int LOG_MAX_COUNT = 10000; 45 | public static final String NON_NEGATIVE_INTEGER_RANGE = "from 0 to 2147483647"; 46 | public static final String DEPLOY_LOG_INTEGER_RANGE = "from 1 to 100"; 47 | public static final String TX_GAS_LIMIT_RANGE = "must be greater than 100000"; 48 | public static final String SYS_CONFIG_RANGE = "must be greater or equal to 1"; 49 | public static final String TX_GAS_PRICE_RANGE = "must be >= 0"; 50 | public static final String AUTH_CHECK_DESC = 51 | "means whether to check auth when deploy/call contract, if value>0, check auth, otherwise not check auth."; 52 | public static final String COMPATIBILITY_VERSION_DESC = 53 | "must be in this format: 3.0.0, 3.1.0, etc. Latest version now is " 54 | + ConsoleVersion.Version; 55 | public static final String EMPTY_CONTRACT_ADDRESS = 56 | "0x0000000000000000000000000000000000000000"; 57 | // BFS common 58 | public static final String BFS_TYPE_DIR = "directory"; 59 | public static final String BFS_TYPE_CON = "contract"; 60 | public static final String BFS_TYPE_LNK = "link"; 61 | public static final BigInteger LS_DEFAULT_COUNT = BigInteger.valueOf(500); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/console/common/ConsoleVersion.java: -------------------------------------------------------------------------------- 1 | package console.common; 2 | 3 | public class ConsoleVersion { 4 | 5 | public static final String Version = "3.8.0"; 6 | 7 | public static void main(String[] args) { 8 | System.out.println("console version: " + Version); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/console/common/StatusCodeLink.java: -------------------------------------------------------------------------------- 1 | package console.common; 2 | 3 | public class StatusCodeLink { 4 | public static String jsonRPCErrorLink = 5 | "https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/api.html#json-rpc"; 6 | public static String bcosRPCErrorLink = 7 | "https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/api.html#fisco-bcos-rpc"; 8 | public static String txReceiptStatusLink = 9 | "https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/api.html#id73"; 10 | public static String precompiledServiceStatusLink = 11 | "https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/api.html#precompiled-service-api"; 12 | public static String groupManagerStatusLink = 13 | "https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/api.html#api"; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/console/contract/ConsoleContractFace.java: -------------------------------------------------------------------------------- 1 | package console.contract; 2 | 3 | import console.ConsoleInitializer; 4 | 5 | public interface ConsoleContractFace { 6 | void deploy(String[] params, String pwd) throws Exception; 7 | 8 | void call(String[] params, String pwd) throws Exception; 9 | 10 | void getDeployLog(String[] params) throws Exception; 11 | 12 | void listAbi(ConsoleInitializer consoleInitializer, String[] params, String pwd) 13 | throws Exception; 14 | 15 | void listDeployContractAddress(ConsoleInitializer consoleInitializer, String[] params) 16 | throws Exception; 17 | 18 | void transfer(ConsoleInitializer consoleInitializer, String[] params) throws Exception; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/console/contract/exceptions/CompileContractException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2020 [fisco-dev] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | package console.contract.exceptions; 16 | 17 | public class CompileContractException extends Exception { 18 | public CompileContractException(String message) { 19 | super(message); 20 | } 21 | 22 | public CompileContractException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/console/contract/model/AbiAndBin.java: -------------------------------------------------------------------------------- 1 | package console.contract.model; 2 | 3 | public class AbiAndBin { 4 | private String abi = ""; 5 | private String bin = ""; 6 | private String smBin = ""; 7 | private String devdoc = ""; 8 | 9 | public AbiAndBin() {} 10 | 11 | public AbiAndBin(String abi, String bin, String smBin, String devdoc) { 12 | this.abi = abi; 13 | this.bin = bin; 14 | this.smBin = smBin; 15 | this.devdoc = devdoc; 16 | } 17 | 18 | public String getSmBin() { 19 | return smBin; 20 | } 21 | 22 | public String getAbi() { 23 | return abi; 24 | } 25 | 26 | public void setAbi(String abi) { 27 | this.abi = abi; 28 | } 29 | 30 | public String getBin() { 31 | return bin; 32 | } 33 | 34 | public void setBin(String bin) { 35 | this.bin = bin; 36 | } 37 | 38 | public String getDevdoc() { 39 | return devdoc; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/console/exception/CompileSolidityException.java: -------------------------------------------------------------------------------- 1 | package console.exception; 2 | 3 | import java.io.IOException; 4 | 5 | public class CompileSolidityException extends IOException { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | public CompileSolidityException() { 10 | super(); 11 | } 12 | 13 | public CompileSolidityException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public CompileSolidityException(String message) { 18 | super(message); 19 | } 20 | 21 | public CompileSolidityException(Throwable cause) { 22 | super(cause); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/console/exception/ConsoleMessageException.java: -------------------------------------------------------------------------------- 1 | package console.exception; 2 | 3 | import java.io.IOException; 4 | 5 | public class ConsoleMessageException extends IOException { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | public ConsoleMessageException() { 10 | super(); 11 | } 12 | 13 | public ConsoleMessageException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public ConsoleMessageException(String message) { 18 | super(message); 19 | } 20 | 21 | public ConsoleMessageException(Throwable cause) { 22 | super(cause); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/console/precompiled/PrecompiledFace.java: -------------------------------------------------------------------------------- 1 | package console.precompiled; 2 | 3 | import console.ConsoleInitializer; 4 | 5 | public interface PrecompiledFace { 6 | // ConsensusPrecompiled 7 | void addSealer(String[] params) throws Exception; 8 | 9 | void addObserver(String[] params) throws Exception; 10 | 11 | void removeNode(String[] params) throws Exception; 12 | 13 | void setSystemConfigByKey(ConsoleInitializer consoleInitializer, String[] params) 14 | throws Exception; 15 | 16 | void createTable(String sql) throws Exception; 17 | 18 | void alterTable(String sql) throws Exception; 19 | 20 | void insert(String sql) throws Exception; 21 | 22 | void update(String sql) throws Exception; 23 | 24 | void remove(String sql) throws Exception; 25 | 26 | void select(String sql) throws Exception; 27 | 28 | void desc(String[] params) throws Exception; 29 | 30 | void setConsensusNodeWeight(String[] params) throws Exception; 31 | 32 | void changeDir(String[] params) throws Exception; 33 | 34 | void makeDir(String[] params) throws Exception; 35 | 36 | void listDir(String[] params) throws Exception; 37 | 38 | void tree(String[] params) throws Exception; 39 | 40 | void link(String[] params) throws Exception; 41 | 42 | void getContractShard(String[] params) throws Exception; 43 | 44 | void makeShard(String[] params) throws Exception; 45 | 46 | void linkShard(String[] params) throws Exception; 47 | 48 | void fixBFS(String[] params) throws Exception; 49 | 50 | void getBalance(String[] params) throws Exception; 51 | 52 | void addBalance(String[] params) throws Exception; 53 | 54 | void subBalance(String[] params) throws Exception; 55 | 56 | void transferBalance(String[] params) throws Exception; 57 | 58 | void registerBalanceGovernor(String[] params) throws Exception; 59 | 60 | void unregisterBalanceGovernor(String[] params) throws Exception; 61 | 62 | void listBalanceGovernor() throws Exception; 63 | 64 | String getPwd(); 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/console/precompiled/model/Table.java: -------------------------------------------------------------------------------- 1 | package console.precompiled.model; 2 | 3 | import java.util.List; 4 | import org.fisco.bcos.sdk.v3.contract.precompiled.crud.common.Common; 5 | 6 | public class Table { 7 | 8 | private String tableName; 9 | private String keyFieldName; 10 | private List valueFields; 11 | private String optional = ""; 12 | private Common.TableKeyOrder keyOrder = Common.TableKeyOrder.Lexicographic; 13 | 14 | public Table() {} 15 | 16 | public String getTableName() { 17 | return tableName; 18 | } 19 | 20 | public String getKeyFieldName() { 21 | return keyFieldName; 22 | } 23 | 24 | public void setKeyFieldName(String keyFieldName) { 25 | this.keyFieldName = keyFieldName; 26 | } 27 | 28 | public List getValueFields() { 29 | return valueFields; 30 | } 31 | 32 | public String getOptional() { 33 | return optional; 34 | } 35 | 36 | public void setTableName(String tableName) { 37 | this.tableName = tableName; 38 | } 39 | 40 | public void setValueFields(List valueFields) { 41 | this.valueFields = valueFields; 42 | } 43 | 44 | public void setOptional(String optional) { 45 | this.optional = optional; 46 | } 47 | 48 | public Common.TableKeyOrder getKeyOrder() { 49 | return keyOrder; 50 | } 51 | 52 | public void setKeyOrder(Common.TableKeyOrder keyOrder) { 53 | this.keyOrder = keyOrder; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/asset/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/asset/.liquid/abi_gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-gen" 3 | version = "1.0.0-rc2" 4 | authors = ["vita-dounai "] 5 | edition = "2018" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "abi-gen" 10 | path = "main.rs" 11 | 12 | [dependencies.contract] 13 | path = "../../" 14 | package = "asset" 15 | default-features = false 16 | features = ["liquid-abi-gen"] 17 | 18 | [dependencies.liquid_lang] 19 | git = "https://github.com/WeBankBlockchain/liquid" 20 | tag = "v1.0.0-rc2" 21 | package = "liquid_lang" 22 | default-features = false 23 | features = ["contract-abi-gen"] 24 | 25 | [dependencies] 26 | serde = "1.0" 27 | serde_json = "1.0" 28 | hermit-abi = "<0.1.20" 29 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/asset/.liquid/abi_gen/main.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, env}; 2 | 3 | fn main() -> Result<(), std::io::Error> { 4 | let mut abi = HashMap::new(); 5 | 6 | let contract_abi = ::generate_abi(); 7 | 8 | let mut local_abi = 9 | Vec::with_capacity(contract_abi.event_abis.len() + contract_abi.fn_abis.len() + 1); 10 | local_abi.extend( 11 | contract_abi 12 | .event_abis 13 | .iter() 14 | .map(|event_abi| liquid_lang::AbiKind::Event(event_abi.clone())), 15 | ); 16 | local_abi.push(liquid_lang::AbiKind::Constructor( 17 | contract_abi.constructor_abi, 18 | )); 19 | local_abi.extend( 20 | contract_abi 21 | .fn_abis 22 | .iter() 23 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())), 24 | ); 25 | abi.insert(String::from("$local"), local_abi); 26 | 27 | for (iface_name, fn_abis) in contract_abi.iface_abis { 28 | let fn_abis = fn_abis 29 | .iter() 30 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())) 31 | .collect::>(); 32 | abi.insert(iface_name, fn_abis); 33 | } 34 | 35 | let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".into()); 36 | std::fs::create_dir(&target_dir).ok(); 37 | std::fs::write("asset.abi", serde_json::to_string(&abi).unwrap())?; 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/asset/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "asset" 3 | version = "0.1.0" 4 | authors = ["[your_name] "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | scale = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive", "full"] } 11 | 12 | liquid_lang = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_lang", default-features = false, features = ["contract"] } 13 | liquid_primitives = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_primitives", default-features = false } 14 | liquid_prelude = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_prelude", default-features = false } 15 | liquid_macro = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_macro", default-features = false } 16 | liquid_abi_gen = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_abi_gen", default-features = false, optional = true } 17 | 18 | [dev-dependencies] 19 | predicates = "1.0.5" 20 | 21 | [lib] 22 | name = "asset" 23 | crate-type = [ 24 | # Used for normal contract Wasm blobs. 25 | "cdylib", 26 | # Used for ABI generation. 27 | "rlib", 28 | ] 29 | 30 | [features] 31 | default = ["std"] 32 | std = [ 33 | "liquid_lang/std", 34 | "scale/std", 35 | "liquid_primitives/std", 36 | "liquid_prelude/std", 37 | "liquid_macro/std", 38 | ] 39 | liquid-abi-gen = [ 40 | "std", 41 | "liquid_abi_gen", 42 | "liquid_lang/contract-abi-gen", 43 | ] 44 | gm = [ 45 | "liquid_lang/gm", 46 | "liquid_primitives/gm", 47 | ] 48 | 49 | [profile.release] 50 | panic = "abort" 51 | lto = true 52 | opt-level = "z" 53 | overflow-checks = true 54 | 55 | [workspace] 56 | members = [ 57 | ".liquid/abi_gen", 58 | ] 59 | exclude = [ 60 | ".liquid", 61 | ] 62 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/asset/asset.abi: -------------------------------------------------------------------------------- 1 | [{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int16","name":"ret_code","type":"int16"},{"indexed":true,"internalType":"string","name":"account","type":"string"},{"indexed":true,"internalType":"uint128","name":"asset_value","type":"uint128"}],"name":"RegisterEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int16","name":"ret_code","type":"int16"},{"indexed":true,"internalType":"string","name":"from","type":"string"},{"indexed":true,"internalType":"string","name":"to","type":"string"},{"indexed":false,"internalType":"uint128","name":"value","type":"uint128"}],"name":"TransferEvent","type":"event"},{"inputs":[],"type":"constructor"},{"constant":true,"inputs":[{"internalType":"string","name":"account","type":"string"}],"name":"select","outputs":[{"internalType":"bool","type":"bool"},{"internalType":"uint128","type":"uint128"}],"selector":[3252934652,2019373659],"type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"account","type":"string"},{"internalType":"uint128","name":"asset_value","type":"uint128"}],"name":"register","outputs":[{"internalType":"int16","type":"int16"}],"selector":[19451446,1364292529],"type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"from","type":"string"},{"internalType":"string","name":"to","type":"string"},{"internalType":"uint128","name":"value","type":"uint128"}],"name":"transfer","outputs":[{"internalType":"int16","type":"int16"}],"selector":[2014342384,1663670743],"type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"account","type":"string"},{"internalType":"uint128","name":"value","type":"uint128"}],"name":"update","outputs":[{"internalType":"int16","type":"int16"}],"selector":[2469104788,4193646944],"type":"function"}] -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/asset/asset.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/asset/asset.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/asset/asset_gm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/asset/asset_gm.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/.liquid/abi_gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-gen" 3 | version = "1.0.0-rc2" 4 | authors = ["vita-dounai "] 5 | edition = "2018" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "abi-gen" 10 | path = "main.rs" 11 | 12 | [dependencies.contract] 13 | path = "../../" 14 | package = "hello_world" 15 | default-features = false 16 | features = ["liquid-abi-gen"] 17 | 18 | [dependencies.liquid_lang] 19 | git = "https://github.com/WeBankBlockchain/liquid" 20 | branch = "dev" 21 | package = "liquid_lang" 22 | default-features = false 23 | features = ["contract-abi-gen"] 24 | 25 | [dependencies] 26 | serde = "1.0" 27 | serde_json = "1.0" -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/.liquid/abi_gen/main.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, env}; 2 | 3 | fn main() -> Result<(), std::io::Error> { 4 | let mut abi = HashMap::new(); 5 | 6 | let contract_abi = ::generate_abi(); 7 | 8 | let mut local_abi = 9 | Vec::with_capacity(contract_abi.event_abis.len() + contract_abi.fn_abis.len() + 1); 10 | local_abi.extend( 11 | contract_abi 12 | .event_abis 13 | .iter() 14 | .map(|event_abi| liquid_lang::AbiKind::Event(event_abi.clone())), 15 | ); 16 | local_abi.push(liquid_lang::AbiKind::Constructor( 17 | contract_abi.constructor_abi, 18 | )); 19 | local_abi.extend( 20 | contract_abi 21 | .fn_abis 22 | .iter() 23 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())), 24 | ); 25 | abi.insert(String::from("$local"), local_abi); 26 | 27 | for (iface_name, fn_abis) in contract_abi.iface_abis { 28 | let fn_abis = fn_abis 29 | .iter() 30 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())) 31 | .collect::>(); 32 | abi.insert(iface_name, fn_abis); 33 | } 34 | 35 | let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".into()); 36 | std::fs::create_dir(&target_dir).ok(); 37 | std::fs::write("hello_world.abi", serde_json::to_string(&abi).unwrap())?; 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_world" 3 | version = "0.1.0" 4 | authors = ["[your_name] "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | scale = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive", "full"] } 11 | 12 | liquid_lang = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_lang", default-features = false, features = ["contract"] } 13 | liquid_primitives = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_primitives", default-features = false } 14 | liquid_prelude = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_prelude", default-features = false } 15 | liquid_macro = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_macro", default-features = false } 16 | liquid_abi_gen = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", branch = "dev", package = "liquid_abi_gen", default-features = false, optional = true } 17 | 18 | [dev-dependencies] 19 | predicates = "1.0.5" 20 | 21 | [lib] 22 | name = "hello_world" 23 | crate-type = [ 24 | # Used for normal contract Wasm blobs. 25 | "cdylib", 26 | # Used for ABI generation. 27 | "rlib", 28 | ] 29 | 30 | [features] 31 | default = ["std"] 32 | std = [ 33 | "liquid_lang/std", 34 | "scale/std", 35 | "liquid_primitives/std", 36 | "liquid_prelude/std", 37 | "liquid_macro/std", 38 | ] 39 | liquid-abi-gen = [ 40 | "std", 41 | "liquid_abi_gen", 42 | "liquid_lang/contract-abi-gen", 43 | ] 44 | gm = [ 45 | "liquid_lang/gm", 46 | "liquid_primitives/gm", 47 | ] 48 | 49 | [profile.release] 50 | panic = "abort" 51 | lto = true 52 | opt-level = "z" 53 | overflow-checks = true 54 | 55 | [workspace] 56 | members = [ 57 | ".liquid/abi_gen", 58 | ] 59 | exclude = [ 60 | ".liquid", 61 | ] 62 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/hello_world.abi: -------------------------------------------------------------------------------- 1 | [{"inputs":[],"type":"constructor"},{"constant":true,"inputs":[],"name":"get","outputs":[{"internalType":"string","type":"string"}],"type":"function"},{"conflictFields":[{"kind":0,"path":[],"read_only":false,"slot":0}],"constant":false,"inputs":[{"internalType":"string","name":"name","type":"string"}],"name":"set","outputs":[],"type":"function"}] -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/hello_world.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/hello_world/hello_world.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/hello_world_gm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/hello_world/hello_world_gm.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/hello_world/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | 3 | use liquid::storage; 4 | use liquid_lang as liquid; 5 | 6 | #[liquid::contract] 7 | mod hello_world { 8 | use super::*; 9 | 10 | #[liquid(storage)] 11 | struct HelloWorld { 12 | name: storage::Value, 13 | } 14 | 15 | #[liquid(methods)] 16 | impl HelloWorld { 17 | pub fn new(&mut self) { 18 | self.name.initialize(String::from("Alice")); 19 | } 20 | 21 | pub fn get(&self) -> String { 22 | self.name.clone() 23 | } 24 | 25 | pub fn set(&mut self, name: String) { 26 | self.name.set(name) 27 | } 28 | } 29 | 30 | #[cfg(test)] 31 | mod tests { 32 | use super::*; 33 | 34 | #[test] 35 | fn get_works() { 36 | let contract = HelloWorld::new(); 37 | assert_eq!(contract.get(), "Alice"); 38 | } 39 | 40 | #[test] 41 | fn set_works() { 42 | let mut contract = HelloWorld::new(); 43 | 44 | let new_name = String::from("Bob"); 45 | contract.set(new_name.clone()); 46 | assert_eq!(contract.get(), "Bob"); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/.liquid/abi_gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-gen" 3 | version = "1.0.0-rc2" 4 | authors = ["vita-dounai "] 5 | edition = "2018" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "abi-gen" 10 | path = "main.rs" 11 | 12 | [dependencies.contract] 13 | path = "../../" 14 | package = "kv_table_test" 15 | default-features = false 16 | features = ["liquid-abi-gen"] 17 | 18 | [dependencies.liquid_lang] 19 | git = "https://github.com/WeBankBlockchain/liquid" 20 | tag = "v1.0.0-rc2" 21 | package = "liquid_lang" 22 | default-features = false 23 | features = ["contract-abi-gen"] 24 | 25 | [dependencies] 26 | serde = "1.0" 27 | serde_json = "1.0" 28 | hermit-abi = "<0.1.20" 29 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/.liquid/abi_gen/main.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, env}; 2 | 3 | fn main() -> Result<(), std::io::Error> { 4 | let mut abi = HashMap::new(); 5 | 6 | let contract_abi = ::generate_abi(); 7 | 8 | let mut local_abi = 9 | Vec::with_capacity(contract_abi.event_abis.len() + contract_abi.fn_abis.len() + 1); 10 | local_abi.extend( 11 | contract_abi 12 | .event_abis 13 | .iter() 14 | .map(|event_abi| liquid_lang::AbiKind::Event(event_abi.clone())), 15 | ); 16 | local_abi.push(liquid_lang::AbiKind::Constructor( 17 | contract_abi.constructor_abi, 18 | )); 19 | local_abi.extend( 20 | contract_abi 21 | .fn_abis 22 | .iter() 23 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())), 24 | ); 25 | abi.insert(String::from("$local"), local_abi); 26 | 27 | for (iface_name, fn_abis) in contract_abi.iface_abis { 28 | let fn_abis = fn_abis 29 | .iter() 30 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())) 31 | .collect::>(); 32 | abi.insert(iface_name, fn_abis); 33 | } 34 | 35 | let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".into()); 36 | std::fs::create_dir(&target_dir).ok(); 37 | std::fs::write("kv_table_test.abi", serde_json::to_string(&abi).unwrap())?; 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "kv_table_test" 3 | version = "0.1.0" 4 | authors = ["[your_name] "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | scale = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive", "full"] } 11 | 12 | liquid_lang = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_lang", default-features = false, features = ["contract"] } 13 | liquid_primitives = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_primitives", default-features = false } 14 | liquid_prelude = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_prelude", default-features = false } 15 | liquid_macro = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_macro", default-features = false } 16 | liquid_abi_gen = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_abi_gen", default-features = false, optional = true } 17 | 18 | [dev-dependencies] 19 | predicates = "1.0.5" 20 | 21 | [lib] 22 | name = "kv_table_test" 23 | crate-type = [ 24 | # Used for normal contract Wasm blobs. 25 | "cdylib", 26 | # Used for ABI generation. 27 | "rlib", 28 | ] 29 | 30 | [features] 31 | default = ["std"] 32 | std = [ 33 | "liquid_lang/std", 34 | "scale/std", 35 | "liquid_primitives/std", 36 | "liquid_prelude/std", 37 | "liquid_macro/std", 38 | ] 39 | liquid-abi-gen = [ 40 | "std", 41 | "liquid_abi_gen", 42 | "liquid_lang/contract-abi-gen", 43 | ] 44 | gm = [ 45 | "liquid_lang/gm", 46 | "liquid_primitives/gm", 47 | ] 48 | 49 | [profile.release] 50 | panic = "abort" 51 | lto = true 52 | opt-level = "z" 53 | overflow-checks = true 54 | 55 | [workspace] 56 | members = [ 57 | ".liquid/abi_gen", 58 | ] 59 | exclude = [ 60 | ".liquid", 61 | ] 62 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/kv_table_test.abi: -------------------------------------------------------------------------------- 1 | [{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int32","name":"count","type":"int32"}],"name":"SetEvent","type":"event"},{"inputs":[],"type":"constructor"},{"constant":true,"inputs":[{"internalType":"string","name":"id","type":"string"}],"name":"get","outputs":[{"internalType":"bool","type":"bool"},{"internalType":"string","type":"string"}],"selector":[1590181481,59644795],"type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"id","type":"string"},{"internalType":"string","name":"item_name","type":"string"}],"name":"set","outputs":[{"internalType":"int32","type":"int32"}],"selector":[380977897,3021748506],"type":"function"},{"constant":true,"inputs":[{"internalType":"string","name":"table_name","type":"string"}],"name":"desc","outputs":[{"internalType":"string","type":"string"},{"internalType":"string","type":"string"}],"selector":[1416432989,2899674552],"type":"function"}] -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/kv_table_test.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/kv_table_test/kv_table_test.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/kv_table_test_gm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/kv_table_test/kv_table_test_gm.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/kv_table_test/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | 3 | use liquid::storage; 4 | use liquid_lang as liquid; 5 | use liquid_lang::InOut; 6 | use liquid_prelude::{string::String, vec::Vec}; 7 | 8 | #[derive(InOut)] 9 | pub struct TableInfo { 10 | key_column: String, 11 | value_columns: Vec, 12 | } 13 | 14 | #[liquid::interface(name = auto)] 15 | mod table_manager { 16 | use super::*; 17 | 18 | extern "liquid" { 19 | fn createKVTable( 20 | &mut self, 21 | table_name: String, 22 | key: String, 23 | value_fields: String, 24 | ) -> i32; 25 | fn desc(&self, table_name: String) -> TableInfo; 26 | } 27 | } 28 | #[liquid::interface(name = auto)] 29 | mod kv_table { 30 | 31 | extern "liquid" { 32 | fn get(&self, key: String) -> (bool, String); 33 | fn set(&mut self, key: String, value: String) -> i32; 34 | } 35 | } 36 | 37 | #[liquid::contract] 38 | mod kv_table_test { 39 | use super::{kv_table::*, table_manager::*, *}; 40 | 41 | #[liquid(storage)] 42 | struct KvTableTest { 43 | table: storage::Value, 44 | tm: storage::Value, 45 | table_name: storage::Value, 46 | } 47 | 48 | #[liquid(event)] 49 | struct SetEvent { 50 | count: i32, 51 | } 52 | 53 | #[liquid(methods)] 54 | impl KvTableTest { 55 | pub fn new(&mut self) { 56 | self.table_name.initialize(String::from("t_kv_test")); 57 | self.tm 58 | .initialize(TableManager::at("/sys/table_manager".parse().unwrap())); 59 | self.tm.createKVTable( 60 | self.table_name.clone(), 61 | String::from("id"), 62 | String::from("item_name"), 63 | ); 64 | self.table 65 | .initialize(KvTable::at("/tables/t_kv_test".parse().unwrap())); 66 | } 67 | 68 | pub fn get(&self, id: String) -> (bool, String) { 69 | if let Some((ok, value)) = (*self.table).get(id) { 70 | return (ok, value); 71 | } 72 | return (false, Default::default()); 73 | } 74 | 75 | pub fn set(&mut self, id: String, item_name: String) -> i32 { 76 | let count = (*self.table).set(id, item_name).unwrap(); 77 | 78 | self.env().emit(SetEvent { 79 | count: count.clone(), 80 | }); 81 | count 82 | } 83 | 84 | pub fn desc(&self, table_name: String) -> (String, String) { 85 | let ti = self.tm.desc(table_name).unwrap(); 86 | return (ti.key_column, ti.value_columns.get(0).unwrap().clone()); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/.liquid/abi_gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-gen" 3 | version = "1.0.0-rc2" 4 | authors = ["vita-dounai "] 5 | edition = "2018" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "abi-gen" 10 | path = "main.rs" 11 | 12 | [dependencies.contract] 13 | path = "../../" 14 | package = "parallel_ok" 15 | default-features = false 16 | features = ["liquid-abi-gen"] 17 | 18 | [dependencies.liquid_lang] 19 | git = "https://github.com/WeBankBlockchain/liquid" 20 | tag = "v1.0.0-rc2" 21 | package = "liquid_lang" 22 | default-features = false 23 | features = ["contract-abi-gen"] 24 | 25 | [dependencies] 26 | serde = "1.0" 27 | serde_json = "1.0" 28 | hermit-abi = "<0.1.20" -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/.liquid/abi_gen/main.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, env}; 2 | 3 | fn main() -> Result<(), std::io::Error> { 4 | let mut abi = HashMap::new(); 5 | 6 | let contract_abi = ::generate_abi(); 7 | 8 | let mut local_abi = 9 | Vec::with_capacity(contract_abi.event_abis.len() + contract_abi.fn_abis.len() + 1); 10 | local_abi.extend( 11 | contract_abi 12 | .event_abis 13 | .iter() 14 | .map(|event_abi| liquid_lang::AbiKind::Event(event_abi.clone())), 15 | ); 16 | local_abi.push(liquid_lang::AbiKind::Constructor( 17 | contract_abi.constructor_abi, 18 | )); 19 | local_abi.extend( 20 | contract_abi 21 | .fn_abis 22 | .iter() 23 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())), 24 | ); 25 | abi.insert(String::from("$local"), local_abi); 26 | 27 | for (iface_name, fn_abis) in contract_abi.iface_abis { 28 | let fn_abis = fn_abis 29 | .iter() 30 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())) 31 | .collect::>(); 32 | abi.insert(iface_name, fn_abis); 33 | } 34 | 35 | let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".into()); 36 | std::fs::create_dir(&target_dir).ok(); 37 | std::fs::write("parallel_ok.abi", serde_json::to_string(&abi).unwrap())?; 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "parallel_ok" 3 | version = "0.1.0" 4 | authors = ["[your_name] "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | scale = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive", "full"] } 11 | 12 | liquid_lang = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_lang", default-features = false, features = ["contract"] } 13 | liquid_primitives = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_primitives", default-features = false } 14 | liquid_prelude = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_prelude", default-features = false } 15 | liquid_macro = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_macro", default-features = false } 16 | liquid_abi_gen = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_abi_gen", default-features = false, optional = true } 17 | 18 | [dev-dependencies] 19 | predicates = "1.0.5" 20 | 21 | [lib] 22 | name = "parallel_ok" 23 | crate-type = [ 24 | # Used for normal contract Wasm blobs. 25 | "cdylib", 26 | # Used for ABI generation. 27 | "rlib", 28 | ] 29 | 30 | [features] 31 | default = ["std"] 32 | std = [ 33 | "liquid_lang/std", 34 | "scale/std", 35 | "liquid_primitives/std", 36 | "liquid_prelude/std", 37 | "liquid_macro/std", 38 | ] 39 | liquid-abi-gen = [ 40 | "std", 41 | "liquid_abi_gen", 42 | "liquid_lang/contract-abi-gen", 43 | ] 44 | gm = [ 45 | "liquid_lang/gm", 46 | "liquid_primitives/gm", 47 | ] 48 | 49 | [profile.release] 50 | panic = "abort" 51 | lto = true 52 | opt-level = "z" 53 | overflow-checks = true 54 | 55 | [workspace] 56 | members = [ 57 | ".liquid/abi_gen", 58 | ] 59 | exclude = [ 60 | ".liquid", 61 | ] 62 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/parallel_ok.abi: -------------------------------------------------------------------------------- 1 | [{"inputs":[],"type":"constructor"},{"constant":true,"inputs":[{"internalType":"string","name":"name","type":"string"}],"name":"balance_of","outputs":[{"internalType":"uint128","type":"uint128"}],"selector":[1497656126,3034578282],"type":"function"},{"conflictFields":[{"kind":1,"read_only":false,"slot":0,"value":[]},{"kind":3,"read_only":false,"slot":0,"value":[0]}],"constant":false,"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint128","name":"num","type":"uint128"}],"name":"set","outputs":[],"selector":[4287653626,3303572462],"type":"function"},{"conflictFields":[{"kind":0,"read_only":false,"slot":0,"value":[]},{"kind":1,"read_only":false,"slot":0,"value":[]}],"constant":false,"inputs":[{"internalType":"string","name":"from","type":"string"},{"internalType":"string","name":"to","type":"string"},{"internalType":"uint128","name":"value","type":"uint128"}],"name":"transfer","outputs":[{"internalType":"bool","type":"bool"}],"selector":[2014342384,1663670743],"type":"function"}] -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/parallel_ok.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/parallel_ok/parallel_ok.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/parallel_ok_gm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/parallel_ok/parallel_ok_gm.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/parallel_ok/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | 3 | use liquid::storage; 4 | use liquid_lang as liquid; 5 | 6 | #[liquid::contract] 7 | mod parallel_ok { 8 | use super::*; 9 | 10 | type Balance = u128; 11 | 12 | #[liquid(storage)] 13 | struct ParallelOk { 14 | balances: storage::Mapping, 15 | } 16 | 17 | #[liquid(methods)] 18 | impl ParallelOk { 19 | pub fn new(&mut self) { 20 | self.balances.initialize(); 21 | } 22 | 23 | pub fn balance_of(&self, name: String) -> Balance { 24 | *self.balances.get(&name).unwrap_or(&0) 25 | } 26 | 27 | pub fn set(&mut self, name: String, num: Balance) { 28 | self.balances.insert(name, num); 29 | } 30 | 31 | pub fn transfer(&mut self, from: String, to: String, value: Balance) -> bool { 32 | let from_balance = self.balance_of(from.clone()); 33 | if from_balance < value { 34 | return false; 35 | } 36 | 37 | self.balances.insert(from.clone(), from_balance - value); 38 | let to_balance = self.balance_of(to.clone()); 39 | self.balances.insert(to.clone(), to_balance + value); 40 | true 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/table_test/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/table_test/.liquid/abi_gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-gen" 3 | version = "1.0.0-rc2" 4 | authors = ["vita-dounai "] 5 | edition = "2018" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "abi-gen" 10 | path = "main.rs" 11 | 12 | [dependencies.contract] 13 | path = "../../" 14 | package = "table_test" 15 | default-features = false 16 | features = ["liquid-abi-gen"] 17 | 18 | [dependencies.liquid_lang] 19 | git = "https://github.com/WeBankBlockchain/liquid" 20 | tag = "v1.0.0-rc2" 21 | package = "liquid_lang" 22 | default-features = false 23 | features = ["contract-abi-gen"] 24 | 25 | [dependencies] 26 | serde = "1.0" 27 | serde_json = "1.0" 28 | hermit-abi = "<0.1.20" -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/table_test/.liquid/abi_gen/main.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, env}; 2 | 3 | fn main() -> Result<(), std::io::Error> { 4 | let mut abi = HashMap::new(); 5 | 6 | let contract_abi = ::generate_abi(); 7 | 8 | let mut local_abi = 9 | Vec::with_capacity(contract_abi.event_abis.len() + contract_abi.fn_abis.len() + 1); 10 | local_abi.extend( 11 | contract_abi 12 | .event_abis 13 | .iter() 14 | .map(|event_abi| liquid_lang::AbiKind::Event(event_abi.clone())), 15 | ); 16 | local_abi.push(liquid_lang::AbiKind::Constructor( 17 | contract_abi.constructor_abi, 18 | )); 19 | local_abi.extend( 20 | contract_abi 21 | .fn_abis 22 | .iter() 23 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())), 24 | ); 25 | abi.insert(String::from("$local"), local_abi); 26 | 27 | for (iface_name, fn_abis) in contract_abi.iface_abis { 28 | let fn_abis = fn_abis 29 | .iter() 30 | .map(|fn_abi| liquid_lang::AbiKind::ExternalFn(fn_abi.clone())) 31 | .collect::>(); 32 | abi.insert(iface_name, fn_abis); 33 | } 34 | 35 | let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".into()); 36 | std::fs::create_dir(&target_dir).ok(); 37 | std::fs::write("table_test.abi", serde_json::to_string(&abi).unwrap())?; 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/table_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "table_test" 3 | version = "0.1.0" 4 | authors = ["[your_name] "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | scale = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive", "full"] } 11 | 12 | liquid_lang = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_lang", default-features = false, features = ["contract"] } 13 | liquid_primitives = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_primitives", default-features = false } 14 | liquid_prelude = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_prelude", default-features = false } 15 | liquid_macro = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_macro", default-features = false } 16 | liquid_abi_gen = { version = "1.0.0-rc2", git = "https://github.com/WeBankBlockchain/liquid", tag = "v1.0.0-rc2", package = "liquid_abi_gen", default-features = false, optional = true } 17 | 18 | [dev-dependencies] 19 | predicates = "1.0.5" 20 | 21 | [lib] 22 | name = "table_test" 23 | crate-type = [ 24 | # Used for normal contract Wasm blobs. 25 | "cdylib", 26 | # Used for ABI generation. 27 | "rlib", 28 | ] 29 | 30 | [features] 31 | default = ["std"] 32 | std = [ 33 | "liquid_lang/std", 34 | "scale/std", 35 | "liquid_primitives/std", 36 | "liquid_prelude/std", 37 | "liquid_macro/std", 38 | ] 39 | liquid-abi-gen = [ 40 | "std", 41 | "liquid_abi_gen", 42 | "liquid_lang/contract-abi-gen", 43 | ] 44 | gm = [ 45 | "liquid_lang/gm", 46 | "liquid_primitives/gm", 47 | ] 48 | 49 | [profile.release] 50 | panic = "abort" 51 | lto = true 52 | opt-level = "z" 53 | overflow-checks = true 54 | 55 | [workspace] 56 | members = [ 57 | ".liquid/abi_gen", 58 | ] 59 | exclude = [ 60 | ".liquid", 61 | ] 62 | -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/table_test/table_test.abi: -------------------------------------------------------------------------------- 1 | [{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int32","name":"count","type":"int32"}],"name":"InsertResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int32","name":"count","type":"int32"}],"name":"UpdateResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int32","name":"count","type":"int32"}],"name":"RemoveResult","type":"event"},{"inputs":[],"type":"constructor"},{"constant":true,"inputs":[{"internalType":"int64","name":"id_low","type":"int64"},{"internalType":"int64","name":"id_high","type":"int64"}],"name":"select","outputs":[{"internalType":"string[]","type":"string[]"}],"type":"function"},{"constant":false,"inputs":[{"internalType":"int64","name":"id","type":"int64"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"age","type":"string"}],"name":"insert","outputs":[{"internalType":"int32","type":"int32"}],"type":"function"},{"constant":false,"inputs":[{"internalType":"int64","name":"id_low","type":"int64"},{"internalType":"int64","name":"id_high","type":"int64"}],"name":"update","outputs":[{"internalType":"int32","type":"int32"}],"type":"function"},{"constant":false,"inputs":[{"internalType":"int64","name":"id_low","type":"int64"},{"internalType":"int64","name":"id_high","type":"int64"}],"name":"remove","outputs":[{"internalType":"int32","type":"int32"}],"type":"function"}] -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/table_test/table_test.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/table_test/table_test.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/liquid/table_test/table_test_gm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FISCO-BCOS/console/fc2a37b0e34b27cfb8cfad6cd4f4d18bf576dfdf/src/main/resources/contract/liquid/table_test/table_test_gm.wasm -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.4.25/BaseEvent.sol: -------------------------------------------------------------------------------- 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 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.4.25/Cast.sol: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.4.25/CastTest.sol: -------------------------------------------------------------------------------- 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 | } 41 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.4.25/Crypto.sol: -------------------------------------------------------------------------------- 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 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.4.25/EchoEvent.sol: -------------------------------------------------------------------------------- 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 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.4.25/HelloWorld.sol: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.4.25/ShaTest.sol: -------------------------------------------------------------------------------- 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 | } 42 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.5.2/BaseEvent.sol: -------------------------------------------------------------------------------- 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 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.5.2/Cast.sol: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.5.2/CastTest.sol: -------------------------------------------------------------------------------- 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 | } 41 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.5.2/Crypto.sol: -------------------------------------------------------------------------------- 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 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.5.2/EchoEvent.sol: -------------------------------------------------------------------------------- 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 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.5.2/HelloWorld.sol: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.5.2/ShaTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity ^0.5.2; 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 | } 42 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/BlobHashExample.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | contract BlobHashExample { 5 | bytes public largeData = "This is a very large data blob that needs to be hashed efficiently."; 6 | 7 | function hashData() public view returns (bytes32) { 8 | bytes32 result; 9 | assembly { 10 | result := blobhash(add(sload(largeData.slot), largeData.offset)) 11 | } 12 | return result; 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/ContractA.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | import "./StorageSlot.sol"; 5 | import "./ContractB.sol"; 6 | 7 | contract ContractA { 8 | using StorageSlot for *; 9 | 10 | StorageSlot.Int256SlotType private intSlot; 11 | constructor(int256 value){ 12 | StorageSlot.tstore(intSlot, value); 13 | } 14 | 15 | function getData() public view returns (int256) { 16 | return StorageSlot.tload(intSlot); 17 | } 18 | 19 | function callContractB() public returns (int256){ 20 | ContractB b = new ContractB(); 21 | return b.callContractA(address(this)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/ContractB.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | import "./StorageSlot.sol"; 5 | import "./ContractA.sol"; 6 | 7 | 8 | contract ContractB { 9 | 10 | function callContractA(address a) public returns (int256){ 11 | ContractA a = ContractA(a); 12 | int256 result = a.getData(); 13 | return result; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/DoubleBufferContract.sol: -------------------------------------------------------------------------------- 1 | contract DoubleBufferContract { 2 | uint[] bufferA; 3 | uint[] bufferB; 4 | 5 | modifier nonreentrant(bytes32 key) { 6 | assembly { 7 | if tload(key) {revert(0, 0)} 8 | tstore(key, 1) 9 | } 10 | _; 11 | assembly { 12 | tstore(key, 0) 13 | } 14 | } 15 | 16 | bytes32 constant A_LOCK = keccak256("a"); 17 | bytes32 constant B_LOCK = keccak256("b"); 18 | 19 | function pushA() nonreentrant(A_LOCK) public payable { 20 | bufferA.push(msg.value); 21 | } 22 | 23 | function popA() nonreentrant(A_LOCK) public { 24 | require(bufferA.length > 0); 25 | 26 | (bool success,) = msg.sender.call{value: bufferA[bufferA.length - 1]}(""); 27 | require(success); 28 | bufferA.pop(); 29 | } 30 | 31 | function pushB() nonreentrant(B_LOCK) public payable { 32 | bufferB.push(msg.value); 33 | } 34 | 35 | function popB() nonreentrant(B_LOCK) public { 36 | require(bufferB.length > 0); 37 | 38 | (bool success,) = msg.sender.call{value: bufferB[bufferB.length - 1]}(""); 39 | require(success); 40 | bufferB.pop(); 41 | } 42 | 43 | function getBufferA() public view returns (uint256[] memory) { 44 | return bufferA; 45 | } 46 | 47 | function getBufferB() public view returns (uint256[] memory) { 48 | return bufferB; 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/MainContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | import "./StorageSlot.sol"; 5 | import "./ContractA.sol"; 6 | import "./ContractB.sol"; 7 | 8 | contract MainContract { 9 | 10 | function checkAndVerifyIntValue(int256 value) public returns (bool) { 11 | ContractA a = new ContractA(value); 12 | int256 result = a.callContractB(); 13 | require(result == value, "store value not equal tload result"); 14 | return true; 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/Mcopy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | contract Mcopy { 5 | function memoryCopy() external pure returns (bytes32 x) { 6 | assembly { 7 | mstore(0x20, 0x50) // Store 0x50 at word 1 in memory 8 | mcopy(0, 0x20, 0x20) // Copies 0x50 to word 0 in memory 9 | x := mload(0) // Returns 32 bytes "0x50" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/StorageContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.10 <=0.8.26; 2 | 3 | import "./StorageSlot.sol"; 4 | 5 | contract StorageContract { 6 | using StorageSlot for *; 7 | 8 | StorageSlot.AddressSlotType private addressSlot = StorageSlot.asAddress(keccak256("address_slot")); 9 | StorageSlot.BooleanSlotType private booleanSlot = StorageSlot.asBoolean(keccak256("boolean_slot")); 10 | StorageSlot.Bytes32SlotType private bytes32Slot = StorageSlot.asBytes32(keccak256("bytes32_slot")); 11 | StorageSlot.Uint256SlotType private uint256Slot = StorageSlot.asUint256(keccak256("uint256_slot")); 12 | StorageSlot.Int256SlotType private int256Slot = StorageSlot.asInt256(keccak256("int256_slot")); 13 | 14 | function setAddress(address _value) public { 15 | require(_value != address(0), "Invalid address"); 16 | addressSlot.tstore(_value); 17 | } 18 | 19 | function getAddress() public view returns (address) { 20 | return addressSlot.tload(); 21 | } 22 | 23 | function setBytes32(bytes32 _value) public { 24 | require(_value != bytes32(0), "Invalid bytes32 value"); 25 | bytes32Slot.tstore(_value); 26 | } 27 | 28 | function getBytes32() public view returns (bytes32) { 29 | return bytes32Slot.tload(); 30 | } 31 | 32 | function setUint256(uint256 _value) public { 33 | require(_value <= type(uint256).max, "Invalid uint256 value"); 34 | uint256Slot.tstore(_value); 35 | } 36 | 37 | function getUint256() public view returns (uint256) { 38 | return uint256Slot.tload(); 39 | } 40 | 41 | function setInt256(int256 _value) public { 42 | require(_value >= type(int256).min, "Invalid int256 value"); 43 | require(_value < type(int256).max, "Invalid int256 value"); 44 | int256Slot.tstore(_value); 45 | } 46 | 47 | function getInt256() public view returns (int256) { 48 | return int256Slot.tload(); 49 | } 50 | 51 | function storeIntTest(int256 _value) public returns (int256) { 52 | require(_value >= type(int256).min, "Invalid int256 value"); 53 | require(_value < type(int256).max, "Invalid int256 value"); 54 | int256Slot.tstore(_value); 55 | 56 | return int256Slot.tload(); 57 | } 58 | 59 | function storeUintTest(uint256 _value) public returns (uint256) { 60 | require(_value <= type(uint256).max, "Invalid uint256 value"); 61 | uint256Slot.tstore(_value); 62 | return uint256Slot.tload(); 63 | } 64 | 65 | function storeBytes32Test(bytes32 _value) public returns (bytes32) { 66 | require(_value != bytes32(0), "Invalid bytes32 value"); 67 | bytes32Slot.tstore(_value); 68 | return bytes32Slot.tload(); 69 | } 70 | 71 | function storeBooleanTest(bool _value) public returns (bool) { 72 | booleanSlot.tstore(_value); 73 | return booleanSlot.tload(); 74 | } 75 | 76 | function storeAddressTest(address _value) public returns (address) { 77 | require(_value != address(0), "Invalid address"); 78 | addressSlot.tstore(_value); 79 | return addressSlot.tload(); 80 | } 81 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/StorageSlot.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | library StorageSlot { 5 | struct AddressSlot { 6 | address value; 7 | } 8 | 9 | struct BooleanSlot { 10 | bool value; 11 | } 12 | 13 | struct Bytes32Slot { 14 | bytes32 value; 15 | } 16 | 17 | struct Uint256Slot { 18 | uint256 value; 19 | } 20 | 21 | struct Int256Slot { 22 | int256 value; 23 | } 24 | 25 | struct StringSlot { 26 | string value; 27 | } 28 | 29 | struct BytesSlot { 30 | bytes value; 31 | } 32 | 33 | function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { 34 | assembly { 35 | r.slot := slot 36 | } 37 | } 38 | 39 | function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { 40 | /// @solidity memory-safe-assembly 41 | assembly { 42 | r.slot := slot 43 | } 44 | } 45 | 46 | function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { 47 | /// @solidity memory-safe-assembly 48 | assembly { 49 | r.slot := slot 50 | } 51 | } 52 | 53 | function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { 54 | /// @solidity memory-safe-assembly 55 | assembly { 56 | r.slot := slot 57 | } 58 | } 59 | 60 | function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) { 61 | /// @solidity memory-safe-assembly 62 | assembly { 63 | r.slot := slot 64 | } 65 | } 66 | 67 | function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { 68 | /// @solidity memory-safe-assembly 69 | assembly { 70 | r.slot := slot 71 | } 72 | } 73 | 74 | function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { 75 | /// @solidity memory-safe-assembly 76 | assembly { 77 | r.slot := store.slot 78 | } 79 | } 80 | 81 | function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { 82 | /// @solidity memory-safe-assembly 83 | assembly { 84 | r.slot := slot 85 | } 86 | } 87 | 88 | function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { 89 | /// @solidity memory-safe-assembly 90 | assembly { 91 | r.slot := store.slot 92 | } 93 | } 94 | 95 | type AddressSlotType is bytes32; 96 | 97 | function asAddress(bytes32 slot) internal pure returns (AddressSlotType) { 98 | return AddressSlotType.wrap(slot); 99 | } 100 | 101 | type BooleanSlotType is bytes32; 102 | 103 | function asBoolean(bytes32 slot) internal pure returns (BooleanSlotType) { 104 | return BooleanSlotType.wrap(slot); 105 | } 106 | 107 | type Bytes32SlotType is bytes32; 108 | 109 | function asBytes32(bytes32 slot) internal pure returns (Bytes32SlotType) { 110 | return Bytes32SlotType.wrap(slot); 111 | } 112 | 113 | type Uint256SlotType is bytes32; 114 | 115 | function asUint256(bytes32 slot) internal pure returns (Uint256SlotType) { 116 | return Uint256SlotType.wrap(slot); 117 | } 118 | 119 | type Int256SlotType is bytes32; 120 | 121 | function asInt256(bytes32 slot) internal pure returns (Int256SlotType) { 122 | return Int256SlotType.wrap(slot); 123 | } 124 | 125 | function tload(AddressSlotType slot) internal view returns (address value) { 126 | /// @solidity memory-safe-assembly 127 | assembly { 128 | value := tload(slot) 129 | } 130 | } 131 | 132 | function tstore(AddressSlotType slot, address value) internal { 133 | /// @solidity memory-safe-assembly 134 | assembly { 135 | tstore(slot, value) 136 | } 137 | } 138 | 139 | function tload(BooleanSlotType slot) internal view returns (bool value) { 140 | /// @solidity memory-safe-assembly 141 | assembly { 142 | value := tload(slot) 143 | } 144 | } 145 | 146 | function tstore(BooleanSlotType slot, bool value) internal { 147 | /// @solidity memory-safe-assembly 148 | assembly { 149 | tstore(slot, value) 150 | } 151 | } 152 | 153 | function tload(Bytes32SlotType slot) internal view returns (bytes32 value) { 154 | /// @solidity memory-safe-assembly 155 | assembly { 156 | value := tload(slot) 157 | } 158 | } 159 | 160 | function tstore(Bytes32SlotType slot, bytes32 value) internal { 161 | /// @solidity memory-safe-assembly 162 | assembly { 163 | tstore(slot, value) 164 | } 165 | } 166 | 167 | function tload(Uint256SlotType slot) internal view returns (uint256 value) { 168 | /// @solidity memory-safe-assembly 169 | assembly { 170 | value := tload(slot) 171 | } 172 | } 173 | 174 | function tstore(Uint256SlotType slot, uint256 value) internal { 175 | /// @solidity memory-safe-assembly 176 | assembly { 177 | tstore(slot, value) 178 | } 179 | } 180 | 181 | function tload(Int256SlotType slot) internal view returns (int256 value) { 182 | /// @solidity memory-safe-assembly 183 | assembly { 184 | value := tload(slot) 185 | } 186 | } 187 | 188 | function tstore(Int256SlotType slot, int256 value) internal { 189 | /// @solidity memory-safe-assembly 190 | assembly { 191 | tstore(slot, value) 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/TestDoubleBufferContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.8.0; 2 | 3 | import "./DoubleBufferContract.sol"; 4 | 5 | contract TestDoubleBufferContract { 6 | DoubleBufferContract public doubleBufferContract; 7 | 8 | constructor() { 9 | doubleBufferContract = new DoubleBufferContract(); 10 | } 11 | 12 | function testReentrancyA() public { 13 | doubleBufferContract.pushA{value: 1 ether}(); 14 | // 尝试再次调用pushA函数,应该被阻止 15 | doubleBufferContract.pushA{value: 1 ether}(); 16 | } 17 | 18 | function testReentrancyB() public { 19 | doubleBufferContract.pushB{value: 1 ether}(); 20 | // 尝试再次调用pushB函数,应该被阻止 21 | doubleBufferContract.pushB{value: 1 ether}(); 22 | } 23 | 24 | receive() external payable { 25 | doubleBufferContract.pushA{value: 1 ether}(); 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/0.8.26/blobBaseFee.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | contract blobBaseFee { 5 | function getBlobBaseFeeYul() external view returns (uint256 blobBaseFee) { 6 | assembly { 7 | blobBaseFee := blobbasefee() 8 | } 9 | } 10 | 11 | function getBlobBaseFeeSolidity() external view returns (uint256 blobBaseFee) { 12 | blobBaseFee = block.blobbasefee; 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/BaseEvent.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 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 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/Cast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | pragma experimental ABIEncoderV2; 5 | 6 | abstract contract Cast { 7 | function stringToS256(string memory) public virtual view returns (int256); 8 | 9 | function stringToS64(string memory) public virtual view returns (int64); 10 | 11 | function stringToU256(string memory) public virtual view returns (uint256); 12 | 13 | function stringToAddr(string memory) public virtual view returns (address); 14 | 15 | function stringToBytes32(string memory) public virtual view returns (bytes32); 16 | 17 | function s256ToString(int256) public virtual view returns (string memory); 18 | function s64ToString(int64) public virtual view returns (string memory); 19 | function u256ToString(uint256) public virtual view returns (string memory); 20 | function addrToString(address) public virtual view returns (string memory); 21 | function bytes32ToString(bytes32) public virtual view returns (string memory); 22 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/CastTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | import "./Cast.sol"; 5 | 6 | contract CastTest { 7 | Cast constant cast = Cast(address(0x100f)); 8 | 9 | function stringToS256(string memory _s) public virtual view returns (int256){ 10 | return cast.stringToS256(_s); 11 | } 12 | 13 | function stringToS64(string memory _s) public virtual view returns (int64){ 14 | return cast.stringToS64(_s); 15 | } 16 | function stringToU256(string memory _s) public virtual view returns (uint256){ 17 | return cast.stringToU256(_s); 18 | } 19 | function stringToAddr(string memory _s) public virtual view returns (address){ 20 | return cast.stringToAddr(_s); 21 | } 22 | function stringToBytes32(string memory _s) public virtual view returns (bytes32){ 23 | return cast.stringToBytes32(_s); 24 | } 25 | function s256ToString(int256 _i) public virtual view returns (string memory){ 26 | return cast.s256ToString(_i); 27 | } 28 | function s64ToString(int64 _i) public virtual view returns (string memory){ 29 | return cast.s64ToString(_i); 30 | } 31 | function u256ToString(uint256 _u) public virtual view returns (string memory){ 32 | return cast.u256ToString(_u); 33 | } 34 | function addrToString(address _a) public virtual view returns (string memory){ 35 | return cast.addrToString(_a); 36 | } 37 | function bytes32ToString(bytes32 _b) public virtual view returns (string memory){ 38 | return cast.bytes32ToString(_b); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/Crypto.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.10 <=0.8.26; 2 | 3 | pragma experimental ABIEncoderV2; 4 | 5 | abstract 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 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/DelegateCallTest.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.10 <=0.8.26; 2 | 3 | contract DelegateCallDest { 4 | int public value = 0; 5 | address public sender; 6 | address public myAddress; 7 | 8 | constructor() public { 9 | myAddress = address(this); 10 | } 11 | 12 | function add() public returns(bytes memory) { 13 | sender = msg.sender; 14 | value += 2; 15 | return "2"; 16 | } 17 | } 18 | 19 | contract DelegateCallTest { 20 | int public value = 0; 21 | address public sender; 22 | address public myAddress; 23 | uint myCodeSize; 24 | bytes32 myCodeHash; 25 | address public delegateDest; 26 | 27 | 28 | constructor() public { 29 | myAddress = address(this); 30 | delegateDest = address(new DelegateCallDest()); 31 | } 32 | 33 | function add() public returns(bytes memory) { 34 | sender = msg.sender; 35 | value += 1; 36 | return "1"; 37 | } 38 | 39 | function testFailed() public returns(bytes memory){ 40 | address addr = address(0x1001); 41 | return dCall(addr, "add()"); 42 | } 43 | 44 | function testSuccess() public returns(bytes memory){ 45 | return dCall(delegateDest, "add()"); 46 | } 47 | 48 | function dCall(address addr, string memory func) private returns(bytes memory) { 49 | bool success; 50 | bytes memory ret; 51 | (success, ret) = addr.delegatecall(abi.encodeWithSignature(func)); 52 | require(success, "delegatecall failed"); 53 | 54 | return ret; 55 | } 56 | 57 | function codesizeAt(address addr) public returns(uint){ 58 | uint len; 59 | assembly { len := extcodesize(addr) } 60 | return len; 61 | } 62 | 63 | function codehashAt(address addr) public returns(bytes32){ 64 | bytes32 codeHash; 65 | assembly { codeHash := extcodehash(addr) } 66 | return codeHash; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/EchoEvent.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 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 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/EntryWrapper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | pragma experimental ABIEncoderV2; 4 | import "./Cast.sol"; 5 | 6 | // 记录,用于select和insert 7 | struct Entry { 8 | string key; 9 | string[] fields; // 考虑2.0的Entry接口,临时Precompiled的问题,考虑加工具类接口 10 | } 11 | 12 | contract EntryWrapper { 13 | Cast constant cast = Cast(address(0x100f)); 14 | Entry entry; 15 | constructor(Entry memory _entry) public { 16 | entry = _entry; 17 | } 18 | function setEntry(Entry memory _entry) public { 19 | entry = _entry; 20 | } 21 | function getEntry() public view returns(Entry memory) { 22 | return entry; 23 | } 24 | function fieldSize() public view returns (uint256) { 25 | return entry.fields.length; 26 | } 27 | function getInt(uint256 idx) public view returns (int256) { 28 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 29 | return cast.stringToS256(entry.fields[idx]); 30 | } 31 | function getUInt(uint256 idx) public view returns (uint256) { 32 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 33 | return cast.stringToU256(entry.fields[idx]); 34 | } 35 | function getAddress(uint256 idx) public view returns (address) { 36 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 37 | return cast.stringToAddr(entry.fields[idx]); 38 | } 39 | function getBytes64(uint256 idx) public view returns (bytes1[64] memory) { 40 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 41 | return bytesToBytes64(bytes(entry.fields[idx])); 42 | } 43 | function getBytes32(uint256 idx) public view returns (bytes32) { 44 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 45 | return cast.stringToBytes32(entry.fields[idx]); 46 | } 47 | function getString(uint256 idx) public view returns (string memory) { 48 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 49 | return entry.fields[idx]; 50 | } 51 | function set(uint256 idx, int256 value) public returns(int32) { 52 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 53 | entry.fields[idx] = cast.s256ToString(value); 54 | return 0; 55 | } 56 | function set(uint256 idx, uint256 value) public returns(int32) { 57 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 58 | entry.fields[idx] = cast.u256ToString(value); 59 | return 0; 60 | } 61 | function set(uint256 idx, string memory value) public returns(int32) { 62 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 63 | entry.fields[idx] = value; 64 | return 0; 65 | } 66 | function set(uint256 idx, address value) public returns(int32) { 67 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 68 | entry.fields[idx] = cast.addrToString(value); 69 | return 0; 70 | } 71 | function set(uint256 idx, bytes32 value) public returns(int32) { 72 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 73 | entry.fields[idx] = cast.bytes32ToString(value); 74 | return 0; 75 | } 76 | function set(uint256 idx, bytes1[64] memory value) public returns(int32) { 77 | require(idx >= 0 && idx < fieldSize(), "Index out of range!"); 78 | entry.fields[idx] = string(bytes64ToBytes(value)); 79 | return 0; 80 | } 81 | function setKey(string memory value) public { 82 | entry.key = value; 83 | } 84 | function getKey() public view returns (string memory) { 85 | return entry.key; 86 | } 87 | function bytes64ToBytes(bytes1[64] memory src) private pure returns(bytes memory) { 88 | bytes memory dst = new bytes(64); 89 | for(uint32 i = 0; i < 64; i++) { 90 | dst[i] = src[i][0]; 91 | } 92 | return dst; 93 | } 94 | function bytesToBytes64(bytes memory src) private pure returns(bytes1[64] memory) { 95 | bytes1[64] memory dst; 96 | for(uint32 i = 0; i < 64; i++) { 97 | dst[i] = src[i]; 98 | } 99 | return dst; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/EventSubDemo.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | 4 | contract EventSubDemo { 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 | //---------------------------------------------------------------------------------------------------------------- 21 | 22 | 23 | //--------------------------------------------------------------------------------------------------------------- 24 | event Echo(uint256 indexed u); 25 | event Echo(int256 indexed i); 26 | event Echo(string indexed s); 27 | event Echo(uint256 indexed u, int256 indexed i, string indexed s); 28 | 29 | function echo(uint256 u, int256 i, string memory s) public returns(uint256, int256, string memory) { 30 | 31 | emit Echo(u); 32 | emit Echo(i); 33 | emit Echo(s); 34 | emit Echo(u, i ,s); 35 | 36 | return (u, i , s); 37 | } 38 | 39 | event Echo(bytes32 indexed bsn); 40 | event Echo(bytes indexed bs); 41 | event Echo(bytes32 indexed bsn, bytes indexed bs); 42 | 43 | function echo(bytes32 bsn, bytes memory bs) public returns(bytes32, bytes memory) { 44 | 45 | emit Echo(bsn); 46 | emit Echo(bs); 47 | emit Echo(bsn, bs); 48 | 49 | return (bsn, bs); 50 | } 51 | //---------------------------------------------------------------------------------------------------------------- 52 | } 53 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/HelloWorld.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.10 <=0.8.26; 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 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/KVTableTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import "./Table.sol"; 6 | 7 | contract KVTableTest { 8 | 9 | TableManager tm; 10 | KVTable table; 11 | string constant tableName = "t_kv_test"; 12 | event SetEvent(int256 count); 13 | constructor () public{ 14 | tm = TableManager(address(0x1002)); 15 | 16 | // create table 17 | tm.createKVTable(tableName, "id", "item_name"); 18 | 19 | // get table address 20 | address t_address = tm.openTable(tableName); 21 | table = KVTable(t_address); 22 | } 23 | 24 | function desc() public view returns(string memory, string memory){ 25 | TableInfo memory tf = tm.desc(tableName); 26 | return (tf.keyColumn, tf.valueColumns[0]); 27 | } 28 | 29 | function get(string memory id) public view returns (bool, string memory) { 30 | bool ok = false; 31 | string memory value; 32 | (ok, value) = table.get(id); 33 | return (ok, value); 34 | } 35 | 36 | function set(string memory id, string memory item_name) 37 | public 38 | returns (int32) 39 | { 40 | int32 result = table.set(id,item_name); 41 | emit SetEvent(result); 42 | return result; 43 | } 44 | 45 | function createKVTableTest(string memory _tableName,string memory keyName,string memory fieldName) public returns(int32){ 46 | int32 result = tm.createKVTable(_tableName, keyName, fieldName); 47 | return result; 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/ShaTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import "./Crypto.sol"; 6 | 7 | contract ShaTest{ 8 | bytes _data = "Hello, ShaTest"; 9 | Crypto crypto; 10 | 11 | constructor() public { 12 | address cryptoAddr = address(0x100a); 13 | crypto = Crypto(cryptoAddr); 14 | } 15 | 16 | function getSha256(bytes memory _memory) public returns(bytes32 result) 17 | { 18 | return sha256(_memory); 19 | } 20 | 21 | function getKeccak256(bytes memory _memory) public returns(bytes32 result) 22 | { 23 | return keccak256(_memory); 24 | } 25 | 26 | function calculateSM3(bytes memory _memory) public returns(bytes32 result) 27 | { 28 | return crypto.sm3(_memory); 29 | } 30 | 31 | function calculateKeccak256(bytes memory _memory) public returns(bytes32 result) 32 | { 33 | return crypto.keccak256Hash(_memory); 34 | } 35 | 36 | function getData() public view returns(bytes memory) 37 | { 38 | return _data; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/Table.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 该接口文件定义了FISCO BCOS v3.1.0及以前版本的接口,使用时需要将该文件放在合约目录下 3 | // 若要使用FISCO BCOS v3.2.0及以后版本的接口,请使用TableV320.sol,旧合约仍然能在新节点中使用 4 | pragma solidity >=0.6.10 <=0.8.26; 5 | pragma experimental ABIEncoderV2; 6 | 7 | // KeyOrder指定Key的排序规则,字典序和数字序,如果指定为数字序,key只能为数字 8 | // enum KeyOrder {Lexicographic, Numerical} 9 | struct TableInfo { 10 | string keyColumn; 11 | string[] valueColumns; 12 | } 13 | 14 | // 记录,用于select和insert 15 | struct Entry { 16 | string key; 17 | string[] fields; // 考虑2.0的Entry接口,临时Precompiled的问题,考虑加工具类接口 18 | } 19 | 20 | // 更新字段,用于update 21 | struct UpdateField { 22 | string columnName; 23 | // 考虑工具类 24 | string value; 25 | } 26 | 27 | // 筛选条件,大于、大于等于、小于、小于等于 28 | enum ConditionOP {GT, GE, LT, LE} 29 | struct Condition { 30 | ConditionOP op; 31 | // string field; 32 | string value; 33 | } 34 | 35 | // 数量限制 36 | struct Limit { 37 | uint32 offset; 38 | // count limit max is 500 39 | uint32 count; 40 | } 41 | 42 | // 表管理合约,是静态Precompiled,有固定的合约地址 43 | abstract contract TableManager { 44 | // 创建表,传入TableInfo 45 | function createTable(string memory path, TableInfo memory tableInfo) public virtual returns (int32); 46 | 47 | // 创建KV表,传入key和value字段名 48 | function createKVTable(string memory tableName, string memory keyField, string memory valueField) public virtual returns (int32); 49 | 50 | // 只提供给Solidity合约调用时使用 51 | function openTable(string memory path) public view virtual returns (address); 52 | 53 | // 变更表字段 54 | // 只能新增字段,不能删除字段,新增的字段默认值为空,不能与原有字段重复 55 | function appendColumns(string memory path, string[] memory newColumns) public virtual returns (int32); 56 | 57 | // 获取表信息 58 | function desc(string memory tableName) public view virtual returns (TableInfo memory); 59 | } 60 | 61 | // 表合约,是动态Precompiled,TableManager创建时指定地址 62 | abstract contract Table { 63 | // 按key查询entry 64 | function select(string memory key) public virtual view returns (Entry memory); 65 | 66 | // 按条件批量查询entry,condition为空则查询所有记录 67 | function select(Condition[] memory conditions, Limit memory limit) public virtual view returns (Entry[] memory); 68 | 69 | // 按照条件查询count数据 70 | function count(Condition[] memory conditions) public virtual view returns (uint32); 71 | 72 | // 插入数据 73 | function insert(Entry memory entry) public virtual returns (int32); 74 | 75 | // 按key更新entry 76 | function update(string memory key, UpdateField[] memory updateFields) public virtual returns (int32); 77 | 78 | // 按条件批量更新entry,condition为空则更新所有记录 79 | function update(Condition[] memory conditions, Limit memory limit, UpdateField[] memory updateFields) public virtual returns (int32); 80 | 81 | // 按key删除entry 82 | function remove(string memory key) public virtual returns (int32); 83 | // 按条件批量删除entry,condition为空则删除所有记录 84 | function remove(Condition[] memory conditions, Limit memory limit) public virtual returns (int32); 85 | } 86 | 87 | abstract contract KVTable { 88 | function get(string memory key) public view virtual returns (bool, string memory); 89 | 90 | function set(string memory key, string memory value) public virtual returns (int32); 91 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/TableTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import "./Table.sol"; 6 | 7 | contract TableTest { 8 | event CreateResult(int256 count); 9 | event InsertResult(int256 count); 10 | event UpdateResult(int256 count); 11 | event RemoveResult(int256 count); 12 | 13 | TableManager constant tm = TableManager(address(0x1002)); 14 | Table table; 15 | string constant TABLE_NAME = "t_test"; 16 | constructor () public{ 17 | // create table 18 | string[] memory columnNames = new string[](2); 19 | columnNames[0] = "name"; 20 | columnNames[1] = "age"; 21 | TableInfo memory tf = TableInfo("id", columnNames); 22 | 23 | tm.createTable(TABLE_NAME, tf); 24 | address t_address = tm.openTable(TABLE_NAME); 25 | require(t_address!=address(0x0),""); 26 | table = Table(t_address); 27 | } 28 | 29 | function select(string memory id) public view returns (string memory,string memory) 30 | { 31 | Entry memory entry = table.select(id); 32 | 33 | string memory name; 34 | string memory age; 35 | if(entry.fields.length==2){ 36 | name = entry.fields[0]; 37 | age = entry.fields[1]; 38 | } 39 | return (name,age); 40 | } 41 | 42 | function insert(string memory id,string memory name,string memory age) public returns (int32){ 43 | string[] memory columns = new string[](2); 44 | columns[0] = name; 45 | columns[1] = age; 46 | Entry memory entry = Entry(id, columns); 47 | int32 result = table.insert(entry); 48 | emit InsertResult(result); 49 | return result; 50 | } 51 | 52 | function update(string memory id, string memory name, string memory age) public returns (int32){ 53 | UpdateField[] memory updateFields = new UpdateField[](2); 54 | updateFields[0] = UpdateField("name", name); 55 | updateFields[1] = UpdateField("age", age); 56 | 57 | int32 result = table.update(id, updateFields); 58 | emit UpdateResult(result); 59 | return result; 60 | } 61 | 62 | function remove(string memory id) public returns(int32){ 63 | int32 result = table.remove(id); 64 | emit RemoveResult(result); 65 | return result; 66 | } 67 | 68 | function createTable(string memory tableName,string memory key,string[] memory fields) public returns(int256){ 69 | TableInfo memory tf = TableInfo(key, fields); 70 | int32 result = tm.createTable(tableName,tf); 71 | emit CreateResult(result); 72 | return result; 73 | } 74 | 75 | function desc() public view returns(string memory, string[] memory){ 76 | TableInfo memory ti = tm.desc(TABLE_NAME); 77 | return (ti.keyColumn,ti.valueColumns); 78 | } 79 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/TableTestV320.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.6.10 <=0.8.26; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import "./TableV320.sol"; 6 | import "./Cast.sol"; 7 | 8 | contract TableTestV320 { 9 | event CreateResult(int256 count); 10 | event InsertResult(int256 count); 11 | event UpdateResult(int256 count); 12 | event RemoveResult(int256 count); 13 | 14 | Cast constant cast = Cast(address(0x100f)); 15 | TableManager constant tm = TableManager(address(0x1002)); 16 | Table table; 17 | string constant TABLE_NAME = "t_testV320"; 18 | constructor () public { 19 | // create table 20 | string[] memory columnNames = new string[](3); 21 | columnNames[0] = "name"; 22 | columnNames[1] = "age"; 23 | columnNames[2] = "status"; 24 | TableInfo memory tf = TableInfo(KeyOrder.Numerical ,"id", columnNames); 25 | 26 | tm.createTable(TABLE_NAME, tf); 27 | address t_address = tm.openTable(TABLE_NAME); 28 | require(t_address!=address(0x0),""); 29 | table = Table(t_address); 30 | } 31 | 32 | function select(int64 id) public view returns (string memory, string memory) 33 | { 34 | Entry memory entry = table.select(cast.s64ToString(id)); 35 | string memory name; 36 | string memory age; 37 | if(entry.fields.length == 3){ 38 | name = entry.fields[0]; 39 | age = entry.fields[1]; 40 | } 41 | return (name, age); 42 | } 43 | 44 | function insert(int64 id, string memory name, string memory age) public returns (int32){ 45 | Entry memory entry = Entry(cast.s64ToString(id), new string[](3)); 46 | entry.fields[0] = name; 47 | entry.fields[1] = age; 48 | entry.fields[2] = "init"; 49 | int32 result = table.insert(entry); 50 | emit InsertResult(result); 51 | return result; 52 | } 53 | 54 | function update(int64 id, string memory name, string memory age) public returns (int32){ 55 | UpdateField[] memory updateFields = new UpdateField[](2); 56 | updateFields[0] = UpdateField("name", name); 57 | updateFields[1] = UpdateField("age", age); 58 | 59 | int32 result = table.update(cast.s64ToString(id), updateFields); 60 | emit UpdateResult(result); 61 | return result; 62 | } 63 | 64 | function remove(int64 id) public returns(int32){ 65 | int32 result = table.remove(cast.s64ToString(id)); 66 | emit RemoveResult(result); 67 | return result; 68 | } 69 | 70 | function select(int64 idLow, int64 idHigh) public view returns (string[] memory) 71 | { 72 | Limit memory limit = Limit(0, 500); 73 | Condition[] memory cond = new Condition[](2); 74 | cond[0] = Condition(ConditionOP.GT, "id", cast.s64ToString(idLow)); 75 | cond[1] = Condition(ConditionOP.LE, "id", cast.s64ToString(idHigh)); 76 | Entry[] memory entries = table.select(cond, limit); 77 | string[] memory names = new string[](entries.length); 78 | for(uint i = 0; i < names.length; i++) 79 | { 80 | names[i] = entries[i].fields[0]; 81 | } 82 | return names; 83 | } 84 | 85 | function count(int64 idLow, int64 idHigh) public view returns (uint32) 86 | { 87 | Condition[] memory cond = new Condition[](2); 88 | cond[0] = Condition(ConditionOP.GT, "id", cast.s64ToString(idLow)); 89 | cond[1] = Condition(ConditionOP.LE, "id", cast.s64ToString(idHigh)); 90 | return table.count(cond); 91 | } 92 | 93 | function update(int64 idLow, int64 idHigh) public returns (int32) 94 | { 95 | UpdateField[] memory updateFields = new UpdateField[](1); 96 | updateFields[0] = UpdateField("status", "updated"); 97 | 98 | Limit memory limit = Limit(0, 500); 99 | Condition[] memory cond = new Condition[](2); 100 | cond[0] = Condition(ConditionOP.GT, "id", cast.s64ToString(idLow)); 101 | cond[1] = Condition(ConditionOP.LE, "id", cast.s64ToString(idHigh)); 102 | return table.update(cond, limit, updateFields); 103 | } 104 | 105 | function remove(int64 idLow, int64 idHigh) public returns (int32) 106 | { 107 | Limit memory limit = Limit(0, 500); 108 | Condition[] memory cond = new Condition[](2); 109 | cond[0] = Condition(ConditionOP.GT, "id", cast.s64ToString(idLow)); 110 | cond[1] = Condition(ConditionOP.LE, "id", cast.s64ToString(idHigh)); 111 | return table.remove(cond, limit); 112 | } 113 | 114 | function createTable(string memory tableName, uint8 keyOrder, string memory key,string[] memory fields) public returns(int256){ 115 | require(keyOrder == 0 || keyOrder == 1); 116 | KeyOrder _keyOrder = KeyOrder.Lexicographic; 117 | if (keyOrder == 1) 118 | { 119 | _keyOrder = KeyOrder.Numerical; 120 | } 121 | TableInfo memory tf = TableInfo(_keyOrder, key, fields); 122 | int32 result = tm.createTable(tableName,tf); 123 | emit CreateResult(result); 124 | return result; 125 | } 126 | 127 | function desc() public view returns(string memory, string[] memory){ 128 | TableInfo memory ti = tm.descWithKeyOrder(TABLE_NAME); 129 | return (ti.keyColumn,ti.valueColumns); 130 | } 131 | } -------------------------------------------------------------------------------- /src/main/resources/contract/solidity/TableV320.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 该接口文件定义了FISCO BCOS v3.2.0及以后版本的接口,使用时需要将该文件放在合约目录下 3 | // 若要使用FISCO BCOS v3.1.0及以前版本的接口,请使用Table.sol,旧合约仍然能在新节点中使用 4 | pragma solidity >=0.6.10 <=0.8.26; 5 | pragma experimental ABIEncoderV2; 6 | import "./EntryWrapper.sol"; 7 | 8 | // KeyOrder指定Key的排序规则,字典序和数字序,如果指定为数字序,key只能为数字 9 | enum KeyOrder {Lexicographic, Numerical} 10 | struct TableInfo { 11 | KeyOrder keyOrder; 12 | string keyColumn; 13 | string[] valueColumns; 14 | } 15 | 16 | // 更新字段,用于update 17 | struct UpdateField { 18 | string columnName; 19 | // 考虑工具类 20 | string value; 21 | } 22 | 23 | // 筛选条件,大于、大于等于、小于、小于等于 24 | enum ConditionOP {GT, GE, LT, LE, EQ, NE, STARTS_WITH, ENDS_WITH, CONTAINS} 25 | struct Condition { 26 | ConditionOP op; 27 | string field; 28 | string value; 29 | } 30 | 31 | // 数量限制 32 | struct Limit { 33 | uint32 offset; 34 | // count limit max is 500 35 | uint32 count; 36 | } 37 | 38 | // 表管理合约,是静态Precompiled,有固定的合约地址 39 | abstract contract TableManager { 40 | // 创建表,传入TableInfo 41 | function createTable(string memory path, TableInfo memory tableInfo) public virtual returns (int32); 42 | 43 | // 创建KV表,传入key和value字段名 44 | function createKVTable(string memory tableName, string memory keyField, string memory valueField) public virtual returns (int32); 45 | 46 | // 只提供给Solidity合约调用时使用 47 | function openTable(string memory path) public view virtual returns (address); 48 | 49 | // 变更表字段 50 | // 只能新增字段,不能删除字段,新增的字段默认值为空,不能与原有字段重复 51 | function appendColumns(string memory path, string[] memory newColumns) public virtual returns (int32); 52 | 53 | // 获取表信息 54 | function descWithKeyOrder(string memory tableName) public view virtual returns (TableInfo memory); 55 | } 56 | 57 | // 表合约,是动态Precompiled,TableManager创建时指定地址 58 | abstract contract Table { 59 | // 按key查询entry 60 | function select(string memory key) public virtual view returns (Entry memory); 61 | 62 | // 按条件批量查询entry,condition为空则查询所有记录 63 | function select(Condition[] memory conditions, Limit memory limit) public virtual view returns (Entry[] memory); 64 | 65 | // 按照条件查询count数据 66 | function count(Condition[] memory conditions) public virtual view returns (uint32); 67 | 68 | // 插入数据 69 | function insert(Entry memory entry) public virtual returns (int32); 70 | 71 | // 按key更新entry 72 | function update(string memory key, UpdateField[] memory updateFields) public virtual returns (int32); 73 | 74 | // 按条件批量更新entry,condition为空则更新所有记录 75 | function update(Condition[] memory conditions, Limit memory limit, UpdateField[] memory updateFields) public virtual returns (int32); 76 | 77 | // 按key删除entry 78 | function remove(string memory key) public virtual returns (int32); 79 | // 按条件批量删除entry,condition为空则删除所有记录 80 | function remove(Condition[] memory conditions, Limit memory limit) public virtual returns (int32); 81 | } 82 | 83 | abstract contract KVTable { 84 | function get(string memory key) public view virtual returns (bool, string memory); 85 | 86 | function set(string memory key, string memory value) public virtual returns (int32); 87 | } -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ./log 5 | 6 | 7 | 8 | 11 | 12 | %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M -- %msg%xEx%n 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tools/console.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dirpath="$(cd "$(dirname "$0")" && pwd)" 4 | cd $dirpath 5 | 6 | LANG=zh_CN.UTF-8 7 | ############################################################################## 8 | ## 9 | ## Console start up script for UN*X 10 | ## 11 | ############################################################################## 12 | 13 | # @function: output log with red color (error log) 14 | # @param: content: error message 15 | 16 | function LOG_ERROR() 17 | { 18 | local content=${1} 19 | echo -e "\033[31m"${content}"\033[0m" 20 | } 21 | 22 | # @function: output information log 23 | # @param: content: information message 24 | function LOG_INFO() 25 | { 26 | local content=${1} 27 | echo -e "\033[32m"${content}"\033[0m" 28 | } 29 | 30 | function Usage() { 31 | LOG_INFO "Usage:start the console in non-interactive mode" 32 | LOG_INFO "./console.sh" 33 | LOG_INFO "./console.sh -h" 34 | LOG_INFO "./console.sh --version or -v" 35 | } 36 | 37 | function check_java(){ 38 | version=$(java -version 2>&1 |grep version |awk '{print $3}') 39 | len=${#version}-2 40 | version=${version:1:len} 41 | 42 | IFS='.' arr=($version) 43 | IFS=' ' 44 | if [ -z ${arr[0]} ];then 45 | LOG_ERROR "At least Java8 is required." 46 | exit 1 47 | fi 48 | if [ ${arr[0]} -eq 1 ];then 49 | if [ ${arr[1]} -lt 8 ];then 50 | LOG_ERROR "At least Java8 is required." 51 | exit 1 52 | fi 53 | elif [ ${arr[0]} -gt 8 ];then 54 | : 55 | else 56 | LOG_ERROR "At least Java8 is required." 57 | exit 1 58 | fi 59 | } 60 | 61 | if [ "${1}" == "-v" ] || [ "${1}" == "--version" ];then 62 | java -cp "apps/*:conf/:lib/*:classes/" console.common.ConsoleVersion 63 | else 64 | check_java 65 | java -cp "apps/*:conf/:lib/*:classes/:accounts/" console.NonInteractiveConsole "$@" 66 | fi 67 | -------------------------------------------------------------------------------- /tools/contract2java.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | LANG=zh_CN.UTF-8 4 | ############################################################################## 5 | ## 6 | ## Console start up script for UN*X 7 | ## 8 | ############################################################################## 9 | 10 | # @function: output log with red color (error log) 11 | # @param: content: error message 12 | function LOG_ERROR() 13 | { 14 | local content=${1} 15 | echo -e "\033[31m"${content}"\033[0m" 16 | } 17 | 18 | # @function: output information log 19 | # @param: content: information message 20 | function LOG_INFO() 21 | { 22 | local content=${1} 23 | echo -e "\033[32m"${content}"\033[0m" 24 | } 25 | 26 | 27 | function check_java(){ 28 | version=$(java -version 2>&1 |grep version |awk '{print $3}') 29 | len=${#version}-2 30 | version=${version:1:len} 31 | 32 | IFS='.' arr=($version) 33 | IFS=' ' 34 | if [ -z ${arr[0]} ];then 35 | LOG_ERROR "At least Java8 is required." 36 | exit 1 37 | fi 38 | if [ ${arr[0]} -eq 1 ];then 39 | if [ ${arr[1]} -lt 8 ];then 40 | LOG_ERROR "At least Java8 is required." 41 | exit 1 42 | fi 43 | elif [ ${arr[0]} -gt 8 ];then 44 | : 45 | else 46 | LOG_ERROR "At least Java8 is required." 47 | exit 1 48 | fi 49 | } 50 | 51 | check_java 52 | java -cp "apps/*:lib/*:conf/" console.common.ConsoleUtils $@ 53 | 54 | 55 | -------------------------------------------------------------------------------- /tools/download_console.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | package_name="console.tar.gz" 3 | solcj_name="" 4 | solcj_default_version="solcJ-0.8.11.1.jar" 5 | only_solc_flag="" 6 | default_version="3.8.0" 7 | download_version="${default_version}" 8 | solc_download_version="3.0.0" 9 | specify_console=0 10 | solc_suffix="" 11 | supported_solc_versions=(0.4 0.5 0.6 0.8) 12 | only_solc_versions=(0.4 0.5 0.6) 13 | 14 | LOG_WARN() 15 | { 16 | local content=${1} 17 | echo -e "\033[31m[WARN] ${content}\033[0m" 18 | } 19 | 20 | LOG_INFO() 21 | { 22 | local content=${1} 23 | echo -e "\033[32m[INFO] ${content}\033[0m" 24 | } 25 | 26 | help() { 27 | echo " 28 | Usage: 29 | -c Specify the downloaded console version, download the latest version of the console by default 30 | -v Download the console with specific solc version, default is 0.8, 0.4, 0.5 and 0.6 are supported 31 | -s Only download solcJ jar with specific solc version, 0.6, 0.4 and 0.5 are supported, 0.6 is recommended 32 | -h Help 33 | e.g 34 | $0 -v 0.6 35 | " 36 | 37 | exit 0 38 | } 39 | 40 | parse_params(){ 41 | while getopts "v:c:hs:" option;do 42 | case $option in 43 | v) solc_suffix="${OPTARG//[vV]/}" 44 | if ! echo "${supported_solc_versions[*]}" | grep -i "${solc_suffix}" &>/dev/null; then 45 | LOG_WARN "${solc_suffix} is not supported. Please set one of ${supported_solc_versions[*]}" 46 | exit 1; 47 | fi 48 | solcj_name="solcJ-${solc_suffix}.tar.gz" 49 | if [ "${solc_suffix}" == "0.8" ]; then solcj_name="";fi 50 | ;; 51 | c) specify_console=1 52 | download_version="${OPTARG//[vV]/}" 53 | ;; 54 | s) solc_suffix="${OPTARG//[vV]/}" 55 | if ! echo "${only_solc_versions[*]}" | grep -i "${solc_suffix}" &>/dev/null; then 56 | LOG_WARN "Download solcJ ${solc_suffix} is not supported. Please set one of ${only_solc_versions[*]}" 57 | exit 1; 58 | fi 59 | only_solc_flag="true" 60 | solcj_name="solcJ-${solc_suffix}.tar.gz" 61 | if [ "${solc_suffix}" == "0.8" ]; then solcj_name="";fi 62 | ;; 63 | h) help;; 64 | *) help;; 65 | esac 66 | done 67 | } 68 | 69 | # check params 70 | check_params() 71 | { 72 | local version=${download_version} 73 | local major_version=$(echo ${version} | awk -F'.' '{print $1}') 74 | local middle_version=$(echo ${version} | awk -F'.' '{print $2}') 75 | local minor_version=$(echo ${version} | awk -F'.' '{print $3}') 76 | if [ -z "${major_version}" ] || [ -z "${middle_version}" ] || [ -z "${minor_version}" ];then 77 | LOG_WARN "Illegal version \"${version}\", please specify a legal version number, latest version is ${default_version}" 78 | exit 1; 79 | fi 80 | } 81 | 82 | download_console(){ 83 | check_params 84 | git_download_link=https://github.com/FISCO-BCOS/console/releases/download/v${download_version}/${package_name} 85 | download_link=https://github.com/FISCO-BCOS/console/releases/v${download_version}/${package_name} 86 | 87 | if [ $(curl -IL -o /dev/null -s -w %{http_code} "${download_link}") == 200 ];then 88 | LOG_INFO "Downloading console ${download_version} from ${download_link}" 89 | curl -#LO "${download_link}" 90 | else 91 | LOG_INFO "Downloading console ${download_version} from ${git_download_link}" 92 | curl -#LO ${git_download_link} 93 | fi 94 | if [ $? -eq 0 ];then 95 | LOG_INFO "Download console successfully" 96 | else 97 | LOG_WARN "Download console failed, please switch to better network and try again!" 98 | fi 99 | tar -zxf ${package_name} && chmod +x console*/*.sh 100 | if [ $? -eq 0 ];then 101 | LOG_INFO "unzip console successfully" 102 | else 103 | LOG_WARN "unzip console failed, please try again!" 104 | fi 105 | } 106 | 107 | download_solcJ(){ 108 | check_params 109 | git_download_link=https://github.com/FISCO-BCOS/console/releases/download/v${solc_download_version}/${solcj_name} 110 | download_link=https://github.com/FISCO-BCOS/console/releases/v${solc_download_version}/${solcj_name} 111 | 112 | if [ $(curl -IL -o /dev/null -s -w %{http_code} "${download_link}") == 200 ];then 113 | LOG_INFO "Downloading solcJ ${solcj_name} from ${download_link}" 114 | curl -#LO "${download_link}" 115 | else 116 | LOG_INFO "Downloading solcJ ${solcj_name} from ${git_download_link}" 117 | curl -#LO ${git_download_link} 118 | fi 119 | if [ $? -eq 0 ];then 120 | LOG_INFO "Download solcJ successfully" 121 | else 122 | LOG_WARN "Download solcJ failed, please switch to better network and try again!" 123 | fi 124 | if [ -z ${only_solc_flag} ];then 125 | LOG_INFO "Switching SolcJ from ${solcj_default_version} to solcJ-${solc_suffix}.jar" 126 | tar -zxf ${solcj_name} && rm ./console/lib/${solcj_default_version} && mv solcJ-*.jar ./console/lib/ 127 | if [ $? -eq 0 ];then 128 | LOG_INFO "Switching solcJ successfully" 129 | else 130 | LOG_WARN "Switching solcJ failed, please try again!" 131 | fi 132 | else 133 | tar -zxf ${solcj_name} 134 | if [ $? -eq 0 ];then 135 | LOG_INFO "Unzip solcJ successfully" 136 | else 137 | LOG_WARN "Unzip solcJ failed, please try again!" 138 | fi 139 | fi 140 | } 141 | 142 | parse_params "$@" 143 | if [ -z "${only_solc_flag}" ];then 144 | download_console 145 | fi 146 | if [ -n "${solcj_name}" ];then 147 | download_solcJ 148 | fi 149 | -------------------------------------------------------------------------------- /tools/start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dirpath="$(cd "$(dirname "$0")" && pwd)" 4 | cd $dirpath 5 | 6 | LANG=zh_CN.UTF-8 7 | ############################################################################## 8 | ## 9 | ## Console start up script for UN*X 10 | ## 11 | ############################################################################## 12 | 13 | # @function: output log with red color (error log) 14 | # @param: content: error message 15 | 16 | function LOG_ERROR() 17 | { 18 | local content=${1} 19 | echo -e "\033[31m"${content}"\033[0m" 20 | } 21 | 22 | # @function: output information log 23 | # @param: content: information message 24 | function LOG_INFO() 25 | { 26 | local content=${1} 27 | echo -e "\033[32m"${content}"\033[0m" 28 | } 29 | 30 | function Usage() { 31 | LOG_INFO "Usage:start the console" 32 | LOG_INFO "./start.sh groupID" 33 | LOG_INFO "./start.sh groupID -pem pemName" 34 | LOG_INFO "./start.sh groupID -p12 p12Name" 35 | LOG_INFO "print console version:" 36 | LOG_INFO "./start.sh --version or -v" 37 | } 38 | 39 | function check_java(){ 40 | version=$(java -version 2>&1 |grep version |awk '{print $3}') 41 | len=${#version}-2 42 | version=${version:1:len} 43 | 44 | IFS='.' arr=($version) 45 | IFS=' ' 46 | if [ -z ${arr[0]} ];then 47 | LOG_ERROR "At least Java8 is required." 48 | exit 1 49 | fi 50 | if [ ${arr[0]} -eq 1 ];then 51 | if [ ${arr[1]} -lt 8 ];then 52 | LOG_ERROR "At least Java8 is required." 53 | exit 1 54 | fi 55 | elif [ ${arr[0]} -gt 8 ];then 56 | : 57 | else 58 | LOG_ERROR "At least Java8 is required." 59 | exit 1 60 | fi 61 | } 62 | if [ "${1}" == "-h" ] || [ "${1}" == "--help" ] || [ "${1}" == "help" ];then 63 | Usage 64 | elif [ "${1}" == "-v" ] || [ "${1}" == "--version" ];then 65 | java -cp "apps/*:conf/:lib/*:classes/" console.common.ConsoleVersion 66 | else 67 | check_java 68 | java -cp "apps/*:conf/:lib/*:classes/:accounts/" console.Console $@ 69 | # java -Dorg.fisco.bcos.jni.disableSsl="true" -cp "apps/*:conf/:lib/*:classes/:accounts/" console.Console $@ 70 | # Note: must put the ffi library into the -Djava.library.ffipath firstly 71 | #java -Djava.library.ffipath="dyn_libs" -Djava.library.path=. -cp "apps/*:conf/:lib/*:classes/:accounts/" console.Console $@ 72 | fi 73 | --------------------------------------------------------------------------------