├── .dockerignore ├── .githooks ├── pre-commit └── pre-push ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── Develop.yml │ ├── Features.yml │ ├── Fn.yml │ ├── Fn_Check.yml │ ├── Main.yml │ ├── Nightly.yml │ ├── Others.yml │ ├── RPCNodeTest.yml │ ├── Release.yml │ ├── WasmCat.yml │ └── WasmCatDelete.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE ├── Makefile ├── README.md ├── container ├── Dockerfile-CI-findorad ├── Dockerfile-binary-image-dev ├── Dockerfile-binary-image-release ├── Dockerfile-binary-rust-base ├── Dockerfile-cleveldb ├── Dockerfile-debug-env ├── Dockerfile-fn-musl-linux ├── Dockerfile-fn-musl-macos ├── Dockerfile-fn-musl-macos-base ├── Dockerfile-fn-musl-windows ├── Dockerfile-goleveldb ├── Dockerfile-wallet_mobile-lib_android ├── docker-entrypoint-findorad.sh ├── docker-entrypoint-wasm-js-bindings.sh └── rosetta.sh ├── docs ├── benchmarks │ ├── README.md │ ├── evm.md │ └── utxo.md ├── compile_build.md ├── contribution_guide.md ├── fn_ddev.md ├── fn_dev.md ├── recover.md └── staking │ ├── pics │ ├── delegation_flow.png │ └── staking_flow.png │ ├── user_guide.md │ ├── workflow_mermaid.md │ └── workflow_pics.md ├── rust-toolchain ├── rustfmt.toml ├── src ├── components │ ├── abciapp │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── build.rs │ │ └── src │ │ │ ├── abci │ │ │ ├── mod.rs │ │ │ ├── server │ │ │ │ ├── callback │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── utils.rs │ │ │ │ ├── mod.rs │ │ │ │ └── tx_sender.rs │ │ │ └── staking │ │ │ │ ├── mod.rs │ │ │ │ ├── test.rs │ │ │ │ └── whoami.rs │ │ │ ├── api │ │ │ ├── mod.rs │ │ │ ├── query_server │ │ │ │ ├── mod.rs │ │ │ │ └── query_api │ │ │ │ │ ├── ledger_api.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── server.rs │ │ │ │ │ └── service.rs │ │ │ └── submission_server │ │ │ │ ├── mod.rs │ │ │ │ └── submission_api.rs │ │ │ ├── bins │ │ │ ├── abcid.rs │ │ │ └── findorad.rs │ │ │ └── lib.rs │ ├── config │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ │ ├── abci │ │ │ └── mod.rs │ │ │ ├── findora │ │ │ └── mod.rs │ │ │ └── lib.rs │ ├── contracts │ │ ├── baseapp │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ ├── app.rs │ │ │ │ ├── extensions.rs │ │ │ │ ├── lib.rs │ │ │ │ ├── modules.rs │ │ │ │ ├── notify.rs │ │ │ │ └── staking.rs │ │ ├── modules │ │ │ ├── account │ │ │ │ ├── Cargo.toml │ │ │ │ ├── README.md │ │ │ │ └── src │ │ │ │ │ ├── basic.rs │ │ │ │ │ ├── impls.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── tests.rs │ │ │ ├── ethereum │ │ │ │ ├── Cargo.toml │ │ │ │ ├── README.md │ │ │ │ ├── src │ │ │ │ │ ├── basic.rs │ │ │ │ │ ├── impls.rs │ │ │ │ │ └── lib.rs │ │ │ │ └── tests │ │ │ │ │ ├── ethereum_db.rs │ │ │ │ │ └── ethereum_integration.rs │ │ │ ├── evm │ │ │ │ ├── Cargo.toml │ │ │ │ ├── README.md │ │ │ │ ├── contracts │ │ │ │ │ ├── EVMStaking.abi.json │ │ │ │ │ └── PrismXXBridge.abi.json │ │ │ │ ├── precompile │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ ├── anemoi │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ ├── benches │ │ │ │ │ │ │ └── anemoi.rs │ │ │ │ │ │ └── src │ │ │ │ │ │ │ └── lib.rs │ │ │ │ │ ├── basic │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ ├── benches │ │ │ │ │ │ │ └── sha256.rs │ │ │ │ │ │ └── src │ │ │ │ │ │ │ └── lib.rs │ │ │ │ │ ├── blake2 │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ ├── eip_152.rs │ │ │ │ │ │ │ └── lib.rs │ │ │ │ │ ├── bn128 │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ └── lib.rs │ │ │ │ │ ├── eth-pairings │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ │ └── tests.rs │ │ │ │ │ ├── frc20 │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ │ └── tests.rs │ │ │ │ │ ├── modexp │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ └── lib.rs │ │ │ │ │ ├── src │ │ │ │ │ │ └── lib.rs │ │ │ │ │ ├── testdata │ │ │ │ │ │ ├── blake2F.json │ │ │ │ │ │ ├── common_bnadd.json │ │ │ │ │ │ ├── common_bnmul.json │ │ │ │ │ │ └── common_bnpair.json │ │ │ │ │ └── utils │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ ├── macro │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ ├── src │ │ │ │ │ │ │ └── lib.rs │ │ │ │ │ │ └── tests │ │ │ │ │ │ │ └── tests.rs │ │ │ │ │ │ └── src │ │ │ │ │ │ ├── data.rs │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ └── tests.rs │ │ │ │ ├── src │ │ │ │ │ ├── basic.rs │ │ │ │ │ ├── impls.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ ├── precompile.rs │ │ │ │ │ ├── runtime │ │ │ │ │ │ ├── mod.rs │ │ │ │ │ │ ├── runner.rs │ │ │ │ │ │ └── stack.rs │ │ │ │ │ ├── system_contracts.rs │ │ │ │ │ └── utils.rs │ │ │ │ └── tests │ │ │ │ │ ├── contracts │ │ │ │ │ ├── ERC20.sol │ │ │ │ │ └── abi │ │ │ │ │ │ ├── Context.abi │ │ │ │ │ │ ├── Context.bin │ │ │ │ │ │ ├── ERC20.abi │ │ │ │ │ │ ├── ERC20.bin │ │ │ │ │ │ ├── IERC20.abi │ │ │ │ │ │ ├── IERC20.bin │ │ │ │ │ │ ├── IERC20Metadata.abi │ │ │ │ │ │ └── IERC20Metadata.bin │ │ │ │ │ ├── evm_integration.rs │ │ │ │ │ └── utils │ │ │ │ │ ├── erc20.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── solidity.rs │ │ │ ├── template │ │ │ │ ├── Cargo.toml │ │ │ │ ├── README.md │ │ │ │ ├── src │ │ │ │ │ ├── basic.rs │ │ │ │ │ └── lib.rs │ │ │ │ └── tests │ │ │ │ │ └── template_integration.rs │ │ │ └── xhub │ │ │ │ ├── Cargo.toml │ │ │ │ ├── README.md │ │ │ │ └── src │ │ │ │ ├── basic.rs │ │ │ │ ├── impls.rs │ │ │ │ └── lib.rs │ │ ├── primitives │ │ │ ├── core │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── account.rs │ │ │ │ │ ├── context.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ ├── macros.rs │ │ │ │ │ ├── module.rs │ │ │ │ │ └── transaction.rs │ │ │ ├── enterprise-web3 │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── events │ │ │ │ ├── Cargo.toml │ │ │ │ ├── event-derive │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ └── src │ │ │ │ │ │ └── lib.rs │ │ │ │ └── src │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── tests.rs │ │ │ ├── evm │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── mocks │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── rpc-core │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── eth.rs │ │ │ │ │ ├── eth_filter.rs │ │ │ │ │ ├── eth_pubsub.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ ├── net.rs │ │ │ │ │ ├── types │ │ │ │ │ ├── account_info.rs │ │ │ │ │ ├── block.rs │ │ │ │ │ ├── block_number.rs │ │ │ │ │ ├── bytes.rs │ │ │ │ │ ├── call_request.rs │ │ │ │ │ ├── filter.rs │ │ │ │ │ ├── index.rs │ │ │ │ │ ├── log.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── pubsub.rs │ │ │ │ │ ├── receipt.rs │ │ │ │ │ ├── sync.rs │ │ │ │ │ ├── transaction.rs │ │ │ │ │ ├── transaction_request.rs │ │ │ │ │ └── work.rs │ │ │ │ │ └── web3.rs │ │ │ ├── rpc-server │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── middleware.rs │ │ │ ├── storage │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── hash.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ ├── tests.rs │ │ │ │ │ └── types │ │ │ │ │ ├── double_map.rs │ │ │ │ │ ├── map.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── value.rs │ │ │ ├── traits │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── account.rs │ │ │ │ │ ├── base.rs │ │ │ │ │ ├── evm.rs │ │ │ │ │ └── lib.rs │ │ │ ├── types │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── actions │ │ │ │ │ ├── account.rs │ │ │ │ │ ├── ethereum.rs │ │ │ │ │ ├── evm.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── template.rs │ │ │ │ │ └── xhub.rs │ │ │ │ │ ├── assemble.rs │ │ │ │ │ ├── crypto.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── transaction.rs │ │ │ ├── utils │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── ecdsa.rs │ │ │ │ │ ├── hashing.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── tx.rs │ │ │ └── wasm │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ └── wasm.rs │ │ └── rpc │ │ │ ├── Cargo.toml │ │ │ ├── README.md │ │ │ └── src │ │ │ ├── eth.rs │ │ │ ├── eth_filter.rs │ │ │ ├── eth_pubsub.rs │ │ │ ├── lib.rs │ │ │ ├── net.rs │ │ │ ├── utils.rs │ │ │ └── web3.rs │ ├── finutils │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ │ ├── api │ │ │ └── mod.rs │ │ │ ├── bins │ │ │ ├── cfg_generator.rs │ │ │ ├── fn.rs │ │ │ ├── fn.yml │ │ │ ├── key_generator.rs │ │ │ └── stt │ │ │ │ ├── init │ │ │ │ ├── i_testing.rs │ │ │ │ └── mod.rs │ │ │ │ ├── mnemonic_list.const │ │ │ │ ├── stt.rs │ │ │ │ ├── td_addr_list.const │ │ │ │ └── td_addr_list.const.debug_env │ │ │ ├── common │ │ │ ├── ddev │ │ │ │ ├── README.md │ │ │ │ ├── init.rs │ │ │ │ └── mod.rs │ │ │ ├── dev │ │ │ │ ├── README.md │ │ │ │ ├── init.rs │ │ │ │ └── mod.rs │ │ │ ├── evm.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ ├── lib.rs │ │ │ └── txn_builder │ │ │ └── mod.rs │ ├── wallet_mobile │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── build.rs │ │ ├── cbindgen.toml │ │ └── src │ │ │ ├── android │ │ │ ├── constructor.rs │ │ │ ├── evm.rs │ │ │ ├── exception.rs │ │ │ ├── mod.rs │ │ │ ├── transfer.rs │ │ │ └── tx_builder.rs │ │ │ ├── ios │ │ │ ├── asset_rules.rs │ │ │ ├── evm.rs │ │ │ ├── fee.rs │ │ │ ├── free.rs │ │ │ ├── mod.rs │ │ │ ├── tx_builder.rs │ │ │ └── tx_op_builder.rs │ │ │ ├── lib.rs │ │ │ ├── rust │ │ │ ├── account.rs │ │ │ ├── crypto.rs │ │ │ ├── data_model.rs │ │ │ ├── mod.rs │ │ │ ├── tests.rs │ │ │ ├── transaction.rs │ │ │ ├── types.rs │ │ │ └── util.rs │ │ │ └── wasm │ │ │ └── mod.rs │ └── wasm │ │ ├── Cargo.toml │ │ ├── build.rs │ │ ├── conf.json │ │ ├── demo.js │ │ ├── input.json │ │ ├── src │ │ ├── wasm.rs │ │ └── wasm_data_model.rs │ │ └── test.js └── ledger │ ├── Cargo.toml │ ├── build.rs │ └── src │ ├── converter │ └── mod.rs │ ├── data_model │ ├── __trash__.rs │ ├── effects.rs │ ├── mod.rs │ └── test.rs │ ├── lib.rs │ ├── staking │ ├── cosig.rs │ ├── evm.rs │ ├── init │ │ ├── mod.rs │ │ ├── staking_config.json │ │ ├── staking_config.json.keys │ │ ├── staking_config_abci_mock.json │ │ └── staking_config_debug_env.json │ ├── mod.rs │ └── ops │ │ ├── claim.rs │ │ ├── delegation.rs │ │ ├── fra_distribution.rs │ │ ├── governance.rs │ │ ├── mint_fra.rs │ │ ├── mod.rs │ │ ├── replace_staker.rs │ │ ├── undelegation.rs │ │ ├── update_staker.rs │ │ └── update_validator.rs │ └── store │ ├── api_cache.rs │ ├── helpers.rs │ ├── mod.rs │ ├── test.rs │ └── utils.rs └── tools ├── benchutils ├── bench.sh ├── static │ ├── root.addr │ └── root.phrase └── utils.sh ├── debug_env.tar.gz ├── devnet ├── cleannodes.sh ├── clitest.sh ├── confignodes.py ├── env.sh ├── resetnodes.sh ├── snapshot.sh ├── startnodes.sh ├── status.sh └── stopnodes.sh ├── devtool ├── download_tendermint.sh ├── fmt.sh ├── fn_check.sh ├── mainnet_0_2_x_validator_id.list ├── node_init.sh ├── sample_keys.list ├── staking ├── demo.sh ├── demo_config.tar.gz └── staker_memo.example ├── systemd_services ├── abcid.service ├── install.sh └── tendermint.service ├── update_staking_cfg.sh └── update_staking_cfg_debug.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .dockerignore 2 | .DS_Store 3 | .git/objects/* 4 | .gitignore 5 | Dockerfile 6 | Jenkinsfile 7 | target 8 | hooks 9 | **/target 10 | checkpoint.toml -------------------------------------------------------------------------------- /.githooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Pre-commit hook verifying that inappropriate code will not be committed. 4 | 5 | # Colors for the terminal output 6 | RED='\033[0;31m' 7 | NC='\033[0m' # No Color 8 | 9 | # Check that Rust formatting rules are not violated. 10 | if ! cargo fmt -- --check; then 11 | echo -e "${RED}Commit error!${NC}" 12 | echo "Please format the code via 'make fmt', cannot commit unformatted code" 13 | exit 1 14 | fi 15 | -------------------------------------------------------------------------------- /.githooks/pre-push: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Pre-push hook verifying that inappropriate code will not be pushed. 4 | 5 | # Colors for the terminal output 6 | RED='\033[0;31m' 7 | NC='\033[0m' # No Color 8 | 9 | # Check that prettier formatting rules are not violated. 10 | if ! cargo fmt -- --check; then 11 | echo -e "${RED}Commit error!${NC}" 12 | echo "Please format the code via 'cargo fmt', cannot push unformatted code" 13 | exit 1 14 | fi 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: issue template_Found issue 3 | about: use this template when you find a problem 4 | --- 5 | ### Problem Description 6 | >description: 7 | 8 | >Screenshots: 9 | 10 | 11 | ### Environmental information 12 | >operating system: 13 | 14 | >service: 15 | 16 | >Code version: 17 | 18 | 19 | ### Steps to reproduce 20 | >1、 21 | 22 | >2、 23 | 24 | >3、 25 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * **make sure that you have executed all the following process and no errors occur** 2 | - [ ] make fmt 3 | - [ ] make lint 4 | - [ ] make test 5 | 6 | * **The major changes of this PR** 7 | 8 | 9 | * **The major impacts of this PR** 10 | - [ ] Impact WASM? 11 | - [ ] Impact Web3 API? 12 | - [ ] Impact mainnet data compatibility? 13 | 14 | * **Extra documentations** 15 | 16 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "cargo" 4 | directory: "/" 5 | target-branch: "develop" 6 | open-pull-requests-limit: 20 7 | schedule: 8 | interval: "daily" 9 | 10 | - package-ecosystem: "cargo" 11 | directory: "/" 12 | schedule: 13 | interval: "daily" 14 | # security update only 15 | open-pull-requests-limit: 0 -------------------------------------------------------------------------------- /.github/workflows/Fn.yml: -------------------------------------------------------------------------------- 1 | name: FN 2 | on: 3 | push: 4 | tags: 5 | - '*-fn' 6 | # branches: 7 | # - "add-fn-build" 8 | env: 9 | CARGO_TERM_COLOR: always 10 | jobs: 11 | build: 12 | strategy: 13 | matrix: 14 | platform: [scalable] 15 | runs-on: ${{ matrix.platform }} 16 | steps: 17 | - uses: actions/checkout@v2 18 | - uses: actions-rs/toolchain@v1 19 | with: 20 | toolchain: stable 21 | override: true 22 | components: rustfmt 23 | 24 | - name: Build fn for Linux 25 | shell: bash 26 | run: | 27 | make build_musl_fn_linux 28 | 29 | - name: Build environment for Macos 30 | shell: bash 31 | run: | 32 | make build_musl_fn_macos_base 33 | 34 | - name: Build fn for Macos 35 | shell: bash 36 | run: | 37 | make build_musl_fn_macos 38 | 39 | # - name: Build fn for Windows 40 | # shell: bash 41 | # run: | 42 | # make build_musl_fn_win 43 | 44 | - name: Create release 45 | uses: "marvinpinto/action-automatic-releases@latest" 46 | with: 47 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 48 | prerelease: true 49 | files: | 50 | fn_linux.tar.gz 51 | fn_macos.tar.gz 52 | # fn_windows.tar.gz 53 | -------------------------------------------------------------------------------- /.github/workflows/Fn_Check.yml: -------------------------------------------------------------------------------- 1 | name: FN_CHECK 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - add-fn-ckeck 7 | pull_request: 8 | branches: 9 | - main 10 | env: 11 | CARGO_TERM_COLOR: always 12 | jobs: 13 | build: 14 | strategy: 15 | matrix: 16 | platform: [scalable] 17 | runs-on: ${{ matrix.platform }} 18 | steps: 19 | - uses: actions/checkout@v3 20 | - uses: actions-rs/toolchain@v1 21 | with: 22 | toolchain: stable 23 | override: true 24 | components: rustfmt 25 | - name: Prepare key 26 | shell: bash 27 | run: | 28 | tar -C ~/.ssh -zcf key.tar.gz ./ 29 | 30 | - name: Build rust base image 31 | shell: bash 32 | run: | 33 | make ci_build_binary_rust_base 34 | 35 | - name: Build debug_env image and Start 36 | shell: bash 37 | run: | 38 | docker build -t findorad:debug_env -f container/Dockerfile-debug-env . 39 | docker rm -f findorad-debug-env || true 40 | docker run -d --rm --network host --name findorad-debug-env findorad:debug_env 41 | sleep 120 42 | 43 | - name: Run fn_check 44 | shell: bash 45 | run: | 46 | docker exec findorad-debug-env /platform/tools/fn_check.sh 47 | docker rm -f findorad-debug-env 48 | -------------------------------------------------------------------------------- /.github/workflows/Others.yml: -------------------------------------------------------------------------------- 1 | name: Others 2 | on: 3 | push: 4 | tags: 5 | - 'test-ci' 6 | env: 7 | CARGO_TERM_COLOR: always 8 | jobs: 9 | build: 10 | strategy: 11 | matrix: 12 | platform: [scalable] 13 | runs-on: ${{ matrix.platform }} 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions-rs/toolchain@v1 17 | with: 18 | toolchain: nightly-2021-03-24 19 | override: true 20 | components: rustfmt 21 | #- name: check fmt 22 | # shell: bash 23 | # run: | 24 | # cargo fmt -- --check 25 | # - name: get env 26 | # env: 27 | # DBG: true 28 | # GITHUB_CONTEXT: ${{ toJSON(github) }} 29 | # shell: bash 30 | # run: | 31 | # PR=$(echo ${GITHUB_REF} | cut -d "/" -f 3) 32 | # BRANCH="${GITHUB_HEAD_REF}" 33 | # TOBRANCH="${GITHUB_BASE_REF}" 34 | # REF=${GITHUB_REF} 35 | # COMMIT_HASH=$(echo ${GITHUB_CONTEXT} | jq '.event.pull_request.head.sha') 36 | # if [ "${COMMIT_HASH}" == "null" ]; then 37 | # COMMIT_HASH="${GITHUB_SHA::7}" 38 | # else 39 | # COMMIT_HASH=${COMMIT_HASH:1:7} 40 | # fi 41 | # echo "GITHUB_SHA: ${GITHUB_SHA}" 42 | # echo "PR: ${PR}" 43 | # echo "BRANCH: ${BRANCH}" 44 | # echo "TOBRANCH: ${TOBRANCH}" 45 | # echo "REF: ${REF}" 46 | # echo "TOBRANCH: ${TOBRANCH}" 47 | # echo "COMMIT_HASH: ${COMMIT_HASH}" 48 | - name: Clean garbage 49 | shell: bash 50 | run: | 51 | rm -rf /tmp/*>/dev/null 2>&1 || true 52 | -------------------------------------------------------------------------------- /.github/workflows/WasmCatDelete.yml: -------------------------------------------------------------------------------- 1 | name: Wasm Delete Destination Branch 2 | # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#delete-event-delete 3 | # delete event will only be triggered by default branch contains this action 4 | on: delete 5 | 6 | jobs: 7 | delete: 8 | runs-on: ubuntu-latest 9 | # check again this is a delete branch event 10 | if: github.event.ref_type == 'branch' 11 | steps: 12 | - name: Delete wasm-js-bindings branch 13 | run: | 14 | set -x 15 | workspace=$(mktemp -d) 16 | cd $workspace 17 | 18 | git config --global user.email "wasmcat-bot@users.noreply.github.com" 19 | git config --global user.name "wasmcat-bot" 20 | 21 | # clone the main branch 22 | git clone --depth 1 https://${{secrets.ACCESS_TOKEN}}@github.com/FindoraNetwork/wasm-js-bindings 23 | cd wasm-js-bindings 24 | 25 | # check target branch exists then we delete it 26 | if git ls-remote --heads --exit-code origin ${{ github.event.ref }}; then 27 | git push -d origin ${{ github.event.ref }} 28 | fi 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | debug/ 2 | release/ 3 | binary/ 4 | 5 | target/ 6 | target 7 | 8 | **/*.rs.bk 9 | .DS_Store 10 | **/*~ 11 | **/.vscode 12 | .*.sw* 13 | .stack-work 14 | stack.yaml.lock 15 | **/history.txt 16 | **/__pycache__ 17 | .idea 18 | 19 | node_modules 20 | package-lock.json 21 | 22 | Cargo.lock 23 | *.tar.gz 24 | nohup.out 25 | 26 | *.keys 27 | 28 | tools/tendermint 29 | tools/tendermint.zip 30 | seq_id.str 31 | utxo.map 32 | checkpoint.toml 33 | 34 | *.tmp 35 | 36 | checkpoint* 37 | proof_tree 38 | proof_tree.1 39 | 40 | wallet_mobile_ffi.h 41 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "src/ledger", 4 | "src/components/finutils", 5 | "src/components/abciapp", 6 | "src/components/config", 7 | "src/components/wasm", 8 | "src/components/wallet_mobile", 9 | "src/components/contracts/baseapp", 10 | "src/components/contracts/modules/account", 11 | "src/components/contracts/modules/ethereum", 12 | "src/components/contracts/modules/evm", 13 | "src/components/contracts/modules/evm/precompile/basic", 14 | "src/components/contracts/modules/evm/precompile/frc20", 15 | "src/components/contracts/modules/evm/precompile/modexp", 16 | "src/components/contracts/modules/evm/precompile/anemoi", 17 | "src/components/contracts/modules/evm/precompile/blake2", 18 | "src/components/contracts/modules/evm/precompile/bn128", 19 | "src/components/contracts/modules/evm/precompile/utils", 20 | "src/components/contracts/modules/evm/precompile/utils/macro", 21 | "src/components/contracts/modules/xhub", 22 | "src/components/contracts/modules/template", 23 | "src/components/contracts/primitives/core", 24 | "src/components/contracts/primitives/events", 25 | "src/components/contracts/primitives/evm", 26 | "src/components/contracts/primitives/mocks", 27 | "src/components/contracts/primitives/storage", 28 | "src/components/contracts/primitives/traits", 29 | "src/components/contracts/primitives/types", 30 | "src/components/contracts/primitives/rpc-core", 31 | "src/components/contracts/primitives/rpc-server", 32 | "src/components/contracts/primitives/utils", 33 | "src/components/contracts/primitives/wasm", 34 | "src/components/contracts/primitives/enterprise-web3", 35 | "src/components/contracts/rpc", 36 | ] 37 | 38 | [profile.dev] 39 | opt-level = 3 40 | lto = "thin" 41 | incremental = true 42 | debug-assertions = true 43 | debug = true 44 | panic = 'abort' 45 | overflow-checks = true 46 | 47 | [profile.release] 48 | opt-level = 3 49 | lto = "thin" 50 | incremental = false 51 | overflow-checks = true 52 | panic = 'abort' 53 | 54 | [profile.bench] 55 | opt-level = 3 56 | debug = false 57 | rpath = false 58 | lto = "thin" 59 | codegen-units = 1 60 | incremental = true 61 | debug-assertions = false 62 | overflow-checks = false 63 | 64 | [profile.test] 65 | opt-level = 2 66 | lto = "off" 67 | incremental = true 68 | debug-assertions = true 69 | debug = true -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![GitHub top language](https://img.shields.io/github/languages/top/FindoraNetwork/platform) 2 | [![Minimum rustc version](https://img.shields.io/badge/rustc-1.63+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) 3 | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/FindoraNetwork/platform/Main.yml?branch=main) 4 | ![Docker Pulls](https://img.shields.io/docker/pulls/findoranetwork/findorad) 5 | ![GitHub issues](https://img.shields.io/github/issues-raw/FindoraNetwork/platform) 6 | ![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/FindoraNetwork/platform) 7 | 8 | # Findora Platform 9 | 10 | - [**Wiki**](https://wiki.findora.org/) 11 | - [**Change log**](CHANGELOG.md) 12 | - [**Benchmarks**](docs/benchmarks) 13 | - [**EVM Benchmarks**](docs/benchmarks/evm.md) 14 | - [**UTXO Benchmarks**](docs/benchmarks/utxo.md) 15 | - ... 16 | 17 | Thanks to all the people who already contributed! 18 | 19 | 20 | 21 | 22 | 23 | ### Licensing 24 | 25 | The primary license for Platform is the Business Source License 1.1 (`BUSL-1.1`), see [`LICENSE`](./LICENSE). 26 | 27 | ### Exceptions 28 | 29 | - All files in `components/contracts` are licensed under `Apache-2.0` 30 | 31 | 32 | -------------------------------------------------------------------------------- /container/Dockerfile-CI-findorad: -------------------------------------------------------------------------------- 1 | FROM debian:11.0-slim 2 | RUN apt update && apt install libssl1.1 && apt install -y libleveldb-dev=1.22-3 && rm -rf /var/lib/apt/lists/* 3 | RUN ln -s /usr/lib/x86_64-linux-gnu/libleveldb.so.1.22.0 /usr/lib/x86_64-linux-gnu/libleveldb.so.1 4 | COPY release/bin/findorad /usr/local/sbin/findorad 5 | COPY container/docker-entrypoint-findorad.sh /docker-entrypoint.sh 6 | WORKDIR / 7 | ENTRYPOINT ["/docker-entrypoint.sh"] 8 | -------------------------------------------------------------------------------- /container/Dockerfile-binary-image-dev: -------------------------------------------------------------------------------- 1 | FROM binary-rust-base 2 | ENV WORK_DIR /platform 3 | ENV WASM_DIR /tmp/wasm-js-bindings 4 | ENV VERGEN_SHA_EXTERN dev_build 5 | ENV PATH=$PATH:/root/.cargo/bin/ 6 | 7 | COPY . $WORK_DIR 8 | WORKDIR $WORK_DIR 9 | 10 | RUN rustup toolchain install stable && \ 11 | rustup component add clippy --toolchain stable && \ 12 | rustup component add rustfmt --toolchain stable 13 | 14 | RUN mkdir /binary 15 | RUN mkdir -p /binary/cleveldb && mkdir -p /binary/goleveldb 16 | 17 | RUN make fmt 18 | RUN make lint 19 | RUN make test 20 | 21 | RUN mkdir -p /root/.cargo/bin/ && \ 22 | DBG=true make build_release && \ 23 | if [ -d /platform/release/bin ] ; then mv /platform/release/bin/* /binary/cleveldb ; rm -rf /platform/release/; else mv /platform/debug/bin/* /binary/cleveldb ; rm -rf /platform/debug/ ;fi 24 | 25 | RUN mkdir -p /root/.cargo/bin/ && \ 26 | DBG=true make build_release_debug && \ 27 | if [ -d /platform/release/bin ] ; then mv /platform/release/bin/* /binary/goleveldb ; rm -rf /platform/release/; else mv /platform/debug/bin/* /binary/goleveldb ; rm -rf /platform/debug/ ;fi 28 | 29 | # Rosetta 30 | ENV GOLANG_VERSION 1.16.8 31 | ENV GOLANG_DOWNLOAD_SHA256 f32501aeb8b7b723bc7215f6c373abb6981bbc7e1c7b44e9f07317e1a300dce2 32 | ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz 33 | 34 | RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ 35 | && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ 36 | && tar -C /usr/local -xzf golang.tar.gz \ 37 | && rm golang.tar.gz 38 | 39 | ENV GOPATH /go 40 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 41 | RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" 42 | 43 | RUN update-ca-certificates 44 | 45 | RUN git clone https://github.com/FindoraNetwork/findora-rosetta.git \ 46 | && cd findora-rosetta \ 47 | && go get \ 48 | && go build \ 49 | && cp findora-rosetta /binary/ 50 | 51 | CMD ["sleep", "999999"] 52 | -------------------------------------------------------------------------------- /container/Dockerfile-binary-image-release: -------------------------------------------------------------------------------- 1 | FROM binary-rust-base 2 | ENV WORK_DIR /platform 3 | ENV WASM_DIR /tmp/wasm-js-bindings 4 | ENV VERGEN_SHA_EXTERN release_build 5 | ENV PATH=$PATH:/root/.cargo/bin/ 6 | 7 | COPY . $WORK_DIR 8 | WORKDIR $WORK_DIR 9 | 10 | RUN rustup toolchain install stable && \ 11 | rustup component add clippy --toolchain stable && \ 12 | rustup component add rustfmt --toolchain stable 13 | 14 | RUN mkdir /binary 15 | RUN mkdir -p /binary/cleveldb && mkdir -p /binary/goleveldb 16 | 17 | RUN make fmt 18 | RUN make lint 19 | RUN make test 20 | 21 | RUN mkdir -p /root/.cargo/bin/ && \ 22 | make build_release && \ 23 | if [ -d /platform/release/bin ] ; then mv /platform/release/bin/* /binary/cleveldb ; rm -rf /platform/release/; else mv /platform/debug/bin/* /binary/cleveldb ; rm -rf /platform/debug/ ;fi 24 | 25 | RUN mkdir -p /root/.cargo/bin/ && \ 26 | make build_release_goleveldb && \ 27 | if [ -d /platform/release/bin ] ; then mv /platform/release/bin/* /binary/goleveldb ; rm -rf /platform/release/; else mv /platform/debug/bin/* /binary/goleveldb ; rm -rf /platform/debug/ ;fi 28 | 29 | # Rosetta 30 | ENV GOLANG_VERSION 1.16.8 31 | ENV GOLANG_DOWNLOAD_SHA256 f32501aeb8b7b723bc7215f6c373abb6981bbc7e1c7b44e9f07317e1a300dce2 32 | ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz 33 | 34 | RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ 35 | && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ 36 | && tar -C /usr/local -xzf golang.tar.gz \ 37 | && rm golang.tar.gz 38 | 39 | ENV GOPATH /go 40 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 41 | RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" 42 | 43 | RUN update-ca-certificates 44 | 45 | RUN git clone https://github.com/FindoraNetwork/findora-rosetta.git \ 46 | && cd findora-rosetta \ 47 | && go get \ 48 | && go build \ 49 | && cp findora-rosetta /binary/ 50 | 51 | CMD ["sleep", "999999"] 52 | -------------------------------------------------------------------------------- /container/Dockerfile-binary-rust-base: -------------------------------------------------------------------------------- 1 | FROM rust:1.56.0-slim 2 | ENV WORK_DIR /platform 3 | ENV WASM_DIR /tmp/wasm-js-bindings 4 | 5 | RUN apt update -y && \ 6 | apt install -y zip unzip git make curl wget python3-pip protobuf-compiler musl-tools jq libleveldb-dev clang libclang-dev pkg-config libssl-dev gcc g++ ca-certificates 7 | RUN pip3 install awscli 8 | 9 | RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh 10 | RUN mkdir -p /opt && \ 11 | cd /opt && \ 12 | wget https://golang.google.cn/dl/go1.15.7.linux-amd64.tar.gz && \ 13 | tar -xpf go1.15.7.linux-amd64.tar.gz 14 | ENV PATH=$PATH:/opt/go/bin 15 | 16 | COPY ./key.tar.gz /key.tar.gz 17 | 18 | RUN mkdir -p ~/.ssh && \ 19 | tar -zxf /key.tar.gz -C ~/.ssh && \ 20 | chown -R root:root ~/.ssh && \ 21 | rm -rf /key.tar.gz 22 | -------------------------------------------------------------------------------- /container/Dockerfile-cleveldb: -------------------------------------------------------------------------------- 1 | FROM debian:11.0-slim 2 | ENV WORK_DIR /platform 3 | ENV WASM_DIR /tmp/wasm-js-bindings 4 | 5 | RUN apt update && apt install -y libleveldb-dev=1.22-3 && rm -rf /var/lib/apt/lists/* 6 | COPY binary/cleveldb/findorad /usr/local/sbin/findorad 7 | COPY container/docker-entrypoint-findorad.sh /docker-entrypoint.sh 8 | WORKDIR / 9 | ENTRYPOINT ["/docker-entrypoint.sh"] 10 | -------------------------------------------------------------------------------- /container/Dockerfile-debug-env: -------------------------------------------------------------------------------- 1 | FROM binary-rust-base 2 | ENV WORK_DIR /platform 3 | ENV WASM_DIR /tmp/wasm-js-bindings 4 | ENV VERGEN_SHA_EXTERN release_build 5 | ENV PATH=$PATH:/root/.cargo/bin/ 6 | 7 | COPY . $WORK_DIR 8 | WORKDIR $WORK_DIR 9 | 10 | RUN apt-get install -y procps 11 | 12 | RUN rustup toolchain install stable && \ 13 | rustup component add clippy --toolchain stable && \ 14 | rustup component add rustfmt 15 | 16 | RUN mkdir -p /root/.cargo/bin/ && make debug_env 17 | 18 | RUN printf "./tools/devnet/startnodes.sh\ntail -f /tmp/findora/devnet/node0/consensus.log" > docker_debug_env.sh 19 | RUN chmod +x docker_debug_env.sh 20 | CMD ["sh","-c","./docker_debug_env.sh"] 21 | -------------------------------------------------------------------------------- /container/Dockerfile-fn-musl-linux: -------------------------------------------------------------------------------- 1 | FROM clux/muslrust 2 | ENV WORK_DIR /volume 3 | COPY . $WORK_DIR 4 | WORKDIR $WORK_DIR 5 | ENV OPENSSL_DIR /musl 6 | RUN rustup target add x86_64-unknown-linux-musl && cargo build --release --bins -p finutils --target=x86_64-unknown-linux-musl 7 | 8 | CMD ["sleep", "999999"] -------------------------------------------------------------------------------- /container/Dockerfile-fn-musl-macos: -------------------------------------------------------------------------------- 1 | FROM musl_fn_macos_base 2 | ENV PATH "/opt/osxcross/target/bin:$PATH" 3 | 4 | RUN wget -nc -P /opt/ https://www.openssl.org/source/openssl-1.1.1s.tar.gz && cd /opt/ && tar -xvf openssl-1.1.1s.tar.gz 5 | WORKDIR /opt/openssl-1.1.1s 6 | ENV CC cc 7 | ENV CXX c++ 8 | RUN ./Configure darwin64-x86_64-cc --prefix=/ssl --cross-compile-prefix=x86_64-apple-darwin14- 9 | RUN make SDKROOT=`xcrun --show-sdk-path` -j `nproc` && make install 10 | 11 | ENV WORK_DIR /platform 12 | COPY . $WORK_DIR 13 | WORKDIR $WORK_DIR 14 | ENV OPENSSL_DIR /ssl 15 | ENV CC o64-clang 16 | ENV CXX o64-clang++ 17 | RUN rustup target add x86_64-apple-darwin && cargo build -p finutils --release --target x86_64-apple-darwin 18 | 19 | CMD ["sleep", "999999"] -------------------------------------------------------------------------------- /container/Dockerfile-fn-musl-macos-base: -------------------------------------------------------------------------------- 1 | FROM clux/muslrust 2 | # ref https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html 3 | RUN apt update 4 | RUN apt -y install \ 5 | clang \ 6 | gcc \ 7 | g++ \ 8 | zlib1g-dev \ 9 | libmpc-dev \ 10 | libmpfr-dev \ 11 | libgmp-dev \ 12 | wget \ 13 | cmake 14 | RUN git clone https://github.com/tpoechtrager/osxcross /opt/osxcross 15 | ENV WORK_DIR /opt/osxcross 16 | WORKDIR $WORK_DIR 17 | RUN wget -nc https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz 18 | RUN mv MacOSX10.10.sdk.tar.xz tarballs/ 19 | RUN CC=clang UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh 20 | RUN rustup toolchain install stable 21 | RUN echo [target.x86_64-apple-darwin] >> /root/.cargo/config 22 | RUN echo linker = \"x86_64-apple-darwin14-clang\" >> /root/.cargo/config 23 | RUN echo ar = \"x86_64-apple-darwin14-ar\" >> /root/.cargo/config 24 | 25 | -------------------------------------------------------------------------------- /container/Dockerfile-fn-musl-windows: -------------------------------------------------------------------------------- 1 | FROM clux/muslrust 2 | RUN apt update 3 | RUN apt -y install gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix 4 | ENV WORK_DIR /volume 5 | COPY . $WORK_DIR 6 | WORKDIR $WORK_DIR 7 | RUN rustup target add x86_64-pc-windows-gnu 8 | RUN echo [target.x86_64-pc-windows-gnu] >> /root/.cargo/config 9 | RUN echo linker = \"x86_64-w64-mingw32-gcc\" >> /root/.cargo/config 10 | ENV CC=x86_64-w64-mingw32-gcc 11 | ENV CXX=x86_64-w64-mingw32-g++ 12 | RUN cargo build -p finutils --release --target x86_64-pc-windows-gnu 13 | CMD ["sleep", "999999"] -------------------------------------------------------------------------------- /container/Dockerfile-goleveldb: -------------------------------------------------------------------------------- 1 | FROM debian:11.0-slim 2 | ENV WORK_DIR /platform 3 | ENV WASM_DIR /tmp/wasm-js-bindings 4 | 5 | RUN apt update && apt install -y libleveldb-dev=1.22-3 && rm -rf /var/lib/apt/lists/* 6 | COPY binary/goleveldb/findorad /usr/local/sbin/findorad 7 | COPY binary/findora-rosetta /usr/local/sbin/findora-rosetta 8 | COPY container/docker-entrypoint-findorad.sh /docker-entrypoint.sh 9 | 10 | # Rosetta 11 | ENV PORT=8080 12 | ENV RPCURL=http://127.0.0.1:8545 13 | ENV NETWORK=PRINET 14 | 15 | WORKDIR / 16 | ENTRYPOINT ["/docker-entrypoint.sh"] 17 | -------------------------------------------------------------------------------- /container/docker-entrypoint-findorad.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export PORT=8080 4 | export RPCURL=http://127.0.0.1:8545 5 | export NETWORK=PRINET 6 | export MODE=ONLINE 7 | 8 | 9 | if [ ! -z $ROSETTA ]; then 10 | if [ $ROSETTA == true ]; then 11 | if [ ! -z $ROSETTA_PORT ]; then 12 | export PORT=$ROSETTA_PORT 13 | fi 14 | 15 | if [ ! -z $ROSETTA_RPCURL ]; then 16 | export RPCURL=$ROSETTA_RPCURL 17 | fi 18 | 19 | if [ ! -z $ROSETTA_NETWORK ]; then 20 | export NETWORK=$ROSETTA_NETWORK 21 | fi 22 | 23 | if [ ! -z $ROSETTA_MODE ]; then 24 | export MODE=$ROSETTA_MODE 25 | fi 26 | nohup findora-rosetta run > /dev/null & 27 | 28 | 29 | fi 30 | fi 31 | 32 | 33 | set -e 34 | 35 | exec findorad "$@" -------------------------------------------------------------------------------- /container/docker-entrypoint-wasm-js-bindings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | WASM_DIR="/build/wasm-js-bindings" 3 | 4 | cd ./src/components/wasm || exit 1 5 | wasm-pack build --target nodejs --out-dir "${WASM_DIR}/nodejs" 6 | rm "${WASM_DIR}/nodejs/.gitignore" 7 | wasm-pack build --target web --out-dir "${WASM_DIR}/web" 8 | rm "${WASM_DIR}/web/.gitignore" 9 | wasm-pack build --target bundler --out-dir "${WASM_DIR}/bundler" 10 | rm "${WASM_DIR}/bundler/.gitignore" 11 | -------------------------------------------------------------------------------- /container/rosetta.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /root/ 3 | 4 | export PORT=8080 5 | export RPCURL=http://127.0.0.1:8545 6 | export NETWORK=PRINET 7 | 8 | if [ ! -n "$MODE" ]; then 9 | export MODE=ONLINE 10 | fi 11 | 12 | nohup /root/findora-rosetta run >/root/findora-rosetta.log 2>&1 & 13 | /bin/bash -c "while true;do echo hello;sleep 50000;done" 14 | -------------------------------------------------------------------------------- /docs/benchmarks/README.md: -------------------------------------------------------------------------------- 1 | # Benchmarks 2 | 3 | #### Benchmark on your localhost 4 | 5 | - `make bench_50k` 6 | - `make bench_100k` 7 | - `make bench_200k` 8 | 9 | #### Benchmark on a real cluster managed by `fn ddev` 10 | 11 | > **NOTE**: check [**moduler documentation**](../../src/components/finutils/src/common/ddev/README.md) for the usage details of `fn ddev`. 12 | 13 | - `make dbench_50k` 14 | - `make dbench_100k` 15 | - `make dbench_200k` 16 | -------------------------------------------------------------------------------- /docs/benchmarks/utxo.md: -------------------------------------------------------------------------------- 1 | # Benchmarks 2 | 3 | TODO 4 | -------------------------------------------------------------------------------- /docs/compile_build.md: -------------------------------------------------------------------------------- 1 | # build 2 | 3 | Assume your OS is ubuntu(1804 or 2004): 4 | 5 | ```shell 6 | # install Rust 7 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 8 | 9 | # install wasm-pack 10 | curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh 11 | 12 | # install golang 13 | cd /opt && \ 14 | sudo wget https://golang.google.cn/dl/go1.15.7.linux-amd64.tar.gz && \ 15 | sudo tar -xpf go1.15.7.linux-amd64.tar.gz && \ 16 | echo "export PATH=/opt/go/bin:$PATH" >> /etc/profile && \ 17 | source /etc/profile 18 | 19 | # install system-deps 20 | sudo apt install libc-dev libssl-dev make git curl wget 21 | 22 | # install toml CLI 23 | `pip3 install toml-cli` 24 | ``` 25 | 26 | > For MacOS 27 | > 28 | > - Install XCode 29 | > - Install Developer tools 30 | > 31 | > ```shell 32 | > # install rust 33 | > curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 34 | > 35 | > # install wasm-pack 36 | > curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh 37 | > 38 | > # install homebrew 39 | > /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 40 | > 41 | > # install golang 42 | > brew install golang 43 | > 44 | > # install system-deps 45 | > brew install gawk glibc openssl wget leveldb 46 | > 47 | > # create directory for binaries 48 | > mkdir ~/go/bin 49 | > ``` 50 | -------------------------------------------------------------------------------- /docs/contribution_guide.md: -------------------------------------------------------------------------------- 1 | # Contribution Guide 2 | 3 | ## Environment Preparements 4 | 5 | - [**Check This Page**](./compile_build.md) 6 | 7 | ## Compiling 8 | 9 | - `make` 10 | 11 | ## Running 12 | 13 | ```shell 14 | make join_testnet 15 | # OR 16 | make join_mainnet 17 | ``` 18 | 19 | ## Code Style 20 | 21 | #### Introduction of dependency 22 | 23 | correct style: 24 | 25 | ```rust 26 | use { 27 | std::{env, thread, rand::random}, 28 | clap::Arg 29 | }; 30 | ``` 31 | 32 | wrong style: 33 | 34 | ```rust 35 | extern crate rand; 36 | 37 | use std::env; 38 | use std::thread; 39 | use rand::random; 40 | 41 | // avoid '*' in importing 42 | use clap::*; 43 | ``` 44 | 45 | #### Warnings 46 | 47 | > Warnings are not allowed in any formal code; However, they are allowed in the test code. 48 | 49 | correct style: 50 | 51 | ```rust 52 | // lib.rs 53 | #![deny(warnings)] 54 | ``` 55 | 56 | wrong style: 57 | 58 | ```rust 59 | // any formal modular 60 | #![allow(warnings)] 61 | ``` 62 | 63 | #### Comments & Document 64 | 65 | correct style: 66 | 67 | ```rust 68 | mod abc { 69 | //! 70 | //! # Modular Docs 71 | //! 72 | 73 | #![deny(missing_docs)] 74 | 75 | fn xxx() {} 76 | } 77 | ``` 78 | 79 | wrong style: 80 | 81 | ```rust 82 | /// # Modular Docs 83 | mod abc { 84 | #![allow(missing_docs)] 85 | 86 | fn xxx() {} 87 | } 88 | ``` 89 | 90 | #### The order of `mod` and `use` 91 | 92 | correct style: 93 | 94 | ```rust 95 | mod a; 96 | mod b; 97 | 98 | use std::env; 99 | ``` 100 | 101 | wrong style: 102 | 103 | ```rust 104 | use std::env; 105 | 106 | mod a; 107 | mod b; 108 | ``` 109 | -------------------------------------------------------------------------------- /docs/fn_ddev.md: -------------------------------------------------------------------------------- 1 | # `fn ddev` 2 | 3 | A powerful and convenient development tool for managing distributed clusters of FindoraNetwork. 4 | 5 | Check [**moduler documentation**](../src/components/finutils/src/common/ddev/README.md) for details. 6 | -------------------------------------------------------------------------------- /docs/fn_dev.md: -------------------------------------------------------------------------------- 1 | # `fn dev` 2 | 3 | A powerful and convenient development tool for managing local clusters of FindoraNetwork. 4 | Its goal is to replace some existing rudimentary development environment management tools, such as: `make debug_env` and `make devnet`. 5 | 6 | Check [**moduler documentation**](../src/components/finutils/src/common/dev/README.md) for details. 7 | -------------------------------------------------------------------------------- /docs/staking/pics/delegation_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindoraNetwork/platform/fa962338be0b3f185731ca3d3a987aca67ec48c2/docs/staking/pics/delegation_flow.png -------------------------------------------------------------------------------- /docs/staking/pics/staking_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindoraNetwork/platform/fa962338be0b3f185731ca3d3a987aca67ec48c2/docs/staking/pics/staking_flow.png -------------------------------------------------------------------------------- /docs/staking/user_guide.md: -------------------------------------------------------------------------------- 1 | # Staking User Guide 2 | 3 | SEE: https://github.com/FindoraNetwork/findora-wiki 4 | -------------------------------------------------------------------------------- /docs/staking/workflow_pics.md: -------------------------------------------------------------------------------- 1 | # Staking Work Flow 2 | 3 | > For simplicity, all the flowcharts and timing diagrams in this article will not show the logics about non-essential nodes, such as SeedNode, SentryNode, etc. 4 | 5 | ## Macro View 6 | 7 | ### \: Delegation 8 | 9 | ![](./pics/delegation_flow.png) 10 | 11 | ### \ Staking(delegate as a new validator) 12 | 13 | > **NOTE**: '**......**' means that the logic there is exactly the same as the delegation process, so the related description will not be repeated. 14 | 15 | ![](pics/staking_flow.png) 16 | 17 | ### \ Deployment 18 | 19 | - **TODO** 20 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | stable 2 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | max_width = 89 2 | # version = "Two" 3 | # comment_width = 89 4 | -------------------------------------------------------------------------------- /src/components/abciapp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abciapp" 3 | version = "0.2.11" 4 | authors = ["FindoraNetwork"] 5 | build = "build.rs" 6 | edition = "2021" 7 | 8 | [[bin]] 9 | name = "findorad" 10 | path = "src/bins/findorad.rs" 11 | 12 | [[bin]] 13 | name = "abcid" 14 | path = "src/bins/abcid.rs" 15 | 16 | [dependencies] 17 | parking_lot = "0.12" 18 | base64 = "0.13" 19 | bincode = "1.3.1" 20 | tracing = "0.1" 21 | rand = "0.8" 22 | rand_chacha = "0.3" 23 | rand_core = { version = "0.6", default-features = false, features = ["alloc"] } 24 | attohttpc = { version = "0.23", default-features = false, features = ["compress", "json", "tls-rustls"] } 25 | serde = { version = "1.0.124", features = ["derive"] } 26 | serde_json = "1.0.40" 27 | lazy_static = "1.4.0" 28 | futures = { version = "0.3.16", features = ["thread-pool"] } 29 | hex = "0.4.3" 30 | ctrlc = { version = "=3.2.5", features = ["termination"] } 31 | protobuf = "2.16" 32 | toml = "0.5.8" 33 | regex = "1" 34 | clap = "2.33.3" 35 | chrono = "0.4.31" 36 | 37 | actix-cors = "0.5.4" 38 | actix-rt = "1.1.0" 39 | actix-service = "1.0.6" 40 | actix-web = "3.3.2" 41 | percent-encoding = "2.1.0" 42 | 43 | nix = "0.22.1" 44 | 45 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 46 | ruc = { version = "1.0.5", default-features = false, features = ["compact"] } 47 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 48 | config = { path = "../config"} 49 | ledger = { path = "../../ledger" } 50 | 51 | globutils = { git = "https://github.com/FindoraNetwork/platform-lib-utils", branch = "fix_dep" } 52 | cryptohash = { git = "https://github.com/FindoraNetwork/platform-lib-cryptohash", branch = "develop" } 53 | finutils = { path = "../finutils" } 54 | 55 | tempfile = "3.1.0" 56 | baseapp = { path = "../contracts/baseapp" } 57 | fc-rpc = { path = "../contracts/rpc" } 58 | fp-storage = { path = "../contracts/primitives/storage" } 59 | fp-utils = { path = "../contracts/primitives/utils" } 60 | fp-types = {path = "../contracts/primitives/types"} 61 | 62 | enterprise-web3 = { path = "../contracts/primitives/enterprise-web3" } 63 | module-evm = { path = "../contracts/modules/evm"} 64 | 65 | [target.'cfg(target_os= "linux")'.dependencies] 66 | btm = "0.1.6" 67 | 68 | [dev-dependencies] 69 | 70 | [build-dependencies] 71 | vergen = "=3.1.0" 72 | 73 | [features] 74 | default = ["diskcache"] 75 | diskcache = ["ledger/diskcache"] 76 | debug_env = ["ledger/debug_env", "config/debug_env", "baseapp/debug_env"] 77 | benchmark = ["baseapp/benchmark"] 78 | -------------------------------------------------------------------------------- /src/components/abciapp/README.md: -------------------------------------------------------------------------------- 1 | # Tendermint ABCI 2 | 3 | ![](https://github.com/FindoraNetwork/FGR/blob/master/src/pics/preflow.png) 4 | -------------------------------------------------------------------------------- /src/components/abciapp/build.rs: -------------------------------------------------------------------------------- 1 | use vergen::{generate_cargo_keys, ConstantsFlags}; 2 | 3 | fn main() { 4 | let mut flags = ConstantsFlags::all(); 5 | // Tell vergen to use the semver from cargo and not `git describe` 6 | flags.set(ConstantsFlags::SEMVER, false); 7 | flags.set(ConstantsFlags::SEMVER_FROM_CARGO_PKG, true); 8 | 9 | // Generate the 'cargo:' key output 10 | generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); 11 | } 12 | -------------------------------------------------------------------------------- /src/components/abciapp/src/abci/server/tx_sender.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # send the transaction to tendermint 3 | //! 4 | 5 | use { 6 | crate::{abci::POOL, api::submission_server::TxnForward}, 7 | ledger::data_model::Transaction, 8 | ruc::*, 9 | std::sync::atomic::{AtomicU16, Ordering}, 10 | }; 11 | 12 | static TX_PENDING_CNT: AtomicU16 = AtomicU16::new(0); 13 | 14 | pub struct TendermintForward { 15 | pub tendermint_reply: String, 16 | } 17 | 18 | impl AsRef for TendermintForward { 19 | fn as_ref(&self) -> &str { 20 | self.tendermint_reply.as_str() 21 | } 22 | } 23 | 24 | impl TxnForward for TendermintForward { 25 | fn forward_txn(&self, txn: Transaction) -> Result<()> { 26 | forward_txn_with_mode(self.as_ref(), txn, false) 27 | } 28 | } 29 | 30 | pub fn forward_txn_with_mode( 31 | url: &str, 32 | txn: Transaction, 33 | async_mode: bool, 34 | ) -> Result<()> { 35 | const SYNC_API: &str = "broadcast_tx_sync"; 36 | const ASYNC_API: &str = "broadcast_tx_async"; 37 | 38 | let txn_json = serde_json::to_string(&txn).c(d!())?; 39 | let txn_b64 = base64::encode_config(&txn_json.as_str(), base64::URL_SAFE); 40 | 41 | let json_rpc = if async_mode { 42 | format!( 43 | "{{\"jsonrpc\":\"2.0\",\"id\":\"anything\",\"method\":\"{}\",\"params\": {{\"tx\": \"{}\"}}}}", 44 | ASYNC_API, &txn_b64 45 | ) 46 | } else { 47 | format!( 48 | "{{\"jsonrpc\":\"2.0\",\"id\":\"anything\",\"method\":\"{}\",\"params\": {{\"tx\": \"{}\"}}}}", 49 | SYNC_API, &txn_b64 50 | ) 51 | }; 52 | 53 | let tendermint_reply = format!("http://{url}"); 54 | if 2000 > TX_PENDING_CNT.fetch_add(1, Ordering::Relaxed) { 55 | POOL.spawn_ok(async move { 56 | ruc::info_omit!(attohttpc::post(&tendermint_reply) 57 | .header(attohttpc::header::CONTENT_TYPE, "application/json") 58 | .text(json_rpc) 59 | .send() 60 | .c(d!())); 61 | TX_PENDING_CNT.fetch_sub(1, Ordering::Relaxed); 62 | }); 63 | } else { 64 | TX_PENDING_CNT.fetch_sub(1, Ordering::Relaxed); 65 | return Err(eg!("Too many pending tasks")); 66 | } 67 | 68 | Ok(()) 69 | } 70 | -------------------------------------------------------------------------------- /src/components/abciapp/src/abci/staking/whoami.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # Tendermint Node Address 3 | //! 4 | //! - `sha256(pubkey)[..20]` 5 | //! 6 | 7 | use { 8 | config::abci::global_cfg::CFG, lazy_static::lazy_static, 9 | ledger::staking::td_addr_to_bytes, ruc::*, serde::Deserialize, std::fs, 10 | }; 11 | 12 | pub fn get_self_addr() -> Result> { 13 | from_env().c(d!()).or_else(|_| from_config_file().c(d!())) 14 | } 15 | 16 | fn from_env() -> Result> { 17 | CFG.tendermint_node_self_addr 18 | .as_ref() 19 | .c(d!()) 20 | .and_then(|td_addr| td_addr_to_bytes(td_addr).c(d!())) 21 | } 22 | 23 | fn from_config_file() -> Result> { 24 | // the config path in the abci container 25 | const CFG_PATH_FF: &str = "/root/.tendermint/config/priv_validator_key.json"; 26 | lazy_static! { 27 | static ref CFG_PATH: &'static str = CFG 28 | .tendermint_node_key_config_path 29 | .as_deref() 30 | .unwrap_or(CFG_PATH_FF); 31 | } 32 | 33 | fs::read_to_string(&*CFG_PATH) 34 | .c(d!()) 35 | .and_then(|cfg| serde_json::from_str::(&cfg).c(d!())) 36 | .and_then(|sa| td_addr_to_bytes(&sa.address).c(d!())) 37 | } 38 | 39 | // 40 | // Structure: 41 | // 42 | // ``` 43 | // { 44 | // "address": "8DB4CBD00D8E6621826BE6A840A98C28D7F27CD9", 45 | // "pub_key": { 46 | // "type": "tendermint/PubKeyEd25519", 47 | // "value": "BSiMm6HFCzWBPB8s1ZOEqtWm6u6dj2Ftamm1s4msg24=" 48 | // }, 49 | // "priv_key": { 50 | // "type": "tendermint/PrivKeyEd25519", 51 | // "value": "ON4RyK6Pevf5UrXJZ7uoPdH3RmnJUKyJlwuHQcEijHAFKIybocULNYE8HyzVk4Sq1abq7p2PYW1qabWziayDbg==" 52 | // } 53 | // } 54 | // ``` 55 | #[derive(Deserialize)] 56 | struct SelfAddr { 57 | address: String, 58 | } 59 | -------------------------------------------------------------------------------- /src/components/abciapp/src/api/mod.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # Services provided by api 3 | //! 4 | 5 | /// Provide query service for ledgerState 6 | pub mod query_server; 7 | 8 | /// Provide services for operating transactions 9 | pub mod submission_server; 10 | -------------------------------------------------------------------------------- /src/components/abciapp/src/api/query_server/mod.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # Query Interface for WebEnd 3 | //! 4 | 5 | pub mod query_api; 6 | 7 | /// used to notify `query server` to do updating 8 | pub use query_api::server::BLOCK_CREATED; 9 | -------------------------------------------------------------------------------- /src/components/abciapp/src/api/query_server/query_api/service.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! new query server 3 | //! 4 | 5 | use { 6 | super::{ 7 | server::{QueryServer, BLOCK_CREATED}, 8 | QueryApi, 9 | }, 10 | ledger::store::LedgerState, 11 | parking_lot::RwLock, 12 | ruc::*, 13 | std::{sync::Arc, thread}, 14 | }; 15 | 16 | pub(crate) fn start_query_server( 17 | ledger: Arc>, 18 | addrs: &[(&str, u16)], 19 | ) -> Result>> { 20 | let qs = Arc::new(RwLock::new(QueryServer::new(ledger))); 21 | let qs1 = Arc::clone(&qs); 22 | let qs2 = Arc::clone(&qs); 23 | 24 | QueryApi::create(qs1, addrs).c(d!()).map(|_| { 25 | thread::spawn(move || loop { 26 | let mut created = BLOCK_CREATED.0.lock(); 27 | if !*created { 28 | BLOCK_CREATED.1.wait(&mut created); 29 | } 30 | qs2.write().update(); 31 | *created = false; 32 | }); 33 | qs 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /src/components/abciapp/src/bins/abcid.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # binary process 3 | //! 4 | 5 | use { 6 | abciapp::abci, 7 | ruc::*, 8 | std::{ 9 | sync::{atomic::Ordering, mpsc::channel}, 10 | thread, 11 | }, 12 | }; 13 | 14 | fn main() { 15 | globutils::logging::init_logging(None); 16 | tracing::info!(target: "abciapp", concat!( 17 | "Build: ", 18 | env!("VERGEN_SHA"), 19 | " ", 20 | env!("VERGEN_BUILD_DATE") 21 | )); 22 | 23 | let thread = thread::spawn(|| pnk!(abci::run())); 24 | 25 | let (tx, rx) = channel(); 26 | 27 | pnk!(ctrlc::set_handler(move || { 28 | println!("Waiting to exit."); 29 | abci::IS_EXITING.store(true, Ordering::SeqCst); 30 | while !abci::IN_SAFE_ITV.load(Ordering::SeqCst) { 31 | sleep_ms!(10); 32 | } 33 | 34 | pnk!(tx.send(())); 35 | })); 36 | 37 | pnk!(rx.recv()); 38 | 39 | println!("Exiting..."); 40 | thread.thread().unpark(); 41 | thread.join().unwrap(); 42 | } 43 | -------------------------------------------------------------------------------- /src/components/abciapp/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! Tendermint-based abci implementation 3 | //! 4 | 5 | #![deny(warnings)] 6 | #![deny(missing_docs)] 7 | #![allow(clippy::needless_borrow)] 8 | #![allow(clippy::field_reassign_with_default)] 9 | 10 | pub mod abci; 11 | pub mod api; 12 | -------------------------------------------------------------------------------- /src/components/config/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "config" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | 7 | [dependencies] 8 | 9 | attohttpc = { version = "0.23", default-features = false, features = ["compress", "json", "tls-rustls"] } 10 | clap = "2.33.3" 11 | lazy_static = { version = "1.2.0" } 12 | ruc = "1.0" 13 | serde = { version = "1.0.124", features = ["derive"] } 14 | serde_derive = "1.0" 15 | serde_json = "1.0" 16 | serde-strz = "1.1.1" 17 | toml = "0.5.8" 18 | 19 | globutils = { git = "https://github.com/FindoraNetwork/platform-lib-utils", branch = "fix_dep" } 20 | 21 | [target.'cfg(target_os= "linux")'.dependencies] 22 | btm = "0.1.6" 23 | 24 | [build-dependencies] 25 | vergen = "=3.1.0" 26 | 27 | [features] 28 | debug_env = [] 29 | -------------------------------------------------------------------------------- /src/components/config/build.rs: -------------------------------------------------------------------------------- 1 | use vergen::{generate_cargo_keys, ConstantsFlags}; 2 | 3 | fn main() { 4 | let mut flags = ConstantsFlags::all(); 5 | // Tell vergen to use the semver from cargo and not `git describe` 6 | flags.set(ConstantsFlags::SEMVER, false); 7 | flags.set(ConstantsFlags::SEMVER_FROM_CARGO_PKG, true); 8 | 9 | // Generate the 'cargo:' key output 10 | generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); 11 | } 12 | -------------------------------------------------------------------------------- /src/components/config/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | 3 | pub mod abci; 4 | pub mod findora; 5 | -------------------------------------------------------------------------------- /src/components/contracts/baseapp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["FindoraNetwork"] 3 | description = "Base application for tendermint abci" 4 | edition = "2021" 5 | homepage = "https://findora.org/technology" 6 | name = "baseapp" 7 | readme = "README.md" 8 | repository = "https://github.com/findoranetwork/platform/" 9 | version = "0.1.0" 10 | 11 | [dependencies] 12 | abci = {git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6"} 13 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 14 | ethereum-types = { version = "0.13.1", default-features = false } 15 | futures = "0.3.16" 16 | lazy_static = "1.4.0" 17 | ledger = {path = "../../../ledger"} 18 | tracing = "0.1" 19 | parking_lot = "0.12" 20 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 21 | protobuf = "2.16" 22 | ruc = "1.0" 23 | serde = {version = "1.0.124", features = ["derive"]} 24 | serde_json = "1.0.40" 25 | storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 26 | fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 27 | sha3 = "0.10" 28 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 29 | 30 | config = { path = "../../config"} 31 | 32 | # primitives 33 | fp-core = {path = "../primitives/core"} 34 | fp-evm = {path = "../primitives/evm"} 35 | fp-traits = {path = "../primitives/traits"} 36 | fp-types = {path = "../primitives/types"} 37 | fp-utils = {path = "../primitives/utils"} 38 | enterprise-web3 = { path = "../primitives/enterprise-web3" } 39 | 40 | # modules 41 | module-account = {path = "../modules/account"} 42 | module-ethereum = {path = "../modules/ethereum"} 43 | module-evm = {path = "../modules/evm"} 44 | module-template = {path = "../modules/template"} 45 | module-xhub = {path = "../modules/xhub"} 46 | 47 | evm-precompile = {path = "../modules/evm/precompile"} 48 | evm-precompile-basic = {path = "../modules/evm/precompile/basic"} 49 | evm-precompile-frc20 = {path = "../modules/evm/precompile/frc20"} 50 | evm-precompile-modexp = {path = "../modules/evm/precompile/modexp"} 51 | evm-precompile-blake2 = {path = "../modules/evm/precompile/blake2"} 52 | evm-precompile-bn128 = {path = "../modules/evm/precompile/bn128"} 53 | evm-precompile-anemoi = {path = "../modules/evm/precompile/anemoi"} 54 | 55 | 56 | [features] 57 | abci_mock = [] 58 | benchmark = ["module-evm/benchmark","module-ethereum/benchmark"] 59 | debug_env = [] 60 | -------------------------------------------------------------------------------- /src/components/contracts/baseapp/src/notify.rs: -------------------------------------------------------------------------------- 1 | use futures::channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}; 2 | use parking_lot::Mutex; 3 | use ruc::*; 4 | 5 | type NotificationSinks = Mutex>>; 6 | 7 | pub struct Notifications { 8 | sinks: NotificationSinks, 9 | } 10 | 11 | impl Default for Notifications { 12 | fn default() -> Self { 13 | Self::new() 14 | } 15 | } 16 | 17 | impl Notifications { 18 | pub fn new() -> Self { 19 | Self { 20 | sinks: Default::default(), 21 | } 22 | } 23 | 24 | pub fn notification_sinks(&self) -> &NotificationSinks { 25 | &self.sinks 26 | } 27 | 28 | pub fn notification_stream(&self) -> UnboundedReceiver { 29 | let (sink, stream) = unbounded(); 30 | self.sinks.lock().push(sink); 31 | stream 32 | } 33 | 34 | pub fn notify(&self, data: T) -> Result<()> { 35 | self.sinks 36 | .lock() 37 | .retain(|sink| sink.unbounded_send(data.clone()).is_ok()); 38 | Ok(()) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/components/contracts/modules/account/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "module-account" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora module supporting smart account function" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 13 | tracing = "0.1" 14 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 15 | ruc = "1.0" 16 | serde = { version = "1.0.124", features = ["derive"] } 17 | serde_json = "1.0.64" 18 | storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 19 | 20 | # primitives, don't depend on any modules 21 | fp-core = { path = "../../primitives/core" } 22 | fp-storage = { path = "../../primitives/storage" } 23 | fp-traits = { path = "../../primitives/traits" } 24 | fp-types = { path = "../../primitives/types" } 25 | enterprise-web3 = { path = "../../primitives/enterprise-web3" } 26 | config = { path = "../../../config"} 27 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 28 | 29 | [dev-dependencies] 30 | rand_chacha = "0.3" 31 | parking_lot = "0.12" 32 | fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 33 | -------------------------------------------------------------------------------- /src/components/contracts/modules/account/README.md: -------------------------------------------------------------------------------- 1 | # Account Module -------------------------------------------------------------------------------- /src/components/contracts/modules/account/src/basic.rs: -------------------------------------------------------------------------------- 1 | use super::{App, Config, MODULE_NAME}; 2 | use fp_core::module::AppModuleBasic; 3 | use ruc::Result; 4 | 5 | impl AppModuleBasic for App { 6 | fn name() -> String { 7 | MODULE_NAME.into() 8 | } 9 | 10 | fn default_genesis(&self) -> Vec { 11 | todo!() 12 | } 13 | 14 | fn init_genesis(&self) { 15 | todo!() 16 | } 17 | 18 | fn validate_genesis(&self) -> Result<()> { 19 | todo!() 20 | } 21 | 22 | fn export_genesis(&self) { 23 | todo!() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/components/contracts/modules/ethereum/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "module-ethereum" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora module supporting execute ethereum transaction" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 13 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 14 | ethereum-types = { version = "0.13.1", default-features = false } 15 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 16 | tracing = "0.1" 17 | rand = "0.8" 18 | rlp = "0.5" 19 | ruc = "1.0" 20 | serde = { version = "1.0.124", features = ["derive"] } 21 | serde_json = "1.0.64" 22 | sha3 = "0.10" 23 | lazy_static = "1.4.0" 24 | 25 | # primitives, don't depend on any modules 26 | fp-core = { path = "../../primitives/core" } 27 | fp-events = { path = "../../primitives/events" } 28 | fp-evm = { path = "../../primitives/evm" } 29 | fp-storage = { path = "../../primitives/storage" } 30 | fp-traits = { path = "../../primitives/traits" } 31 | fp-types = { path = "../../primitives/types" } 32 | fp-utils = { path = "../../primitives/utils" } 33 | config = { path = "../../../config"} 34 | enterprise-web3 = { path = "../../primitives/enterprise-web3" } 35 | 36 | [dev-dependencies] 37 | baseapp = { path = "../../baseapp" } 38 | fp-mocks = { path = "../../primitives/mocks" } 39 | module-account = { path = "../account" } 40 | storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 41 | fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 42 | 43 | [features] 44 | default = [] 45 | debug_env = [] 46 | benchmark = [] 47 | -------------------------------------------------------------------------------- /src/components/contracts/modules/ethereum/README.md: -------------------------------------------------------------------------------- 1 | # Ethereum Module -------------------------------------------------------------------------------- /src/components/contracts/modules/ethereum/src/basic.rs: -------------------------------------------------------------------------------- 1 | use super::{App, Config, MODULE_NAME}; 2 | use fp_core::module::AppModuleBasic; 3 | use ruc::Result; 4 | 5 | impl AppModuleBasic for App { 6 | fn name() -> String { 7 | MODULE_NAME.into() 8 | } 9 | 10 | fn default_genesis(&self) -> Vec { 11 | todo!() 12 | } 13 | 14 | fn init_genesis(&self) { 15 | todo!() 16 | } 17 | 18 | fn validate_genesis(&self) -> Result<()> { 19 | todo!() 20 | } 21 | 22 | fn export_genesis(&self) { 23 | todo!() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "module-evm" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora module supporting evm smart contract" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 13 | ethereum-types = { version = "0.13.1", default-features = false } 14 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 15 | evm-runtime = { version = "0.35.0", default-features = false } 16 | evm-gasometer = { version = "0.35.0", default-features = false } 17 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 18 | impl-trait-for-tuples = "0.2" 19 | tracing = "0.1" 20 | rlp = { version = "0.5", default-features = false } 21 | ruc = "1.0" 22 | serde = { version = "1.0.124", features = ["derive"] } 23 | serde_json = "1.0.64" 24 | sha3 = { version = "0.10", default-features = false } 25 | hex = "0.4.3" 26 | ethabi = "17.1.0" 27 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 28 | protobuf = "2.16" 29 | 30 | # primitives, don't depend on any modules 31 | fp-core = { path = "../../primitives/core" } 32 | fp-evm = { path = "../../primitives/evm" } 33 | fp-storage = { path = "../../primitives/storage" } 34 | fp-traits = { path = "../../primitives/traits" } 35 | fp-types = { path = "../../primitives/types" } 36 | fp-utils = { path = "../../primitives/utils" } 37 | config = { path = "../../../config"} 38 | storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 39 | fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 40 | ledger = { path = "../../../../ledger" } 41 | enterprise-web3 = { path = "../../primitives/enterprise-web3" } 42 | module-ethereum = { path = "../ethereum" } 43 | 44 | [dev-dependencies] 45 | baseapp = { path = "../../baseapp" } 46 | fp-mocks = { path = "../../primitives/mocks" } 47 | hex = "0.4.3" 48 | module-account = { path = "../account" } 49 | serde_json = "1.0.64" 50 | 51 | [features] 52 | benchmark = [] 53 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/README.md: -------------------------------------------------------------------------------- 1 | # EVM Module -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["FindoraNetwork"] 3 | description = "MODEXP precompiles for EVM module." 4 | edition = "2021" 5 | homepage = "https://findora.org/technology" 6 | name = "evm-precompile" 7 | readme = "README.md" 8 | repository = "https://github.com/findoranetwork/platform/" 9 | version = "0.1.0" 10 | 11 | [dependencies] 12 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 13 | ethereum-types = "0.13.1" 14 | evm-precompile-basic = {path = "./basic"} 15 | evm-precompile-frc20 = {path = "./frc20"} 16 | evm-precompile-modexp = {path = "./modexp"} 17 | evm-precompile-anemoi = {path = "./anemoi"} 18 | evm-precompile-blake2 = {path = "./blake2"} 19 | evm-precompile-bn128 = {path = "./bn128"} 20 | fp-core = {path = "../../../primitives/core"} 21 | module-evm = {path = "../../../modules/evm"} 22 | parking_lot = "0.12" 23 | evm-precompile-eth-pairings = { path = "./eth-pairings" } 24 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/anemoi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-anemoi" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [[bench]] 9 | name = 'anemoi' 10 | path = 'benches/anemoi.rs' 11 | harness = false 12 | 13 | [dependencies] 14 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 15 | evm-precompile-utils = { path = "../utils"} 16 | tracing = "0.1" 17 | module-evm = { path = "../../../../modules/evm"} 18 | num_enum = { version = "0.5.4", default-features = false } 19 | platform-lib-noah = { git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 20 | 21 | [dev-dependencies] 22 | baseapp = { path = "../../../../baseapp" } 23 | fp-mocks = { path = "../../../../primitives/mocks" } 24 | ethereum-types = { version = "0.13.1", default-features = false } 25 | hex = "0.4" -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/anemoi/benches/anemoi.rs: -------------------------------------------------------------------------------- 1 | use evm_precompile_anemoi::Anemoi381; 2 | use noah_algebra::bls12_381::BLSScalar; 3 | use noah_algebra::prelude::Scalar; 4 | use std::time::Instant; 5 | 6 | fn main() { 7 | let mut prng = noah_algebra::rand_helper::test_rng(); 8 | let mut elems = Vec::with_capacity(32); 9 | for _ in 0..32 { 10 | elems.push(BLSScalar::random(&mut prng)); 11 | } 12 | 13 | let data = elems 14 | .iter() 15 | .map(|x| x.to_bytes()) 16 | .flatten() 17 | .collect::>(); 18 | 19 | println!("Benchmarking 2 field elements for 1000 times"); 20 | let start = Instant::now(); 21 | for _ in 0..1000 { 22 | _ = Anemoi381::execute_with_input_and_gas(&data[0..64], None); 23 | } 24 | let time = start.elapsed().as_nanos() / 1000; 25 | let gas = Anemoi381::GAS_PER_PERM; 26 | println!("Result = {} ns every time", time); 27 | println!("Cost = {} every time", gas); 28 | println!("NS per gas = {}", (time as f64) / (gas as f64)); 29 | 30 | println!("Benchmarking 32 field elements for 1000 times"); 31 | let start = Instant::now(); 32 | for _ in 0..1000 { 33 | _ = Anemoi381::execute_with_input_and_gas(&data[0..1024], None); 34 | } 35 | let time = start.elapsed().as_nanos() / 1000; 36 | let gas = Anemoi381::GAS_PER_PERM * 11; 37 | println!("Result = {} ns every time", time); 38 | println!("Cost = {} every time", gas); 39 | println!("NS per gas = {}", (time as f64) / (gas as f64)); 40 | } 41 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/basic/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-basic" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Basic precompiles for EVM module." 9 | readme = "README.md" 10 | 11 | [[bench]] 12 | name = 'sha256' 13 | path = 'benches/sha256.rs' 14 | harness = false 15 | 16 | [dependencies] 17 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 18 | module-evm = { path = "../../../../modules/evm"} 19 | ripemd = "0.1" 20 | 21 | fp-types = { path = "../../../../primitives/types" } 22 | fp-utils = { path = "../../../../primitives/utils" } -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/basic/benches/sha256.rs: -------------------------------------------------------------------------------- 1 | use evm_precompile_basic::Sha256; 2 | use module_evm::precompile::LinearCostPrecompile; 3 | use std::time::Instant; 4 | 5 | fn main() { 6 | let data = vec![1u8; 16384]; 7 | 8 | println!("Benchmarking SHA256 for 1KB data for 10000 times"); 9 | let start = Instant::now(); 10 | for _ in 0..10000 { 11 | _ = Sha256::execute(&data[0..1024], 0); 12 | } 13 | let time = start.elapsed().as_nanos() / 10000; 14 | let gas = Sha256::BASE + Sha256::WORD * 1024 / 32; 15 | println!("Result = {} ns every time", time); 16 | println!("Cost = {} every time", gas); 17 | println!("NS per gas = {}", (time as f64) / (gas as f64)); 18 | 19 | println!("Benchmarking SHA256 for 4KB data for 10000 times"); 20 | let start = Instant::now(); 21 | for _ in 0..10000 { 22 | _ = Sha256::execute(&data[0..4096], 0); 23 | } 24 | let time = start.elapsed().as_nanos() / 10000; 25 | let gas = Sha256::BASE + Sha256::WORD * 4096 / 32; 26 | println!("Result = {} ns every time", time); 27 | println!("Cost = {} every time", gas); 28 | println!("NS per gas = {}", (time as f64) / (gas as f64)); 29 | 30 | println!("Benchmarking SHA256 for 16KB data for 10000 times"); 31 | let start = Instant::now(); 32 | for _ in 0..10000 { 33 | _ = Sha256::execute(&data, 0); 34 | } 35 | let time = start.elapsed().as_nanos() / 10000; 36 | let gas = Sha256::BASE + Sha256::WORD * 16384 / 32; 37 | println!("Result = {} ns every time", time); 38 | println!("Cost = {} every time", gas); 39 | println!("NS per gas = {}", (time as f64) / (gas as f64)); 40 | } 41 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/blake2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-blake2" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 10 | evm-precompile-utils = { path = "../utils"} 11 | tracing = "0.1" 12 | module-evm = { path = "../../../../modules/evm"} 13 | num_enum = { version = "0.5.4", default-features = false } 14 | 15 | [dev-dependencies] 16 | baseapp = { path = "../../../../baseapp" } 17 | fp-mocks = { path = "../../../../primitives/mocks" } 18 | ethereum-types = { version = "0.13.1", default-features = false } 19 | hex = "0.4" 20 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/bn128/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-bn128" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 10 | evm-precompile-utils = { path = "../utils"} 11 | tracing = "0.1" 12 | module-evm = { path = "../../../../modules/evm"} 13 | num_enum = { version = "0.5.4", default-features = false } 14 | fp-types = {path = "../../../../primitives/types"} 15 | bn = { package = "findora-bn", git = "https://github.com/FindoraNetwork/findora-bn.git", default-features = false } 16 | 17 | [dev-dependencies] 18 | baseapp = { path = "../../../../baseapp" } 19 | fp-mocks = { path = "../../../../primitives/mocks" } 20 | ethereum-types = { version = "0.13.1", default-features = false } 21 | hex = "0.4" 22 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/eth-pairings/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-eth-pairings" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | eth_pairings = { git = "https://github.com/FindoraNetwork/eip1962", branch = "master" } 10 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 11 | evm-precompile-utils = { path = "../utils"} 12 | tracing = "0.1" 13 | module-evm = { path = "../../../../modules/evm"} 14 | num_enum = { version = "0.5.4", default-features = false } 15 | 16 | [dev-dependencies] 17 | baseapp = { path = "../../../../baseapp" } 18 | fp-mocks = { path = "../../../../primitives/mocks" } 19 | ethereum-types = { version = "0.13.1", default-features = false } 20 | hex = "0.4" -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/eth-pairings/src/tests.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use ethereum_types::H160; 3 | use fp_mocks::*; 4 | 5 | // Test from eth-pairings (eip1962) repository https://github.com/FindoraNetwork/eip1962 6 | #[test] 7 | fn test_bls12_pairing() { 8 | use hex; 9 | let hex_string = "07202912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011603e65409b693c8a08aeb3478d10aa3732a6672ba06d12912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010206059efde42f3701020127ccb2831f0011c1d547c491b9dffbd4cfdb87598a4b370f5873ea62094a2f201faa6cb7f6fcca66de3f308a25776dac3f61edb792948fbe53e4d18a3d8aefbe011a7e9f75f3fdc77b83a97f7acd58326a0545f8aa37b69bfb32c52dc195763e8c17176e0ad4ee94d9c720e922d42688127c4b812cd7c2f8cf6126acd4c3d7568121e48b3fefe66c279f2ec71f0d6f8156a3343d1cfa54b808d747cd02419278290ad2d7d03f5de1e7b3c97732f53dbe1dfd42e51f9571f7fee3d9c1785d5a1ed6010b4f7f211a0a5f4425728e2df580196d3e3b85ef148ed769acd23e9be6e8440726cb40655787f48eaf46154cb740e2a58db5b96fa02d83fb9d0f94320da1471e0104ece4c46ac4f05a7c28ecda84292f15999747bb77c530c65448f1f837a47dd70e972c4065d0b39d40b5d550a55901516afa7f02b395963d1535fcba1705e31a117cb4beab1dc582198c4ab0c02e96a22f7bd10dde3bbbdbc9182a9596cb0ed32121616b692e8036437efb4c3816f018f11e643c6e0a049da431986a3a722b06"; 10 | let data = hex::decode(hex_string).unwrap(); 11 | 12 | let output = EthPairing::execute( 13 | &EvmDataWriter::new() 14 | .write_selector(Call::ExecuteOperation) 15 | .write_raw_bytes(&data) 16 | .build(), 17 | None, 18 | &evm::Context { 19 | address: H160::from_low_u64_be(2001), 20 | caller: ALICE_ECDSA.address, 21 | apparent_value: From::from(0), 22 | }, 23 | &BASE_APP.lock().unwrap().deliver_state, 24 | ); 25 | 26 | assert!(output.is_ok()); 27 | assert_eq!(output.as_ref().unwrap().cost, 164986); 28 | assert_eq!(output.unwrap().output, vec![0x1]); 29 | } 30 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/frc20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-frc20" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "FRC20 precompiles for EVM module." 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | ethereum-types = { version = "0.13.1", default-features = false } 13 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 14 | evm-precompile-utils = { path = "../utils"} 15 | fp-traits = { path = "../../../../primitives/traits" } 16 | tracing = "0.1" 17 | module-evm = { path = "../../../../modules/evm"} 18 | num_enum = { version = "0.5.4", default-features = false } 19 | slices = "0.2.0" 20 | config = { path = "../../../../../config" } 21 | 22 | [dev-dependencies] 23 | baseapp = { path = "../../../../baseapp" } 24 | fp-mocks = { path = "../../../../primitives/mocks" } 25 | sha3 = "0.10" 26 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/modexp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-modexp" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "MODEXP precompiles for EVM module." 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 13 | module-evm = { path = "../../../../modules/evm"} 14 | num = { version = "0.4", features = ["alloc"] } 15 | ethereum-types = { version = "0.13.1", default-features = false } 16 | 17 | [dev-dependencies] 18 | hex = "0.4.3" 19 | fp-mocks = { path = "../../../../primitives/mocks" } 20 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-precompile-utils" 3 | version = "0.1.0" 4 | authors = ["PureStake"] 5 | edition = "2021" 6 | description = "Utils to write EVM precompiles." 7 | 8 | [dependencies] 9 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 10 | ethereum-types = { version = "0.13.1", default-features = false } 11 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 12 | tracing = "0.1" 13 | num_enum = { version = "0.5.3", default-features = false } 14 | precompile-utils-macro = { path = "macro" } 15 | sha3 = { version = "0.10", default-features = false } 16 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/utils/macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "precompile-utils-macro" 3 | version = "0.1.0" 4 | authors = ["PureStake"] 5 | edition = "2021" 6 | description = "" 7 | 8 | [lib] 9 | proc-macro = true 10 | 11 | [[test]] 12 | name = "tests" 13 | path = "tests/tests.rs" 14 | 15 | [dependencies] 16 | quote = "1.0" 17 | proc-macro2 = "1.0" 18 | sha3 = "0.10" 19 | syn = { version = "1.0", features = ["full", "fold", "extra-traits", "visit"] } 20 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/precompile/utils/macro/tests/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2021 PureStake Inc. 2 | // This file is part of Moonbeam. 3 | 4 | // Moonbeam is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Moonbeam is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | use sha3::{Digest, Keccak256}; 15 | 16 | #[precompile_utils_macro::generate_function_selector] 17 | pub enum Action { 18 | Toto = "toto()", 19 | Tata = "tata()", 20 | } 21 | 22 | #[test] 23 | fn tests() { 24 | assert_eq!( 25 | &(Action::Toto as u32).to_be_bytes()[..], 26 | &Keccak256::digest(b"toto()")[0..4], 27 | ); 28 | assert_eq!( 29 | &(Action::Tata as u32).to_be_bytes()[..], 30 | &Keccak256::digest(b"tata()")[0..4], 31 | ); 32 | assert_ne!(Action::Toto as u32, Action::Tata as u32); 33 | } 34 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/src/basic.rs: -------------------------------------------------------------------------------- 1 | use super::{App, Config, MODULE_NAME}; 2 | use fp_core::module::AppModuleBasic; 3 | use ruc::Result; 4 | 5 | impl AppModuleBasic for App { 6 | fn name() -> String { 7 | MODULE_NAME.into() 8 | } 9 | 10 | fn default_genesis(&self) -> Vec { 11 | todo!() 12 | } 13 | 14 | fn init_genesis(&self) { 15 | todo!() 16 | } 17 | 18 | fn validate_genesis(&self) -> Result<()> { 19 | todo!() 20 | } 21 | 22 | fn export_genesis(&self) { 23 | todo!() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/src/runtime/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod runner; 2 | pub mod stack; 3 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/src/system_contracts.rs: -------------------------------------------------------------------------------- 1 | use std::str::FromStr; 2 | 3 | use config::abci::global_cfg::CFG; 4 | use ethabi::Contract; 5 | use ethereum_types::H160; 6 | use ruc::*; 7 | use serde::{Deserialize, Serialize}; 8 | 9 | pub static SYSTEM_ADDR: &str = "0x0000000000000000000000000000000000002000"; 10 | 11 | #[derive(Serialize, Deserialize, Debug, Clone)] 12 | pub struct SystemContracts { 13 | pub bridge: Contract, 14 | pub bridge_address: H160, 15 | pub staking: Contract, 16 | pub staking_address: H160, 17 | } 18 | 19 | impl SystemContracts { 20 | pub fn new() -> Result { 21 | let abi_str = include_str!("../contracts/PrismXXBridge.abi.json"); 22 | let bridge = Contract::load(abi_str.as_bytes()).c(d!())?; 23 | let bridge_address = 24 | H160::from_str(&CFG.checkpoint.prism_bridge_address).unwrap_or_default(); 25 | let abi_str = include_str!("../contracts/EVMStaking.abi.json"); 26 | let staking = Contract::load(abi_str.as_bytes()).c(d!())?; 27 | let staking_address = 28 | H160::from_str(&CFG.checkpoint.evm_staking_address).unwrap_or_default(); 29 | 30 | Ok(Self { 31 | bridge, 32 | bridge_address, 33 | staking, 34 | staking_address, 35 | }) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/tests/contracts/abi/Context.abi: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/tests/contracts/abi/Context.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindoraNetwork/platform/fa962338be0b3f185731ca3d3a987aca67ec48c2/src/components/contracts/modules/evm/tests/contracts/abi/Context.bin -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/tests/contracts/abi/IERC20.abi: -------------------------------------------------------------------------------- 1 | [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/tests/contracts/abi/IERC20.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindoraNetwork/platform/fa962338be0b3f185731ca3d3a987aca67ec48c2/src/components/contracts/modules/evm/tests/contracts/abi/IERC20.bin -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/tests/contracts/abi/IERC20Metadata.abi: -------------------------------------------------------------------------------- 1 | [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/tests/contracts/abi/IERC20Metadata.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindoraNetwork/platform/fa962338be0b3f185731ca3d3a987aca67ec48c2/src/components/contracts/modules/evm/tests/contracts/abi/IERC20Metadata.bin -------------------------------------------------------------------------------- /src/components/contracts/modules/evm/tests/utils/mod.rs: -------------------------------------------------------------------------------- 1 | mod erc20; 2 | mod solidity; 3 | 4 | pub use erc20::*; 5 | pub use solidity::*; 6 | -------------------------------------------------------------------------------- /src/components/contracts/modules/template/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "module-template" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora template module for value store" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 13 | ruc = "1.0" 14 | serde = { version = "1.0.124", features = ["derive"] } 15 | serde_json = "1.0" 16 | 17 | # primitives, don't depend on any modules 18 | fp-core = { path = "../../primitives/core" } 19 | fp-storage = { path = "../../primitives/storage" } 20 | fp-types = { path = "../../primitives/types" } 21 | fp-utils = { path = "../../primitives/utils" } 22 | 23 | [dev-dependencies] 24 | fp-mocks = { path = "../../primitives/mocks" } 25 | fp-traits = { path = "../../primitives/traits" } 26 | module-account = { path = "../../modules/account" } 27 | -------------------------------------------------------------------------------- /src/components/contracts/modules/template/README.md: -------------------------------------------------------------------------------- 1 | # Template Module 2 | Developers can copy the module when adding a new module, and then add application logic. -------------------------------------------------------------------------------- /src/components/contracts/modules/template/src/basic.rs: -------------------------------------------------------------------------------- 1 | use super::{App, Config, MODULE_NAME}; 2 | use fp_core::module::AppModuleBasic; 3 | use ruc::Result; 4 | 5 | impl AppModuleBasic for App { 6 | fn name() -> String { 7 | MODULE_NAME.into() 8 | } 9 | 10 | fn default_genesis(&self) -> Vec { 11 | todo!() 12 | } 13 | 14 | fn init_genesis(&self) { 15 | todo!() 16 | } 17 | 18 | fn validate_genesis(&self) -> Result<()> { 19 | todo!() 20 | } 21 | 22 | fn export_genesis(&self) { 23 | todo!() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/components/contracts/modules/template/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | mod basic; 5 | 6 | pub use crate::storage::*; 7 | use fp_core::{ 8 | context::Context, 9 | module::AppModule, 10 | transaction::{ActionResult, Executable}, 11 | }; 12 | // use fp_storage::{hash::StoragePrefixKey, Deref, StatelessStore}; 13 | use abci::{RequestQuery, ResponseQuery}; 14 | use fp_storage::BorrowMut; 15 | use fp_types::{actions::template::Action, crypto::Address}; 16 | use ruc::Result; 17 | use std::marker::PhantomData; 18 | 19 | pub const MODULE_NAME: &str = "template"; 20 | 21 | pub trait Config {} 22 | 23 | mod storage { 24 | use fp_storage::*; 25 | 26 | // Two new types will be defined: 27 | // 1. type ValueStore = StorageValue (at /primitive/storage/types/value.rs) 28 | // 2. ValueStoreInstance: which ("ValueStore" + "Instance") impls StatelessStore traits 29 | generate_storage!(Template, ValueStore => Value); 30 | } 31 | 32 | #[derive(Clone)] 33 | pub struct App { 34 | phantom: PhantomData, 35 | } 36 | 37 | impl Default for App { 38 | fn default() -> Self { 39 | App { 40 | phantom: Default::default(), 41 | } 42 | } 43 | } 44 | 45 | impl AppModule for App { 46 | fn query_route( 47 | &self, 48 | ctx: Context, 49 | path: Vec<&str>, 50 | _req: &RequestQuery, 51 | ) -> ResponseQuery { 52 | let mut resp = ResponseQuery::default(); 53 | if path.len() != 1 { 54 | resp.code = 1; 55 | resp.log = String::from("template: invalid query path"); 56 | return resp; 57 | } 58 | 59 | let value = ValueStore::get(&ctx.state.read()).unwrap_or_default(); 60 | 61 | // let value: u64 = ::get_obj( 62 | // ctx.store.read().deref(), 63 | // ValueStore::store_key().as_ref(), 64 | // ) 65 | // .unwrap() 66 | // .unwrap_or_default(); 67 | 68 | resp.value = serde_json::to_vec(&value).unwrap_or_default(); 69 | resp 70 | } 71 | } 72 | 73 | impl Executable for App { 74 | type Origin = Address; 75 | type Call = Action; 76 | 77 | fn execute( 78 | _origin: Option, 79 | call: Self::Call, 80 | ctx: &Context, 81 | ) -> Result { 82 | match call { 83 | Action::SetValue(v) => ValueStore::put(ctx.state.write().borrow_mut(), &v) 84 | .map(|()| ActionResult { 85 | data: v.to_be_bytes().to_vec(), 86 | ..Default::default() 87 | }), 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/components/contracts/modules/xhub/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "module-xhub" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "UTXO and Account state transit hub" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 13 | lazy_static = "1.4.0" 14 | ledger = { path = "../../../../ledger" } 15 | tracing = "0.1" 16 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 17 | ruc = "1.0" 18 | serde = { version = "1.0.124", features = ["derive"] } 19 | serde_json = "1.0" 20 | 21 | # primitives, don't depend on any modules 22 | fp-core = { path = "../../primitives/core" } 23 | fp-storage = { path = "../../primitives/storage" } 24 | fp-traits = { path = "../../primitives/traits" } 25 | fp-types = { path = "../../primitives/types" } 26 | 27 | [dev-dependencies] 28 | fp-mocks = { path = "../../primitives/mocks" } 29 | -------------------------------------------------------------------------------- /src/components/contracts/modules/xhub/README.md: -------------------------------------------------------------------------------- 1 | # XHub Module 2 | UTXO and Account state transit hub. -------------------------------------------------------------------------------- /src/components/contracts/modules/xhub/src/basic.rs: -------------------------------------------------------------------------------- 1 | use super::{App, Config, MODULE_NAME}; 2 | use fp_core::module::AppModuleBasic; 3 | use ruc::Result; 4 | 5 | impl AppModuleBasic for App { 6 | fn name() -> String { 7 | MODULE_NAME.into() 8 | } 9 | 10 | fn default_genesis(&self) -> Vec { 11 | todo!() 12 | } 13 | 14 | fn init_genesis(&self) { 15 | todo!() 16 | } 17 | 18 | fn validate_genesis(&self) -> Result<()> { 19 | todo!() 20 | } 21 | 22 | fn export_genesis(&self) { 23 | todo!() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/components/contracts/modules/xhub/src/impls.rs: -------------------------------------------------------------------------------- 1 | use crate::storage::*; 2 | use crate::{App, Config}; 3 | use fp_core::{context::Context, ensure, transaction::ActionResult}; 4 | use fp_storage::BorrowMut; 5 | use fp_traits::{account::AccountAsset, evm::DecimalsMapping}; 6 | use fp_types::actions::xhub::NonConfidentialTransfer; 7 | use fp_types::{actions::xhub::NonConfidentialOutput, crypto::Address}; 8 | use ledger::data_model::ASSET_TYPE_FRA; 9 | use primitive_types::U256; 10 | use ruc::*; 11 | use tracing::debug; 12 | 13 | impl App { 14 | pub fn transfer_to_nonconfidential_utxo( 15 | ctx: &Context, 16 | sender: Address, 17 | call: NonConfidentialTransfer, 18 | ) -> Result { 19 | let mut transfer_amount = 0; 20 | for output in &call.outputs { 21 | ensure!( 22 | output.asset == ASSET_TYPE_FRA, 23 | "Invalid asset type only support FRA" 24 | ); 25 | transfer_amount += output.amount; 26 | } 27 | 28 | debug!(target: "xhub", "transfer to UTXO {} FRA", transfer_amount); 29 | 30 | ensure!( 31 | call.input_value == transfer_amount, 32 | "Input value mismatch utxo output" 33 | ); 34 | 35 | let amount = C::DecimalsMapping::from_native_token(U256::from(transfer_amount)) 36 | .ok_or_else(|| eg!("the transfer to UTXO amount is too large"))?; 37 | 38 | let sa = C::AccountAsset::account_of(ctx, &sender, None) 39 | .c(d!("account does not exist"))?; 40 | if sa.balance < amount { 41 | return Err(eg!("insufficient balance")); 42 | } 43 | 44 | if !amount.is_zero() { 45 | C::AccountAsset::burn(ctx, &sender, amount)?; 46 | Self::add_mint(ctx, call.outputs)?; 47 | } 48 | Ok(ActionResult::default()) 49 | } 50 | 51 | pub(crate) fn add_mint( 52 | ctx: &Context, 53 | mut outputs: Vec, 54 | ) -> Result<()> { 55 | let ops = if let Some(mut ori_outputs) = PendingUTXOs::get(&ctx.db.read()) { 56 | ori_outputs.append(&mut outputs); 57 | ori_outputs 58 | } else { 59 | outputs 60 | }; 61 | PendingUTXOs::put(ctx.db.write().borrow_mut(), &ops) 62 | } 63 | 64 | pub fn consume_mint(ctx: &Context) -> Option> { 65 | PendingUTXOs::take(ctx.db.write().borrow_mut()) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/components/contracts/modules/xhub/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | mod basic; 5 | mod impls; 6 | 7 | use fp_core::{ 8 | context::Context, 9 | module::AppModule, 10 | transaction::{ActionResult, Executable}, 11 | }; 12 | use fp_traits::{account::AccountAsset, evm::DecimalsMapping}; 13 | use fp_types::{actions::xhub::Action, crypto::Address}; 14 | use ruc::*; 15 | use std::marker::PhantomData; 16 | 17 | pub const MODULE_NAME: &str = "xhub"; 18 | 19 | pub trait Config { 20 | /// Account module interface to read/write account assets. 21 | type AccountAsset: AccountAsset
; 22 | /// Mapping from eth decimals to native token decimals. 23 | type DecimalsMapping: DecimalsMapping; 24 | } 25 | 26 | mod storage { 27 | use fp_types::actions::xhub::NonConfidentialOutput; 28 | 29 | use fp_storage::*; 30 | 31 | // The following data is stored in non-state rocksdb 32 | // account balance transfer to utxo waiting to be mint. 33 | generate_storage!(XHub, PendingUTXOs => Value>); 34 | } 35 | 36 | #[derive(Clone)] 37 | pub struct App { 38 | phantom: PhantomData, 39 | } 40 | 41 | impl Default for App { 42 | fn default() -> Self { 43 | App { 44 | phantom: Default::default(), 45 | } 46 | } 47 | } 48 | 49 | impl AppModule for App {} 50 | 51 | impl Executable for App { 52 | type Origin = Address; 53 | type Call = Action; 54 | 55 | fn execute( 56 | origin: Option, 57 | call: Self::Call, 58 | ctx: &Context, 59 | ) -> Result { 60 | match call { 61 | Action::NonConfidentialTransfer(action) => { 62 | if let Some(sender) = origin { 63 | Self::transfer_to_nonconfidential_utxo(ctx, sender, action) 64 | } else { 65 | Err(eg!("invalid transaction origin")) 66 | } 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-core" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora Primitive core types" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6", optional = true } 13 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 14 | impl-trait-for-tuples = "0.2" 15 | parking_lot = "0.12" 16 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 17 | ruc = "1.0" 18 | serde = { version = "1.0.124", features = ["derive"] } 19 | storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9", optional = true } 20 | fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9", optional = true } 21 | serde_with = { version = "1.9.4"} 22 | 23 | # primitives 24 | fp-types = { path = "../types" } 25 | config = { path = "../../../config"} 26 | 27 | [features] 28 | default = ["with-storage-net"] 29 | with-storage-net = ["storage", "fin_db", "abci"] 30 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/core/src/account.rs: -------------------------------------------------------------------------------- 1 | use primitive_types::U256; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] 5 | pub struct SmartAccount { 6 | /// Account nonce. 7 | pub nonce: U256, 8 | /// Account balance(native asset). Note: decimals is 6. 9 | pub balance: U256, 10 | /// Balance which is reserved and may not be used. 11 | /// such as: staking deposit, transaction fee 12 | pub reserved: U256, 13 | } 14 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/core/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | pub mod account; 5 | #[cfg(feature = "with-storage-net")] 6 | pub mod context; 7 | pub mod macros; 8 | #[cfg(feature = "with-storage-net")] 9 | pub mod module; 10 | #[cfg(feature = "with-storage-net")] 11 | pub mod transaction; 12 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/core/src/module.rs: -------------------------------------------------------------------------------- 1 | use crate::context::Context; 2 | use abci::*; 3 | use fp_types::U256; 4 | use ruc::Result; 5 | 6 | /// AppModuleBasic is the standard form for basic non-dependant elements of an application module. 7 | pub trait AppModuleBasic { 8 | /// Returns the module's name. 9 | fn name() -> String; 10 | 11 | /// Returns default genesis state as raw bytes for the module. 12 | fn default_genesis(&self) -> Vec; 13 | 14 | /// Performs genesis initialization for the module. It returns no validator updates. 15 | fn init_genesis(&self); 16 | 17 | /// Performs genesis state validation for the module. 18 | fn validate_genesis(&self) -> Result<()>; 19 | 20 | /// Returns the exported genesis state as raw bytes for the module. 21 | fn export_genesis(&self); 22 | } 23 | 24 | /// AppModule is the standard form for an application module 25 | pub trait AppModule: AppModuleBasic { 26 | /// query_route returns the application module's query response. 27 | fn query_route( 28 | &self, 29 | _ctx: Context, 30 | _path: Vec<&str>, 31 | _req: &RequestQuery, 32 | ) -> ResponseQuery { 33 | Default::default() 34 | } 35 | 36 | /// Tendermint consensus connection: called at the start of processing a block of transactions. 37 | fn begin_block(&mut self, _ctx: &mut Context, _req: &RequestBeginBlock) {} 38 | 39 | /// Tendermint consensus connection: called at the end of the block. 40 | fn end_block( 41 | &mut self, 42 | _ctx: &mut Context, 43 | _req: &RequestEndBlock, 44 | _ff_addr_balance: u64, 45 | ) -> ResponseEndBlock { 46 | Default::default() 47 | } 48 | 49 | fn commit( 50 | &mut self, 51 | _ctx: &mut Context, 52 | _height: U256, 53 | _root_hash: &[u8], 54 | ) -> Result<()> { 55 | Ok(()) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/enterprise-web3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "enterprise-web3" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | lazy_static = "1.4.0" 10 | evm-exporter = { package = "evm-exporter", git = "https://github.com/FindoraNetwork/enterprise-web3.git", tag = "1.2.1"} 11 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 12 | primitive-types = "0.11.1" 13 | redis = { version = "0.21", default-features = false, features = [ "tls", "r2d2" ] } 14 | r2d2 = { version = "0.8.8"} 15 | ruc = "1.0" 16 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/events/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-events" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora Primitive transaction events" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 13 | fp-event-derive = { path = "event-derive" } 14 | protobuf = "2.16" 15 | serde_json = "1.0" 16 | 17 | [dev-dependencies] 18 | serde = { version = "1.0.124", features = ["derive"] } 19 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/events/event-derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-event-derive" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Proc derive macro for findora transaction events" 9 | readme = "README.md" 10 | 11 | [lib] 12 | proc-macro = true 13 | 14 | [dependencies] 15 | quote = "1" 16 | syn = "1" 17 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/events/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | #[cfg(test)] 5 | mod tests; 6 | 7 | pub use abci::{Event as AbciEvent, Pair as AbciPair}; 8 | pub use fp_event_derive::Event; 9 | pub use protobuf::RepeatedField; 10 | pub use serde_json::to_vec; 11 | 12 | pub trait Event { 13 | /// Generates `Event` where value types are all casted to strings. 14 | #[allow(clippy::wrong_self_convention)] 15 | fn emit_event(field_type: String, structure: Self) -> AbciEvent; 16 | 17 | /// Generates `Event` where value types are serializable. 18 | #[allow(clippy::wrong_self_convention)] 19 | fn emit_serde_event(field_type: String, structure: Self) -> AbciEvent; 20 | } 21 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/events/src/tests.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Event)] 5 | struct MockEvent { 6 | name: String, 7 | value: u64, 8 | } 9 | 10 | #[derive(Debug, Deserialize, Serialize)] 11 | struct TestPair { 12 | key: String, 13 | val: String, 14 | } 15 | 16 | #[derive(Event)] 17 | struct MockEvent2 { 18 | name: String, 19 | value: TestPair, 20 | } 21 | 22 | #[test] 23 | fn test_emit_event() { 24 | let test_struct = MockEvent { 25 | name: String::from("example"), 26 | value: 10, 27 | }; 28 | let pair = AbciPair::default(); 29 | 30 | let event = Event::emit_event("mock".to_string(), test_struct); 31 | assert_eq!(event.get_field_type(), "mock_MockEvent"); 32 | assert_eq!( 33 | event.attributes.to_vec(), 34 | vec![ 35 | AbciPair { 36 | key: "name".as_bytes().to_vec(), 37 | value: serde_json::to_vec("example").unwrap(), 38 | ..pair.clone() 39 | }, 40 | AbciPair { 41 | key: "value".as_bytes().to_vec(), 42 | value: 10_u32.to_string().as_bytes().to_vec(), 43 | ..pair 44 | } 45 | ] 46 | ); 47 | } 48 | 49 | #[test] 50 | fn test_emit_serde_event() { 51 | let test_struct = MockEvent2 { 52 | name: String::from("example"), 53 | value: TestPair { 54 | key: String::from("key"), 55 | val: String::from("100"), 56 | }, 57 | }; 58 | let pair = AbciPair::default(); 59 | 60 | let event = Event::emit_serde_event("mock".to_string(), test_struct); 61 | assert_eq!(event.get_field_type(), "mock_MockEvent2"); 62 | assert_eq!( 63 | event.attributes.to_vec(), 64 | vec![ 65 | AbciPair { 66 | key: "name".as_bytes().to_vec(), 67 | value: serde_json::to_vec("example").unwrap(), 68 | ..pair.clone() 69 | }, 70 | AbciPair { 71 | key: "value".as_bytes().to_vec(), 72 | value: serde_json::to_vec(&TestPair { 73 | key: String::from("key"), 74 | val: String::from("100"), 75 | }) 76 | .unwrap(), 77 | ..pair 78 | } 79 | ] 80 | ); 81 | } 82 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/evm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-evm" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora Primitive EVM abstractions types" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 13 | ethereum-types = { version = "0.13.1", default-features = false } 14 | evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } 15 | ruc = "1.0" 16 | serde = { version = "1.0.124", features = ["derive"] } 17 | 18 | # primitives 19 | fp-core = { path = "../core" } 20 | fp-types = { path = "../types" } 21 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/evm/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | pub use ethereum::Log; 5 | use ethereum_types::{Bloom, H160, H256, U256}; 6 | pub use evm::backend::Basic as Account; 7 | use evm::ExitReason; 8 | use fp_core::context::Context; 9 | use fp_types::actions::evm::{Call, Create, Create2}; 10 | use ruc::*; 11 | use serde::{Deserialize, Serialize}; 12 | 13 | #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize, Default)] 14 | /// External input from the transaction. 15 | pub struct Vicinity { 16 | /// Current transaction gas price. 17 | pub gas_price: U256, 18 | /// Origin of the transaction. 19 | pub origin: H160, 20 | } 21 | 22 | #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] 23 | pub struct ExecutionInfo { 24 | pub exit_reason: ExitReason, 25 | pub value: T, 26 | pub used_gas: U256, 27 | pub logs: Vec, 28 | } 29 | 30 | pub type CallInfo = ExecutionInfo>; 31 | pub type CreateInfo = ExecutionInfo; 32 | 33 | #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] 34 | pub enum CallOrCreateInfo { 35 | Call(CallInfo), 36 | Create(CreateInfo), 37 | } 38 | 39 | #[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, Default)] 40 | pub struct TransactionStatus { 41 | pub transaction_hash: H256, 42 | pub transaction_index: u32, 43 | pub from: H160, 44 | pub to: Option, 45 | pub contract_address: Option, 46 | pub logs: Vec, 47 | pub logs_bloom: Bloom, 48 | } 49 | 50 | pub trait Runner { 51 | fn call(ctx: &Context, args: Call, config: &evm::Config) -> Result; 52 | 53 | fn create(ctx: &Context, args: Create, config: &evm::Config) -> Result; 54 | 55 | fn create2(ctx: &Context, args: Create2, config: &evm::Config) 56 | -> Result; 57 | } 58 | 59 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 60 | pub enum BlockId { 61 | /// Identify by block header hash. 62 | Hash(H256), 63 | /// Identify by block number. 64 | Number(U256), 65 | } 66 | 67 | impl BlockId { 68 | /// Create a block ID from a hash. 69 | pub fn hash(hash: H256) -> Self { 70 | BlockId::Hash(hash) 71 | } 72 | 73 | /// Create a block ID from a number. 74 | pub fn number(number: U256) -> Self { 75 | BlockId::Number(number) 76 | } 77 | } 78 | 79 | impl core::fmt::Display for BlockId { 80 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 81 | write!(f, "{self:?}") 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/mocks/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-mocks" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora primitive mock functions for testing" 9 | 10 | [dependencies] 11 | abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.6" } 12 | baseapp = { path = "../../baseapp" } 13 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 14 | lazy_static = "1.4.0" 15 | libsecp256k1 = { version = "0.7", features = ["static-context", "hmac"] } 16 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 17 | rand_chacha = "0.3" 18 | rlp = "0.5" 19 | serde_json = "1.0" 20 | sha3 = "0.10" 21 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 22 | 23 | # primitives 24 | fp-traits = { path = "../traits" } 25 | fp-types = { path = "../types" } 26 | fp-utils = { path = "../utils" } 27 | 28 | # modules 29 | module-account = { path = "../../modules/account" } 30 | 31 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-rpc-core" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "RPC traits of Ethereum." 9 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 10 | 11 | [dependencies] 12 | ethereum-types = "0.13.1" 13 | futures = "0.3.16" 14 | jsonrpc-core = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-core" } 15 | jsonrpc-core-client = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-core-client" } 16 | jsonrpc-derive = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-derive" } 17 | jsonrpc-pubsub = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-pubsub" } 18 | rustc-hex = "2.1.0" 19 | serde = { version = "1.0", features = ["derive"] } 20 | serde_json = "1.0" 21 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/eth_filter.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Eth filter rpc interface. 20 | 21 | use ethereum_types::U256; 22 | use jsonrpc_core::Result; 23 | use jsonrpc_derive::rpc; 24 | 25 | use crate::types::{Filter, FilterChanges, Index, Log}; 26 | 27 | pub use rpc_impl_EthFilterApi::gen_server::EthFilterApi as EthFilterApiServer; 28 | 29 | /// Eth filters rpc api (polling). 30 | #[rpc(server)] 31 | pub trait EthFilterApi { 32 | /// Returns id of new filter. 33 | #[rpc(name = "eth_newFilter")] 34 | fn new_filter(&self, _: Filter) -> Result; 35 | 36 | /// Returns id of new block filter. 37 | #[rpc(name = "eth_newBlockFilter")] 38 | fn new_block_filter(&self) -> Result; 39 | 40 | /// Returns id of new block filter. 41 | #[rpc(name = "eth_newPendingTransactionFilter")] 42 | fn new_pending_transaction_filter(&self) -> Result; 43 | 44 | /// Returns filter changes since last poll. 45 | #[rpc(name = "eth_getFilterChanges")] 46 | fn filter_changes(&self, _: Index) -> Result; 47 | 48 | /// Returns all logs matching given filter (in a range 'from' - 'to'). 49 | #[rpc(name = "eth_getFilterLogs")] 50 | fn filter_logs(&self, _: Index) -> Result>; 51 | 52 | /// Uninstalls filter. 53 | #[rpc(name = "eth_uninstallFilter")] 54 | fn uninstall_filter(&self, _: Index) -> Result; 55 | } 56 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/eth_pubsub.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Eth PUB-SUB rpc interface. 20 | 21 | use jsonrpc_core::Result; 22 | use jsonrpc_derive::rpc; 23 | use jsonrpc_pubsub::{typed, SubscriptionId}; 24 | 25 | use crate::types::pubsub; 26 | 27 | pub use rpc_impl_EthPubSubApi::gen_server::EthPubSubApi as EthPubSubApiServer; 28 | 29 | /// Eth PUB-SUB rpc interface. 30 | #[rpc(server)] 31 | pub trait EthPubSubApi { 32 | /// RPC Metadata 33 | type Metadata; 34 | 35 | /// Subscribe to Eth subscription. 36 | #[pubsub(subscription = "eth_subscription", subscribe, name = "eth_subscribe")] 37 | fn subscribe( 38 | &self, 39 | _: Self::Metadata, 40 | _: typed::Subscriber, 41 | _: pubsub::Kind, 42 | _: Option, 43 | ); 44 | 45 | /// Unsubscribe from existing Eth subscription. 46 | #[pubsub( 47 | subscription = "eth_subscription", 48 | unsubscribe, 49 | name = "eth_unsubscribe" 50 | )] 51 | fn unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; 52 | } 53 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | mod eth; 20 | mod eth_filter; 21 | mod eth_pubsub; 22 | mod net; 23 | mod web3; 24 | 25 | pub mod types; 26 | 27 | pub use eth::{EthApi, EthApiServer}; 28 | pub use eth_filter::{EthFilterApi, EthFilterApiServer}; 29 | pub use eth_pubsub::{EthPubSubApi, EthPubSubApiServer}; 30 | pub use net::{NetApi, NetApiServer}; 31 | pub use web3::{Web3Api, Web3ApiServer}; 32 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/net.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Net rpc interface. 20 | use crate::types::PeerCount; 21 | use jsonrpc_core::{BoxFuture, Result}; 22 | use jsonrpc_derive::rpc; 23 | 24 | pub use rpc_impl_NetApi::gen_server::NetApi as NetApiServer; 25 | 26 | /// Net rpc interface. 27 | #[rpc(server)] 28 | pub trait NetApi { 29 | /// Returns protocol version. 30 | #[rpc(name = "net_version")] 31 | fn version(&self) -> BoxFuture>; 32 | 33 | /// Returns number of peers connected to node. 34 | #[rpc(name = "net_peerCount")] 35 | fn peer_count(&self) -> BoxFuture>; 36 | 37 | /// Returns true if client is actively listening for network connections. 38 | /// Otherwise false. 39 | #[rpc(name = "net_listening")] 40 | fn is_listening(&self) -> BoxFuture>; 41 | } 42 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/types/call_request.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use crate::types::Bytes; 20 | use ethereum_types::{H160, U256}; 21 | use serde::Deserialize; 22 | 23 | /// Call request 24 | #[derive(Debug, Default, PartialEq, Eq, Deserialize, Clone)] 25 | #[serde(deny_unknown_fields)] 26 | #[serde(rename_all = "camelCase")] 27 | pub struct CallRequest { 28 | /// From 29 | pub from: Option, 30 | /// To 31 | pub to: Option, 32 | /// Gas Price 33 | pub gas_price: Option, 34 | /// Gas 35 | pub gas: Option, 36 | /// Value 37 | pub value: Option, 38 | /// Data 39 | pub data: Option, 40 | /// Nonce 41 | pub nonce: Option, 42 | } 43 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/types/log.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use crate::types::Bytes; 20 | use ethereum_types::{H160, H256, U256}; 21 | use serde::Serialize; 22 | 23 | /// Log 24 | #[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)] 25 | #[serde(rename_all = "camelCase")] 26 | pub struct Log { 27 | /// H160 28 | pub address: H160, 29 | /// Topics 30 | pub topics: Vec, 31 | /// Data 32 | pub data: Bytes, 33 | /// Block Hash 34 | pub block_hash: Option, 35 | /// Block Number 36 | pub block_number: Option, 37 | /// Transaction Hash 38 | pub transaction_hash: Option, 39 | /// Transaction Index 40 | pub transaction_index: Option, 41 | /// Log Index in Block 42 | pub log_index: Option, 43 | /// Log Index in Transaction 44 | pub transaction_log_index: Option, 45 | /// Whether Log Type is Removed (Geth Compatibility Field) 46 | #[serde(default)] 47 | pub removed: bool, 48 | } 49 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! RPC types 20 | 21 | mod account_info; 22 | mod block; 23 | mod block_number; 24 | mod bytes; 25 | mod call_request; 26 | mod filter; 27 | mod index; 28 | mod log; 29 | mod receipt; 30 | mod sync; 31 | mod transaction; 32 | mod transaction_request; 33 | mod work; 34 | 35 | pub mod pubsub; 36 | 37 | pub use self::account_info::{ 38 | AccountInfo, EthAccount, ExtAccountInfo, RecoveredAccount, StorageProof, 39 | }; 40 | pub use self::block::{Block, BlockTransactions, Header, Rich, RichBlock, RichHeader}; 41 | pub use self::block_number::BlockNumber; 42 | pub use self::bytes::Bytes; 43 | pub use self::call_request::CallRequest; 44 | pub use self::filter::{ 45 | Filter, FilterAddress, FilterChanges, FilterPool, FilterPoolItem, FilterType, 46 | FilteredParams, Topic, VariadicValue, 47 | }; 48 | pub use self::index::Index; 49 | pub use self::log::Log; 50 | pub use self::receipt::Receipt; 51 | pub use self::sync::{ 52 | ChainStatus, EthProtocolInfo, PeerCount, PeerInfo, PeerNetworkInfo, 53 | PeerProtocolsInfo, Peers, PipProtocolInfo, SyncInfo, SyncStatus, TransactionStats, 54 | }; 55 | pub use self::transaction::{ 56 | LocalTransactionStatus, PendingTransaction, PendingTransactions, RichRawTransaction, 57 | Transaction, 58 | }; 59 | pub use self::transaction_request::TransactionRequest; 60 | pub use self::work::Work; 61 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/types/receipt.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use crate::types::Log; 20 | use ethereum_types::{Bloom as H2048, H160, H256, U256, U64}; 21 | use serde::Serialize; 22 | 23 | /// Receipt 24 | #[derive(Debug, Serialize)] 25 | #[serde(rename_all = "camelCase")] 26 | pub struct Receipt { 27 | /// Transaction Hash 28 | pub transaction_hash: Option, 29 | /// Transaction index 30 | pub transaction_index: Option, 31 | /// Block hash 32 | pub block_hash: Option, 33 | /// Sender 34 | pub from: Option, 35 | /// Recipient 36 | pub to: Option, 37 | /// Block number 38 | pub block_number: Option, 39 | /// Cumulative gas used 40 | pub cumulative_gas_used: U256, 41 | /// Gas used 42 | pub gas_used: Option, 43 | /// Contract address 44 | pub contract_address: Option, 45 | /// Logs 46 | pub logs: Vec, 47 | /// State Root 48 | // NOTE(niklasad1): EIP98 makes this optional field, if it's missing then skip serializing it 49 | #[serde(skip_serializing_if = "Option::is_none", rename = "root")] 50 | pub state_root: Option, 51 | /// Logs bloom 52 | pub logs_bloom: H2048, 53 | /// Status code 54 | // NOTE(niklasad1): Unknown after EIP98 rules, if it's missing then skip serializing it 55 | #[serde(skip_serializing_if = "Option::is_none", rename = "status")] 56 | pub status_code: Option, 57 | } 58 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/types/transaction_request.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! `TransactionRequest` type 20 | 21 | use crate::types::Bytes; 22 | use ethereum_types::{H160, U256}; 23 | use serde::{Deserialize, Serialize}; 24 | 25 | /// Transaction request coming from RPC 26 | #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] 27 | #[serde(deny_unknown_fields)] 28 | #[serde(rename_all = "camelCase")] 29 | pub struct TransactionRequest { 30 | /// Sender 31 | pub from: Option, 32 | /// Recipient 33 | pub to: Option, 34 | /// Gas Price 35 | pub gas_price: Option, 36 | /// Gas 37 | pub gas: Option, 38 | /// Value of transaction in wei 39 | pub value: Option, 40 | /// Additional data sent with transaction 41 | pub data: Option, 42 | /// Transaction's nonce 43 | pub nonce: Option, 44 | } 45 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/types/work.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use ethereum_types::{H256, U256}; 20 | 21 | use serde::{Serialize, Serializer}; 22 | 23 | /// The result of an `eth_getWork` call: it differs based on an option 24 | /// whether to send the block number. 25 | #[derive(Debug, PartialEq, Eq)] 26 | pub struct Work { 27 | /// The proof-of-work hash. 28 | pub pow_hash: H256, 29 | /// The seed hash. 30 | pub seed_hash: H256, 31 | /// The target. 32 | pub target: H256, 33 | /// The block number: this isn't always stored. 34 | pub number: Option, 35 | } 36 | 37 | impl Serialize for Work { 38 | fn serialize(&self, s: S) -> Result 39 | where 40 | S: Serializer, 41 | { 42 | match self.number.as_ref() { 43 | Some(num) => ( 44 | &self.pow_hash, 45 | &self.seed_hash, 46 | &self.target, 47 | U256::from(*num), 48 | ) 49 | .serialize(s), 50 | None => (&self.pow_hash, &self.seed_hash, &self.target).serialize(s), 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-core/src/web3.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Web3 rpc interface. 20 | use ethereum_types::H256; 21 | use jsonrpc_core::Result; 22 | use jsonrpc_derive::rpc; 23 | 24 | use crate::types::Bytes; 25 | 26 | pub use rpc_impl_Web3Api::gen_server::Web3Api as Web3ApiServer; 27 | 28 | /// Web3 rpc interface. 29 | #[rpc(server)] 30 | pub trait Web3Api { 31 | /// Returns current client version. 32 | #[rpc(name = "web3_clientVersion")] 33 | fn client_version(&self) -> Result; 34 | 35 | /// Returns sha3 of the given data 36 | #[rpc(name = "web3_sha3")] 37 | fn sha3(&self, _: Bytes) -> Result; 38 | } 39 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-server/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-rpc-server" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 9 | description = "EVM RPC servers." 10 | readme = "README.md" 11 | 12 | [dependencies] 13 | futures = "0.3.16" 14 | jsonrpc-core = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-core" } 15 | pubsub = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-pubsub" } 16 | tracing = "0.1" 17 | serde_json = "1.0.41" 18 | 19 | http = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-http-server" } 20 | ipc = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-ipc-server" } 21 | ws = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-ws-server" } 22 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/rpc-server/src/middleware.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2020-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Middleware for RPC requests. 20 | 21 | use futures::{future::Either, Future}; 22 | use jsonrpc_core::{ 23 | FutureOutput, FutureResponse, Metadata, Middleware as RequestMiddleware, Request, 24 | Response, 25 | }; 26 | 27 | /// Middleware for RPC calls 28 | pub struct RpcMiddleware; 29 | 30 | impl RpcMiddleware { 31 | /// Create an instance of middleware. 32 | /// 33 | /// - `metrics`: Will be used to report statistics. 34 | /// - `transport_label`: The label that is used when reporting the statistics. 35 | pub fn new() -> Self { 36 | RpcMiddleware {} 37 | } 38 | } 39 | 40 | impl Default for RpcMiddleware { 41 | fn default() -> Self { 42 | Self::new() 43 | } 44 | } 45 | 46 | impl RequestMiddleware for RpcMiddleware { 47 | type Future = FutureResponse; 48 | type CallFuture = FutureOutput; 49 | 50 | fn on_request( 51 | &self, 52 | request: Request, 53 | meta: M, 54 | next: F, 55 | ) -> Either 56 | where 57 | F: Fn(Request, M) -> X + Send + Sync, 58 | X: Future> + Send + 'static, 59 | { 60 | Either::Right(next(request, meta)) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/storage/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-storage" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora Primitive storage structure definition" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | parking_lot = "0.12" 13 | paste = "1.0" 14 | ruc = "1.0" 15 | serde = { version = "1.0.124", features = ["derive"] } 16 | serde_json = "1.0" 17 | sha2 = "0.9.5" 18 | storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 19 | 20 | # primitives 21 | fp-core = { path = "../core" } 22 | config = { path = "../../../config"} 23 | 24 | [dev-dependencies] 25 | temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.9" } 26 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/storage/src/hash.rs: -------------------------------------------------------------------------------- 1 | use sha2::Digest; 2 | 3 | /// Hasher to use to hash keys to insert to storage. 4 | pub trait StorageHasher: 'static { 5 | type Output: AsRef<[u8]>; 6 | fn hash(x: &[u8]) -> Self::Output; 7 | } 8 | 9 | pub struct Sha256; 10 | 11 | impl StorageHasher for Sha256 { 12 | type Output = [u8; 32]; 13 | 14 | fn hash(x: &[u8]) -> Self::Output { 15 | let mut dest = [0; 32]; 16 | dest.copy_from_slice(sha2::Sha256::digest(x).as_slice()); 17 | dest 18 | } 19 | } 20 | 21 | /// Get the storage hashed key. 22 | pub trait StorageHashedKey { 23 | fn store_key() -> Vec; 24 | } 25 | 26 | /// Get the storage prefix key. 27 | pub trait StoragePrefixKey { 28 | fn store_key() -> Vec; 29 | } 30 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/storage/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | mod double_map; 2 | mod map; 3 | mod value; 4 | 5 | pub use double_map::StorageDoubleMap; 6 | pub use map::StorageMap; 7 | pub use value::StorageValue; 8 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-traits" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora Primitive Trait definitions for all module interactions" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | # config = {path = "../../../config"} 13 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 14 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 15 | ruc = "1.0" 16 | 17 | # primitives 18 | fp-core = { path = "../core" } 19 | fp-evm = { path = "../evm" } 20 | fp-types = { path = "../types" } -------------------------------------------------------------------------------- /src/components/contracts/primitives/traits/src/account.rs: -------------------------------------------------------------------------------- 1 | use fp_core::{account::SmartAccount, context::Context}; 2 | use primitive_types::{H160, U256}; 3 | use ruc::Result; 4 | 5 | pub trait AccountAsset
{ 6 | /// The total units transferred from the UTXO side. 7 | fn total_issuance(ctx: &Context) -> U256; 8 | 9 | /// The smart account info of `who`. 10 | fn account_of( 11 | ctx: &Context, 12 | who: &Address, 13 | height: Option, 14 | ) -> Option; 15 | 16 | /// The balance of `who`. 17 | fn balance(ctx: &Context, who: &Address) -> U256; 18 | 19 | /// The reserved balance of `who`. 20 | fn reserved_balance(ctx: &Context, who: &Address) -> U256; 21 | 22 | /// The nonce of `who`. 23 | fn nonce(ctx: &Context, who: &Address) -> U256; 24 | 25 | /// The account executes new transactions and increase nonce 26 | fn inc_nonce(ctx: &Context, who: &Address) -> Result; 27 | 28 | /// Transfer some balance from `sender` to `dest` 29 | fn transfer( 30 | ctx: &Context, 31 | sender: &Address, 32 | dest: &Address, 33 | balance: U256, 34 | ) -> Result<()>; 35 | 36 | /// Mints `value` to the free balance of `who`. 37 | fn mint(ctx: &Context, target: &Address, balance: U256) -> Result<()>; 38 | 39 | /// Burns `value` to the free balance of `who`. 40 | fn burn(ctx: &Context, target: &Address, balance: U256) -> Result<()>; 41 | 42 | /// Removes some balance from `who` account. 43 | fn withdraw(ctx: &Context, who: &Address, value: U256) -> Result<()>; 44 | 45 | /// Refund some balance from `who` account. 46 | fn refund(ctx: &Context, who: &Address, value: U256) -> Result<()>; 47 | 48 | /// Returns the remaining number of tokens that `spender` will be allowed to spend on behalf 49 | /// of `owner` through {transferFrom}. This is zero by default. 50 | fn allowance(ctx: &Context, owner: &Address, spender: &Address) -> U256; 51 | 52 | /// Sets `amount` as the allowance of `spender` over the caller's tokens. 53 | fn approve( 54 | ctx: &Context, 55 | owner: &Address, 56 | owner_addr: H160, 57 | spender: &Address, 58 | spender_addr: H160, 59 | amount: U256, 60 | ) -> Result<()>; 61 | } 62 | 63 | /// Outputs the current transaction fee. 64 | pub trait FeeCalculator { 65 | fn min_fee() -> U256; 66 | } 67 | 68 | impl FeeCalculator for () { 69 | fn min_fee() -> U256 { 70 | U256::zero() 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/traits/src/base.rs: -------------------------------------------------------------------------------- 1 | use ethereum::{BlockV0 as Block, ReceiptV0 as Receipt}; 2 | use fp_core::account::SmartAccount; 3 | use fp_evm::BlockId; 4 | use fp_types::crypto::Address; 5 | use primitive_types::{H160, H256, U256}; 6 | use ruc::*; 7 | 8 | /// Provide query and call interface provided by each module. 9 | pub trait BaseProvider { 10 | fn account_of(&self, who: &Address, height: Option) -> Result; 11 | 12 | fn current_block(&self, id: Option) -> Option; 13 | 14 | fn current_block_number(&self) -> Option; 15 | 16 | fn current_transaction_statuses( 17 | &self, 18 | id: Option, 19 | ) -> Option>; 20 | 21 | fn current_receipts(&self, id: Option) -> Option>; 22 | 23 | fn block_hash(&self, id: Option) -> Option; 24 | 25 | fn transaction_index(&self, hash: H256) -> Option<(U256, u32)>; 26 | 27 | fn account_code_at(&self, address: H160, height: Option) -> Option>; 28 | 29 | fn account_storage_at( 30 | &self, 31 | address: H160, 32 | index: H256, 33 | height: Option, 34 | ) -> Option; 35 | } 36 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/traits/src/evm.rs: -------------------------------------------------------------------------------- 1 | use core::{convert::From, ops::Div}; 2 | use fp_core::context::Context; 3 | use fp_types::crypto::Address; 4 | use primitive_types::{H160, H256, U256}; 5 | use ruc::Result; 6 | 7 | pub trait AddressMapping { 8 | fn convert_to_account_id(address: H160) -> Address; 9 | } 10 | 11 | /// Ethereum address mapping. 12 | pub struct EthereumAddressMapping; 13 | 14 | impl AddressMapping for EthereumAddressMapping { 15 | fn convert_to_account_id(address: H160) -> Address { 16 | Address::from(address) 17 | } 18 | } 19 | 20 | /// A trait for getting a block hash by number. 21 | pub trait BlockHashMapping { 22 | fn block_hash(ctx: &Context, number: U256) -> Option; 23 | } 24 | 25 | pub trait DecimalsMapping { 26 | fn from_native_token(balance: U256) -> Option; 27 | 28 | fn convert_to_native_token(balance: U256) -> U256; 29 | } 30 | 31 | /// FRA decimals 32 | const FRA_DECIMALS: u32 = 6; 33 | 34 | /// ETH decimals 35 | const ETH_DECIMALS: u32 = 18; 36 | 37 | /// Ethereum decimals mapping. 38 | pub struct EthereumDecimalsMapping; 39 | 40 | impl DecimalsMapping for EthereumDecimalsMapping { 41 | fn from_native_token(balance: U256) -> Option { 42 | balance.checked_mul(U256::from(10_u64.pow(ETH_DECIMALS - FRA_DECIMALS))) 43 | } 44 | 45 | fn convert_to_native_token(balance: U256) -> U256 { 46 | balance.div(U256::from(10_u64.pow(ETH_DECIMALS - FRA_DECIMALS))) 47 | } 48 | } 49 | 50 | /// Trait that outputs the current transaction gas price. 51 | pub trait FeeCalculator { 52 | /// Return the minimal required gas price. 53 | fn min_gas_price() -> U256; 54 | fn max_gas_price() -> U256; 55 | } 56 | 57 | impl FeeCalculator for () { 58 | fn min_gas_price() -> U256 { 59 | // 10 GWEI, min gas limit: 21000, min gas price must > 50_0000_0000 60 | U256::from(100_0000_0000_u64) 61 | } 62 | fn max_gas_price() -> U256 { 63 | U256::from(5_000_000_000_000_u64) 64 | } 65 | } 66 | 67 | /// Handle withdrawing, refunding and depositing of transaction fees. 68 | pub trait OnChargeEVMTransaction { 69 | /// Before the transaction is executed the payment of the transaction fees 70 | /// need to be secured. 71 | fn withdraw_fee(ctx: &Context, who: &H160, fee: U256) -> Result<()>; 72 | 73 | /// After the transaction was executed the actual fee can be calculated. 74 | /// This function should refund any overpaid fees. 75 | fn correct_and_deposit_fee( 76 | ctx: &Context, 77 | who: &H160, 78 | corrected_fee: U256, 79 | already_withdrawn: U256, 80 | ) -> Result<()>; 81 | } 82 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/traits/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | pub mod account; 5 | pub mod base; 6 | pub mod evm; 7 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-types" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora Primitive data types" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | bech32 = "0.7.2" 13 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 14 | hex = "0.4.3" 15 | 16 | globutils = { git = "https://github.com/FindoraNetwork/platform-lib-utils", branch = "fix_dep" } 17 | 18 | libsecp256k1 = { version = "0.7", features = ["static-context", "hmac"] } 19 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 20 | ruc = "1.0" 21 | serde = { version = "1.0.124", features = ["derive"] } 22 | serde_json = "1.0" 23 | serde-big-array = "0.4" 24 | sha3 = "0.10" 25 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 26 | fixed-hash = "0.8.0" 27 | 28 | # primitives 29 | fp-utils = { path = "../utils" } 30 | 31 | [dev-dependencies] 32 | rand_chacha = "0.3" 33 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/actions/account.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | use zei::{ 3 | noah_api::xfr::structs::AssetType, XfrPublicKey 4 | }; 5 | 6 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 7 | pub enum Action { 8 | TransferToUTXO(TransferToUTXO), 9 | } 10 | 11 | /// Account balance convert to utxo balance. 12 | #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] 13 | pub struct MintOutput { 14 | pub asset: AssetType, 15 | pub amount: u64, 16 | pub target: XfrPublicKey, 17 | } 18 | 19 | /// Findora or Ethereum account address balance transfer to utxo. 20 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 21 | pub struct TransferToUTXO { 22 | pub outputs: Vec, 23 | } 24 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/actions/ethereum.rs: -------------------------------------------------------------------------------- 1 | use ethereum::TransactionV0 as Transaction; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 5 | pub enum Action { 6 | Transact(Transaction), 7 | } 8 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/actions/evm.rs: -------------------------------------------------------------------------------- 1 | use primitive_types::{H160, H256, U256}; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 5 | pub enum Action { 6 | Call(Call), 7 | Create(Create), 8 | Create2(Create2), 9 | } 10 | 11 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 12 | pub struct Call { 13 | pub source: H160, 14 | pub target: H160, 15 | pub input: Vec, 16 | pub value: U256, 17 | pub gas_limit: u64, 18 | pub gas_price: Option, 19 | pub nonce: Option, 20 | } 21 | 22 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 23 | pub struct Create { 24 | pub source: H160, 25 | pub init: Vec, 26 | pub value: U256, 27 | pub gas_limit: u64, 28 | pub gas_price: Option, 29 | pub nonce: Option, 30 | } 31 | 32 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 33 | pub struct Create2 { 34 | pub source: H160, 35 | pub init: Vec, 36 | pub salt: H256, 37 | pub value: U256, 38 | pub gas_limit: u64, 39 | pub gas_price: Option, 40 | pub nonce: Option, 41 | } 42 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/actions/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod ethereum; 2 | pub mod evm; 3 | pub mod template; 4 | pub mod xhub; 5 | 6 | use serde::{Deserialize, Serialize}; 7 | 8 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 9 | pub enum Action { 10 | Ethereum(ethereum::Action), 11 | Evm(evm::Action), 12 | XHub(xhub::Action), 13 | Template(template::Action), 14 | } 15 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/actions/template.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 4 | pub enum Action { 5 | SetValue(u64), 6 | } 7 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/actions/xhub.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | use zei::{noah_api::xfr::structs::AssetType, XfrPublicKey}; 3 | 4 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 5 | pub enum Action { 6 | NonConfidentialTransfer(NonConfidentialTransfer), 7 | } 8 | 9 | /// Findora evm account balance transfer to NonConfidential utxo. 10 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] 11 | pub struct NonConfidentialTransfer { 12 | pub input_value: u64, 13 | pub outputs: Vec, 14 | } 15 | 16 | /// Evm account balance convert to NonConfidential utxo. 17 | #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] 18 | pub struct NonConfidentialOutput { 19 | pub asset: AssetType, 20 | pub amount: u64, 21 | pub target: XfrPublicKey, 22 | #[serde(skip)] 23 | pub decimal: u8, 24 | #[serde(skip)] 25 | pub max_supply: u64, 26 | } 27 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/assemble.rs: -------------------------------------------------------------------------------- 1 | use crate::actions::ethereum::Action as EtherAction; 2 | use crate::actions::Action; 3 | use crate::crypto::{Address, Signature}; 4 | use crate::transaction; 5 | use ethereum::TransactionV0 as Transaction; 6 | use primitive_types::U256; 7 | use ruc::*; 8 | use serde::{Deserialize, Serialize}; 9 | 10 | // Same as baseapp/src/extensions/SignedExtra used by wasm 11 | pub type SignedExtra = (CheckNonce, CheckFee); 12 | 13 | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] 14 | pub struct CheckNonce(U256); 15 | 16 | impl CheckNonce { 17 | pub fn new(nonce: U256) -> Self { 18 | CheckNonce(nonce) 19 | } 20 | } 21 | 22 | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] 23 | pub struct CheckFee(Option); 24 | 25 | impl CheckFee { 26 | pub fn new(fee: Option) -> Self { 27 | CheckFee(fee) 28 | } 29 | } 30 | 31 | /// Unchecked transaction type as expected by this application. 32 | pub type UncheckedTransaction = 33 | transaction::UncheckedTransaction; 34 | 35 | /// Transaction type that has already been checked. 36 | pub type CheckedTransaction = 37 | transaction::CheckedTransaction; 38 | 39 | /// Convert base action to sub module action within CheckedTransaction 40 | /// if tx is unsigned transaction. 41 | pub fn convert_unsigned_transaction( 42 | action: Action, 43 | tx: CheckedTransaction, 44 | ) -> transaction::CheckedTransaction { 45 | transaction::CheckedTransaction { 46 | signed: tx.signed, 47 | function: action, 48 | } 49 | } 50 | 51 | /// Convert raw transaction to unchecked transaction. 52 | pub fn convert_unchecked_transaction<'a, Extra: Deserialize<'a>>( 53 | transaction: &'a [u8], 54 | ) -> Result> { 55 | serde_json::from_slice::>(transaction) 56 | .map_err(|e| eg!(e)) 57 | } 58 | 59 | /// Convert raw ethereum transaction to unified format unchecked transaction. 60 | pub fn convert_ethereum_transaction( 61 | transaction: &[u8], 62 | ) -> Result> { 63 | let tx = serde_json::from_slice::(transaction).map_err(|e| eg!(e))?; 64 | Ok(UncheckedTransaction::::new_unsigned( 65 | Action::Ethereum(EtherAction::Transact(tx)), 66 | )) 67 | } 68 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | pub use primitive_types::{H160, H256, U256}; 5 | 6 | pub mod actions; 7 | pub mod assemble; 8 | pub mod crypto; 9 | pub mod transaction; 10 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/types/src/transaction.rs: -------------------------------------------------------------------------------- 1 | use crate::crypto::{IdentifyAccount, Verify}; 2 | use core::fmt::Debug; 3 | use ruc::*; 4 | use serde::{Deserialize, Serialize}; 5 | 6 | /// This is unchecked and so can contain a signature. 7 | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] 8 | pub struct UncheckedTransaction { 9 | /// The signature is to use the Address sign the function if this is a signed transaction. 10 | pub signature: Option<(Address, Signature, Extra)>, 11 | /// The function that should be called. 12 | pub function: Call, 13 | } 14 | 15 | impl 16 | UncheckedTransaction 17 | { 18 | pub fn new_signed( 19 | function: Call, 20 | signed: Address, 21 | signature: Signature, 22 | extra: Extra, 23 | ) -> Self { 24 | Self { 25 | signature: Some((signed, signature, extra)), 26 | function, 27 | } 28 | } 29 | 30 | pub fn new_unsigned(function: Call) -> Self { 31 | Self { 32 | signature: None, 33 | function, 34 | } 35 | } 36 | } 37 | 38 | impl 39 | UncheckedTransaction 40 | where 41 | Call: Serialize + Clone, 42 | Signature: Verify, 43 | ::Signer: IdentifyAccount, 44 | Extra: Serialize + Clone, 45 | { 46 | pub fn check(self) -> Result> { 47 | Ok(match self.signature { 48 | Some((signed, signature, extra)) => { 49 | let msg = 50 | serde_json::to_vec(&(self.function.clone(), extra.clone())).unwrap(); 51 | 52 | if !signature.verify(msg.as_slice(), &signed) { 53 | return Err(eg!("bad transaction signature")); 54 | } 55 | 56 | CheckedTransaction { 57 | signed: Some((signed, extra)), 58 | function: self.function, 59 | } 60 | } 61 | None => CheckedTransaction { 62 | signed: None, 63 | function: self.function, 64 | }, 65 | }) 66 | } 67 | } 68 | 69 | /// It has been checked and is good, particularly with regards to the signature. 70 | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] 71 | pub struct CheckedTransaction { 72 | /// The function signer, if anyone 73 | pub signed: Option<(Address, Extra)>, 74 | 75 | /// The function that should be called. 76 | pub function: Call, 77 | } 78 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-utils" 3 | version = "0.1.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | homepage = "https://findora.org/technology" 7 | repository = "https://github.com/findoranetwork/platform/" 8 | description = "Findora Primitive utility functions" 9 | readme = "README.md" 10 | 11 | [dependencies] 12 | futures = "0.3.16" 13 | base64 = "0.13" 14 | bip0039 = "0.8.0" 15 | blake2-rfc = "0.2.18" 16 | byteorder = "1.4.3" 17 | hex = "0.4.3" 18 | libsecp256k1 = { version = "0.7", features = ["static-context", "hmac"] } 19 | primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } 20 | protobuf = "2.16" 21 | rand = "0.8" 22 | ruc = "1.0" 23 | serde = { version = "1.0.124", features = ["derive"] } 24 | sha2 = "0.10" 25 | sha3 = "0.10" 26 | bip32 = "0.2.1" 27 | tiny-keccak = { version = "2.0", features = ["keccak"] } 28 | twox-hash = "1.6.0" 29 | 30 | [dev-dependencies] 31 | hex-literal = "0.3.1" 32 | serde_json = "1.0" 33 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/utils/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | #![allow(missing_docs)] 3 | 4 | pub mod ecdsa; 5 | pub mod hashing; 6 | pub mod tx; 7 | 8 | use primitive_types::H160; 9 | 10 | pub fn timestamp_converter(timestamp: protobuf::well_known_types::Timestamp) -> u64 { 11 | let unix_time = 12 | core::time::Duration::new(timestamp.seconds as u64, timestamp.nanos as u32); 13 | unix_time.as_secs() 14 | } 15 | 16 | pub fn proposer_converter(address: Vec) -> Option { 17 | if address.len() < 20 { 18 | None 19 | } else { 20 | Some(H160::from_slice(&address[0..20])) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/utils/src/tx.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! EVM tx functions 3 | //! 4 | 5 | use ruc::*; 6 | 7 | /// EVM_TX_TAG = "evm:" 8 | pub const EVM_TX_TAG: [u8; 4] = [0x65, 0x76, 0x6d, 0x3a]; 9 | 10 | /// Evm Tx wrapper 11 | pub struct EvmRawTxWrapper {} 12 | impl EvmRawTxWrapper { 13 | /// wrap 14 | pub fn wrap(raw_tx: &[u8]) -> Vec { 15 | let mut txn_with_tag: Vec = vec![]; 16 | txn_with_tag.extend_from_slice(&EVM_TX_TAG); 17 | txn_with_tag.extend_from_slice(raw_tx); 18 | 19 | txn_with_tag 20 | } 21 | 22 | // unwrap 23 | // Evm tx bytes starts with EVM_TX_TAG 24 | pub fn unwrap(tx: &[u8]) -> Result<&[u8]> { 25 | let len = EVM_TX_TAG.len(); 26 | if tx.len() <= len || !tx[..len].eq(&EVM_TX_TAG) { 27 | return Err(eg!("Invalide evm transaction")); 28 | } 29 | 30 | Ok(&tx[len..]) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/components/contracts/primitives/wasm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evm-wasm-util" 3 | version = "0.2.0" 4 | authors = ["FindoraNetwork"] 5 | edition = "2021" 6 | 7 | description = "" 8 | repository = "" 9 | license = "" 10 | 11 | # wasm-opt has a segfaulting issue. Disabling for now 12 | [package.metadata.wasm-pack.profile.release] 13 | wasm-opt = false 14 | 15 | [dependencies] 16 | base64 = "0.13" 17 | ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } 18 | ethereum-types = { version = "0.13.1", default-features = false } 19 | fp-types = { path = "../../primitives/types" } 20 | fp-utils = { path = "../../primitives/utils" } 21 | rlp = "0.5" 22 | ruc = "1.0" 23 | sha3 = "0.10" 24 | serde_json = "1.0" 25 | wasm-bindgen = { version = "=0.2.84", features = ["serde-serialize"] } 26 | 27 | # Must enable the "js"-feature, 28 | # OR the compiling will fail. 29 | getrandom = { version = "0.2", features = ["js"] } 30 | 31 | [lib] 32 | crate-type = ["cdylib", "rlib"] 33 | path = "src/wasm.rs" 34 | -------------------------------------------------------------------------------- /src/components/contracts/rpc/README.md: -------------------------------------------------------------------------------- 1 | ### `lib.rs` 2 | 3 | 4 | --- 5 | 6 | ### `net.rs` 7 | exposes methods to interact with the RPC APIs under the net_ namespace. 8 | * `version` => `web3.net.version` 9 | Returns the current network id (523). 10 | 11 | * `peer_count` => `web3.net.peer_count` 12 | Returns number of peers currently connected to the client. 13 | 14 | * `is_listening` => `web3.net.listening` 15 | Returns true if client is actively listening for network connections. 16 | 17 | --- 18 | 19 | ### `web3.rs` 20 | exposes the following APIs. 21 | 22 | * `client_version` => `web3.clientVersion` 23 | Returns the current client version. 24 | 25 | * `sha3` => `web3.sha3(primitive=None, hexstr=None, text=None)` 26 | Returns the Keccak SHA256 of the given value. 27 | 28 | --- 29 | 30 | ### `eth.rs` 31 | exposes the following properties and methods to interact with the RPC APIs under the eth_ namespace. 32 | 33 | --- 34 | 35 | ### `eth_pubsub.rs` 36 | * `subscribe` 37 | subscribe to specific events in the blockchain. 38 | 39 | * `unsubscribe` 40 | 41 | support subscription types: 42 | ```rust 43 | /// New block headers subscription. 44 | NewHeads, 45 | /// Logs subscription. 46 | Logs, 47 | /// New Pending Transactions subscription. 48 | NewPendingTransactions, 49 | /// Node syncing status subscription. 50 | Syncing, 51 | ``` 52 | 53 | --- 54 | 55 | ### `eth_filter.rs` 56 | Interacting with the filtering APIs. 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/components/contracts/rpc/src/net.rs: -------------------------------------------------------------------------------- 1 | use baseapp::BaseApp; 2 | use fp_rpc_core::types::PeerCount; 3 | use fp_rpc_core::NetApi; 4 | use jsonrpc_core::{BoxFuture, Result}; 5 | use tracing::warn; 6 | 7 | pub struct NetApiImpl; 8 | 9 | impl NetApiImpl { 10 | pub fn new() -> Self { 11 | Self 12 | } 13 | } 14 | 15 | impl Default for NetApiImpl { 16 | fn default() -> Self { 17 | NetApiImpl::new() 18 | } 19 | } 20 | 21 | impl NetApi for NetApiImpl { 22 | fn version(&self) -> BoxFuture> { 23 | Box::pin(async move { 24 | let chain_id = ::ChainId::get(); 25 | Ok(chain_id.to_string()) 26 | }) 27 | } 28 | 29 | fn peer_count(&self) -> BoxFuture> { 30 | Box::pin(async move { 31 | warn!(target: "eth_rpc", "NetApi::peer_count"); 32 | Ok(PeerCount::String(format!("0x{:x}", 1))) 33 | }) 34 | } 35 | 36 | fn is_listening(&self) -> BoxFuture> { 37 | Box::pin(async move { 38 | warn!(target: "eth_rpc", "NetApi::is_listening"); 39 | Ok(true) 40 | }) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/components/contracts/rpc/src/utils.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Debug; 2 | 3 | use jsonrpc_core::{Error, ErrorCode}; 4 | use tokio::task::JoinError; 5 | 6 | pub fn convert_join_error_to_rpc_error(e: JoinError) -> Error { 7 | Error { 8 | code: ErrorCode::InternalError, 9 | message: format!("{e:?}"), 10 | data: None, 11 | } 12 | } 13 | 14 | pub fn convert_error_to_rpc_error(e: impl Debug) -> Error { 15 | Error { 16 | code: ErrorCode::InternalError, 17 | message: format!("{e:?}"), 18 | data: None, 19 | } 20 | } 21 | 22 | #[allow(dead_code)] 23 | pub fn build_rpc_error() -> Error { 24 | Error::new(ErrorCode::InternalError) 25 | } 26 | 27 | pub fn build_method_not_found() -> Error { 28 | Error::method_not_found() 29 | } 30 | -------------------------------------------------------------------------------- /src/components/contracts/rpc/src/web3.rs: -------------------------------------------------------------------------------- 1 | use ethereum_types::H256; 2 | use fp_rpc_core::{types::Bytes, Web3Api}; 3 | use jsonrpc_core::Result; 4 | use rustc_version::version; 5 | use sha3::{Digest, Keccak256}; 6 | 7 | pub struct Web3ApiImpl; 8 | 9 | impl Web3ApiImpl { 10 | pub fn new() -> Self { 11 | Self 12 | } 13 | } 14 | 15 | impl Default for Web3ApiImpl { 16 | fn default() -> Self { 17 | Web3ApiImpl::new() 18 | } 19 | } 20 | 21 | impl Web3Api for Web3ApiImpl { 22 | fn client_version(&self) -> Result { 23 | Ok(format!( 24 | "findora-web3-engine/{}-{}-{}", 25 | version().unwrap_or_else(|_| semver::Version::parse("1.55.0").unwrap()), 26 | std::env::var("CARGO_CFG_TARGET_ARCH") 27 | .unwrap_or_else(|_| "amd64".to_string()), 28 | std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "linux".to_string()) 29 | )) 30 | } 31 | 32 | fn sha3(&self, input: Bytes) -> Result { 33 | Ok(H256::from_slice( 34 | Keccak256::digest(input.into_vec()).as_slice(), 35 | )) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/components/finutils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "finutils" 3 | version = "0.2.11" 4 | authors = ["FindoraNetwork"] 5 | build = "build.rs" 6 | edition = "2021" 7 | 8 | [dependencies] 9 | 10 | hex = "0.4.3" 11 | base64 = "0.13" 12 | clap = { version = "2.33.3", features = ["yaml"] } 13 | lazy_static = "1.4.0" 14 | attohttpc = { version = "0.23", default-features = false, features = ["compress", "json", "tls-rustls"] } 15 | serde_json = "1.0.40" 16 | serde = { version = "1.0.124", features = ["derive"] } 17 | rand = "0.8" 18 | rand_core = { version = "0.6", default-features = false, features = ["alloc"] } 19 | rand_chacha = "0.3" 20 | curve25519-dalek = { package = "noah-curve25519-dalek", version = "4.0.0", default-features = false, features = ['serde'] } 21 | wasm-bindgen = { version = "=0.2.84", features = ["serde-serialize"] } 22 | sha2 = "0.10" 23 | sha3 = "0.10" 24 | digest = '0.10' 25 | parking_lot = "0.12" 26 | getrandom = "0.2" 27 | 28 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 29 | ruc = "1.0" 30 | rucv4 = { package = "ruc", version = "4.0" } 31 | nix = "0.25" 32 | ledger = { path = "../../ledger", default-features = false } 33 | globutils = { git = "https://github.com/FindoraNetwork/platform-lib-utils", branch = "fix_dep" } 34 | credentials = { git = "https://github.com/FindoraNetwork/platform-lib-credentials", branch = "fix_dep" } 35 | 36 | eth_checksum = { version = "0.1.2", optional = true } 37 | fp-core = { path = "../contracts/primitives/core", default-features = false } 38 | fp-utils = { path = "../contracts/primitives/utils" } 39 | fp-types = { path = "../contracts/primitives/types" } 40 | 41 | tendermint = { git = "https://github.com/FindoraNetwork/tendermint-rs", tag = "v0.19.0c" } 42 | tendermint-rpc = { git = "https://github.com/FindoraNetwork/tendermint-rs", features = ["http-client", "websocket-client"], optional = true, tag = "v0.19.0c" } 43 | 44 | [target.'cfg(not(target_arch = "wasm32"))'.dependencies] 45 | chaindev = { git = "https://github.com/FindoraNetwork/chaindev", branch = "platform", default-features = false, features = ["tendermint_based", "vsdb_sled_engine"] } 46 | web3 = "0.19.0" 47 | tokio = "1.10.1" 48 | 49 | [dev-dependencies] 50 | 51 | [build-dependencies] 52 | vergen = "=3.1.0" 53 | 54 | [features] 55 | default = ["std"] 56 | std = [ 57 | "eth_checksum", 58 | "tendermint-rpc" 59 | ] 60 | abci_mock = ["ledger/abci_mock"] 61 | debug_env = ["ledger/debug_env"] 62 | genstx = [] 63 | 64 | [[bin]] 65 | name = "fn" 66 | path = "src/bins/fn.rs" 67 | 68 | [[bin]] 69 | name = "stt" 70 | path = "src/bins/stt/stt.rs" 71 | 72 | [[bin]] 73 | name = "key_generator" 74 | path = "src/bins/key_generator.rs" 75 | 76 | [[bin]] 77 | name = "staking_cfg_generator" 78 | path = "src/bins/cfg_generator.rs" 79 | -------------------------------------------------------------------------------- /src/components/finutils/build.rs: -------------------------------------------------------------------------------- 1 | use vergen::{generate_cargo_keys, ConstantsFlags}; 2 | 3 | fn main() { 4 | let mut flags = ConstantsFlags::all(); 5 | // Tell vergen to use the semver from cargo and not `git describe` 6 | flags.set(ConstantsFlags::SEMVER, false); 7 | flags.set(ConstantsFlags::SEMVER_FROM_CARGO_PKG, true); 8 | 9 | // Generate the 'cargo:' key output 10 | generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); 11 | } 12 | -------------------------------------------------------------------------------- /src/components/finutils/src/bins/cfg_generator.rs: -------------------------------------------------------------------------------- 1 | use { 2 | globutils::wallet, 3 | ledger::staking::init, 4 | ruc::*, 5 | std::{env, fs}, 6 | }; 7 | 8 | fn main() { 9 | pnk!(gen()); 10 | } 11 | 12 | fn gen() -> Result<()> { 13 | let cfg_path = init::get_cfg_path().c(d!())?; 14 | let secret_info_path = format!("{}.keys", &cfg_path); 15 | let mut cfg_template = init::get_cfg_data().c(d!())?; 16 | 17 | let mnemonics = (0..cfg_template.valiators.len()) 18 | .map(|_| { 19 | wallet::generate_mnemonic_custom(24, "en") 20 | .c(d!()) 21 | .and_then(|m| { 22 | wallet::restore_keypair_from_mnemonic_default(&m) 23 | .c(d!()) 24 | .map(|k| (m, wallet::public_key_to_bech32(k.get_pk_ref()), k)) 25 | }) 26 | }) 27 | .collect::>>()?; 28 | 29 | println!("Public Key List:"); 30 | mnemonics 31 | .iter() 32 | .map(|kp| serde_json::to_string(kp.2.get_pk_ref()).unwrap()) 33 | .for_each(|pk| { 34 | println!("{}", pk.trim_matches(|c| c == '"')); 35 | }); 36 | 37 | println!("Private Key List:"); 38 | mnemonics 39 | .iter() 40 | .map(|kp| serde_json::to_string(kp.2.get_sk_ref()).unwrap()) 41 | .for_each(|pk| { 42 | println!("{}", pk.trim_matches(|c| c == '"')); 43 | }); 44 | 45 | let id_list = if let Ok(file) = env::var("MAINNET_0_2_X_VALIDATOR_ID_LIST") { 46 | fs::read_to_string(file).c(d!()).and_then(|list| { 47 | list.lines() 48 | .map(|id| { 49 | wallet::public_key_from_base64(id) 50 | .c(d!()) 51 | .or_else(|e| wallet::public_key_from_bech32(id).c(d!(e))) 52 | .map(|pk| wallet::public_key_to_base64(&pk)) 53 | }) 54 | .collect::>>() 55 | })? 56 | } else { 57 | mnemonics 58 | .iter() 59 | .map(|m| wallet::public_key_to_base64(&m.2.get_pk())) 60 | .collect() 61 | }; 62 | 63 | cfg_template 64 | .valiators 65 | .iter_mut() 66 | .zip(id_list) 67 | .for_each(|(v, id)| { 68 | v.id = id; 69 | }); 70 | 71 | let cfg = cfg_template; 72 | serde_json::to_vec_pretty(&cfg) 73 | .c(d!()) 74 | .and_then(|cfg| fs::write(cfg_path, cfg).c(d!())) 75 | .and_then(|_| serde_json::to_vec_pretty(&mnemonics).c(d!())) 76 | .and_then(|m| fs::write(&secret_info_path, m).c(d!())) 77 | .map(|_| { 78 | println!( 79 | "\x1b[01mSecret info has been writed to \x1b[31m{secret_info_path}\x1b[00m", 80 | ); 81 | }) 82 | } 83 | -------------------------------------------------------------------------------- /src/components/finutils/src/bins/key_generator.rs: -------------------------------------------------------------------------------- 1 | use {finutils::common::gen_key_and_print, ruc::*, std::env::args}; 2 | 3 | fn main() { 4 | let n = pnk!(args() 5 | .nth(1) 6 | .unwrap_or_else(|| "1".to_owned()) 7 | .parse::()); 8 | (0..n).for_each(|_| gen_key_and_print(false)); 9 | } 10 | -------------------------------------------------------------------------------- /src/components/finutils/src/bins/stt/td_addr_list.const: -------------------------------------------------------------------------------- 1 | [ 2 | "FD8C65634A9D8899FA14200177AF19D24F6E1C37", 3 | "0856654F7CD4BB0D6CC4409EF4892136C9D24692", 4 | "5C97EE9B91D90B332813078957E3A96B304791B4", 5 | "000E33AB7471186F3B1DE9FC08BB9C480F453590", 6 | "EA70EB6087E3D606730C4E9062CC24A5BD7D2B37", 7 | "E5705FED0049EDA431D37B37947A136F22F8F054", 8 | "9ED0D8D661C99A58F78F80816968E61AAE8DC649", 9 | "9AB077E00C8B731AE1F82DEC5E45CB3D1E9BBB12", 10 | "8CB713C8EA32223FCAC66B966FCFA9BAEE257946", 11 | "EAC5792572EB726AA0DBA9A7AFA9757F8063C6C9", 12 | "A50D65F2F63F65D845A7C5CBB989FF94D6688F38", 13 | "A8DFD116BA9664F38958C721688FA73E6320755B", 14 | "A07875BBD4E062BAB2C162E180237FC3B30C4ABC", 15 | "39F0C5E451394FAAE7213FD914EFBA8F963CCB90", 16 | "EE2F73BAA1605C998BB106E5A38DBD79B5209F1D", 17 | "09EF1DB6B67D1CBF7EBA6BD9B204611848993DF7", 18 | "AD2C69A9432E8F6634E1ADC3D6CA69EA9E1F4114", 19 | "510082967DFA7DEBA11267B26A6318D07A457B48", 20 | "60689516C566F27E03794329C431D0084299480A", 21 | "5C71532CEEFC43EE3857905AB94FDA505BFC06F3", 22 | ] 23 | -------------------------------------------------------------------------------- /src/components/finutils/src/bins/stt/td_addr_list.const.debug_env: -------------------------------------------------------------------------------- 1 | [ 2 | "611C922247C3BE7EA13455B191B6EFD909F10196", 3 | "5A006EA8455C6DB35B4B60B7218774B2E589482B", 4 | "0F64C8259BFCD1A9F6E21958D0A60D9E370D9C13", 5 | "A9534BB329FE980838EC0FEB7550AD66228D581B", 6 | "7DEFDDA9E24A1C4320A9D45B8E7F14A40E479713", 7 | "4C2582DC314575DE73AD1EAA06726E555786900E", 8 | "82DEBD3B6C108095BDD3FE7352B9C538BDEFA621", 9 | "EC046D54F2FA16AE7126343425C1E91A96ED18BD", 10 | "325EC027285ABAA2A755286E1982E8F66633C05B", 11 | "CF7D19D604FF5EFE7EC90583D5700D7FF1CF63BA", 12 | "30E07994969FFE8007481914335521CE665BEEFE", 13 | "59A3EC547FCFA2434F64A09F0B85A9BB6262F71B", 14 | "88C045F586A338E90CE9A712FC4F13D04764E28F", 15 | "91F40F5F761DF9A09D9CA7E6200D02551BBA31F1", 16 | "57AF4341DE9A2A3725123718DEDBA5C7B9141E7D", 17 | "908D050231F5D568DB11F379DC5B3E8A7C8A453D", 18 | "D88C6FE77A7F3F84578D6D9AA2718BB034743902", 19 | "55B8CF069F6F6C75935F8EB5FAC6B8C8138BC954", 20 | "8424784D8505B2661F120831D18BE0021DD0CDA8", 21 | "9F832EE81DB4FBDAA8D3541ECA6ECEE0E97C119B", 22 | ] 23 | -------------------------------------------------------------------------------- /src/components/finutils/src/common/dev/init.rs: -------------------------------------------------------------------------------- 1 | include!("../ddev/init.rs"); 2 | -------------------------------------------------------------------------------- /src/components/finutils/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # Command Line Util Collection 3 | //! 4 | 5 | #![deny(warnings)] 6 | #![deny(missing_docs)] 7 | 8 | #[cfg(feature = "std")] 9 | pub mod api; 10 | #[cfg(feature = "std")] 11 | pub mod common; 12 | pub mod txn_builder; 13 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wallet_mobile" 3 | version = "0.1.0" 4 | authors = ["tyler "] 5 | edition = "2018" 6 | build = "build.rs" 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [lib] 11 | name = "wallet_mobile" 12 | crate-type = ["cdylib", "staticlib", "rlib"] 13 | 14 | # wasm-opt has a segfaulting issue. Disabling for now 15 | [package.metadata.wasm-pack.profile.release] 16 | wasm-opt = false 17 | 18 | [dependencies] 19 | aes-gcm = "^0.10.1" 20 | base64 = "0.13" 21 | bech32 = "0.7.2" 22 | ffi-support = "0.4" 23 | futures = "0.3.16" 24 | getrandom = { version = "0.2", features = ["js"] } 25 | hex = "0.4.3" 26 | js-sys = "0.3.27" 27 | rand = { version = "0.7", features = ["wasm-bindgen"] } 28 | rand_chacha = "0.3" 29 | rand_core = { version = "0.6", default-features = false, features = ["alloc"] } 30 | ring = "0.16.19" 31 | ruc = "1.0" 32 | serde = { version = "1.0.124", features = ["derive"] } 33 | serde_derive = "^1.0.59" 34 | serde_json = "1.0" 35 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 36 | 37 | finutils = { path = "../finutils", default-features = false, features = []} 38 | fp-types = { path = "../contracts/primitives/types" } 39 | fp-utils = { path = "../contracts/primitives/utils" } 40 | globutils = { git = "https://github.com/FindoraNetwork/platform-lib-utils", branch = "fix_dep" } 41 | credentials = { git = "https://github.com/FindoraNetwork/platform-lib-credentials", branch = "fix_dep" } 42 | cryptohash = { git = "https://github.com/FindoraNetwork/platform-lib-cryptohash", branch = "develop" } 43 | 44 | ledger = { path = "../../ledger" } 45 | 46 | [dependencies.web-sys] 47 | version = "0.3.4" 48 | features = [ 49 | 'Headers', 50 | 'Request', 51 | 'RequestInit', 52 | 'RequestMode', 53 | 'Response', 54 | 'Window', 55 | 'console', 56 | ] 57 | 58 | [target.'cfg(target_os="android")'.dependencies] 59 | jni = "0.20" 60 | 61 | [target.'cfg(target_arch="wasm32")'.dependencies] 62 | wasm-bindgen = { version = "=0.2.84", features = ["serde-serialize"] } 63 | 64 | [target.'cfg(not(target_arch="wasm32"))'.dependencies] 65 | safer-ffi = "0.0.10" 66 | 67 | [build-dependencies] 68 | cbindgen = "0.24" 69 | vergen = "3.1.0" -------------------------------------------------------------------------------- /src/components/wallet_mobile/README.md: -------------------------------------------------------------------------------- 1 | # wallet-mobile-libs 2 | Compiled by [platform/componets/wallet_mobile](https://github.com/FindoraNetwork/platform/tree/wallet_mobile/components/wallet_mobile) 3 | 4 | ## Usage 5 | 6 | ### Android example 7 | - https://medium.com/visly/rust-on-android-19f34a2fb43 8 | - [Chinese Example](https://zhuanlan.zhihu.com/p/73473362) 9 | 10 | ### IOS example 11 | - https://medium.com/visly/rust-on-ios-39f799b3c1dd 12 | - [Chinese Example](https://zhuanlan.zhihu.com/p/73890910) 13 | 14 | ## Compile 15 | 16 | ### Wasm 17 | ``` 18 | cd components/wallet_mobile 19 | wasm-pack build 20 | ``` 21 | 22 | ### Android 23 | ``` 24 | export TARGET_AR=~/.NDK/arm64/bin/aarch64-linux-android-ar 25 | export TARGET_CC=~/.NDK/arm64/bin/aarch64-linux-android-clang 26 | 27 | cargo build -p wallet_mobile --target aarch64-linux-android --release --lib 28 | ``` 29 | 30 | ### IOS 31 | ``` 32 | cargo lipo --release -p wallet_mobile 33 | ``` 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/build.rs: -------------------------------------------------------------------------------- 1 | use std::{env, path::PathBuf}; 2 | use vergen::{generate_cargo_keys, ConstantsFlags}; 3 | 4 | fn main() { 5 | let mut flags = ConstantsFlags::all(); 6 | // Tell vergen to use the semver from cargo and not `git describe` 7 | flags.set(ConstantsFlags::SEMVER, false); 8 | flags.set(ConstantsFlags::SEMVER_FROM_CARGO_PKG, true); 9 | 10 | // Generate the 'cargo:' key output 11 | generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); 12 | 13 | // Export c header file for ffi interface 14 | let crate_dir = env::var("CARGO_MANIFEST_DIR") 15 | .expect("CARGO_MANIFEST_DIR env var is not defined"); 16 | let config = cbindgen::Config::from_file("cbindgen.toml") 17 | .expect("Unable to find cbindgen.toml configuration file"); 18 | cbindgen::generate_with_config(&crate_dir, config) 19 | .unwrap() 20 | .write_to_file(target_dir(crate_dir).join("wallet_mobile_ffi.h")); 21 | } 22 | 23 | fn target_dir(crate_dir: String) -> PathBuf { 24 | if let Ok(target) = env::var("CARGO_TARGET_DIR") { 25 | PathBuf::from(target) 26 | } else { 27 | PathBuf::from(crate_dir) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/cbindgen.toml: -------------------------------------------------------------------------------- 1 | include_guard = "wallet_mobile_ffi_h" 2 | autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" 3 | language = "C" 4 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/android/constructor.rs: -------------------------------------------------------------------------------- 1 | use crate::rust::types; 2 | use jni::objects::JClass; 3 | use jni::sys::{jbyteArray, jlong}; 4 | use jni::JNIEnv; 5 | use rand_chacha::ChaChaRng; 6 | use rand_core::SeedableRng; 7 | use zei::noah_api::{keys::KeyPair as RawXfrKeyPair, xfr::structs::ASSET_TYPE_LENGTH}; 8 | 9 | #[no_mangle] 10 | pub unsafe extern "system" fn Java_com_findora_JniApi_xfrKeyPairNew( 11 | env: JNIEnv, 12 | _class: JClass, 13 | seed: jbyteArray, 14 | ) -> jlong { 15 | let input = env.convert_byte_array(seed).unwrap(); 16 | let mut buf = [0u8; ASSET_TYPE_LENGTH]; 17 | buf.copy_from_slice(input.as_ref()); 18 | let mut prng = ChaChaRng::from_seed(buf); 19 | let val = types::XfrKeyPair::from(RawXfrKeyPair::generate_ed25519(&mut prng)); 20 | Box::into_raw(Box::new(val)) as jlong 21 | } 22 | 23 | #[no_mangle] 24 | pub unsafe extern "system" fn Java_com_findora_JniApi_xfrKeyPairDestroy( 25 | _env: JNIEnv, 26 | _class: JClass, 27 | xfr_keypair_ptr: jlong, 28 | ) { 29 | let _boxed_key = Box::from_raw(xfr_keypair_ptr as *mut types::XfrKeyPair); 30 | } 31 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/android/evm.rs: -------------------------------------------------------------------------------- 1 | use crate::rust::account::{get_serialized_address, EVMTransactionBuilder}; 2 | use jni::objects::{JClass, JString}; 3 | use jni::sys::{jlong, jstring}; 4 | use jni::JNIEnv; 5 | use zei::{noah_api::keys::PublicKey, XfrPublicKey}; 6 | 7 | use super::{jStringToString, parseU64}; 8 | 9 | #[no_mangle] 10 | /// # Safety 11 | /// Construct a serialzied EVM Transaction that transfer account balance to UTXO. 12 | /// @param {XfrPublicKey} recipient - UTXO Asset receiver. 13 | /// @param {u64} amount - Transfer amount. 14 | /// @param {string} sk - Ethereum wallet private key. 15 | /// @param {U256} nonce - Transaction nonce for sender. 16 | pub unsafe extern "system" fn Java_com_findora_JniApi_transferToUtxoFromAccount( 17 | env: JNIEnv, 18 | _: JClass, 19 | recipient: jlong, 20 | amount: JString, 21 | sk: JString, 22 | nonce: JString, 23 | ) -> jstring { 24 | let nonce = serde_json::from_str(&jStringToString(env, nonce)).unwrap(); 25 | 26 | let amount = parseU64(env, amount); 27 | 28 | let sk = jStringToString(env, sk); 29 | 30 | let recipient = *(recipient as *mut PublicKey); 31 | 32 | let ser_tx = EVMTransactionBuilder::new_transfer_to_utxo_from_account( 33 | XfrPublicKey::from_noah(&recipient).unwrap(), 34 | amount, 35 | sk, 36 | nonce, 37 | ) 38 | .unwrap(); 39 | 40 | **env 41 | .new_string(ser_tx) 42 | .expect("Couldn't create java String!") 43 | } 44 | 45 | #[no_mangle] 46 | /// Serialize ethereum address used to abci query nonce. 47 | pub extern "system" fn Java_com_findora_JniApi_getSerializedAddress( 48 | env: JNIEnv, 49 | _: JClass, 50 | address: JString, 51 | ) -> jstring { 52 | let addr = jStringToString(env, address); 53 | let data = get_serialized_address(&addr).unwrap(); 54 | **env.new_string(data).expect("Couldn't create java String!") 55 | } 56 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/android/exception.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::needless_return)] 2 | 3 | use core::fmt::Display; 4 | use jni::sys::jobject; 5 | use jni::JNIEnv; 6 | 7 | /// throw exception and return null if res is an Err(..), this behave like `?` but return null pointer. 8 | macro_rules! throw_exception { 9 | ($env:expr, $res: expr) => { 10 | match ThrowExceptionImpl($env, $res) { 11 | Ok(t) => t, 12 | Err(null) => return null as _, 13 | } 14 | }; 15 | } 16 | 17 | ///Throw exception if result it's an Err(..) and return Err(null). 18 | pub(super) fn ThrowExceptionImpl( 19 | env: JNIEnv, 20 | result: Result, 21 | ) -> Result 22 | where 23 | E: Display, 24 | { 25 | match result { 26 | Ok(t) => Ok(t), 27 | Err(e) => { 28 | let exception_occurred = env.exception_occurred().unwrap(); 29 | if !exception_occurred.is_null() { 30 | println!("Uncleared Exception."); 31 | env.exception_describe().unwrap(); 32 | env.exception_clear().unwrap(); 33 | } 34 | 35 | env.throw_new("java/lang/Exception", format!("{}", e)) 36 | .unwrap(); 37 | 38 | let null = core::ptr::null_mut() as jobject; 39 | 40 | return Err(null); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/ios/evm.rs: -------------------------------------------------------------------------------- 1 | use std::os::raw::c_char; 2 | use zei::XfrPublicKey; 3 | 4 | use crate::rust::{ 5 | self, account::EVMTransactionBuilder, c_char_to_string, string_to_c_char, 6 | }; 7 | 8 | use super::parse_u64; 9 | 10 | use fp_types::U256; 11 | 12 | #[no_mangle] 13 | /// Construct a serialzed EVM Transaction that transfer account balance to UTXO. 14 | /// @param {XfrPublicKey} recipient - UTXO Asset receiver. 15 | /// @param {u64} amount - Transfer amount. 16 | /// @param {string} sk - Ethereum wallet private key. 17 | /// @param {U256} nonce - Transaction nonce for sender. 18 | pub extern "C" fn findora_ffi_transfer_to_utxo_from_account( 19 | recipient: &XfrPublicKey, 20 | amount: *const c_char, 21 | sk: *const c_char, 22 | nonce: *const c_char, 23 | ) -> *const c_char { 24 | let nonce: U256 = { 25 | let nonce_str = c_char_to_string(nonce); 26 | match serde_json::from_str(&nonce_str) { 27 | Ok(n) => n, 28 | Err(e) => { 29 | println!("{:?}", e); 30 | return core::ptr::null_mut(); 31 | } 32 | } 33 | }; 34 | 35 | let sk = c_char_to_string(sk); 36 | 37 | match EVMTransactionBuilder::new_transfer_to_utxo_from_account( 38 | *recipient, 39 | parse_u64(amount), 40 | sk, 41 | nonce, 42 | ) { 43 | Ok(tx) => string_to_c_char(tx), 44 | Err(e) => { 45 | println!("{:?}", e); 46 | core::ptr::null_mut() 47 | } 48 | } 49 | } 50 | 51 | #[no_mangle] 52 | /// Serialize ethereum address used to abci query nonce. 53 | pub extern "C" fn get_serialized_address(address: *const c_char) -> *const c_char { 54 | let addr = c_char_to_string(address); 55 | if let Ok(data) = rust::account::get_serialized_address(&addr) { 56 | string_to_c_char(data) 57 | } else { 58 | core::ptr::null() 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/ios/fee.rs: -------------------------------------------------------------------------------- 1 | use crate::rust::types; 2 | use crate::rust::*; 3 | use std::os::raw::c_char; 4 | 5 | use super::parse_u64; 6 | 7 | #[no_mangle] 8 | /// Fee smaller than this value will be denied. 9 | pub extern "C" fn findora_ffi_fra_get_minimal_fee() -> u64 { 10 | fra_get_minimal_fee() 11 | } 12 | 13 | #[no_mangle] 14 | /// The destination for fee to be transfered to. 15 | pub extern "C" fn findora_ffi_fra_get_dest_pubkey() -> *mut types::XfrPublicKey { 16 | Box::into_raw(Box::new(types::XfrPublicKey::from(fra_get_dest_pubkey()))) 17 | } 18 | 19 | #[no_mangle] 20 | pub extern "C" fn findora_ffi_fee_inputs_new() -> *mut FeeInputs { 21 | Box::into_raw(Box::new(FeeInputs::new())) 22 | } 23 | 24 | #[no_mangle] 25 | /// # Safety 26 | /// 27 | pub unsafe extern "C" fn findora_ffi_fee_inputs_append( 28 | ptr: *mut FeeInputs, 29 | am: *const c_char, 30 | tr: *const TxoRef, 31 | ar: *const ClientAssetRecord, 32 | om: *const OwnerMemo, 33 | kp: *const types::XfrKeyPair, 34 | ) { 35 | let am = parse_u64(am); 36 | assert!(!ptr.is_null()); 37 | let input = &mut *ptr; 38 | 39 | let om_op = if om.is_null() { 40 | None 41 | } else { 42 | Some((*om).clone()) 43 | }; 44 | 45 | input.append(am, *tr, (*ar).clone(), om_op, (**kp).clone()); 46 | } 47 | 48 | #[no_mangle] 49 | /// The system address used to reveive delegation principals. 50 | pub extern "C" fn findora_ffi_get_delegation_target_address() -> *mut c_char { 51 | string_to_c_char(get_delegation_target_address()) 52 | } 53 | 54 | #[no_mangle] 55 | pub extern "C" fn findora_ffi_get_coinbase_address() -> *mut c_char { 56 | string_to_c_char(get_coinbase_address()) 57 | } 58 | 59 | #[no_mangle] 60 | pub extern "C" fn findora_ffi_get_coinbase_principal_address() -> *mut c_char { 61 | string_to_c_char(get_coinbase_principal_address()) 62 | } 63 | 64 | #[no_mangle] 65 | pub extern "C" fn findora_ffi_get_delegation_min_amount() -> u64 { 66 | get_delegation_min_amount() 67 | } 68 | 69 | #[no_mangle] 70 | pub extern "C" fn findora_ffi_get_delegation_max_amount() -> u64 { 71 | get_delegation_max_amount() 72 | } 73 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/ios/free.rs: -------------------------------------------------------------------------------- 1 | use crate::rust::types; 2 | use crate::rust::*; 3 | 4 | #[no_mangle] 5 | /// # Safety 6 | /// 7 | pub unsafe extern "C" fn findora_ffi_xfr_public_key_free(ptr: *mut types::XfrPublicKey) { 8 | if ptr.is_null() { 9 | return; 10 | } 11 | let _ = Box::from_raw(ptr); 12 | } 13 | 14 | #[no_mangle] 15 | /// # Safety 16 | /// 17 | pub unsafe extern "C" fn findora_ffi_fee_inputs_free(ptr: *mut FeeInputs) { 18 | if ptr.is_null() { 19 | return; 20 | } 21 | let _ = Box::from_raw(ptr); 22 | } 23 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(target_os = "android")] 2 | #[allow(non_snake_case)] 3 | pub mod android; 4 | #[cfg(target_os = "ios")] 5 | pub mod ios; 6 | pub mod rust; 7 | #[cfg(target_arch = "wasm32")] 8 | pub mod wasm; 9 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/rust/mod.rs: -------------------------------------------------------------------------------- 1 | #[cfg(target_arch = "wasm32")] 2 | use wasm_bindgen::prelude::*; 3 | 4 | pub mod account; 5 | mod crypto; 6 | mod data_model; 7 | #[cfg(test)] 8 | mod tests; 9 | pub mod transaction; 10 | pub mod types; 11 | mod util; 12 | 13 | pub use crypto::*; 14 | pub use data_model::*; 15 | pub use transaction::*; 16 | pub use util::*; 17 | 18 | /// Constant defining the git commit hash and commit date of the commit this library was built 19 | /// against. 20 | const BUILD_ID: &str = concat!(env!("VERGEN_SHA_SHORT"), " ", env!("VERGEN_BUILD_DATE")); 21 | 22 | #[cfg_attr(target_arch = "wasm32", wasm_bindgen)] 23 | /// Returns the git commit hash and commit date of the commit this library was built against. 24 | pub fn build_id() -> String { 25 | BUILD_ID.to_string() 26 | } 27 | -------------------------------------------------------------------------------- /src/components/wallet_mobile/src/rust/util.rs: -------------------------------------------------------------------------------- 1 | #[cfg(target_arch = "wasm32")] 2 | use core::fmt::Display; 3 | #[cfg(target_arch = "wasm32")] 4 | use wasm_bindgen::prelude::*; 5 | 6 | use std::ffi::{CStr, CString}; 7 | use std::os::raw::c_char; 8 | 9 | #[allow(clippy::not_unsafe_ptr_arg_deref)] 10 | #[inline(always)] 11 | pub fn c_char_to_string(cchar: *const c_char) -> String { 12 | let c_str = unsafe { CStr::from_ptr(cchar) }; 13 | c_str.to_str().unwrap_or("").to_string() 14 | } 15 | 16 | #[inline(always)] 17 | pub fn string_to_c_char(r_string: String) -> *mut c_char { 18 | let c_str = CString::new(r_string).expect("CString::new failed"); 19 | c_str.into_raw() 20 | } 21 | 22 | #[cfg(target_arch = "wasm32")] 23 | #[inline(always)] 24 | pub fn error_to_jsvalue(e: T) -> JsValue { 25 | JsValue::from_str(&e.to_string()) 26 | } 27 | -------------------------------------------------------------------------------- /src/components/wasm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasm" 3 | version = "0.2.11" 4 | authors = ["FindoraNetwork"] 5 | build = "build.rs" 6 | edition = "2021" 7 | 8 | description = "" 9 | repository = "" 10 | license = "" 11 | 12 | # wasm-opt has a segfaulting issue. Disabling for now 13 | [package.metadata.wasm-pack.profile.release] 14 | wasm-opt = false 15 | 16 | [dependencies] 17 | base64 = "0.13" 18 | hex = "0.4.3" 19 | js-sys = "0.3.27" 20 | rand_chacha = "0.3" 21 | rand_core = { version = "0.6", default-features = false, features = ["alloc"] } 22 | serde = { version = "1.0.124", features = ["derive"] } 23 | serde_json = "1.0" 24 | wasm-bindgen = { version = "=0.2.84", features = ["serde-serialize"] } 25 | wasm-bindgen-futures = "^0.4.34" 26 | fbnc = { version = "0.2.9", default-features = false} 27 | 28 | ring = "0.16.19" 29 | aes-gcm = "^0.10.1" 30 | bech32 = "0.7.2" 31 | ruc = "1.0" 32 | bs58 = "0.4" 33 | 34 | # Must enable the "js"-feature, 35 | # OR the compiling will fail. 36 | getrandom = { version = "0.2", features = ["js"] } 37 | 38 | zei = { package="platform-lib-noah", git = "https://github.com/FindoraNetwork/platform-lib-noah", branch = "main" } 39 | 40 | finutils = { path = "../finutils", default-features = false } 41 | 42 | globutils = { git = "https://github.com/FindoraNetwork/platform-lib-utils", branch = "fix_dep" } 43 | credentials = { git = "https://github.com/FindoraNetwork/platform-lib-credentials", branch = "fix_dep" } 44 | cryptohash = { git = "https://github.com/FindoraNetwork/platform-lib-cryptohash", branch = "develop" } 45 | 46 | ledger = { path = "../../ledger" } 47 | 48 | 49 | fp-utils = { path = "../contracts/primitives/utils" } 50 | fp-types = { path = "../contracts/primitives/types" } 51 | 52 | [lib] 53 | crate-type = ["cdylib", "rlib"] 54 | path = "src/wasm.rs" 55 | 56 | [dependencies.web-sys] 57 | version = "0.3.4" 58 | features = [ 59 | 'Headers', 60 | 'Request', 61 | 'RequestInit', 62 | 'RequestMode', 63 | 'Response', 64 | 'Window', 65 | 'console', 66 | ] 67 | 68 | [build-dependencies] 69 | serde = "1.0.124" 70 | serde_json = "1.0.41" 71 | vergen = "=3.1.0" 72 | 73 | [dev-dependencies] 74 | # Must enable the "js"-feature, 75 | # OR the compiling will fail. 76 | getrandom = { version = "0.2", features = ["js"] } 77 | wasm-bindgen-test = "0.3.0" 78 | 79 | [features] 80 | lightweight = ["zei/lightweight"] # Minimize size for only AR2ABAR and ABAR2AR. 81 | -------------------------------------------------------------------------------- /src/components/wasm/build.rs: -------------------------------------------------------------------------------- 1 | use vergen::{generate_cargo_keys, ConstantsFlags}; 2 | 3 | fn main() { 4 | let mut flags = ConstantsFlags::all(); 5 | // Tell vergen to use the semver from cargo and not `git describe` 6 | flags.set(ConstantsFlags::SEMVER, false); 7 | flags.set(ConstantsFlags::SEMVER_FROM_CARGO_PKG, true); 8 | 9 | // Generate the 'cargo:' key output 10 | generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); 11 | } 12 | -------------------------------------------------------------------------------- /src/components/wasm/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["plugins/markdown"] 3 | } 4 | -------------------------------------------------------------------------------- /src/components/wasm/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "wasm-funcs": [ 3 | { "name": "create_asset", 4 | "result": "Result", 5 | "args": [ [ "key_pair", "KeyPair" ], 6 | [ "token_code", "String" ], 7 | [ "updatable", "bool" ], 8 | [ "traceable", "bool" ] 9 | ] 10 | }, 11 | { "name": "issue_asset", 12 | "result": "Result", 13 | "args": [ [ "key_pair", "KeyPair" ], 14 | [ "token_code", "String" ], 15 | [ "seq_num", "u64" ], 16 | [ "amount", "u64" ] 17 | ] 18 | }, 19 | { "name": "transfer_asset", 20 | "result": "Result", 21 | "args": [ [ "key_pair", "KeyPair" ], 22 | [ "txo_sid", "u64" ], 23 | [ "amount", "u64" ], 24 | [ "blind_asset_record_str", "String" ] 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/components/wasm/test.js: -------------------------------------------------------------------------------- 1 | 2 | // Call 'wasm-pack build --target nodejs' to build from this directory for this command to work 3 | const wasm = require('./pkg/wasm.js'); 4 | const axios = require('axios'); 5 | const HOST = "localhost"; 6 | const SUBMISSION_PORT = "8669"; 7 | 8 | // Create some keypairs 9 | let kp_alice = wasm.new_keypair(); 10 | 11 | let define = function() { 12 | let memo = "test asset"; 13 | let asset_type = wasm.random_asset_type(); 14 | let definition_transaction = wasm.WasmTransactionBuilder.new().add_operation_create_asset(kp_alice, memo, asset_type).transaction(); 15 | 16 | // define an asset 17 | let route = 'http://' + HOST + ':' + SUBMISSION_PORT; 18 | 19 | axios.post(route + '/submit_transaction', JSON.parse(definition_transaction)) 20 | .then(function(response) { 21 | console.log("Successfully defined asset."); 22 | }) 23 | .catch(function(e) { 24 | console.log("Error defining asset. Perhaps the asset has already been created?"); 25 | console.log(e); 26 | }); 27 | 28 | let issuance_transaction = wasm.WasmTransactionBuilder.new() 29 | .add_basic_issue_asset(kp_alice, "", asset_type, 0n, 1000n) 30 | .transaction(); 31 | 32 | axios.post(route + '/submit_transaction', JSON.parse(issuance_transaction)) 33 | .then(function(response) { 34 | console.log("Successfully issued asset."); 35 | }) 36 | .catch(function(e) { 37 | console.log("Error issuing asset."); 38 | console.log(e); 39 | }); 40 | } 41 | 42 | setInterval(define, 1000); 43 | -------------------------------------------------------------------------------- /src/ledger/build.rs: -------------------------------------------------------------------------------- 1 | use vergen::{generate_cargo_keys, ConstantsFlags}; 2 | 3 | fn main() { 4 | let mut flags = ConstantsFlags::all(); 5 | // Tell vergen to use the semver from cargo and not `git describe` 6 | flags.set(ConstantsFlags::SEMVER, false); 7 | flags.set(ConstantsFlags::SEMVER_FROM_CARGO_PKG, true); 8 | 9 | // Generate the 'cargo:' key output 10 | generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); 11 | } 12 | -------------------------------------------------------------------------------- /src/ledger/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! The findora ledger core implementation 3 | //! 4 | 5 | #![deny(warnings)] 6 | #![deny(missing_docs)] 7 | #![allow(clippy::needless_borrow)] 8 | 9 | #[macro_use] 10 | pub mod data_model; 11 | pub mod converter; 12 | pub mod staking; 13 | #[cfg(all(not(target_arch = "wasm32"), feature = "fin_storage"))] 14 | pub mod store; 15 | 16 | use {ruc::*, std::sync::atomic::AtomicI64}; 17 | 18 | #[allow(missing_docs)] 19 | pub static LEDGER_TENDERMINT_BLOCK_HEIGHT: AtomicI64 = AtomicI64::new(0); 20 | const LSSED_VAR: &str = "LEDGER_STATE_SNAPSHOT_ENTRIES_DIR"; 21 | lazy_static::lazy_static! { 22 | static ref SNAPSHOT_ENTRIES_DIR: String = pnk!(std::env::var(LSSED_VAR)); 23 | } 24 | -------------------------------------------------------------------------------- /src/ledger/src/staking/evm.rs: -------------------------------------------------------------------------------- 1 | //! For interact with BaseApp (EVM) 2 | 3 | use super::{Delegation, Validator}; 4 | use once_cell::sync::{Lazy, OnceCell}; 5 | use parking_lot::{Mutex, RwLock}; 6 | use ruc::Result; 7 | use std::{collections::BTreeMap, sync::Arc}; 8 | use zei::XfrPublicKey; 9 | 10 | ///EVM staking interface 11 | pub static EVM_STAKING: OnceCell>> = OnceCell::new(); 12 | 13 | ///Mints from EVM staking 14 | pub static EVM_STAKING_MINTS: Lazy>> = 15 | Lazy::new(|| Mutex::new(Vec::with_capacity(64))); 16 | 17 | /// For account base app 18 | pub trait EVMStaking: Sync + Send + 'static { 19 | /// import_validators call 20 | fn import_validators( 21 | &self, 22 | validators: &[Validator], 23 | delegations: &BTreeMap, 24 | coinbase_balance: u64, 25 | ) -> Result<()>; 26 | /// stake call 27 | fn stake( 28 | &self, 29 | from: &XfrPublicKey, 30 | value: u64, 31 | td_addr: &[u8], 32 | td_pubkey: Vec, 33 | memo: String, 34 | rate: [u64; 2], 35 | ) -> Result<()>; 36 | /// delegate call 37 | fn delegate(&self, from: &XfrPublicKey, value: u64, td_addr: &[u8]) -> Result<()>; 38 | /// undelegate call 39 | fn undelegate(&self, from: &XfrPublicKey, td_addr: &[u8], amount: u64) 40 | -> Result<()>; 41 | ///update the memo and rate of the validator 42 | fn update_validator( 43 | &self, 44 | staker: &XfrPublicKey, 45 | validator: &[u8], 46 | memo: String, 47 | rate: [u64; 2], 48 | ) -> Result<()>; 49 | 50 | /// claim call 51 | fn claim(&self, td_addr: &[u8], delegator_pk: &XfrPublicKey) -> Result<()>; 52 | } 53 | -------------------------------------------------------------------------------- /src/ledger/src/staking/init/staking_config.json.keys: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /src/ledger/src/staking/ops/mod.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # Staking About Operations 3 | //! 4 | //! All the logic in this module relies on other operations in the same transaction 5 | //! to prevent replay attacks, and it does not implement this mechanism by itself. 6 | //! 7 | //! In the current implementation, the first operation must be a `TransferAsset`. 8 | //! 9 | 10 | pub mod claim; 11 | pub mod delegation; 12 | pub mod fra_distribution; 13 | pub mod governance; 14 | pub mod mint_fra; 15 | pub mod replace_staker; 16 | pub mod undelegation; 17 | pub mod update_staker; 18 | pub mod update_validator; 19 | -------------------------------------------------------------------------------- /tools/benchutils/static/root.addr: -------------------------------------------------------------------------------- 1 | 0x48baee8bd7e3a18cb2fc8e61a451ee50671a5116 2 | -------------------------------------------------------------------------------- /tools/benchutils/static/root.phrase: -------------------------------------------------------------------------------- 1 | jeans salmon solar horror video disagree casual forward token beach interest basic 2 | -------------------------------------------------------------------------------- /tools/benchutils/utils.sh: -------------------------------------------------------------------------------- 1 | 2 | # for 'perl' 3 | export LC_ALL=en_US.UTF-8 4 | 5 | export OSMAKE=make 6 | if [[ "FreeBSD" == `uname -s` ]]; then 7 | export OSMAKE=gmake 8 | fi 9 | 10 | function dbg() { 11 | msg=$* 12 | echo -e "\033[01m[** Debug **]\033[00m $msg" 13 | } 14 | 15 | function log() { 16 | msg="$*" 17 | echo -e "\033[01m[## Log ##]\033[00m $msg" 18 | } 19 | 20 | function die() { 21 | log "$*" 22 | echo -e "\033[31;01m[!! Panic !!]\033[00m $msg" 23 | exit 1 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tools/debug_env.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindoraNetwork/platform/fa962338be0b3f185731ca3d3a987aca67ec48c2/tools/debug_env.tar.gz -------------------------------------------------------------------------------- /tools/devnet/cleannodes.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # env 4 | source tools/devnet/env.sh || exit 5 | 6 | 7 | # stop nodes 8 | Node="" 9 | if [ ! -z "$1" ]; 10 | then 11 | Node="node$1" 12 | tools/devnet/stopnodes.sh "$1" 13 | else 14 | tools/devnet/stopnodes.sh 15 | fi 16 | 17 | # clean nodes 18 | nodes=`ls -l $DEVNET | grep node | awk '(NR>0){print $9}' | sort -V` 19 | echo -n "cleaned: " 20 | for node in $nodes 21 | do 22 | if [ -z "$Node" ] || ([ ! -z "$Node" ] && [ "$Node" = "$node" ]); then 23 | echo -en "$node " 24 | # abcis 25 | ls -d $DEVNET/$node/abci/* | grep -v 'abci.toml' | xargs rm -r 26 | 27 | # tendermint 28 | rm -rf $DEVNET/$node/data/*.db 29 | rm -rf $DEVNET/$node/data/cs.wal 30 | rm -rf $DEVNET/$node/config/addrbook.json 31 | rm -rf $DEVNET/$node/abcid.log 32 | rm -rf $DEVNET/$node/consensus.log 33 | cat > $DEVNET/$node/data/priv_validator_state.json < /dev/null 19 | 20 | # create abci dirs 21 | nodes=`ls -l $DEVNET | grep node | awk '(NR>0){print $9}' | sort -V` 22 | for node in $nodes 23 | do 24 | mkdir -p $DEVNET/$node/abci 25 | done 26 | 27 | # config nodes and abcis 28 | script_config=$(dirname "$0")/confignodes.py 29 | echo -n "setting $(($V+$N)) nodes: " 30 | python3 $script_config 31 | if [ $? -ne 0 ]; then 32 | echo -en "${RED}failed${NC}" 33 | else 34 | echo -en "${GRN}finish${NC}" 35 | fi 36 | echo 37 | -------------------------------------------------------------------------------- /tools/devnet/snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # env 4 | source tools/devnet/env.sh || exit 1 5 | 6 | # paths 7 | WALLET="$HOME/.findora" 8 | 9 | # clean and recreate mnemonic 10 | rm -rf $WALLET/mnenomic.key 11 | rm -rf $WALLET/snapshot.tar.gz 12 | echo "$MNEMONIC" > $WALLET/mnenomic.key 13 | 14 | # show and confirm genesis keypair 15 | echo -e "${GRN}step-0: keypair-------------------------------------------------${NC}" 16 | echo -e "mnemonic = ${YEL}$MNEMONIC${NC}" 17 | echo -e "private_key = ${YEL}$PRIV_KEY${NC}" 18 | echo 19 | echo -n "confirm (y/n)? " 20 | read answer 21 | if [ "$answer" != "${answer#[Nn]}" ] ;then 22 | exit 0 23 | fi 24 | echo 25 | 26 | # scripts 27 | cleannodes=$(dirname "$0")/cleannodes.sh 28 | startnodes=$(dirname "$0")/startnodes.sh 29 | stopnodes=$(dirname "$0")/stopnodes.sh 30 | 31 | # clean and restart nodes 32 | echo -e "${GRN}step-1: run network------------------------------------------------${NC}" 33 | ./$cleannodes 34 | ./$startnodes 35 | sleep 3 36 | echo 37 | 38 | # init network 39 | echo -e "${GRN}step-2: init network-----------------------------------------------${NC}" 40 | $BIN/fn setup -S http://0.0.0.0 > /dev/null 41 | $BIN/fn setup -O $WALLET/mnenomic.key > /dev/null 42 | echo -e "host: http://0.0.0.0" 43 | echo -e "key : $WALLET/mnenomic.key" 44 | sleep 3 45 | #echo -e "$BIN/stt" 46 | $BIN/stt init -i $BLOCK_INTERVAL -s 47 | #./$stopnodes 48 | echo 49 | 50 | # done 51 | echo -e "${GRN}step-3: harvest snapshot-------------------------------------------${NC}" 52 | tar -czf $WALLET/snapshot.tar.gz -C $DEVNET . > /dev/null 53 | echo -e "Done. Genesis snapshot saved to: ${GRN}$WALLET${NC}" 54 | -------------------------------------------------------------------------------- /tools/devnet/startnodes.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # env 4 | source ./tools/devnet/env.sh || exit 1 5 | 6 | # start one single node if specified 7 | Node="" 8 | if [ ! -z "$1" ]; then 9 | Node="node$1" 10 | fi 11 | 12 | # start abcis 13 | nodes=`ls -l $DEVNET | grep node | awk '(NR>0){print $9}' | sort -V` 14 | for node in $nodes 15 | do 16 | if [ -z "$Node" ] || ([ ! -z "$Node" ] && [ "$Node" = "$node" ]); then 17 | SelfAddr=$(grep 'address' ${DEVNET}/${node}/config/priv_validator_key.json | grep -oE '[^",]{40}') 18 | TD_NODE_SELF_ADDR=$SelfAddr \ 19 | RUST_LOG=$ABCI_LOG_LEVEL \ 20 | LEDGER_DIR=$DEVNET/$node/abci \ 21 | ENABLE_QUERY_SERVICE=true \ 22 | ENABLE_ETH_API_SERVICE=true \ 23 | ARC_HISTORY=4,2 \ 24 | abcid $DEVNET/$node >> $DEVNET/$node/abcid.log 2>&1 & 25 | fi 26 | done 27 | 28 | # start nodes 29 | for node in $nodes 30 | do 31 | perl -pi -e 's/addr_book_strict\s*=.*/addr_book_strict = false/g' $DEVNET/$node/config/config.toml || exit 1 32 | if [[ "" != ${DEBUG_ENV_IP} ]]; then 33 | perl -pi -e "s/127.0.0.1/${DEBUG_ENV_IP}/g" $DEVNET/$node/config/config.toml || exit 1 34 | fi 35 | tendermint node --home $DEVNET/$node >> $DEVNET/$node/consensus.log 2>&1 & 36 | done 37 | 38 | # show abcis and nodes 39 | for node in $nodes 40 | do 41 | if [ -z "$Node" ] || ([ ! -z "$Node" ] && [ "$Node" = "$node" ]); then 42 | echo -n "$node: " 43 | abci=`pgrep -f "abcid $DEVNET/$node$" | tr "\n" " " | xargs echo -n` 44 | echo -en "abci(${GRN}$abci${NC}) <---> " 45 | sleep 0.2 46 | node=`pgrep -f "tendermint node --home $DEVNET/$node$" | tr "\n" " " | xargs echo -n` 47 | echo -e "node(${GRN}$node${NC})" 48 | fi 49 | done 50 | -------------------------------------------------------------------------------- /tools/devnet/status.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # env 4 | source tools/devnet/env.sh || exit 1 5 | 6 | # show abcis and nodes 7 | nodes=`ls -l $DEVNET | grep node | awk '(NR>0){print $9}' | sort -V` 8 | for node in $nodes 9 | do 10 | abci=`pgrep -f "abcid $DEVNET/$node$" | tr "\n" " " | xargs echo -n` 11 | if ! [ -z "$abci" ] 12 | then 13 | echo -n "$node: " 14 | echo -en "abci(${GRN}$abci${NC}) <---> " 15 | node=`pgrep -f "tendermint node --home $DEVNET/$node$" | tr "\n" " " | xargs echo -n` 16 | echo -e "node(${GRN}$node${NC})" 17 | fi 18 | done 19 | -------------------------------------------------------------------------------- /tools/devnet/stopnodes.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # env 4 | source ./tools/devnet/env.sh || exit 1 5 | 6 | # stop one single node if specified 7 | Node="" 8 | if [ ! -z "$1" ]; then 9 | Node="node$1" 10 | fi 11 | 12 | # stop abcis 13 | nodes=`ls -l $DEVNET | grep node | awk '(NR>0){print $9}' | sort -V` 14 | 15 | killed=false 16 | tdmt_pids=() 17 | for node in $nodes 18 | do 19 | abci=`pgrep -f "abcid $DEVNET/$node$" | tr "\n" " " | xargs echo -n` 20 | tdmt=`pgrep -f "tendermint node --home $DEVNET/$node$"` 21 | if [ ! -z "$abci" ] && ([ -z "$Node" ] || [ "$Node" = "$node" ]); then 22 | if [ "$killed" = false ]; then 23 | echo -n "killed abci: " 24 | killed=true 25 | fi 26 | kill -9 $tdmt 27 | kill -9 $abci 28 | tdmt_pids+=("$tdmt") 29 | echo -en "${YEL}$abci ${NC}" 30 | fi 31 | done 32 | 33 | if [ "$killed" = true ]; then 34 | echo 35 | echo -n "killed node: " 36 | for tdmt in "${tdmt_pids[@]}" 37 | do 38 | echo -en "${YEL}$tdmt ${NC}" 39 | done 40 | echo 41 | fi 42 | 43 | exit 0 44 | -------------------------------------------------------------------------------- /tools/download_tendermint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | target_path=$1 4 | 5 | if [[ ! -d "${target_path}/.git" ]]; then 6 | rm -rf $target_path 7 | url='https://github.com/FindoraNetwork/tendermint.git' 8 | git clone -b findora-v0.33.9p3 --depth=1 $url $target_path 9 | fi 10 | -------------------------------------------------------------------------------- /tools/fmt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################# 4 | #### Ensure we are in the right path. ########### 5 | ################################################# 6 | if [[ 0 -eq $(echo $0 | grep -c '^/') ]]; then 7 | # relative path 8 | EXEC_PATH=$(dirname "`pwd`/$0") 9 | else 10 | # absolute path 11 | EXEC_PATH=$(dirname "$0") 12 | fi 13 | 14 | EXEC_PATH=$(echo ${EXEC_PATH} | sed 's@/\./@/@g' | sed 's@/\.*$@@') 15 | cd $EXEC_PATH || exit 1 16 | ################################################# 17 | 18 | for file in $(find .. -type f \ 19 | -name "*.rs" \ 20 | -o -name "*.c" \ 21 | -o -name "*.h" \ 22 | -o -name "*.sh" \ 23 | -o -name "*.toml" \ 24 | -o -name "*.json" \ 25 | -o -name "*.md"\ 26 | -o -name "rc.local"\ 27 | | grep -v "$(basename $0)" \ 28 | | grep -v 'target/' \ 29 | | grep -v 'tendermint'); do 30 | 31 | perl -pi -e 's/ / /g' $file 32 | perl -pi -e 's/!/!/g' $file 33 | perl -pi -e 's/(/(/g' $file 34 | perl -pi -e 's/)/)/g' $file 35 | 36 | perl -pi -e 's/:/: /g' $file 37 | perl -pi -e 's/, */, /g' $file 38 | perl -pi -e 's/。 */. /g' $file 39 | perl -pi -e 's/、 +/、/g' $file 40 | 41 | perl -pi -e 's/, +/, /g' $file 42 | perl -pi -e 's/\. +/. /g' $file 43 | 44 | perl -pi -e 's/\t/ /g' $file 45 | perl -pi -e 's/ +$//g' $file 46 | done 47 | 48 | make -C .. fmt 49 | -------------------------------------------------------------------------------- /tools/fn_check.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | set -e 3 | 4 | echo "Set Faucet Mnemonic" 5 | echo "zoo nerve assault talk depend approve mercy surge bicycle ridge dismiss satoshi boring opera next fat cinnamon valley office actor above spray alcohol giant" > /tmp/Faucet_Mnemonic 6 | fn setup -O /tmp/Faucet_Mnemonic -S http://localhost 7 | 8 | echo "Init network" 9 | stt init 10 | sleep 15 11 | 12 | echo "1. transfer" 13 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= 14 | 15 | echo "2. confidential-amount transfer" 16 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= --confidential-amount 17 | 18 | echo "3. confidential-type transfer" 19 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= --confidential-type 20 | 21 | echo "4. confidential-amount and confidential-type transfer" 22 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= --confidential-amount --confidential-type 23 | 24 | echo "5. transfer-batch" 25 | echo -e "WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0=\nevNR_3Jk8lSMSSHNdkk3d8Lq2peHicpKl0-_Wf2clfo=\nEGrwne7CoB6c3NgydG_CBmQFBL-27Shd6_cZ68ktOR8=" > /tmp/batch_list 26 | fn transfer-batch -n 1000000 -t /tmp/batch_list 27 | 28 | echo "6. Create Asset" 29 | fn asset --create --memo TTT --decimal 6 --code VG9rZW4wMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDBUVFQ= --transferable 30 | sleep 30 31 | 32 | echo "7. Issue Asset" 33 | fn asset --issue --code VG9rZW4wMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDBUVFQ= --amount 8000000 34 | sleep 30 35 | 36 | echo "8. Asset transfer" 37 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= --asset VG9rZW4wMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDBUVFQ= 38 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= --confidential-amount --asset VG9rZW4wMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDBUVFQ= 39 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= --confidential-type --asset VG9rZW4wMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDBUVFQ= 40 | fn transfer -n 1000000 -t WJZKo8_BwLMeSz3h7jYdfjjBZlJiRdhUXkqgUVzReE0= --confidential-amount --confidential-type --asset VG9rZW4wMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDBUVFQ= 41 | 42 | echo "9. Stake" 43 | fn delegate -n 1000000 --validator 611C922247C3BE7EA13455B191B6EFD909F10196 44 | sleep 30 45 | 46 | echo "10. Claim rewards" 47 | fn claim 48 | 49 | echo "11. Unstake" 50 | fn undelegate -n 900000 --validator 611C922247C3BE7EA13455B191B6EFD909F10196 51 | 52 | echo "12. UTXO to EVM" 53 | fn contract-deposit -a 0xE89441fDD60b473fBaC19F6DBcee7e7D61Bd99e6 -n 1000000 54 | sleep 30 55 | 56 | echo "13. EVM to UTXO" 57 | fn contract-withdraw -n 900000 -e "abuse plug bench require oval youth spike country ten pudding power hedgehog" 58 | -------------------------------------------------------------------------------- /tools/mainnet_0_2_x_validator_id.list: -------------------------------------------------------------------------------- 1 | fra17el6dvkac7n8rn606la87n85k835y7lvacjy9lzcdmwts608zgxsl9julx 2 | fra15e7cezphpy2r7jy9lnt7a0x9ydx37w2hmnxenwj7ed8mcm9mtllqucmpd8 3 | fra1czj2vetaqdhmt0yczkwcec89d5twvz9t65lq5fwwfedfjnra04ls3e2ewz 4 | fra1rtyjhqug8ecm5jxnxjgyu486gv8l02xu3sfj6tu9e4ydz4m94ytqpf0t2g 5 | fra196mw6lvgq4am7cg73ucaxtctzf53xzdevlmac69cyt35qnzvdrgq95jyzd 6 | fra1m6vqz4d0xvk6dapvcucwyzcwzgffpv6ky02s0u5mdy4jc6xx4etqcw8kpf 7 | fra1qqq5vycjmjj3sc2wf9v9wl47y8k9qqnuaju3xhqy97wm0h4wv45q8lsz3q 8 | fra1mrzgjtjsucfyg4fudqldfh964m5p3tklq9v7slpjdpr8ekjqz93qhf06cu 9 | fra1k7d7fv4vs6k48xp8u3xexwvgwxgr8awssgnayf70fvp7zk6ne7kqpsmzkd 10 | fra1nwwv66q7jzqerwkeraj2w0xzchvchtmq0wgyyswrscf93zj9ywysj8um6u 11 | fra1rsmz6h2qnz9c7wmyrjr66wv45ultpt528xhgad3f8j4skrqnyz9sq22v9k 12 | fra1hfx62mu360v8rsfyhreue93yy3hwdg7mgkzqne5z276f2mjvl5qsq5e8dr 13 | fra1cs9h4ssgfsxphx8g3pyxp62kh2ugvddv3lrga08mftwqck644ewq9pl9se 14 | fra189k3vkr92kkzgqe50ef2vauuq2qd9lpczhl55w0euqddhvm60jps9h2psw 15 | fra1wt7jfyw5u88qwt756rz4sk4eerxc2f26snl9et3duaexjf6c5jxslh34jh 16 | fra1w4j8xjn7mg47ns97uq8xgrmuhaqx6t6rvrc7fha6vwzmkq6vcf3qh0s43x 17 | fra1xg8vwj5kw2sm3k4kq64ut7akkvfsxtm8mhf8mkf3c35uflkvyn0sg0anax 18 | fra1glz2xudvasrns4vmmnl85xqe0va6nctkcsy4zctqw5fymv89dqfqzqcujt 19 | fra107zlq7mh4xvkcjm8pg5cges37pvnqklxttty70e9zmlze2rhlsxsuzwpa8 20 | fra1fyyqara2l9kn3c5v5ul3s8djy3un3g9c5787eljwyedpvw20nussq6hjeh 21 | -------------------------------------------------------------------------------- /tools/sample_keys.list: -------------------------------------------------------------------------------- 1 | 2 | Public Key List: 3 | 4 | Q3P9vdbYAvj-kAHfZO1jRw9TYTXVLF3gugZLOGrpl9o= 5 | dEEJ7EWQylSdUi6hwEnXo3OXgiVTXBuGWw-NbJgQC_s= 6 | 59UbLODg0Vqrx481C8ZmA205DHAqgdk5r8R7RxO3e_g= 7 | DgH4ePkKcyDP2aSRSuErN6X25QAhItTBli7UugYyU1Y= 8 | PqU6ihAElOvJfmjYze1aQNZbKN6lcLRQEzXfv2AV2cA= 9 | 2Wfvd4W_hHytXNk-YnKZAzhlN6nR9FmwRoFmUnVUVXU= 10 | ht08DPD2X-JpHAgZIfjFuYkzwMyiWXNxGq80Ie0mXW4= 11 | 64rV4uf7Ujg30XN99loZb9WYsk-1y5_AWvoIy1zkJ1U= 12 | 2P29mkbsFKFMfCvWtA8kzGodZ97arWAx5caa3PWA9yM= 13 | UWFVOekT2LBwpGjKVcDJPPWmd6SzRXcmI0tRqADxLRc= 14 | 5AsRoVeBdvpjH-29OQ7dK8vkc9ehenakatvYvanDY9Q= 15 | wPEFtnEnsVJVq88r8CiVGI0Zwi7Mm5FQqw0tE_Bt1qc= 16 | O_xpC3mlfYPoIQ6cdcqiUa8MdlwfYqalDIwim5MKMRs= 17 | JCuxB5Drmny-AjqPbxbGQnNoDoWSnOBVDIQuFzqJRdw= 18 | F3DNwVdlVsvWG_nbpKNcyL1TzwqkpIiNbrsQDGDXZzY= 19 | mwlRfKHU_H0fpdg1t4QtBgMBEo5AVVThKEYnampqalQ= 20 | lHW6dbs_mwheiUl41kxTs_Kp-QKaV9kALDlZqOJOCuM= 21 | jHXHRYkuC1JPjn50tNksgSL2SUaDR5mCrU9GKzCQgQY= 22 | wL5bpdrM5F8MgdN8KsUG1gi5xmP_Bm_eDCS-5FSkPp0= 23 | R2tPSySJRPz1khxs7iEw5Y7rCAF73Wpu9wPzvpSMcvw= 24 | 25 | Private Key List: 26 | 27 | y4YUtvNcruaid6R9B4FSWjicByVZR9mX5qtilUisHv0= 28 | U5u-1tm3vBRpsy4GIU6-KAhGk9huNKasVgYULWN2e3Q= 29 | gjMiP0hbDDzAzk-cLfUlCqIFigb9-ZspoOoUkyzaAGo= 30 | o7JfBE9Q0O7_YVbxrofO-a3jbZ8hyj2hu4tiHrTHxVw= 31 | nzXce_PGdaDqFg31l61omi_2mwb-AWwsyKUi5e59QhM= 32 | e5jI8e6krX_M0IItM7ygiiNl1599pr2fR1Ie6QQNFEA= 33 | LNACZrdrZHp24u59vsEudDAHyY69LDMDYiG31Gn0nOo= 34 | 4MDRl_TzxyLl2XxB7fy9blzoHPWiAy1Wjq5G_87pFsE= 35 | Dsxpd9_nKhNGDv67XN66i_Zh7PTkbKJq85n_xle4s5c= 36 | ZltB8csB0WlypvmD9TsGkwb8I-qNgpLAhDCoRjMWy4c= 37 | WW5TVNsWH8zGMVWncOQYn5p5hUuiip9zYbLU_Uv93Ko= 38 | x1SMlq42IuLYEqo3NpUAm087tDrql8q6alLDU_QHTUg= 39 | o3nOFqHzwmcP68-sewJPorq5gjXmcSe3CNotnNsjfgc= 40 | z0UvP0DeMCoaFfXCekAd4tfjG3vidmb_AzsZJEDdywA= 41 | YqikGXz8TcBnRDJU9O6r64mcMhA37HY1AueIDiGkGv8= 42 | JThjaM1cuSwTDmEr4hj81XQKnXoRL8EFqerfeGkjsOI= 43 | Qo02qLs-lXTt1JQ1_4Tu-tYqzaa1Tnq84dPaCRfMdH4= 44 | eu33fdmvFimdIpIq30qpkx2E94h-oVVhrCngPY4wd-E= 45 | TuS_bFYdOfZM_uV-AdADqP7oOSNXHxjXu2_038m6jhY= 46 | bP7L99M1fXArcrASgHrNOl4lCWgo7XJhxE1cdm6jKFY= 47 | 48 | -------------------------------------------------------------------------------- /tools/staking/demo_config.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindoraNetwork/platform/fa962338be0b3f185731ca3d3a987aca67ec48c2/tools/staking/demo_config.tar.gz -------------------------------------------------------------------------------- /tools/staking/staker_memo.example: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ExampleNode", 3 | "desc": "I am just a example description, please change me.", 4 | "website": "https://www.example.com", 5 | "logo": "https://www.example.com/logo" 6 | } 7 | -------------------------------------------------------------------------------- /tools/systemd_services/abcid.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description="ABCI Daemon" 3 | After=network.target 4 | 5 | [Service] 6 | Restart=on-failure 7 | RestartSec=5s 8 | 9 | ExecStart=/usr/local/bin/abcid --ledger-dir /data/findora/__findora__ --enable-snapshot --snapshot-algo fade --snapshot-target zroot/findora 10 | 11 | LimitNOFILE=200000 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /tools/systemd_services/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################# 4 | #### Ensure we are in the right path. ########### 5 | ################################################# 6 | if [[ 0 -eq $(echo $0 | grep -c '^/') ]]; then 7 | # relative path 8 | EXEC_PATH=$(dirname "`pwd`/$0") 9 | else 10 | # absolute path 11 | EXEC_PATH=$(dirname "$0") 12 | fi 13 | 14 | EXEC_PATH=$(echo ${EXEC_PATH} | sed 's@/\./@/@g' | sed 's@/\.*$@@') 15 | cd $EXEC_PATH || exit 1 16 | ################################################# 17 | 18 | ext_addr=$1 19 | if [[ "" != $ext_addr ]]; then 20 | ext_addr="tcp://${ext_addr}:26656" 21 | fi 22 | 23 | if [[ -d /data/findora/config ]]; then 24 | rm -rf ~/.tendermint ~/config_bak 25 | mv /data/findora/config ~/config_bak 26 | findorad init --mainnet || exit 1 27 | cp -r ~/.tendermint/config /data/findora/ || exit 1 28 | else 29 | rm -rf /data/findora/* 30 | findorad init -b /data/findora --mainnet || exit 1 31 | fi 32 | 33 | sed -ri "s#(external_address =).*#\1 \"${ext_addr}\"#" /data/findora/config/config.toml || exit 1 34 | 35 | target_path=$(dirname $(systemctl cat network.target | grep -o '#.*/network.target' | sed -r 's/^\s*#\s+//g')) 36 | cp -f abcid.service tendermint.service ${target_path}/ || exit 1 37 | 38 | for s in abcid tendermint; do 39 | systemctl disable ${s}.service 40 | systemctl enable ${s}.service 41 | systemctl stop ${s}.service 42 | systemctl start ${s}.service 43 | systemctl status ${s}.service 2>/dev/null 44 | done 45 | -------------------------------------------------------------------------------- /tools/systemd_services/tendermint.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description="Tendermint Daemon" 3 | Requires=abcid.service 4 | After=network.target abcid.service 5 | 6 | [Service] 7 | Restart=on-failure 8 | RestartSec=5s 9 | 10 | ExecStart=/usr/local/bin/tendermint node --home /data/findora 11 | 12 | LimitNOFILE=200000 13 | 14 | [Install] 15 | WantedBy=multi-user.target 16 | -------------------------------------------------------------------------------- /tools/update_staking_cfg.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################# 4 | #### Ensure we are in the right path. ########### 5 | ################################################# 6 | if [[ 0 -eq $(echo $0 | grep -c '^/') ]]; then 7 | # relative path 8 | EXEC_PATH=$(dirname "`pwd`/$0") 9 | else 10 | # absolute path 11 | EXEC_PATH=$(dirname "$0") 12 | fi 13 | 14 | EXEC_PATH=$(echo ${EXEC_PATH} | sed 's@/\./@/@g' | sed 's@/\.*$@@') 15 | cd $EXEC_PATH || exit 1 16 | ################################################# 17 | 18 | MAINNET_0_2_X_VALIDATOR_ID_LIST="$(pwd)/mainnet_0_2_x_validator_id.list" \ 19 | cargo run --bin staking_cfg_generator || exit 1 20 | 21 | cd ../src/ledger/src/staking/init || exit 1 22 | 23 | echo "[]" > staking_config.json.keys 24 | echo 25 | echo -e "\033[31;1m'Secret info' is invalid in this scene, so we clean it up!\033[0m" 26 | echo 27 | 28 | cd $EXEC_PATH || exit 1 29 | make -C .. 30 | -------------------------------------------------------------------------------- /tools/update_staking_cfg_debug.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################# 4 | #### Ensure we are in the right path. ########### 5 | ################################################# 6 | if [[ 0 -eq $(echo $0 | grep -c '^/') ]]; then 7 | # relative path 8 | EXEC_PATH=$(dirname "`pwd`/$0") 9 | else 10 | # absolute path 11 | EXEC_PATH=$(dirname "$0") 12 | fi 13 | 14 | EXEC_PATH=$(echo ${EXEC_PATH} | sed 's@/\./@/@g' | sed 's@/\.*$@@') 15 | cd $EXEC_PATH || exit 1 16 | ################################################# 17 | 18 | cargo run --bin staking_cfg_generator || exit 1 19 | 20 | cd ../src/ledger/src/staking/init || exit 1 21 | 22 | ml_path="${EXEC_PATH}/../src/components/finutils/src/bins/stt/mnemonic_list.const" 23 | echo "[" > $ml_path || exit 1 24 | grep -Ev '=|\[|\]|}|{' staking_config.json.keys | grep -E '( [a-z]+){9,}' >> $ml_path 25 | echo "]" >> $ml_path 26 | 27 | tal_path="${EXEC_PATH}/../src/components/finutils/src/bins/stt/td_addr_list.const" 28 | echo "[" > $tal_path || exit 1 29 | grep '"td_addr"' staking_config.json | sed 's/ \+"td_addr": *//g' >> $tal_path 30 | echo "]" >> $tal_path 31 | 32 | tal_path_debug_env="${EXEC_PATH}/../src/components/finutils/src/bins/stt/td_addr_list.const.debug_env" 33 | echo "[" > $tal_path_debug_env || exit 1 34 | grep '"td_addr"' staking_config_debug_env.json | sed 's/ \+"td_addr": *//g' >> $tal_path_debug_env 35 | echo "]" >> $tal_path_debug_env 36 | 37 | OS=$(uname -s) 38 | 39 | if [[ "Linux" == $OS ]]; then 40 | SED="sed -i" 41 | elif [[ "FreeBSD" == $OS || "Darwin" == $OS ]]; then 42 | SED="sed -i ''" 43 | else 44 | echo -e '\033[31;01mUnsupported OS !!\033[00m' 45 | exit 1 46 | fi 47 | 48 | for ((i=1;i<=$(grep -c '"id"' staking_config.json);i++)); do 49 | idx=$(grep -n '"id"' staking_config_debug_env.json | grep -o '^[0-9]\+' | head -n $i | tail -1) 50 | $SED "${idx}s/.*/$(grep '"id"' staking_config.json | head -n $i | tail -1)/" staking_config_debug_env.json 51 | done 52 | 53 | for ((i=1;i<=$(grep -c '"id"' staking_config.json);i++)); do 54 | idx=$(grep -n '"id"' staking_config_abci_mock.json | grep -o '^[0-9]\+' | head -n $i | tail -1) 55 | $SED "${idx}s/.*/$(grep '"id"' staking_config.json | head -n $i | tail -1)/" staking_config_abci_mock.json 56 | done 57 | 58 | cd $EXEC_PATH || exit 1 59 | make -C .. build_release_debug 60 | --------------------------------------------------------------------------------