├── .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 | 
2 | [](https://github.com/rust-random/rand#rust-version-requirements)
3 | 
4 | 
5 | 
6 | 
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 | 
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 | 
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 | 
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