├── .devcontainer └── devcontainer.json ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── ask-a-question.md │ ├── report-a-bug.md │ └── suggest-a-feature.md ├── dependabot.yml └── workflows │ ├── CI.yml │ └── check.yml ├── .gitignore ├── .maintain └── frame-weight-template.hbs ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── Jenkinsfile ├── LICENSE ├── Makefile ├── README.md ├── bin └── node │ ├── cli │ ├── Cargo.toml │ ├── bin │ │ └── main.rs │ ├── browser-demo │ │ ├── build.sh │ │ └── index.html │ ├── build.rs │ ├── res │ │ └── flaming-fir.json │ └── src │ │ ├── browser.rs │ │ ├── chain_spec │ │ ├── development.rs │ │ ├── local_testnet.rs │ │ ├── mod.rs │ │ ├── realis.rs │ │ ├── realis_testnet.rs │ │ └── testnet.rs │ │ ├── cli.rs │ │ ├── command.rs │ │ ├── lib.rs │ │ └── service.rs │ └── runtime │ ├── Cargo.toml │ ├── build.rs │ └── src │ ├── constants.rs │ ├── impls.rs │ └── lib.rs ├── docker ├── .env ├── Dockerfile ├── docker-compose.yaml ├── local.Dockerfile ├── realis ├── realis.json └── run-realis.sh ├── frame ├── marketplace │ ├── Cargo.toml │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ └── weights.rs ├── nft-delegate │ ├── Cargo.toml │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ └── weights.rs ├── nft │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── realis-bridge │ ├── Cargo.toml │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── realis-game-api │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs └── staking-pool │ ├── Cargo.toml │ ├── README.md │ ├── fuzzer │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── mock.rs │ │ └── submit_solution.rs │ ├── reward-curve │ ├── Cargo.toml │ ├── src │ │ ├── lib.rs │ │ └── log.rs │ └── tests │ │ └── test.rs │ ├── reward-fn │ ├── Cargo.toml │ ├── src │ │ └── lib.rs │ └── tests │ │ └── test.rs │ └── src │ ├── benchmarking.rs │ ├── default_weights.rs │ ├── inflation.rs │ ├── lib.rs │ ├── migrations.rs │ ├── mock.rs │ ├── offchain_election.rs │ ├── pallet │ ├── impls.rs │ └── mod.rs │ ├── slashing.rs │ ├── testing_utils.rs │ ├── tests.rs │ └── weights.rs ├── primitives └── realis │ ├── Cargo.toml │ ├── res │ └── types.json │ └── src │ ├── constants.rs │ └── lib.rs ├── realis.json ├── scripts ├── benchmark_bridge.sh ├── benchmark_marketplace.sh ├── benchmark_nft.sh ├── benchmark_nft_delegate.sh ├── benchmark_realis.sh ├── build_separately.sh ├── create_custom_spec.sh ├── create_realis_json.sh ├── insert_aura_key_node01.sh ├── insert_aura_key_node02.sh ├── insert_grandpa_key_node01.sh ├── insert_grandpa_key_node02.sh ├── run_node01.sh ├── run_node02.sh ├── run_node_alice.sh └── run_node_bob.sh └── types.json /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReAlis Node template", 3 | "context": "..", 4 | "settings": { 5 | "terminal.integrated.shell.linux": "/bin/bash", 6 | "lldb.executable": "/usr/bin/lldb" 7 | }, 8 | "extensions": [ 9 | "rust-lang.rust", 10 | "bungcip.better-toml", 11 | "vadimcn.vscode-lldb" 12 | ], 13 | "forwardPorts": [ 14 | 3000, 15 | 9944 16 | ], 17 | "preCreateCommand": "cargo build --release && cargo check", 18 | "postStartCommand": "./target/release/node-template --dev --ws-external", 19 | "menuActions": [ 20 | {"id": "polkadotjs", 21 | "label": "Open PolkadotJS Apps", 22 | "type": "external-preview", 23 | "args": ["https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/$HOST/wss"]} 24 | ], 25 | "image": "paritytech/substrate-playground-template-node-template:latest" 26 | } 27 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*.rs] 3 | indent_style=tab 4 | indent_size=tab 5 | tab_width=4 6 | end_of_line=lf 7 | charset=utf-8 8 | trim_trailing_whitespace=true 9 | max_line_length=100 10 | insert_final_newline=true 11 | 12 | [*.yml] 13 | indent_style=space 14 | indent_size=2 15 | tab_width=8 16 | end_of_line=lf 17 | 18 | [*.sh] 19 | indent_style=space 20 | indent_size=2 21 | tab_width=8 22 | end_of_line=lf 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/ask-a-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Ask a Question 3 | about: Ask a question about this template. 4 | title: "" 5 | labels: question 6 | assignees: "" 7 | --- 8 | 9 | **Question** 10 | 11 | _Please include information such as the following: is your question to clarify an existing resource 12 | or are you asking about something new? what are you trying to accomplish? where have you looked for 13 | answers?_ 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/report-a-bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Report a Bug 3 | about: Report a problem with this template. 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | **Description** 10 | 11 | _Tell us what happened. In particular, be specific about any changes you made to this template. 12 | Ideally, provide a link to your project's GitHub repository. Please note that we are not able to 13 | support all conceivable changes to this template project, but the more information you are able to 14 | provide the more equipped we will be to help._ 15 | 16 | **Steps to Reproduce** 17 | 18 | _Replace the example steps below with actual steps to reproduce the bug you're reporting._ 19 | 20 | 1. Go to '...' 21 | 2. Click on '....' 22 | 3. Scroll down to '....' 23 | 4. See error 24 | 25 | **Expected vs. Actual Behavior** 26 | 27 | _What did you expect to happen after you followed the steps you described in the last section? What 28 | actually happened?_ 29 | 30 | **Environment** 31 | 32 | _Describe the environment in which you encountered this bug. Use the list below as a starting point 33 | and add additional information if you think it's relevant._ 34 | 35 | - Operating system: 36 | - Template version/tag: 37 | - Rust version (run `rustup show`): 38 | 39 | **Logs, Errors or Screenshots** 40 | 41 | _Please provide the text of any logs or errors that you experienced; if 42 | applicable, provide screenshots to help illustrate the problem._ 43 | 44 | **Additional Information** 45 | 46 | _Please add any other details that you think may help us solve your problem._ 47 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggest-a-feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Suggest a Feature 3 | about: Suggest a new feature or an improvement to an existing feature for this template. 4 | title: "" 5 | labels: enhancement 6 | assignees: "" 7 | --- 8 | 9 | **Motivation** 10 | 11 | _Describe the need or frustration that motivated you to make this suggestion. Please note that the 12 | goal of this project is to provide a general-purpose template project, so please take care when 13 | suggesting features that may be specific to a particular use case._ 14 | 15 | **Suggested Solution** 16 | 17 | _Describe your suggested solution to the need or frustration that you are experiencing._ 18 | 19 | **Alternatives** 20 | 21 | _Describe any alternative solutions or features you considered and why you believe your suggested 22 | solution is preferable._ 23 | 24 | **Additional Information** 25 | 26 | _Provide any additional information that you believe may help us evaluate your suggestion._ 27 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "cargo" 4 | directory: "/" 5 | labels: ["A2-insubstantial", "B0-silent", "C1-low 📌"] 6 | ignore: 7 | - dependency-name: "substrate-*" 8 | - dependency-name: "sc-*" 9 | - dependency-name: "sp-*" 10 | - dependency-name: "frame-*" 11 | - dependency-name: "fork-tree" 12 | - dependency-name: "remote-externalities" 13 | - dependency-name: "pallet-*" 14 | - dependency-name: "beefy-*" 15 | - dependency-name: "try-runtime-*" 16 | schedule: 17 | interval: "daily" -------------------------------------------------------------------------------- /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | # push: 4 | # branches: 5 | # - ngubin 6 | # - main 7 | # - develop 8 | # - bridges 9 | # - dkireev 10 | pull_request: 11 | branches: 12 | - ngubin 13 | - main 14 | - develop 15 | - bridges 16 | - dkireev 17 | 18 | env: 19 | CARGO_TERM_COLOR: always 20 | 21 | jobs: 22 | test: 23 | name: Run Tests 24 | runs-on: ubuntu-latest 25 | strategy: 26 | fail-fast: false 27 | steps: 28 | - uses: actions/checkout@v2 29 | 30 | - uses: actions-rs/toolchain@v1 31 | with: 32 | toolchain: nightly-2021-05-11 33 | override: true 34 | target: wasm32-unknown-unknown 35 | 36 | - name: Overall test 37 | run: cargo test 38 | 39 | dvm-rpc-test: 40 | name: Run DVM RPC Tests 41 | runs-on: ubuntu-latest 42 | steps: 43 | - uses: actions/checkout@v2 44 | 45 | - uses: actions-rs/toolchain@v1 46 | with: 47 | toolchain: nightly-2021-03-01 48 | override: true 49 | target: wasm32-unknown-unknown 50 | 51 | - name: Build and Run node 52 | run: | 53 | cargo build 54 | ./target/debug/drml --dev --tmp & 55 | sleep 60 56 | - name: Set up node env 57 | uses: actions/setup-node@v1 58 | with: 59 | node-version: 10 60 | -------------------------------------------------------------------------------- /.github/workflows/check.yml: -------------------------------------------------------------------------------- 1 | name: Check Set-Up & Build 2 | 3 | # Controls when the action will run. 4 | on: 5 | # Triggers the workflow on push or pull request events but only for the master branch 6 | # push: 7 | # branches: [ ngubin, main, develop, bridges, dkireev ] 8 | pull_request: 9 | branches: [ ngubin, main, develop, bridges, dkireev ] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 15 | jobs: 16 | check: 17 | # The type of runner that the job will run on 18 | runs-on: ubuntu-20.04 19 | 20 | # Steps represent a sequence of tasks that will be executed as part of the job 21 | steps: 22 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 23 | - uses: actions/checkout@v2 24 | 25 | - name: Set-Up 26 | run: sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl 27 | 28 | - name: Install Rustup 29 | run: | 30 | curl https://sh.rustup.rs -sSf | sh -s -- -y 31 | source ~/.cargo/env 32 | rustup default stable 33 | rustup update 34 | rustup update nightly 35 | rustup target add wasm32-unknown-unknown --toolchain nightly 36 | rustup toolchain install nightly-2021-05-10 37 | rustup override set nightly-2021-05-10 38 | rustup target add wasm32-unknown-unknown --toolchain nightly-2021-05-10 39 | 40 | - name: Check Build 41 | run: | 42 | cargo check --all 43 | 44 | - name: Build 45 | run: | 46 | cargo build --release 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | **/target/ 4 | # These are backup files generated by rustfmt 5 | **/*.rs.bk 6 | 7 | .idea/ 8 | .vscode/ 9 | .devcontainer/ 10 | ./tests/ 11 | /*.iml 12 | .DS_Store 13 | common.rs 14 | 15 | # The cache for docker container dependency 16 | .cargo 17 | 18 | # The cache for chain data in container 19 | .local 20 | 21 | CustomSpecRaw.json 22 | customSpecRaw.json 23 | CustomSpecRealis.json 24 | customSpecRealis.json 25 | CustomSpeRealis.json 26 | customSpeRealis.json 27 | CustomSpRealis.json 28 | customSpRealis.json 29 | CustomRealis.json 30 | customRealis.json 31 | customSpec.json 32 | CustomSpec.json 33 | Realis.json 34 | REALIS.json 35 | ReAlIs.json 36 | ReaLIS.json 37 | -------------------------------------------------------------------------------- /.maintain/frame-weight-template.hbs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Autogenerated weights for {{pallet}} 19 | //! 20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} 21 | //! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` 22 | //! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} 23 | 24 | // Executed Command: 25 | {{#each args as |arg|~}} 26 | // {{arg}} 27 | {{/each}} 28 | 29 | #![allow(unused_parens)] 30 | #![allow(unused_imports)] 31 | 32 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; 33 | use sp_std::marker::PhantomData; 34 | 35 | /// Weight functions needed for {{pallet}}. 36 | pub trait WeightInfo { 37 | {{~#each benchmarks as |benchmark|}} 38 | fn {{benchmark.name~}} 39 | ( 40 | {{~#each benchmark.components as |c| ~}} 41 | {{c.name}}: u32, {{/each~}} 42 | ) -> Weight; 43 | {{~/each}} 44 | } 45 | 46 | /// Weights for {{pallet}} using the Substrate node and recommended hardware. 47 | pub struct SubstrateWeight(PhantomData); 48 | impl WeightInfo for SubstrateWeight { 49 | {{~#each benchmarks as |benchmark|}} 50 | fn {{benchmark.name~}} 51 | ( 52 | {{~#each benchmark.components as |c| ~}} 53 | {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} 54 | ) -> Weight { 55 | ({{underscore benchmark.base_weight}} as Weight) 56 | {{~#each benchmark.component_weight as |cw|}} 57 | // Standard Error: {{underscore cw.error}} 58 | .saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)) 59 | {{~/each}} 60 | {{~#if (ne benchmark.base_reads "0")}} 61 | .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight)) 62 | {{~/if}} 63 | {{~#each benchmark.component_reads as |cr|}} 64 | .saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight))) 65 | {{~/each}} 66 | {{~#if (ne benchmark.base_writes "0")}} 67 | .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight)) 68 | {{~/if}} 69 | {{~#each benchmark.component_writes as |cw|}} 70 | .saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))) 71 | {{~/each}} 72 | } 73 | {{~/each}} 74 | } 75 | 76 | // For backwards compatibility and tests 77 | impl WeightInfo for () { 78 | {{~#each benchmarks as |benchmark|}} 79 | fn {{benchmark.name~}} 80 | ( 81 | {{~#each benchmark.components as |c| ~}} 82 | {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} 83 | ) -> Weight { 84 | ({{underscore benchmark.base_weight}} as Weight) 85 | {{~#each benchmark.component_weight as |cw|}} 86 | // Standard Error: {{underscore cw.error}} 87 | .saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)) 88 | {{~/each}} 89 | {{~#if (ne benchmark.base_reads "0")}} 90 | .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight)) 91 | {{~/if}} 92 | {{~#each benchmark.component_reads as |cr|}} 93 | .saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight))) 94 | {{~/each}} 95 | {{~#if (ne benchmark.base_writes "0")}} 96 | .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight)) 97 | {{~/if}} 98 | {{~#each benchmark.component_writes as |cw|}} 99 | .saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))) 100 | {{~/each}} 101 | } 102 | {{~/each}} 103 | } 104 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | cargo-features = ["resolver"] 2 | 3 | [workspace] 4 | resolver = "2" 5 | 6 | members = [ 7 | "bin/node/cli", 8 | "bin/node/runtime", 9 | "primitives/realis", 10 | "frame/nft", 11 | "frame/nft-delegate", 12 | "frame/realis-game-api", 13 | "frame/staking-pool", 14 | "frame/realis-bridge", 15 | "frame/marketplace" 16 | ] 17 | 18 | # Override `node-runtime` dependency in `node-executor` dependencies with our local forked version. 19 | # `node-executor` is a dependecy of a `node-cli` at `bin/node/cli`. 20 | #[patch.'https://github.com/RealisNetwork/substrate'] 21 | #node-cli = { path = "bin/node/cli" } 22 | #node-runtime = { path = "bin/node/runtime" } 23 | #pallet-staking = { path = "frame/staking-pool" } 24 | #pallet-nft = { path = "frame/nft" } 25 | #pallet-nft-delegate = { path = "frame/nft-delegate" } 26 | #realis-bridge = {path = "frame/realis-bridge"} 27 | 28 | [profile.dev] 29 | split-debuginfo = "unpacked" 30 | 31 | [profile.release] 32 | panic = "unwind" 33 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ### 2 | FROM ubuntu:18.04 as builder 3 | RUN apt update && apt install curl build-essential libclang-dev clang git -y 4 | RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y 5 | 6 | RUN . $HOME/.cargo/env && \ 7 | rustup install nightly && \ 8 | rustup target add wasm32-unknown-unknown --toolchain nightly 9 | 10 | COPY . . 11 | RUN . $HOME/.cargo/env && \ 12 | cargo build --release 13 | 14 | ### 15 | 16 | FROM ubuntu:20.04 17 | RUN apt-get update && apt-get install ca-certificates -y && update-ca-certificates 18 | 19 | ARG NODENAME=REALIS-NODE 20 | ARG DISCOVERY_HOST=rpc.realis.network 21 | 22 | ENV NODENAME=$NODENAME 23 | ENV DISCOVERY_HOST=$DISCOVERY_HOST 24 | 25 | 26 | RUN mkdir -p /realis-blockchain/data 27 | WORKDIR /realis-blockchain 28 | COPY realis.json /realis-blockchain/realis.json 29 | COPY --from=builder ./target/release/realis /realis-blockchain/realis 30 | 31 | ENTRYPOINT ["/bin/bash", "-c", \ 32 | "/realis-blockchain/realis \ 33 | --chain=/realis-blockchain/realis.json \ 34 | --reserved-nodes /ip4/${DISCOVERY_HOST}/tcp/30333/p2p/12D3KooW9poizzemF6kb6iSbkoJynMhswa4oJe5W9v34eFuRcU47 \ 35 | --ws-port=9944 \ 36 | --rpc-port=9933 \ 37 | --validator \ 38 | --rpc-methods=Unsafe \ 39 | --name=${NODENAME} \ 40 | --unsafe-ws-external \ 41 | --unsafe-rpc-external \ 42 | --rpc-cors='*' \ 43 | --base-path=/realis-blockchain/data"] 44 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | // Uses Declarative syntax to run commands inside a container. 2 | pipeline { 3 | agent { 4 | kubernetes { 5 | yaml ''' 6 | apiVersion: v1 7 | kind: Pod 8 | spec: 9 | containers: 10 | - name: "shell" 11 | image: "docker:20" 12 | imagePullPolicy: IfNotPresent 13 | env: 14 | - name: DOCKER_HOST 15 | value: "ssh://root@94.130.8.239" 16 | command: 17 | - '/bin/sh' 18 | - '-c' 19 | - apk add git && mkdir ~/.ssh && 20 | echo LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUJsd0FBQUFkemMyZ3RjbgpOaEFBQUFBd0VBQVFBQUFZRUF2RThwZVN0dGxKVkJLQVpvSXY1dWh2U3YvRTZJaldnWUhmNjVUbnB6My8zSndtUE15NXNxCmIzWkhqbStHUzVvZjUrbG1rbzhTRnQ3aHlXV2ZqL1d1OW84MDNKL1VVOVp3b1grbVFvMjhXejBRK0FBckg0V3phQm12Y1MKcDVjdjU5UTZXTjljampxNEpQT2JDbHNXcFNyL1ZyekdYbXFtODJDZ3ZaL1Q0YXN6RGtZQTFaV2tYTzRpKytqSE5Cb3J2aQoxdTltTzNlWkZoeThyVDV1TzBVdkN6WEdSU1J1S1ltSGptK0Y5MEZETnoyV1d1NnQwM2dpSUJpaUgrRWhKSmIvcERJSmgxCi9PWEpMcndzcVh0aXRKVDM0V09MZzFScHBhREZLbXFvMFJ1UnpKa1hTM3VmVVpzVjJBcU0xZzZFa1lLSXBMS3F2cUZEcWwKdStDV3VlTVVQbWtQR2d5MEVUVVJFOEs0Smx0V0FwTWhnQzgzWmlRSGZrOTgzZ3d1dlpIWTRLTXVlQjhPc3llVUpNMzl0bApjU2hpeFdhYU5wSjdLL1BxaW9veElCeUNEVXpZa3B2T3d6WGlpUlAxckp5bW9aOG4veFE4dHB1THdDanQzSFF1MEZkV2tSCitWWHJFNzNvWkVGUEUyaHM5TzlnTndwMy9Rb3lVZU9FcXdIaTlDbkxBQUFGaURiZVlmYzIzbUgzQUFBQUIzTnphQzF5YzIKRUFBQUdCQUx4UEtYa3JiWlNWUVNnR2FDTCtib2Iwci94T2lJMW9HQjMrdVU1NmM5Lzl5Y0pqek11YkttOTJSNDV2aGt1YQpIK2ZwWnBLUEVoYmU0Y2xsbjQvMXJ2YVBOTnlmMUZQV2NLRi9wa0tOdkZzOUVQZ0FLeCtGczJnWnIzRXFlWEwrZlVPbGpmClhJNDZ1Q1R6bXdwYkZxVXEvMWE4eGw1cXB2TmdvTDJmMCtHck13NUdBTldWcEZ6dUl2dm94elFhSzc0dGJ2Wmp0M21SWWMKdkswK2JqdEZMd3MxeGtVa2JpbUpoNDV2aGZkQlF6YzlsbHJ1cmRONElpQVlvaC9oSVNTVy82UXlDWWRmemx5UzY4TEtsNwpZclNVOStGamk0TlVhYVdneFNwcXFORWJrY3laRjB0N24xR2JGZGdLak5ZT2hKR0NpS1N5cXI2aFE2cGJ2Z2xybmpGRDVwCkR4b010QkUxRVJQQ3VDWmJWZ0tUSVlBdk4yWWtCMzVQZk40TUxyMlIyT0NqTG5nZkRyTW5sQ1ROL2JaWEVvWXNWbW1qYVMKZXl2ejZvcUtNU0FjZ2cxTTJKS2J6c00xNG9rVDlheWNwcUdmSi84VVBMYWJpOEFvN2R4MEx0QlhWcEVmbFY2eE85NkdSQgpUeE5vYlBUdllEY0tkLzBLTWxIamhLc0I0dlFweXdBQUFBTUJBQUVBQUFHQkFKaDhEZHhsczBWbkd5emJDMGFTKzFOakhvCkxUNFRXSWZrY0R0bkI3TGd2S2lhOVVlMGpBYkR0Mzd2ZkREVjk0L2E4Z3pBT1B3Umt1QUczQ1VkUVVJVXJjcWZTaHBDRUQKZTQ3N085bVd4bGluZVc4cFM4SXAxUjVOOWtoUUdhcHBzMnVzeXVpbGRONjBGWTFrb3Jlb25pNklNSE9DYktmRWlHRFlPZgp3Y1p5aUZSZGtWMWk0SWF6K3pZN3g5dEQrZm4wOW02a1RyVXRhYURKckkvQ0FZcE1DU0dleHhWSmRrRzVYV2J3ZktIRERHCk9WT0hCTkZCN1hoS0dqWndhaE1rQlpmOEhES0JkbDcwYmJERWUrQTNwdFpUQjFkQWZWbExTblNLV3hQRk5UcGVieUZiSk4KL2h0VGFCZFM3M1YrV0RoWmJ0cTlLSENwL0FzekpZYW9xOXZ2MmdLNVQ3SHZMQTFLVStNelhjQ2M1SE44bG95MWE3Q1dCWQpMeWZvTHBOOHQ2K0ZWQ0xQWXpja0tteW96NVFtZ1hpUmptTUVlMlJEOVFYY2d1QTc1SjhUcjBORnZKL0gzbTRDUUU3YVpSCnBvT3pZSE95Unp1VEdlV1BsN3JwcDdCSk1OYUlLbUUwWjRDVFYvUzhCbVhYSlArMzFjTVBlU0R5QTVleUt6cnpjK1VRQUEKQU1FQWt4L3FKOTFIYjVSaW9ZaWcydmQrc2hrOTEvRFdXZUsvaFhNb3FTUWhVTmFSSWFDTWZtNE8zdnFPanVuTUNWbHF3WgprbDFrdlJ1a2NESUJPVWEyL2tsck1qZ0hiSTJjRER4cmRjVlhObDJKVkpKTDIwbDlrVHEwd3hUaURqQUdpVmNMRTNxY1NICkIzMFBTSy9md2lTTFBkUHRlNGRUU3BXSnB2UGVpNkRzQUZWeUpxa09KTXF0MVRBYlI0TnlGUWdNSkZOcm53SW9DYTRVSHMKVDdXOXRPTTRRSmQzVWpPNk1seHAxRDNxS0dVZUVERVBnODlhd3JsUmR0Q043clFlNTRBQUFBd1FEdE9lMWs2YnlZNFhkUQo5WjUyZ0xSbWt3OFVFRm5zSEFXN0RZcW50WnRqNlVZckR2WTUwV21PUlF2RXpLM1J4VTJJeWxpYVo1UVF1QlZrSTFlS2U3CldkMk5JTkR0WXBiTUNmc0tZR0pxTWhhaGx5QlRDQ0IxTm5zbHZQTEoyaVZKeElFKzdtYkpYc0lPNUxrSGcrd1VCK0Y5dUoKc1ZkRU1iSVpHaXRwT2FmSTlUUEpUdFZJR1VSRURWRUo1U2VCOU4zMkp4c3hCcWRROHc0WUVidkZWRFFKdTQ2cGE5VnFBRgpDNWhsNnNVSmxETzl3MGdBREV5WDVUajY2bnYxdlQ4d2tBQUFEQkFNczJNODZ3MitUUjV2VmVrcEJIN0Q4dlJ6YUdOa2FMCkpKTjRLR21xclZVTnBlUld1VFFMVk9nRGpsMFlRcHdNV0tESklpajducUpDS2pjdUF0UGlHYzY2T3Njb1NlSm1hbnVjY1UKTThZb1YyWmFHZElHZ3htYUhXdHV3SnljVUdYNkYrVGJlTVB6dzlneUwzd2NCdmZKWFhEcStzWWJpRVBrN2JPREp5Uk1sRApBMzN6Rk02a2k5aUlJbkhlNlQ1aVRxRCttWEExVmk4bmpjSlA2bWhQbE1uZjFCTGlZWmEzNnBBdWpET3kxdEpUL1I5RXo4Cndva2crTHdNUnhuVW1ITXdBQUFBMXliMjkwUUVoUUxWcENiMjlyQVFJREJBPT0KLS0tLS1FTkQgT1BFTlNTSCBQUklWQVRFIEtFWS0tLS0tCg== 21 | | base64 -d > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa && 22 | echo SG9zdCAqCiAgU3RyaWN0SG9zdEtleUNoZWNraW5nPW5vCiAgU2VydmVyQWxpdmVJbnRlcnZhbD0xMAogIFRDUEtlZXBBbGl2ZT15ZXMKICBJZGVudGl0aWVzT25seT15ZXMK 23 | | base64 -d > ~/.ssh/config && 24 | tail -f /dev/null 25 | resources: 26 | requests: 27 | cpu: 500m 28 | memory: "256Mi" 29 | ''' 30 | defaultContainer 'shell' 31 | } 32 | } 33 | stages { 34 | stage('BUILD IMAGE') { 35 | steps { 36 | script { 37 | git branch: 'stable', credentialsId: 'github-token', 38 | url: 'https://github.com/RealisNetwork/Realis.Network.git' 39 | withCredentials([string(credentialsId: 'dockerhub-token', variable: 'dockerhub')]) { 40 | sh ''' 41 | docker build . -t realisnetwrok/blockchain:${GIT_COMMIT} 42 | echo $dockerhub | docker login -u realisnetwrok --password-stdin 43 | docker push realisnetwrok/blockchain:${GIT_COMMIT} 44 | ''' 45 | } 46 | } 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: init 2 | init: 3 | ./scripts/init.sh 4 | 5 | .PHONY: check 6 | check: 7 | SKIP_WASM_BUILD=1 cargo check --release 8 | 9 | .PHONY: test 10 | test: 11 | SKIP_WASM_BUILD=1 cargo test --release --all 12 | 13 | .PHONY: run 14 | run: 15 | ./target/release/realis --dev --tmp --ws-port 9943 --rpc-port 9922 --validator --rpc-methods=Unsafe --listen-addr /ip4/0.0.0.0/tcp/30333 --name MyNode01 --unsafe-ws-external --unsafe-rpc-external --rpc-cors '*' 16 | 17 | .PHONY: build 18 | build: 19 | cargo build --release 20 | 21 | .PHONY: clean 22 | clean: 23 | cd ../soul/nikita/chains/realis/ && rm -rf db && rm -rf network && cd ../../../danil/chains/realis/ && rm -rf db && rm -rf network && cd ../../../../Realis.Network 24 | 25 | .PHONY: docker 26 | docker: 27 | make build && cd target/release && mv realis ../../docker && cd ../../docker && bash ./run-realis.sh 28 | 29 | .PHONY: fmt 30 | fmt: 31 | cargo fmt --all 32 | 33 | .PHONY: clippy 34 | clippy: 35 | cargo clippy 36 | -------------------------------------------------------------------------------- /bin/node/cli/bin/main.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2018-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 | //! Substrate Node CLI 20 | 21 | #![warn(missing_docs)] 22 | 23 | fn main() -> sc_cli::Result<()> { 24 | node_cli::run() 25 | } 26 | -------------------------------------------------------------------------------- /bin/node/cli/browser-demo/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e -x 3 | cargo +nightly build --release -p realis-cli --target wasm32-unknown-unknown --no-default-features --features browser -Z features=itarget 4 | wasm-bindgen ../../../../target/wasm32-unknown-unknown/release/realis_cli.wasm --out-dir pkg --target web 5 | python -m http.server 8000 6 | -------------------------------------------------------------------------------- /bin/node/cli/browser-demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Realis node 6 | 7 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /bin/node/cli/build.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2017-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 | fn main() { 20 | #[cfg(feature = "cli")] 21 | cli::main(); 22 | } 23 | 24 | #[cfg(feature = "cli")] 25 | mod cli { 26 | include!("src/cli.rs"); 27 | 28 | use sc_cli::structopt::clap::Shell; 29 | use std::{env, fs, path::Path}; 30 | use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; 31 | 32 | pub fn main() { 33 | build_shell_completion(); 34 | generate_cargo_keys(); 35 | 36 | rerun_if_git_head_changed(); 37 | } 38 | 39 | /// Build shell completion scripts for all known shells 40 | /// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123 41 | fn build_shell_completion() { 42 | for shell in &[ 43 | Shell::Bash, 44 | Shell::Fish, 45 | Shell::Zsh, 46 | Shell::Elvish, 47 | Shell::PowerShell, 48 | ] { 49 | build_completion(shell); 50 | } 51 | } 52 | 53 | /// Build the shell auto-completion for a given Shell 54 | fn build_completion(shell: &Shell) { 55 | let outdir = match env::var_os("OUT_DIR") { 56 | None => return, 57 | Some(dir) => dir, 58 | }; 59 | let path = Path::new(&outdir) 60 | .parent() 61 | .unwrap() 62 | .parent() 63 | .unwrap() 64 | .parent() 65 | .unwrap() 66 | .join("completion-scripts"); 67 | 68 | fs::create_dir(&path).ok(); 69 | 70 | Cli::clap().gen_completions("substrate-node", *shell, &path); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /bin/node/cli/src/browser.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2019-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 | use crate::chain_spec::ChainSpec; 20 | use browser_utils::{browser_configuration, init_logging, set_console_error_panic_hook, Client}; 21 | use log::info; 22 | use wasm_bindgen::prelude::*; 23 | 24 | /// Starts the client. 25 | #[wasm_bindgen] 26 | pub async fn start_client( 27 | chain_spec: Option, 28 | log_level: String, 29 | ) -> Result { 30 | start_inner(chain_spec, log_level) 31 | .await 32 | .map_err(|err| JsValue::from_str(&err.to_string())) 33 | } 34 | 35 | async fn start_inner( 36 | chain_spec: Option, 37 | log_directives: String, 38 | ) -> Result> { 39 | set_console_error_panic_hook(); 40 | init_logging(&log_directives)?; 41 | let chain_spec = match chain_spec { 42 | Some(chain_spec) => ChainSpec::from_json_bytes(chain_spec.as_bytes().to_vec()) 43 | .map_err(|e| format!("{:?}", e))?, 44 | None => crate::chain_spec::development_config(), 45 | }; 46 | 47 | let config = browser_configuration(chain_spec).await?; 48 | 49 | info!("Realis browser node"); 50 | info!("✌️ version {}", config.impl_version); 51 | info!("❤️ by Parity Technologies, 2017-2021"); 52 | info!("📋 Chain specification: {}", config.chain_spec.name()); 53 | info!("🏷 Node name: {}", config.network.node_name); 54 | info!("👤 Role: {:?}", config.role); 55 | 56 | // Create the service. This is the most heavy initialization step. 57 | let (task_manager, rpc_handlers) = crate::service::new_light_base(config) 58 | .map(|(components, rpc_handlers, _, _, _)| (components, rpc_handlers)) 59 | .map_err(|e| format!("{:?}", e))?; 60 | 61 | Ok(browser_utils::start_client(task_manager, rpc_handlers)) 62 | } 63 | -------------------------------------------------------------------------------- /bin/node/cli/src/chain_spec/local_testnet.rs: -------------------------------------------------------------------------------- 1 | use crate::chain_spec::testnet::testnet_genesis; 2 | use crate::chain_spec::ChainSpec; 3 | use crate::chain_spec::{authority_keys_from_seed, get_account_id_from_seed}; 4 | pub use node_primitives::{AccountId, Balance, Signature}; 5 | pub use node_runtime::{Block, GenesisConfig}; 6 | use sc_service::ChainType; 7 | use sp_core::sr25519; 8 | 9 | /// Local testnet config (multivalidator Alice + Bob) 10 | pub fn local_testnet_config() -> ChainSpec { 11 | ChainSpec::from_genesis( 12 | "Local Testnet", 13 | "local_testnet", 14 | ChainType::Local, 15 | local_testnet_genesis, 16 | vec![], 17 | None, 18 | None, 19 | None, 20 | Default::default(), 21 | ) 22 | } 23 | 24 | fn local_testnet_genesis() -> GenesisConfig { 25 | testnet_genesis( 26 | vec![ 27 | authority_keys_from_seed("Alice"), 28 | authority_keys_from_seed("Bob"), 29 | ], 30 | vec![], 31 | get_account_id_from_seed::("Alice"), 32 | vec![get_account_id_from_seed::("Alice")], 33 | vec![get_account_id_from_seed::("Alice")], 34 | vec![get_account_id_from_seed::("Alice")], 35 | vec![get_account_id_from_seed::("Alice")], 36 | None, 37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /bin/node/cli/src/chain_spec/realis.rs: -------------------------------------------------------------------------------- 1 | use grandpa_primitives::AuthorityId as GrandpaId; 2 | use hex_literal::hex; 3 | use node_runtime::{ 4 | wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, 5 | BalancesConfig, /*CouncilConfig,*/ 6 | /*DemocracyConfig,*/ /*ElectionsConfig,*/ GrandpaConfig, ImOnlineConfig, IndicesConfig, 7 | NftConfig, RealisBridgeConfig, RealisGameApiConfig, SessionConfig, 8 | /*SocietyConfig,*/ StakerStatus, StakingConfig, SudoConfig, SystemConfig, 9 | /*TechnicalCommitteeConfig,*/ MAX_NOMINATIONS, 10 | }; 11 | use pallet_im_online::sr25519::AuthorityId as ImOnlineId; 12 | use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; 13 | use sp_consensus_babe::AuthorityId as BabeId; 14 | use sp_runtime::Perbill; 15 | 16 | use crate::chain_spec::{session_keys, ChainSpec}; 17 | pub use node_primitives::{AccountId, Balance, Signature}; 18 | use node_runtime::constants::currency::DOLLARS; 19 | use node_runtime::pallet_staking; 20 | use node_runtime::realis_game_api; 21 | use node_runtime::Runtime; 22 | pub use node_runtime::{Block, GenesisConfig}; 23 | 24 | ///Realis chain-spec from realis.json 25 | pub fn realis_config() -> Result { 26 | ChainSpec::from_json_bytes(&include_bytes!("../../../../../docker/realis.json")[..]) 27 | } 28 | 29 | ///Realis chain-spec 30 | pub fn realis_genesis( 31 | initial_authorities: Vec<( 32 | AccountId, 33 | AccountId, 34 | GrandpaId, 35 | BabeId, 36 | ImOnlineId, 37 | AuthorityDiscoveryId, 38 | )>, 39 | initial_nominators: Vec, 40 | root_key: AccountId, 41 | nft_master: Vec, 42 | api_master: Vec, 43 | white_list: Vec, 44 | bridge_master: Vec, 45 | endowed_accounts: Option>, 46 | ) -> GenesisConfig { 47 | let mut endowed_accounts: Vec = endowed_accounts.unwrap_or_else(|| { 48 | vec![ 49 | hex!["781f4331933557680355932ef7f39b88e938fcb4338cc0e03edb3c523e47fd09"].into(), 50 | hex!["fe8823fb870f61eed24638a228adbe5885de6e945bb1375ca6a7415a4824756e"].into(), 51 | hex!["bc95bdafa3582b0ecbf5caf1e30b00412fa7c2dfbccd518f3b842c63890cc979"].into(), 52 | hex!["08bdc3547dc26a647391b509960b00adafa550496e9a95339a2faa02343be20f"].into(), 53 | hex!["d4c2ffb1322efb7fe78463ad6f24301751454685edd96640197cab2c44e1b16c"].into(), 54 | hex!["10f908b91793b30fc4870e255a0e102745e2a8f268814cd28389ba7f4220764d"].into(), 55 | hex!["d671cde125c8b7f42afbf40fb9d0d93d4d80c888cd34824c99ab292b589dbe75"].into(), 56 | hex!["d4c2ffb1322efb7fe78463ad6f24301751454685edd96640197cab2c44e1b16c"].into(), 57 | pallet_staking::Pallet::::account_id(), 58 | realis_game_api::Pallet::::account_id(), 59 | ] 60 | }); 61 | // endow all authorities and nominators. 62 | initial_authorities 63 | .iter() 64 | .map(|x| &x.0) 65 | .chain(initial_nominators.iter()) 66 | .for_each(|x| { 67 | if !endowed_accounts.contains(&x) { 68 | endowed_accounts.push(x.clone()) 69 | } 70 | }); 71 | 72 | // stakers: all validators and nominators. 73 | let mut rng = rand::thread_rng(); 74 | let stakers = initial_authorities 75 | .iter() 76 | .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) 77 | .chain(initial_nominators.iter().map(|x| { 78 | use rand::{seq::SliceRandom, Rng}; 79 | let limit = (MAX_NOMINATIONS as usize).min(initial_authorities.len()); 80 | let count = rng.gen::() % limit; 81 | let nominations = initial_authorities 82 | .as_slice() 83 | .choose_multiple(&mut rng, count) 84 | .into_iter() 85 | .map(|choice| choice.0.clone()) 86 | .collect::>(); 87 | ( 88 | x.clone(), 89 | x.clone(), 90 | STASH, 91 | StakerStatus::Nominator(nominations), 92 | ) 93 | })) 94 | .collect::>(); 95 | let _num_endowed_accounts = endowed_accounts.len(); 96 | 97 | const ENDOWMENT: Balance = 900_000 * DOLLARS / 12 * 100; 98 | const GAME_WALLET: Balance = 10_000_000 * DOLLARS / 10; 99 | const STAKING_POOL: Balance = 30_000_000 * DOLLARS / 10; 100 | const STASH: Balance = ENDOWMENT / 1000; 101 | 102 | let pallet_id_staking = pallet_staking::Pallet::::account_id().clone(); 103 | let game_wallet = realis_game_api::Pallet::::account_id().clone(); 104 | 105 | GenesisConfig { 106 | system: SystemConfig { 107 | code: wasm_binary_unwrap().to_vec(), 108 | changes_trie_config: Default::default(), 109 | }, 110 | balances: BalancesConfig { 111 | balances: endowed_accounts 112 | .iter() 113 | .cloned() 114 | .map(|x| { 115 | if x == pallet_id_staking { 116 | (x, STAKING_POOL) 117 | } else if x == game_wallet { 118 | (x, GAME_WALLET) 119 | } else { 120 | (x, ENDOWMENT) 121 | } 122 | }) 123 | .collect(), 124 | }, 125 | indices: IndicesConfig { indices: vec![] }, 126 | session: SessionConfig { 127 | keys: initial_authorities 128 | .iter() 129 | .map(|x| { 130 | ( 131 | x.0.clone(), 132 | x.0.clone(), 133 | session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()), 134 | ) 135 | }) 136 | .collect::>(), 137 | }, 138 | staking: StakingConfig { 139 | validator_count: initial_authorities.len() as u32, 140 | minimum_validator_count: initial_authorities.len() as u32, 141 | invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), 142 | slash_reward_fraction: Perbill::from_percent(10), 143 | stakers, 144 | ..Default::default() 145 | }, 146 | // democracy: DemocracyConfig::default(), 147 | // elections: ElectionsConfig { 148 | // members: endowed_accounts 149 | // .iter() 150 | // .take((num_endowed_accounts + 1) / 2) 151 | // .cloned() 152 | // .map(|member| (member, STASH)) 153 | // .collect(), 154 | // }, 155 | // council: CouncilConfig::default(), 156 | // technical_committee: TechnicalCommitteeConfig { 157 | // members: endowed_accounts 158 | // .iter() 159 | // .take((num_endowed_accounts + 1) / 2) 160 | // .cloned() 161 | // .collect(), 162 | // phantom: Default::default(), 163 | // }, 164 | sudo: SudoConfig { key: root_key }, 165 | babe: BabeConfig { 166 | authorities: vec![], 167 | epoch_config: Some(node_runtime::BABE_GENESIS_EPOCH_CONFIG), 168 | }, 169 | im_online: ImOnlineConfig { keys: vec![] }, 170 | authority_discovery: AuthorityDiscoveryConfig { keys: vec![] }, 171 | grandpa: GrandpaConfig { 172 | authorities: vec![], 173 | }, 174 | // technical_membership: Default::default(), 175 | // treasury: Default::default(), 176 | // society: SocietyConfig { 177 | // members: endowed_accounts 178 | // .iter() 179 | // .take((num_endowed_accounts + 1) / 2) 180 | // .cloned() 181 | // .collect(), 182 | // pot: 0, 183 | // max_members: 999, 184 | // }, 185 | vesting: Default::default(), 186 | gilt: Default::default(), 187 | nft: NftConfig { 188 | nft_masters: nft_master, 189 | }, 190 | realis_game_api: RealisGameApiConfig { 191 | api_masters: api_master, 192 | whitelist: white_list, 193 | }, 194 | realis_bridge: RealisBridgeConfig { 195 | bridge_masters: bridge_master, 196 | }, 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /bin/node/cli/src/chain_spec/realis_testnet.rs: -------------------------------------------------------------------------------- 1 | use hex_literal::hex; 2 | use sc_service::ChainType; 3 | use sp_core::crypto::UncheckedInto; 4 | use std::str::FromStr; 5 | 6 | use crate::chain_spec::realis::realis_genesis; 7 | use crate::chain_spec::ChainSpec; 8 | pub use node_primitives::{AccountId, Balance, Signature}; 9 | use node_runtime::pallet_staking; 10 | use node_runtime::realis_game_api; 11 | use node_runtime::Runtime; 12 | pub use node_runtime::{Block, GenesisConfig}; 13 | use sc_telemetry::serde_json::Map; 14 | 15 | ///Realis test chain-spec 16 | pub fn realis_testnet_config() -> ChainSpec { 17 | let mut properties = Map::new(); 18 | properties.insert("tokenDecimals".into(), 12.into()); 19 | properties.insert("tokenSymbol".into(), "LIS".into()); 20 | properties.insert("ss58Format".into(), 42.into()); 21 | 22 | ChainSpec::from_genesis( 23 | "Realis Network", 24 | "realis", 25 | ChainType::Live, 26 | realis_testnet_genesis, 27 | vec![], 28 | None, 29 | None, 30 | Some(properties), 31 | Default::default(), 32 | ) 33 | } 34 | 35 | ///Realis ctestnet genesis 36 | pub fn realis_testnet_genesis() -> GenesisConfig { 37 | let initial_authorities = vec![ 38 | ( 39 | hex!["1aa0d5c594a4581ec17069ec9631cd6225d5fb403fe4d85c8ec8aa51833fdf7f"].into(), 40 | hex!["d671cde125c8b7f42afbf40fb9d0d93d4d80c888cd34824c99ab292b589dbe75"].into(), 41 | hex!["b7606f13fb700cdabffd98bf466557a9faeb68bc773ef6e2bf681b9913079d37"] 42 | .unchecked_into(), 43 | hex!["d671cde125c8b7f42afbf40fb9d0d93d4d80c888cd34824c99ab292b589dbe75"] 44 | .unchecked_into(), 45 | hex!["d671cde125c8b7f42afbf40fb9d0d93d4d80c888cd34824c99ab292b589dbe75"] 46 | .unchecked_into(), 47 | hex!["d671cde125c8b7f42afbf40fb9d0d93d4d80c888cd34824c99ab292b589dbe75"] 48 | .unchecked_into(), 49 | ), 50 | ( 51 | hex!["cc32b24b66c8636b31394dce95949a27022c901d2597c5584554aa5d81db7416"].into(), 52 | hex!["10f908b91793b30fc4870e255a0e102745e2a8f268814cd28389ba7f4220764d"].into(), 53 | hex!["4a9e6cc2606a74d65ee2ba026e986024de8b60a22890023552b6cf6c977c8420"] 54 | .unchecked_into(), 55 | hex!["10f908b91793b30fc4870e255a0e102745e2a8f268814cd28389ba7f4220764d"] 56 | .unchecked_into(), 57 | hex!["10f908b91793b30fc4870e255a0e102745e2a8f268814cd28389ba7f4220764d"] 58 | .unchecked_into(), 59 | hex!["10f908b91793b30fc4870e255a0e102745e2a8f268814cd28389ba7f4220764d"] 60 | .unchecked_into(), 61 | ), 62 | ( 63 | hex!["24c42c17c4f95987c9916fc7e9bcd0c9385b6724f72658d943b643b6c3d83b73"].into(), 64 | hex!["dc869f188c87d823da3d8e6b069a2688d0772d2dc3f09d8dfa96b8551a601513"].into(), 65 | hex!["32e610d5ed216b2681ba9ad4907f05220ef9b81edf7049dd73c732a670c14379"] 66 | .unchecked_into(), 67 | hex!["dc869f188c87d823da3d8e6b069a2688d0772d2dc3f09d8dfa96b8551a601513"] 68 | .unchecked_into(), 69 | hex!["dc869f188c87d823da3d8e6b069a2688d0772d2dc3f09d8dfa96b8551a601513"] 70 | .unchecked_into(), 71 | hex!["dc869f188c87d823da3d8e6b069a2688d0772d2dc3f09d8dfa96b8551a601513"] 72 | .unchecked_into(), 73 | ), 74 | ]; 75 | //sudo account 76 | let root_key = hex!["10f908b91793b30fc4870e255a0e102745e2a8f268814cd28389ba7f4220764d"].into(); 77 | //NFT Master 78 | let sudo_1: AccountId = 79 | hex!["10f908b91793b30fc4870e255a0e102745e2a8f268814cd28389ba7f4220764d"].into(); 80 | let sudo_2: AccountId = 81 | hex!["1aa0d5c594a4581ec17069ec9631cd6225d5fb403fe4d85c8ec8aa51833fdf7f"].into(); 82 | let sudo_3: AccountId = 83 | hex!["cc32b24b66c8636b31394dce95949a27022c901d2597c5584554aa5d81db7416"].into(); 84 | let sudo_4: AccountId = 85 | hex!["24c42c17c4f95987c9916fc7e9bcd0c9385b6724f72658d943b643b6c3d83b73"].into(); 86 | let sudo_5: AccountId = 87 | hex!["a662140fcc5ff36f191a4f8ce6fd314a33c0149a5864060d50fd06c44535b777"].into(); 88 | 89 | let test_acc_1: AccountId = 90 | sp_core::sr25519::Public::from_str("5CFvFsZy7ViPUdEuuK19QuUqqCApVr2wbRWkHjcvQGsgzQmv") 91 | .unwrap() 92 | .into(); 93 | let test_acc_2: AccountId = 94 | sp_core::sr25519::Public::from_str("5DHasdJm8bVxqxuAu5p8QfDMFfABtt3Rgf8feWSDP8KmYVAL") 95 | .unwrap() 96 | .into(); 97 | let test_acc_3: AccountId = 98 | sp_core::sr25519::Public::from_str("5EAH4UrLxaNM6Kz1pH9bNSkKxAe21DkdDfyPahoj6KFN79Ax") 99 | .unwrap() 100 | .into(); 101 | let test_acc_4: AccountId = 102 | sp_core::sr25519::Public::from_str("5HnBcUqsgjBKD5cpAi4wDrTBhftFjt1ZFG8pXLmN5u1zozRk") 103 | .unwrap() 104 | .into(); 105 | 106 | let endowed_accounts = vec![ 107 | sudo_1.clone(), 108 | sudo_2.clone(), 109 | sudo_3.clone(), 110 | sudo_4.clone(), 111 | sudo_5.clone(), 112 | realis_game_api::Pallet::::account_id(), 113 | pallet_staking::Pallet::::account_id(), 114 | ]; 115 | 116 | let nft_master = vec![ 117 | sudo_1.clone(), 118 | sudo_2.clone(), 119 | sudo_3.clone(), 120 | sudo_4.clone(), 121 | sudo_5.clone(), 122 | ]; 123 | 124 | let api_master = vec![ 125 | sudo_1.clone(), 126 | sudo_2.clone(), 127 | sudo_3.clone(), 128 | sudo_4.clone(), 129 | sudo_5.clone(), 130 | ]; 131 | 132 | let bridge_master = vec![ 133 | sudo_1.clone(), 134 | sudo_2.clone(), 135 | sudo_3.clone(), 136 | sudo_4.clone(), 137 | sudo_5.clone(), 138 | ]; 139 | 140 | let white_list = vec![ 141 | test_acc_1.clone(), 142 | test_acc_2.clone(), 143 | test_acc_3.clone(), 144 | test_acc_4.clone(), 145 | ]; 146 | 147 | realis_genesis( 148 | initial_authorities, 149 | vec![], 150 | root_key, 151 | nft_master, 152 | api_master, 153 | white_list, 154 | bridge_master, 155 | Some(endowed_accounts), 156 | ) 157 | } 158 | -------------------------------------------------------------------------------- /bin/node/cli/src/chain_spec/testnet.rs: -------------------------------------------------------------------------------- 1 | use crate::chain_spec::{get_account_id_from_seed, session_keys}; 2 | use grandpa_primitives::AuthorityId as GrandpaId; 3 | pub use node_primitives::{AccountId, Balance, Signature}; 4 | use node_runtime::constants::currency::DOLLARS; 5 | use node_runtime::pallet_staking; 6 | use node_runtime::realis_game_api; 7 | use node_runtime::Runtime; 8 | use node_runtime::{ 9 | wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, 10 | BalancesConfig, /*CouncilConfig,*/ 11 | /*DemocracyConfig,*/ /*ElectionsConfig,*/ GrandpaConfig, ImOnlineConfig, IndicesConfig, 12 | NftConfig, RealisBridgeConfig, RealisGameApiConfig, SessionConfig, 13 | /*SocietyConfig,*/ StakerStatus, StakingConfig, SudoConfig, SystemConfig, 14 | /*TechnicalCommitteeConfig,*/ MAX_NOMINATIONS, 15 | }; 16 | pub use node_runtime::{Block, GenesisConfig}; 17 | use pallet_im_online::sr25519::AuthorityId as ImOnlineId; 18 | use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; 19 | use sp_consensus_babe::AuthorityId as BabeId; 20 | use sp_core::sr25519; 21 | use sp_runtime::Perbill; 22 | 23 | /// Helper function to create GenesisConfig for testing 24 | pub fn testnet_genesis( 25 | initial_authorities: Vec<( 26 | AccountId, 27 | AccountId, 28 | GrandpaId, 29 | BabeId, 30 | ImOnlineId, 31 | AuthorityDiscoveryId, 32 | )>, 33 | initial_nominators: Vec, 34 | root_key: AccountId, 35 | nft_master: Vec, 36 | api_master: Vec, 37 | white_list: Vec, 38 | bridge_master: Vec, 39 | endowed_accounts: Option>, 40 | ) -> GenesisConfig { 41 | let mut endowed_accounts: Vec = endowed_accounts.unwrap_or_else(|| { 42 | vec![ 43 | get_account_id_from_seed::("Alice"), 44 | get_account_id_from_seed::("Bob"), 45 | get_account_id_from_seed::("Charlie"), 46 | get_account_id_from_seed::("Dave"), 47 | get_account_id_from_seed::("Eve"), 48 | get_account_id_from_seed::("Ferdie"), 49 | get_account_id_from_seed::("Alice//stash"), 50 | get_account_id_from_seed::("Bob//stash"), 51 | get_account_id_from_seed::("Charlie//stash"), 52 | get_account_id_from_seed::("Dave//stash"), 53 | get_account_id_from_seed::("Eve//stash"), 54 | get_account_id_from_seed::("Ferdie//stash"), 55 | realis_game_api::Pallet::::account_id(), 56 | pallet_staking::Pallet::::account_id(), 57 | ] 58 | }); 59 | // endow all authorities and nominators. 60 | initial_authorities 61 | .iter() 62 | .map(|x| &x.0) 63 | .chain(initial_nominators.iter()) 64 | .for_each(|x| { 65 | if !endowed_accounts.contains(&x) { 66 | endowed_accounts.push(x.clone()) 67 | } 68 | }); 69 | 70 | // stakers: all validators and nominators. 71 | let mut rng = rand::thread_rng(); 72 | let stakers = initial_authorities 73 | .iter() 74 | .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)) 75 | .chain(initial_nominators.iter().map(|x| { 76 | use rand::{seq::SliceRandom, Rng}; 77 | let limit = (MAX_NOMINATIONS as usize).min(initial_authorities.len()); 78 | let count = rng.gen::() % limit; 79 | let nominations = initial_authorities 80 | .as_slice() 81 | .choose_multiple(&mut rng, count) 82 | .into_iter() 83 | .map(|choice| choice.0.clone()) 84 | .collect::>(); 85 | ( 86 | x.clone(), 87 | x.clone(), 88 | STASH, 89 | StakerStatus::Nominator(nominations), 90 | ) 91 | })) 92 | .collect::>(); 93 | 94 | let _num_endowed_accounts = endowed_accounts.len(); 95 | 96 | const ENDOWMENT: Balance = 30_000 * DOLLARS / 10; 97 | const GAME_WALLET: Balance = 10_000_000 * DOLLARS / 10; 98 | const STAKING_POOL: Balance = 30_000_000 * DOLLARS / 10; 99 | const STASH: Balance = ENDOWMENT / 1000; 100 | 101 | let pallet_id_staking = pallet_staking::Pallet::::account_id(); 102 | let game_wallet = realis_game_api::Pallet::::account_id(); 103 | 104 | GenesisConfig { 105 | system: SystemConfig { 106 | code: wasm_binary_unwrap().to_vec(), 107 | changes_trie_config: Default::default(), 108 | }, 109 | balances: BalancesConfig { 110 | balances: endowed_accounts 111 | .iter() 112 | .cloned() 113 | .map(|x| { 114 | if x == pallet_id_staking { 115 | (x, STAKING_POOL) 116 | } else if x == game_wallet { 117 | (x, GAME_WALLET) 118 | } else { 119 | (x, ENDOWMENT) 120 | } 121 | }) 122 | .collect(), 123 | }, 124 | indices: IndicesConfig { indices: vec![] }, 125 | session: SessionConfig { 126 | keys: initial_authorities 127 | .iter() 128 | .map(|x| { 129 | ( 130 | x.0.clone(), 131 | x.0.clone(), 132 | session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()), 133 | ) 134 | }) 135 | .collect::>(), 136 | }, 137 | staking: StakingConfig { 138 | validator_count: initial_authorities.len() as u32, 139 | minimum_validator_count: initial_authorities.len() as u32, 140 | invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), 141 | slash_reward_fraction: Perbill::from_percent(10), 142 | stakers, 143 | ..Default::default() 144 | }, 145 | // democracy: DemocracyConfig::default(), 146 | // elections: ElectionsConfig { 147 | // members: endowed_accounts 148 | // .iter() 149 | // .take((num_endowed_accounts + 1) / 2) 150 | // .cloned() 151 | // .map(|member| (member, STASH)) 152 | // .collect(), 153 | // }, 154 | // council: CouncilConfig::default(), 155 | // technical_committee: TechnicalCommitteeConfig { 156 | // members: endowed_accounts 157 | // .iter() 158 | // .take((num_endowed_accounts + 1) / 2) 159 | // .cloned() 160 | // .collect(), 161 | // phantom: Default::default(), 162 | // }, 163 | sudo: SudoConfig { key: root_key }, 164 | babe: BabeConfig { 165 | authorities: vec![], 166 | epoch_config: Some(node_runtime::BABE_GENESIS_EPOCH_CONFIG), 167 | }, 168 | im_online: ImOnlineConfig { keys: vec![] }, 169 | authority_discovery: AuthorityDiscoveryConfig { keys: vec![] }, 170 | grandpa: GrandpaConfig { 171 | authorities: vec![], 172 | }, 173 | // technical_membership: Default::default(), 174 | // treasury: Default::default(), 175 | // society: SocietyConfig { 176 | // members: endowed_accounts 177 | // .iter() 178 | // .take((num_endowed_accounts + 1) / 2) 179 | // .cloned() 180 | // .collect(), 181 | // pot: 0, 182 | // max_members: 999, 183 | // }, 184 | vesting: Default::default(), 185 | gilt: Default::default(), 186 | nft: NftConfig { 187 | nft_masters: nft_master, 188 | }, 189 | realis_game_api: RealisGameApiConfig { 190 | api_masters: api_master, 191 | whitelist: white_list, 192 | }, 193 | realis_bridge: RealisBridgeConfig { 194 | bridge_masters: bridge_master, 195 | }, 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /bin/node/cli/src/cli.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2018-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 | use sc_cli::structopt::StructOpt; 20 | use sc_cli::{KeySubcommand, RunCmd, SignCmd, VanityCmd, VerifyCmd}; 21 | 22 | /// An overarching CLI command definition. 23 | #[derive(Debug, StructOpt)] 24 | pub struct Cli { 25 | /// Possible subcommand with parameters. 26 | #[structopt(subcommand)] 27 | pub subcommand: Option, 28 | #[allow(missing_docs)] 29 | #[structopt(flatten)] 30 | pub run: RunCmd, 31 | } 32 | 33 | /// Possible subcommands of the main binary. 34 | #[derive(Debug, StructOpt)] 35 | pub enum Subcommand { 36 | /// Key management cli utilities 37 | Key(KeySubcommand), 38 | 39 | /// The custom inspect subcommmand for decoding blocks and extrinsics. 40 | #[structopt( 41 | name = "inspect", 42 | about = "Decode given block or extrinsic using current native runtime." 43 | )] 44 | Inspect(node_inspect::cli::InspectCmd), 45 | 46 | /// The custom benchmark subcommmand benchmarking runtime pallets. 47 | #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")] 48 | Benchmark(frame_benchmarking_cli::BenchmarkCmd), 49 | 50 | /// Try some command against runtime state. 51 | #[cfg(feature = "try-runtime")] 52 | TryRuntime(try_runtime_cli::TryRuntimeCmd), 53 | 54 | /// Try some command against runtime state. Note: `try-runtime` feature must be enabled. 55 | #[cfg(not(feature = "try-runtime"))] 56 | TryRuntime, 57 | 58 | /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. 59 | Verify(VerifyCmd), 60 | 61 | /// Generate a seed that provides a vanity address. 62 | Vanity(VanityCmd), 63 | 64 | /// Sign a message, with a given (secret) key. 65 | Sign(SignCmd), 66 | 67 | /// Build a chain specification. 68 | BuildSpec(sc_cli::BuildSpecCmd), 69 | 70 | /// Validate blocks. 71 | CheckBlock(sc_cli::CheckBlockCmd), 72 | 73 | /// Export blocks. 74 | ExportBlocks(sc_cli::ExportBlocksCmd), 75 | 76 | /// Export the state of a given block into a chain spec. 77 | ExportState(sc_cli::ExportStateCmd), 78 | 79 | /// Import blocks. 80 | ImportBlocks(sc_cli::ImportBlocksCmd), 81 | 82 | /// Remove the whole chain. 83 | PurgeChain(sc_cli::PurgeChainCmd), 84 | 85 | /// Revert the chain to a previous state. 86 | Revert(sc_cli::RevertCmd), 87 | } 88 | -------------------------------------------------------------------------------- /bin/node/cli/src/command.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2017-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 | use crate::{chain_spec, service, service::new_partial, Cli, Subcommand}; 20 | use node_executor::Executor; 21 | use node_runtime::{Block, RuntimeApi}; 22 | use sc_cli::{ChainSpec, Result, Role, RuntimeVersion, SubstrateCli}; 23 | use sc_service::PartialComponents; 24 | 25 | impl SubstrateCli for Cli { 26 | fn impl_name() -> String { 27 | "Realis Node".into() 28 | } 29 | 30 | fn impl_version() -> String { 31 | env!("SUBSTRATE_CLI_IMPL_VERSION").into() 32 | } 33 | 34 | fn description() -> String { 35 | env!("CARGO_PKG_DESCRIPTION").into() 36 | } 37 | 38 | fn author() -> String { 39 | env!("CARGO_PKG_AUTHORS").into() 40 | } 41 | 42 | fn support_url() -> String { 43 | "https://github.com/paritytech/substrate/issues/new".into() 44 | } 45 | 46 | fn copyright_start_year() -> i32 { 47 | 2017 48 | } 49 | 50 | fn load_spec(&self, id: &str) -> std::result::Result, String> { 51 | let spec = match id { 52 | "" => { 53 | return Err( 54 | "Please specify which chain you want to run, e.g. --dev or --chain=local" 55 | .into(), 56 | ) 57 | } 58 | "dev" => Box::new(chain_spec::development_config()), 59 | "local" => Box::new(chain_spec::local_testnet_config()), 60 | "fir" | "flaming-fir" => Box::new(chain_spec::flaming_fir_config()?), 61 | "staging" => Box::new(chain_spec::staging_testnet_config()), 62 | path => Box::new(chain_spec::ChainSpec::from_json_file( 63 | std::path::PathBuf::from(path), 64 | )?), 65 | }; 66 | Ok(spec) 67 | } 68 | 69 | fn native_runtime_version(_: &Box) -> &'static RuntimeVersion { 70 | &node_runtime::VERSION 71 | } 72 | } 73 | 74 | /// Parse command line arguments into service configuration. 75 | pub fn run() -> Result<()> { 76 | let cli = Cli::from_args(); 77 | 78 | match &cli.subcommand { 79 | None => { 80 | let runner = cli.create_runner(&cli.run)?; 81 | runner.run_node_until_exit(|config| async move { 82 | match config.role { 83 | Role::Light => service::new_light(config), 84 | _ => service::new_full(config), 85 | } 86 | .map_err(sc_cli::Error::Service) 87 | }) 88 | } 89 | Some(Subcommand::Inspect(cmd)) => { 90 | let runner = cli.create_runner(cmd)?; 91 | 92 | runner.sync_run(|config| cmd.run::(config)) 93 | } 94 | Some(Subcommand::Benchmark(cmd)) => { 95 | if cfg!(feature = "runtime-benchmarks") { 96 | let runner = cli.create_runner(cmd)?; 97 | 98 | runner.sync_run(|config| cmd.run::(config)) 99 | } else { 100 | Err("Benchmarking wasn't enabled when building the node. \ 101 | You can enable it with `--features runtime-benchmarks`." 102 | .into()) 103 | } 104 | } 105 | Some(Subcommand::Key(cmd)) => cmd.run(&cli), 106 | Some(Subcommand::Sign(cmd)) => cmd.run(), 107 | Some(Subcommand::Verify(cmd)) => cmd.run(), 108 | Some(Subcommand::Vanity(cmd)) => cmd.run(), 109 | Some(Subcommand::BuildSpec(cmd)) => { 110 | let runner = cli.create_runner(cmd)?; 111 | runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) 112 | } 113 | Some(Subcommand::CheckBlock(cmd)) => { 114 | let runner = cli.create_runner(cmd)?; 115 | runner.async_run(|config| { 116 | let PartialComponents { 117 | client, 118 | task_manager, 119 | import_queue, 120 | .. 121 | } = new_partial(&config)?; 122 | Ok((cmd.run(client, import_queue), task_manager)) 123 | }) 124 | } 125 | Some(Subcommand::ExportBlocks(cmd)) => { 126 | let runner = cli.create_runner(cmd)?; 127 | runner.async_run(|config| { 128 | let PartialComponents { 129 | client, 130 | task_manager, 131 | .. 132 | } = new_partial(&config)?; 133 | Ok((cmd.run(client, config.database), task_manager)) 134 | }) 135 | } 136 | Some(Subcommand::ExportState(cmd)) => { 137 | let runner = cli.create_runner(cmd)?; 138 | runner.async_run(|config| { 139 | let PartialComponents { 140 | client, 141 | task_manager, 142 | .. 143 | } = new_partial(&config)?; 144 | Ok((cmd.run(client, config.chain_spec), task_manager)) 145 | }) 146 | } 147 | Some(Subcommand::ImportBlocks(cmd)) => { 148 | let runner = cli.create_runner(cmd)?; 149 | runner.async_run(|config| { 150 | let PartialComponents { 151 | client, 152 | task_manager, 153 | import_queue, 154 | .. 155 | } = new_partial(&config)?; 156 | Ok((cmd.run(client, import_queue), task_manager)) 157 | }) 158 | } 159 | Some(Subcommand::PurgeChain(cmd)) => { 160 | let runner = cli.create_runner(cmd)?; 161 | runner.sync_run(|config| cmd.run(config.database)) 162 | } 163 | Some(Subcommand::Revert(cmd)) => { 164 | let runner = cli.create_runner(cmd)?; 165 | runner.async_run(|config| { 166 | let PartialComponents { 167 | client, 168 | task_manager, 169 | backend, 170 | .. 171 | } = new_partial(&config)?; 172 | Ok((cmd.run(client, backend), task_manager)) 173 | }) 174 | } 175 | #[cfg(feature = "try-runtime")] 176 | Some(Subcommand::TryRuntime(cmd)) => { 177 | let runner = cli.create_runner(cmd)?; 178 | runner.async_run(|config| { 179 | // we don't need any of the components of new_partial, just a runtime, or a task 180 | // manager to do `async_run`. 181 | let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); 182 | let task_manager = 183 | sc_service::TaskManager::new(config.task_executor.clone(), registry) 184 | .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; 185 | 186 | Ok((cmd.run::(config), task_manager)) 187 | }) 188 | } 189 | #[cfg(not(feature = "try-runtime"))] 190 | Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \ 191 | You can enable it with `--features try-runtime`." 192 | .into()), 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /bin/node/cli/src/lib.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2018-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 | //! Substrate CLI library. 20 | //! 21 | //! This package has two Cargo features: 22 | //! 23 | //! - `cli` (default): exposes functions that parse command-line options, then start and run the 24 | //! node as a CLI application. 25 | //! 26 | //! - `browser`: exposes the content of the `browser` module, which consists of exported symbols 27 | //! that are meant to be passed through the `wasm-bindgen` utility and called from JavaScript. 28 | //! Despite its name the produced WASM can theoretically also be used from NodeJS, although this 29 | //! hasn't been tested. 30 | 31 | // #![warn(missing_docs)] 32 | 33 | pub mod chain_spec; 34 | 35 | #[macro_use] 36 | mod service; 37 | #[cfg(feature = "browser")] 38 | mod browser; 39 | /// 40 | #[cfg(feature = "cli")] 41 | pub mod cli; 42 | #[cfg(feature = "cli")] 43 | mod command; 44 | 45 | #[cfg(feature = "browser")] 46 | pub use browser::*; 47 | #[cfg(feature = "cli")] 48 | pub use cli::*; 49 | #[cfg(feature = "cli")] 50 | pub use command::*; 51 | -------------------------------------------------------------------------------- /bin/node/runtime/build.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2019-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | use substrate_wasm_builder::WasmBuilder; 19 | 20 | fn main() { 21 | WasmBuilder::new() 22 | .with_current_project() 23 | .export_heap_base() 24 | .import_memory() 25 | .build() 26 | } 27 | -------------------------------------------------------------------------------- /bin/node/runtime/src/constants.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2019-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! A set of constant values used in substrate runtime. 19 | 20 | /// Money matters. 21 | pub mod currency { 22 | use node_primitives::Balance; 23 | 24 | pub const MILLICENTS: Balance = 1_000_000_000; 25 | pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent. 26 | pub const DOLLARS: Balance = 100 * CENTS; 27 | 28 | pub const fn deposit(items: u32, bytes: u32) -> Balance { 29 | items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS 30 | } 31 | 32 | pub const MILLI: Balance = MICRO * 1_000; // 10^(-3) 33 | pub const MICRO: Balance = NANO * 1_000; // 10^(-6) 34 | pub const NANO: Balance = PICO * 1_000; // 10^(-9) 35 | pub const PICO: Balance = 1; // 10^(-12) 36 | } 37 | 38 | /// Time. 39 | pub mod time { 40 | use node_primitives::{BlockNumber, Moment}; 41 | 42 | /// Since BABE is probabilistic this is the average expected block time that 43 | /// we are targeting. Blocks will be produced at a minimum duration defined 44 | /// by `SLOT_DURATION`, but some slots will not be allocated to any 45 | /// authority and hence no block will be produced. We expect to have this 46 | /// block time on average following the defined slot duration and the value 47 | /// of `c` configured for BABE (where `1 - c` represents the probability of 48 | /// a slot being empty). 49 | /// This value is only used indirectly to define the unit constants below 50 | /// that are expressed in blocks. The rest of the code should use 51 | /// `SLOT_DURATION` instead (like the Timestamp pallet for calculating the 52 | /// minimum period). 53 | /// 54 | /// If using BABE with secondary slots (default) then all of the slots will 55 | /// always be assigned, in which case `MILLISECS_PER_BLOCK` and 56 | /// `SLOT_DURATION` should have the same value. 57 | /// 58 | /// 59 | pub const MILLISECS_PER_BLOCK: Moment = 6000; 60 | pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000; 61 | 62 | // NOTE: Currently it is not possible to change the slot duration after the chain has started. 63 | // Attempting to do so will brick block production. 64 | pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; 65 | 66 | // 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks. 67 | pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); 68 | 69 | // NOTE: Currently it is not possible to change the epoch duration after the chain has started. 70 | // Attempting to do so will brick block production. 71 | pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES; 72 | pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = 1 * HOURS; 73 | 74 | // These time units are defined in number of blocks. 75 | pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber); 76 | pub const HOURS: BlockNumber = MINUTES * 60; 77 | pub const DAYS: BlockNumber = HOURS * 24; 78 | } 79 | -------------------------------------------------------------------------------- /docker/.env: -------------------------------------------------------------------------------- 1 | NATS_PORT=4222 2 | 3 | DATABASE_USER=postgres 4 | DATABASE_PASSWORD=postgres 5 | DATABASE_NAME=postgres1 6 | DATABASE_PORT=5431 -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | #ADD /blockchain_soul/ReAlis-Network/target/release/realis /realis/realis0 3 | #ENTRYPOINT ["bash","entrypoint.prod.sh"]tttt 4 | ADD ./realis /realis/realis 5 | RUN chmod +x /realis/realis 6 | RUN apt-get update 7 | RUN apt-get install ca-certificates -y 8 | RUN update-ca-certificates 9 | ADD ./realis.json /realis/realis.json 10 | WORKDIR /realis/chain 11 | EXPOSE 9944 9044 9033 12 | -------------------------------------------------------------------------------- /docker/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "2.2" 2 | 3 | services: 4 | blockchain: 5 | build: 6 | context: . 7 | dockerfile: local.Dockerfile 8 | ports: 9 | - 9944:9944 10 | - 9044:9044 11 | - 9033:9033 12 | 13 | nats: 14 | image: nats-streaming 15 | ports: 16 | - "${NATS_PORT}:4222" 17 | command: '--max_channels=2000' 18 | env_file: 19 | - .env 20 | 21 | db: 22 | image: postgres:latest 23 | restart: unless-stopped 24 | environment: 25 | POSTGRES_USER: ${DATABASE_USER} 26 | POSTGRES_PASSWORD: ${DATABASE_PASSWORD} # username: postgres 27 | POSTGRES_DB: ${DATABASE_NAME} # db name 28 | ports: 29 | - ${DATABASE_PORT}:5432 30 | env_file: 31 | - .env 32 | # volumes: 33 | # - ${HOME}/.postgres:/root/.postgres 34 | -------------------------------------------------------------------------------- /docker/local.Dockerfile: -------------------------------------------------------------------------------- 1 | ### 2 | FROM ubuntu:18.04 as builder 3 | RUN apt update && apt install curl build-essential libclang-dev clang git -y 4 | RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y 5 | 6 | RUN . $HOME/.cargo/env && \ 7 | rustup install nightly-2021-10-20 && \ 8 | rustup target add wasm32-unknown-unknown --toolchain nightly-2021-10-20 9 | 10 | COPY . . 11 | RUN . $HOME/.cargo/env && \ 12 | cargo build --release 13 | 14 | ### 15 | 16 | FROM ubuntu:20.04 17 | RUN apt-get update && apt-get install ca-certificates -y && update-ca-certificates 18 | 19 | ARG NODENAME=REALIS-NODE 20 | ENV NODENAME=$NODENAME 21 | 22 | RUN mkdir -p /realis-blockchain/data 23 | WORKDIR /realis-blockchain 24 | COPY realis.json /realis-blockchain/realis.json 25 | COPY --from=builder ./target/release/realis /realis-blockchain/realis 26 | 27 | ENTRYPOINT ["/bin/bash", "-c", \ 28 | "/realis-blockchain/realis \ 29 | --dev \ 30 | --tmp \ 31 | --ws-port=9943 \ 32 | --rpc-port=9922 \ 33 | --validator \ 34 | --rpc-methods=Unsafe \ 35 | --listen-addr /ip4/0.0.0.0/tcp/30333 \ 36 | --name=${NODENAME} \ 37 | --unsafe-ws-external \ 38 | --unsafe-rpc-external \ 39 | --rpc-cors='*'"] 40 | -------------------------------------------------------------------------------- /docker/realis: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RealisNetwork/Realis.Network/20a4c14e6e268e802062fc4d7e41b504d87186e4/docker/realis -------------------------------------------------------------------------------- /docker/run-realis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | IMAGE="daelon02/realis-network" 3 | CONTAINER="realis-test" 4 | docker rm -f ${CONTAINER} 5 | docker rmi ${IMAGE} 6 | docker build -t ${IMAGE} . 7 | docker push ${IMAGE} 8 | docker run -d --name=${CONTAINER} --net=host \ 9 | -v /blockchain_soul/soul/nikita1:/realis/chain \ 10 | ${IMAGE} \ 11 | /realis/realis \ 12 | --chain ../realis.json \ 13 | --ws-port 9944 \ 14 | --rpc-port 9933 \ 15 | --validator \ 16 | --reserved-nodes /ip4/135.181.18.215/tcp/30333/p2p/12D3KooW9poizzemF6kb6iSbkoJynMhswa4oJe5W9v34eFuRcU47 \ 17 | --rpc-methods=Unsafe \ 18 | --name MyNode01 \ 19 | --unsafe-ws-external \ 20 | --unsafe-rpc-external \ 21 | --rpc-cors '*' \ 22 | -d /realis/chain 23 | -------------------------------------------------------------------------------- /frame/marketplace/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marketplace" 3 | version = "0.0.1" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [package.metadata.docs.rs] 9 | targets = ["x86_64-unknown-linux-gnu"] 10 | 11 | [dependencies] 12 | codec = { package = 'parity-scale-codec', version = '2.3.0', default-features = false, features = ['derive'] } 13 | primitive-types = { version = "0.10.1", default-features = false } 14 | serde = { version = "1.0.133", default-features = false } 15 | serde_json = { version = "1.0.79", default-features = false } 16 | pallet-staking = { version = "4.0.0-dev", path="../staking-pool", default-features = false } 17 | 18 | frame-benchmarking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", version = "4.0.0-dev", default-features = false, optional = true } 19 | frame-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 20 | frame-system = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 21 | sp-std = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 22 | sp-runtime = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 23 | sp-io = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 24 | sp-core = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 25 | sp-arithmetic = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 26 | pallet-balances = { default-features = false, git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 27 | node-primitives = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 28 | 29 | realis-primitives = { path = "../../primitives/realis", default-features = false } 30 | pallet-nft = { version = "0.0.2", path = "../nft", default-features = false } 31 | #realis-game-api = { path = "../realis-game-api", default-features = false } 32 | 33 | [dev-dependencies] 34 | node-primitives = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 35 | sp-io = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 36 | 37 | 38 | [features] 39 | default = ["std"] 40 | std = [ 41 | "codec/std", 42 | "serde/std", 43 | "frame-benchmarking/std", 44 | "frame-support/std", 45 | "frame-system/std", 46 | "pallet-balances/std", 47 | "sp-runtime/std", 48 | "sp-std/std", 49 | "node-primitives/std", 50 | "realis-primitives/std", 51 | "pallet-nft/std", 52 | "sp-core/std", 53 | "sp-io/std", 54 | "serde_json/std", 55 | "pallet-staking/std", 56 | # "realis-game-api/std" 57 | ] 58 | 59 | runtime-benchmarks = ["frame-benchmarking"] 60 | try-runtime = ["frame-support/try-runtime"] 61 | 62 | -------------------------------------------------------------------------------- /frame/marketplace/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "runtime-benchmarks")] 2 | 3 | mod benchmarking { 4 | use crate::*; 5 | use frame_benchmarking::benchmarks; 6 | use frame_support::traits::Currency; 7 | use frame_system::RawOrigin as SystemOrigin; 8 | use pallet::Pallet as Marketplace; 9 | use pallet_nft::NftMasters; 10 | use pallet_nft::Pallet as Nft; 11 | use primitive_types::U256; 12 | use realis_primitives::*; 13 | 14 | const ED_MULTIPLIER: u128 = 1_000_000_000_000_000; 15 | 16 | // Get Alice AccountId 17 | fn alice() -> T::AccountId { 18 | let alice = NftMasters::::get(); 19 | alice.get(0).unwrap().clone() 20 | } 21 | 22 | benchmarks! { 23 | sell_nft { 24 | let caller = alice::(); 25 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 26 | let balance = T::MarketCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 27 | T::MarketCurrency::make_free_balance_be(&caller, balance); 28 | Nft::::mint( 29 | owner_origin.clone(), 30 | caller.clone(), 31 | b"QQ".to_vec(), 32 | U256([1, 0, 0, 0]), 33 | 1, 34 | Rarity::Common, 35 | b"QQ".to_vec(), 36 | )?; 37 | }: _( 38 | SystemOrigin::Signed(caller.clone()), 39 | U256([1, 0, 0, 0]), 40 | 10 41 | ) 42 | 43 | buy_nft { 44 | let caller = alice::(); 45 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 46 | let balance = T::MarketCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 47 | T::MarketCurrency::make_free_balance_be(&caller, balance); 48 | Nft::::mint( 49 | owner_origin.clone(), 50 | caller.clone(), 51 | b"QQ".to_vec(), 52 | U256([1, 0, 0, 0]), 53 | 1, 54 | Rarity::Common, 55 | b"QQ".to_vec(), 56 | )?; 57 | Marketplace::::sell_nft ( 58 | owner_origin, 59 | U256([1, 0, 0, 0]), 60 | 10 61 | )?; 62 | }: _( 63 | SystemOrigin::Signed(caller.clone()), 64 | U256([1, 0, 0, 0]) 65 | ) 66 | 67 | change_price_nft { 68 | let caller = alice::(); 69 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 70 | let balance = T::MarketCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 71 | T::MarketCurrency::make_free_balance_be(&caller, balance); 72 | Nft::::mint( 73 | owner_origin.clone(), 74 | caller.clone(), 75 | b"QQ".to_vec(), 76 | U256([1, 0, 0, 0]), 77 | 1, 78 | Rarity::Common, 79 | b"QQ".to_vec(), 80 | )?; 81 | Marketplace::::sell_nft ( 82 | owner_origin, 83 | U256([1, 0, 0, 0]), 84 | 10 85 | )?; 86 | }: _( 87 | SystemOrigin::Signed(caller.clone()), 88 | U256([1, 0, 0, 0]), 89 | 5 90 | ) 91 | 92 | remove_from_marketplace_nft { 93 | let caller = alice::(); 94 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 95 | let balance = T::MarketCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 96 | T::MarketCurrency::make_free_balance_be(&caller, balance); 97 | Nft::::mint( 98 | owner_origin.clone(), 99 | caller.clone(), 100 | b"QQ".to_vec(), 101 | U256([1, 0, 0, 0]), 102 | 1, 103 | Rarity::Common, 104 | b"QQ".to_vec(), 105 | )?; 106 | Marketplace::::sell_nft ( 107 | owner_origin, 108 | U256([1, 0, 0, 0]), 109 | 10 110 | )?; 111 | }: _( 112 | SystemOrigin::Signed(caller.clone()), 113 | U256([1, 0, 0, 0]) 114 | ) 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /frame/marketplace/src/weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Autogenerated weights for marketplace 19 | //! 20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 21 | //! DATE: 2021-11-25, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` 22 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 23 | 24 | // Executed Command: 25 | // ./target/release/realis 26 | // benchmark 27 | // --chain 28 | // dev 29 | // --execution 30 | // wasm 31 | // --wasm-execution 32 | // compiled 33 | // --pallet 34 | // marketplace 35 | // --extrinsic 36 | // * 37 | // --steps 38 | // 20 39 | // --repeat 40 | // 10 41 | // --raw 42 | // --output=./frame/marketplace/src/weights.rs 43 | // --template=./.maintain/frame-weight-template.hbs 44 | 45 | #![allow(unused_parens)] 46 | #![allow(unused_imports)] 47 | 48 | use frame_support::{ 49 | traits::Get, 50 | weights::{constants::RocksDbWeight, Weight}, 51 | }; 52 | use sp_std::marker::PhantomData; 53 | 54 | /// Weight functions needed for marketplace. 55 | pub trait WeightInfoMarketplace { 56 | fn sell_nft() -> Weight; 57 | fn buy_nft() -> Weight; 58 | fn change_price_nft() -> Weight; 59 | fn remove_from_marketplace_nft() -> Weight; 60 | } 61 | 62 | /// Weights for marketplace using the Substrate node and recommended hardware. 63 | pub struct SubstrateWeight(PhantomData); 64 | impl WeightInfoMarketplace for SubstrateWeight { 65 | fn sell_nft() -> Weight { 66 | (69_251_000 as Weight) 67 | .saturating_add(T::DbWeight::get().reads(4 as Weight)) 68 | .saturating_add(T::DbWeight::get().writes(3 as Weight)) 69 | } 70 | fn buy_nft() -> Weight { 71 | (96_914_000 as Weight) 72 | .saturating_add(T::DbWeight::get().reads(5 as Weight)) 73 | .saturating_add(T::DbWeight::get().writes(5 as Weight)) 74 | } 75 | fn change_price_nft() -> Weight { 76 | (49_904_000 as Weight) 77 | .saturating_add(T::DbWeight::get().reads(3 as Weight)) 78 | .saturating_add(T::DbWeight::get().writes(2 as Weight)) 79 | } 80 | fn remove_from_marketplace_nft() -> Weight { 81 | (57_829_000 as Weight) 82 | .saturating_add(T::DbWeight::get().reads(4 as Weight)) 83 | .saturating_add(T::DbWeight::get().writes(3 as Weight)) 84 | } 85 | } 86 | 87 | // For backwards compatibility and tests 88 | impl WeightInfoMarketplace for () { 89 | fn sell_nft() -> Weight { 90 | (69_251_000 as Weight) 91 | .saturating_add(RocksDbWeight::get().reads(4 as Weight)) 92 | .saturating_add(RocksDbWeight::get().writes(3 as Weight)) 93 | } 94 | fn buy_nft() -> Weight { 95 | (96_914_000 as Weight) 96 | .saturating_add(RocksDbWeight::get().reads(5 as Weight)) 97 | .saturating_add(RocksDbWeight::get().writes(5 as Weight)) 98 | } 99 | fn change_price_nft() -> Weight { 100 | (49_904_000 as Weight) 101 | .saturating_add(RocksDbWeight::get().reads(3 as Weight)) 102 | .saturating_add(RocksDbWeight::get().writes(2 as Weight)) 103 | } 104 | fn remove_from_marketplace_nft() -> Weight { 105 | (57_829_000 as Weight) 106 | .saturating_add(RocksDbWeight::get().reads(4 as Weight)) 107 | .saturating_add(RocksDbWeight::get().writes(3 as Weight)) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /frame/nft-delegate/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-nft-delegate" 3 | version = "0.0.1" 4 | edition = "2018" 5 | 6 | [package.metadata.docs.rs] 7 | targets = ["x86_64-unknown-linux-gnu"] 8 | 9 | [dependencies] 10 | realis-primitives = { path = "../../primitives/realis", default-features = false } 11 | pallet-nft = { version = "0.0.2", path = "../nft", default-features = false } 12 | pallet-staking = { version = "4.0.0-dev", path="../staking-pool", default-features = false } 13 | 14 | frame-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 15 | frame-system = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 16 | frame-benchmarking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", version = "4.0.0-dev", default-features = false, optional = true } 17 | node-primitives = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 18 | sp-std = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 19 | primitive-types = { version = "0.10.1", default-features = false } 20 | 21 | 22 | codec = { package = "parity-scale-codec", version = "2.0.1", default-features = false, features = ["derive"] } 23 | 24 | 25 | [features] 26 | default = ["std"] 27 | std = [ 28 | "codec/std", 29 | "frame-support/std", 30 | "frame-system/std", 31 | "pallet-staking/std", 32 | "frame-benchmarking/std", 33 | "pallet-nft/std", 34 | "realis-primitives/std", 35 | ] 36 | 37 | runtime-benchmarks = ["frame-benchmarking"] 38 | try-runtime = ["frame-support/try-runtime"] 39 | -------------------------------------------------------------------------------- /frame/nft-delegate/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "runtime-benchmarks")] 2 | 3 | mod benchmarking { 4 | use crate::*; 5 | use frame_benchmarking::{account, benchmarks}; 6 | use frame_support::traits::Currency; 7 | use frame_system::RawOrigin as SystemOrigin; 8 | use pallet::Pallet as NftDelegate; 9 | use pallet_nft::NftMasters; 10 | use pallet_nft::Pallet as Nft; 11 | use primitive_types::U256; 12 | use realis_primitives::*; 13 | 14 | const ED_MULTIPLIER: u128 = 1_000_000_000_000_000; 15 | 16 | // Get Alice AccountId 17 | fn alice() -> T::AccountId { 18 | let alice = NftMasters::::get(); 19 | alice.get(0).unwrap().clone() 20 | } 21 | 22 | benchmarks! { 23 | delegate { 24 | let caller = alice::(); 25 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 26 | let buyer: T::AccountId = account("buyer", 0, 1); 27 | let balance = T::DelegateCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 28 | T::DelegateCurrency::make_free_balance_be(&caller, balance); 29 | T::DelegateCurrency::make_free_balance_be(&buyer, balance); 30 | Nft::::mint( 31 | owner_origin.clone(), 32 | caller.clone(), 33 | b"QQ".to_vec(), 34 | U256([1, 0, 0, 0]), 35 | 1, 36 | Rarity::Common, 37 | b"QQ".to_vec(), 38 | )?; 39 | }: _( 40 | SystemOrigin::Signed(caller.clone()), 41 | buyer, 42 | U256([1, 0, 0, 0]), 43 | 10 44 | ) 45 | 46 | sell_delegate { 47 | let caller = alice::(); 48 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 49 | Nft::::mint( 50 | owner_origin.clone(), 51 | caller.clone(), 52 | b"QQ".to_vec(), 53 | U256([1, 0, 0, 0]), 54 | 1, 55 | Rarity::Common, 56 | b"QQ".to_vec(), 57 | )?; 58 | }: _( 59 | SystemOrigin::Signed(caller.clone()), 60 | U256([1, 0, 0, 0]), 61 | 10, 62 | 100 63 | ) 64 | 65 | buy_delegate { 66 | let caller = alice::(); 67 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 68 | let buyer: T::AccountId = account("buyer", 0, 1); 69 | let balance = T::DelegateCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 70 | T::DelegateCurrency::make_free_balance_be(&caller, balance); 71 | T::DelegateCurrency::make_free_balance_be(&buyer, balance); 72 | Nft::::mint( 73 | owner_origin.clone(), 74 | caller.clone(), 75 | b"QQ".to_vec(), 76 | U256([1, 0, 0, 0]), 77 | 1, 78 | Rarity::Common, 79 | b"QQ".to_vec(), 80 | )?; 81 | }: _( 82 | SystemOrigin::Signed(buyer.clone()), 83 | U256([1, 0, 0, 0]) 84 | ) 85 | 86 | change_price_delegate { 87 | let caller = alice::(); 88 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 89 | let buyer: T::AccountId = account("buyer", 0, 1); 90 | let balance = T::DelegateCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 91 | T::DelegateCurrency::make_free_balance_be(&caller, balance); 92 | T::DelegateCurrency::make_free_balance_be(&buyer, balance); 93 | Nft::::mint( 94 | owner_origin.clone(), 95 | caller.clone(), 96 | b"QQ".to_vec(), 97 | U256([1, 0, 0, 0]), 98 | 1, 99 | Rarity::Common, 100 | b"QQ".to_vec(), 101 | )?; 102 | NftDelegate::::sell_delegate ( 103 | owner_origin, 104 | U256([1, 0, 0, 0]), 105 | 5, 106 | 20 107 | )?; 108 | }: _( 109 | SystemOrigin::Signed(caller.clone()), 110 | U256([1, 0, 0, 0]), 111 | 200 112 | ) 113 | 114 | change_delegate_time_on_sale { 115 | let caller = alice::(); 116 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 117 | Nft::::mint( 118 | owner_origin.clone(), 119 | caller.clone(), 120 | b"QQ".to_vec(), 121 | U256([1, 0, 0, 0]), 122 | 1, 123 | Rarity::Common, 124 | b"QQ".to_vec(), 125 | )?; 126 | NftDelegate::::sell_delegate ( 127 | owner_origin, 128 | U256([1, 0, 0, 0]), 129 | 2, 130 | 20 131 | )?; 132 | }: _( 133 | SystemOrigin::Signed(caller.clone()), 134 | U256([1, 0, 0, 0]), 135 | 200 136 | ) 137 | 138 | remove_from_sell { 139 | let caller = alice::(); 140 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 141 | let buyer: T::AccountId = account("buyer", 0, 1); 142 | let balance = T::DelegateCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 143 | T::DelegateCurrency::make_free_balance_be(&caller, balance); 144 | T::DelegateCurrency::make_free_balance_be(&buyer, balance); 145 | Nft::::mint( 146 | owner_origin.clone(), 147 | caller.clone(), 148 | b"QQ".to_vec(), 149 | U256([1, 0, 0, 0]), 150 | 1, 151 | Rarity::Common, 152 | b"QQ".to_vec(), 153 | )?; 154 | NftDelegate::::sell_delegate ( 155 | owner_origin, 156 | U256([1, 0, 0, 0]), 157 | 2, 158 | 20 159 | )?; 160 | }: _( 161 | SystemOrigin::Signed(caller.clone()), 162 | U256([1, 0, 0, 0]) 163 | ) 164 | 165 | remove_delegate { 166 | let caller = alice::(); 167 | let buyer: T::AccountId = account("buyer", 0, 1); 168 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 169 | let balance = T::DelegateCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER * 10).into()); 170 | T::DelegateCurrency::make_free_balance_be(&caller, balance); 171 | T::DelegateCurrency::make_free_balance_be(&buyer, balance); 172 | Nft::::mint( 173 | owner_origin.clone(), 174 | caller.clone(), 175 | b"QQ".to_vec(), 176 | U256([1, 0, 0, 0]), 177 | 1, 178 | Rarity::Common, 179 | b"QQ".to_vec(), 180 | )?; 181 | NftDelegate::::sell_delegate ( 182 | owner_origin.clone(), 183 | U256([1, 0, 0, 0]), 184 | 2, 185 | 20 186 | )?; 187 | NftDelegate::::delegate ( 188 | owner_origin, 189 | buyer, 190 | U256([1, 0, 0, 0]), 191 | 1 192 | )?; 193 | CurrentBlock::::mutate(|x| *x = T::BlockNumber::from(2_u32)); 194 | }: _ ( 195 | SystemOrigin::Signed(caller.clone()), 196 | U256([1, 0, 0, 0]) 197 | ) 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /frame/nft-delegate/src/weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Autogenerated weights for pallet_nft_delegate 19 | //! 20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 21 | //! DATE: 2021-11-24, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` 22 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 23 | 24 | // Executed Command: 25 | // ./target/release/realis 26 | // benchmark 27 | // --chain 28 | // dev 29 | // --execution 30 | // wasm 31 | // --wasm-execution 32 | // compiled 33 | // --pallet 34 | // pallet-nft-delegate 35 | // --extrinsic 36 | // * 37 | // --steps 38 | // 20 39 | // --repeat 40 | // 10 41 | // --raw 42 | // --output=./frame/nft-delegate/src/weights.rs 43 | // --template=./.maintain/frame-weight-template.hbs 44 | 45 | #![allow(unused_parens)] 46 | #![allow(unused_imports)] 47 | 48 | use frame_support::{ 49 | traits::Get, 50 | weights::{constants::RocksDbWeight, Weight}, 51 | }; 52 | use sp_std::marker::PhantomData; 53 | 54 | /// Weight functions needed for pallet_nft_delegate. 55 | pub trait WeightInfoNftDelegate { 56 | fn delegate() -> Weight; 57 | fn sell_delegate() -> Weight; 58 | fn buy_delegate() -> Weight; 59 | fn change_price_delegate() -> Weight; 60 | fn change_delegate_time_on_sale() -> Weight; 61 | fn remove_from_sell() -> Weight; 62 | fn remove_delegate() -> Weight; 63 | } 64 | 65 | /// Weights for pallet_nft_delegate using the Substrate node and recommended hardware. 66 | pub struct SubstrateWeight(PhantomData); 67 | impl WeightInfoNftDelegate for SubstrateWeight { 68 | fn delegate() -> Weight { 69 | (76_114_000 as Weight) 70 | .saturating_add(T::DbWeight::get().reads(4 as Weight)) 71 | .saturating_add(T::DbWeight::get().writes(3 as Weight)) 72 | } 73 | fn sell_delegate() -> Weight { 74 | (48_542_000 as Weight) 75 | .saturating_add(T::DbWeight::get().reads(3 as Weight)) 76 | .saturating_add(T::DbWeight::get().writes(2 as Weight)) 77 | } 78 | fn buy_delegate() -> Weight { 79 | (136_088_000 as Weight) 80 | .saturating_add(T::DbWeight::get().reads(7 as Weight)) 81 | .saturating_add(T::DbWeight::get().writes(6 as Weight)) 82 | } 83 | fn change_price_delegate() -> Weight { 84 | (19_887_000 as Weight) 85 | .saturating_add(T::DbWeight::get().reads(2 as Weight)) 86 | .saturating_add(T::DbWeight::get().writes(1 as Weight)) 87 | } 88 | fn change_delegate_time_on_sale() -> Weight { 89 | (19_818_000 as Weight) 90 | .saturating_add(T::DbWeight::get().reads(2 as Weight)) 91 | .saturating_add(T::DbWeight::get().writes(1 as Weight)) 92 | } 93 | fn remove_from_sell() -> Weight { 94 | (33_133_000 as Weight) 95 | .saturating_add(T::DbWeight::get().reads(3 as Weight)) 96 | .saturating_add(T::DbWeight::get().writes(2 as Weight)) 97 | } 98 | fn remove_delegate() -> Weight { 99 | (41_839_000 as Weight) 100 | .saturating_add(T::DbWeight::get().reads(4 as Weight)) 101 | .saturating_add(T::DbWeight::get().writes(2 as Weight)) 102 | } 103 | } 104 | 105 | // For backwards compatibility and tests 106 | impl WeightInfoNftDelegate for () { 107 | fn delegate() -> Weight { 108 | (76_114_000 as Weight) 109 | .saturating_add(RocksDbWeight::get().reads(4 as Weight)) 110 | .saturating_add(RocksDbWeight::get().writes(3 as Weight)) 111 | } 112 | fn sell_delegate() -> Weight { 113 | (48_542_000 as Weight) 114 | .saturating_add(RocksDbWeight::get().reads(3 as Weight)) 115 | .saturating_add(RocksDbWeight::get().writes(2 as Weight)) 116 | } 117 | fn buy_delegate() -> Weight { 118 | (136_088_000 as Weight) 119 | .saturating_add(RocksDbWeight::get().reads(7 as Weight)) 120 | .saturating_add(RocksDbWeight::get().writes(6 as Weight)) 121 | } 122 | fn change_price_delegate() -> Weight { 123 | (19_887_000 as Weight) 124 | .saturating_add(RocksDbWeight::get().reads(2 as Weight)) 125 | .saturating_add(RocksDbWeight::get().writes(1 as Weight)) 126 | } 127 | fn change_delegate_time_on_sale() -> Weight { 128 | (19_818_000 as Weight) 129 | .saturating_add(RocksDbWeight::get().reads(2 as Weight)) 130 | .saturating_add(RocksDbWeight::get().writes(1 as Weight)) 131 | } 132 | fn remove_from_sell() -> Weight { 133 | (33_133_000 as Weight) 134 | .saturating_add(RocksDbWeight::get().reads(3 as Weight)) 135 | .saturating_add(RocksDbWeight::get().writes(2 as Weight)) 136 | } 137 | fn remove_delegate() -> Weight { 138 | (41_839_000 as Weight) 139 | .saturating_add(RocksDbWeight::get().reads(4 as Weight)) 140 | .saturating_add(RocksDbWeight::get().writes(2 as Weight)) 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /frame/nft/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Substrate DevHub "] 3 | description = "FRAME pallet template for defining custom runtime logic." 4 | edition = "2018" 5 | homepage = "https://substrate.dev" 6 | license = "Unlicense" 7 | name = "pallet-nft" 8 | repository = "https://github.com/substrate-developer-hub/substrate-node-template/" 9 | version = "0.0.2" 10 | 11 | [package.metadata.docs.rs] 12 | targets = ["x86_64-unknown-linux-gnu"] 13 | 14 | [dependencies] 15 | hex-literal = "0.3.4" 16 | codec = { package = "parity-scale-codec", version = "2.0.1", default-features = false, features = ["derive"] } 17 | serde = { version = "1.0.133", optional = true } 18 | primitive-types = { version = "0.10.1", default-features = false } 19 | frame-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 20 | frame-system = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 21 | frame-benchmarking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", version = "4.0.0-dev", default-features = false, optional = true } 22 | pallet-balances = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 23 | sp-runtime = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 24 | sp-std = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 25 | sp-core = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 26 | node-primitives = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 27 | realis-primitives = { path = "../../primitives/realis", default-features = false } 28 | 29 | [dev-dependencies] 30 | node-primitives = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 31 | sp-io ={ git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 32 | #sp-runtime = { version = "2.0.0", default-features = false, path = "../../primitives/runtime" } 33 | 34 | 35 | [features] 36 | default = ["std"] 37 | std = [ 38 | "serde", 39 | "codec/std", 40 | "frame-benchmarking/std", 41 | "frame-support/std", 42 | "frame-system/std", 43 | "pallet-balances/std", 44 | "sp-runtime/std", 45 | "sp-std/std", 46 | "primitive-types/std", 47 | "node-primitives/std", 48 | "realis-primitives/std" 49 | ] 50 | 51 | runtime-benchmarks = ["frame-benchmarking"] 52 | try-runtime = ["frame-support/try-runtime"] 53 | -------------------------------------------------------------------------------- /frame/nft/README.md: -------------------------------------------------------------------------------- 1 | NFT module for create a NFT-Tokens. 2 | 3 | You can burn and transfer your NFT-Tokens, only sudo account can mint NFT-Tokens. 4 | In order to see the number of tokens on the account, you need to go to the chain state, select the nft pallet, 5 | and select tokenForAccount. 6 | To view who the user is by token ID, you need to go to the chain state, select the nft pallet, and select AccountForToken, and write TokenId. 7 | 8 | License: Apache-2.0 -------------------------------------------------------------------------------- /frame/nft/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "runtime-benchmarks")] 2 | 3 | mod benchmarking { 4 | use crate::Pallet as Nft; 5 | use crate::*; 6 | use frame_benchmarking::{account, benchmarks}; 7 | use frame_system::RawOrigin as SystemOrigin; 8 | use primitive_types::U256; 9 | use realis_primitives::*; 10 | 11 | const SEED: u32 = 1; 12 | 13 | // Get Alice AccountId 14 | fn alice() -> T::AccountId { 15 | let alice = crate::NftMasters::::get(); 16 | alice.get(0).unwrap().clone() 17 | } 18 | 19 | benchmarks! { 20 | mint { 21 | let caller = alice::(); 22 | }: _( 23 | SystemOrigin::Signed(caller.clone()), 24 | caller.clone(), 25 | b"QQ".to_vec(), 26 | U256([1, 1, 1, 0]), 27 | 1, 28 | Rarity::Common, 29 | b"QQ".to_vec() 30 | ) 31 | 32 | // burn { 33 | // let caller = alice::(); 34 | // let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 35 | // Nft::::mint( 36 | // owner_origin, 37 | // caller.clone(), 38 | // U256([1, 0, 0, 0]), 39 | // Rarity::Common, 40 | // Socket::Head, 41 | // Params { 42 | // strength: 1, 43 | // agility: 1, 44 | // intelligence: 1 45 | // }); 46 | // }: _( 47 | // SystemOrigin::Signed(caller.clone()), 48 | // U256([1, 0, 0, 0]) 49 | // ) 50 | 51 | transfer { 52 | let caller = alice::(); 53 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 54 | let recipient: T::AccountId = account("recipient", 1, SEED); 55 | Nft::::mint( 56 | owner_origin, 57 | caller.clone(), 58 | b"QQ".to_vec(), 59 | U256([1, 1, 1, 0]), 60 | 1, 61 | Rarity::Common, 62 | b"QQ".to_vec() 63 | )?; 64 | }: _( 65 | SystemOrigin::Signed(caller.clone()), 66 | recipient, 67 | U256([1, 1, 1, 0]) 68 | ) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /frame/nft/src/mock.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | use crate::{self as pallet_nft}; 4 | 5 | use frame_support::traits::GenesisBuild; 6 | use frame_support::{construct_runtime, parameter_types}; 7 | use sp_core::H256; 8 | use sp_runtime::{ 9 | testing::Header, 10 | traits::{BlakeTwo256, IdentityLookup}, 11 | }; 12 | 13 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; 14 | type Block = frame_system::mocking::MockBlock; 15 | 16 | construct_runtime!( 17 | pub enum Test where 18 | Block = Block, 19 | NodeBlock = Block, 20 | UncheckedExtrinsic = UncheckedExtrinsic, 21 | { 22 | System: frame_system::{Pallet, Call, Config, Storage, Event}, 23 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, 24 | Nft: pallet_nft::{Pallet, Call, Storage, Event}, 25 | } 26 | ); 27 | 28 | parameter_types! { 29 | pub const BlockHashCount: u64 = 250; 30 | } 31 | impl frame_system::Config for Test { 32 | type BaseCallFilter = frame_support::traits::AllowAll; 33 | type BlockWeights = (); 34 | type BlockLength = (); 35 | type Origin = Origin; 36 | type Call = Call; 37 | type Index = u64; 38 | type BlockNumber = u64; 39 | type Hash = H256; 40 | type Hashing = BlakeTwo256; 41 | type AccountId = u64; 42 | type Lookup = IdentityLookup; 43 | type Header = Header; 44 | type Event = Event; 45 | type BlockHashCount = BlockHashCount; 46 | type DbWeight = (); 47 | type Version = (); 48 | type PalletInfo = PalletInfo; 49 | type AccountData = pallet_balances::AccountData; 50 | type OnNewAccount = (); 51 | type OnKilledAccount = (); 52 | type SystemWeightInfo = (); 53 | type SS58Prefix = (); 54 | type OnSetCode = (); 55 | } 56 | 57 | parameter_types! { 58 | pub const ExistentialDeposit: u64 = 1; 59 | } 60 | 61 | impl pallet_balances::Config for Test { 62 | type MaxLocks = (); 63 | type MaxReserves = (); 64 | type ReserveIdentifier = [u8; 8]; 65 | type Balance = u64; 66 | type Event = Event; 67 | type DustRemoval = (); 68 | type ExistentialDeposit = ExistentialDeposit; 69 | type AccountStore = System; 70 | type WeightInfo = (); 71 | } 72 | 73 | parameter_types! { 74 | pub const ExistentialDepositOfRealisTokens: u128 = 1; 75 | } 76 | 77 | impl Config for Test { 78 | type Event = Event; 79 | type Balance = u128; 80 | type WeightInfo = pallet_nft::weights::SubstrateWeight; 81 | } 82 | 83 | pub fn new_test_ext(nft_master: Vec) -> sp_io::TestExternalities { 84 | let mut t = frame_system::GenesisConfig::default() 85 | .build_storage::() 86 | .unwrap(); 87 | pallet_nft::GenesisConfig:: { 88 | nft_masters: nft_master, 89 | } 90 | .assimilate_storage(&mut t) 91 | .unwrap(); 92 | t.into() 93 | } 94 | -------------------------------------------------------------------------------- /frame/nft/src/weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Autogenerated weights for pallet_nft 19 | //! 20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 21 | //! DATE: 2021-11-25, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` 22 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 23 | 24 | // Executed Command: 25 | // ./target/release/realis 26 | // benchmark 27 | // --chain 28 | // dev 29 | // --execution 30 | // wasm 31 | // --wasm-execution 32 | // compiled 33 | // --pallet 34 | // pallet-nft 35 | // --extrinsic 36 | // * 37 | // --steps 38 | // 20 39 | // --repeat 40 | // 10 41 | // --raw 42 | // --output=./frame/nft/src/weights.rs 43 | // --template=./.maintain/frame-weight-template.hbs 44 | 45 | #![allow(unused_parens)] 46 | #![allow(unused_imports)] 47 | 48 | use frame_support::{ 49 | traits::Get, 50 | weights::{constants::RocksDbWeight, Weight}, 51 | }; 52 | use sp_std::marker::PhantomData; 53 | 54 | /// Weight functions needed for pallet_nft. 55 | pub trait WeightInfoNft { 56 | fn mint() -> Weight; 57 | fn transfer() -> Weight; 58 | } 59 | 60 | /// Weights for pallet_nft using the Substrate node and recommended hardware. 61 | pub struct SubstrateWeight(PhantomData); 62 | impl WeightInfoNft for SubstrateWeight { 63 | fn mint() -> Weight { 64 | (89_289_000 as Weight) 65 | .saturating_add(T::DbWeight::get().reads(4 as Weight)) 66 | .saturating_add(T::DbWeight::get().writes(3 as Weight)) 67 | } 68 | fn transfer() -> Weight { 69 | (88_487_000 as Weight) 70 | .saturating_add(T::DbWeight::get().reads(5 as Weight)) 71 | .saturating_add(T::DbWeight::get().writes(5 as Weight)) 72 | } 73 | } 74 | 75 | // For backwards compatibility and tests 76 | impl WeightInfoNft for () { 77 | fn mint() -> Weight { 78 | (89_289_000 as Weight) 79 | .saturating_add(RocksDbWeight::get().reads(4 as Weight)) 80 | .saturating_add(RocksDbWeight::get().writes(3 as Weight)) 81 | } 82 | fn transfer() -> Weight { 83 | (88_487_000 as Weight) 84 | .saturating_add(RocksDbWeight::get().reads(5 as Weight)) 85 | .saturating_add(RocksDbWeight::get().writes(5 as Weight)) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /frame/realis-bridge/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = 'realis-bridge' 3 | version = '0.0.1' 4 | authors = ['exlead@gmail.com'] 5 | edition = '2018' 6 | 7 | [dependencies] 8 | # third-party dependencies 9 | codec = { package = 'parity-scale-codec', version = '2.0.0', default-features = false, features = ['derive'] } 10 | serde = { version = '1.0.133', optional = true } 11 | primitive-types = { version = "0.10.1", default-features = false } 12 | 13 | frame-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 14 | frame-system = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 15 | sp-std = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 16 | frame-benchmarking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", version = "4.0.0-dev", default-features = false, optional = true } 17 | sp-runtime = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 18 | sp-io = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 19 | sp-core = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 20 | sp-arithmetic = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 21 | pallet-balances = { default-features = false, git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 22 | realis-primitives = { path = "../../primitives/realis", default-features = false } 23 | pallet-nft = { version = "0.0.2", path = "../nft", default-features = false } 24 | realis-game-api = { version = "0.0.1", path = "../realis-game-api", default-features = false } 25 | 26 | [dev-dependencies] 27 | pallet-balances = { default-features = false, git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 28 | [build-dependencies] 29 | wasm-builder-runner = { version = '3.0.0', package = 'substrate-wasm-builder-runner' } 30 | [features] 31 | default = ['std'] 32 | std = [ 33 | 'codec/std', 34 | 'serde', 35 | 'sp-std/std', 36 | 'sp-runtime/std', 37 | "frame-benchmarking/std", 38 | 'sp-io/std', 39 | 'sp-core/std', 40 | 'sp-arithmetic/std', 41 | 'frame-support/std', 42 | 'frame-system/std', 43 | 'pallet-nft/std', 44 | "realis-primitives/std", 45 | "realis-game-api/std" 46 | ] 47 | 48 | runtime-benchmarks = ["frame-benchmarking"] 49 | try-runtime = ["frame-support/try-runtime"] 50 | -------------------------------------------------------------------------------- /frame/realis-bridge/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "runtime-benchmarks")] 2 | mod benchmarking { 3 | use crate::Pallet as RealisBridge; 4 | use crate::*; 5 | use frame_benchmarking::{account, benchmarks}; 6 | use frame_support::traits::Currency; 7 | use frame_system::RawOrigin as SystemOrigin; 8 | use pallet_nft::Pallet as Nft; 9 | use primitive_types::U256; 10 | use realis_primitives::*; 11 | use sp_core::H160; 12 | use sp_runtime::traits::Saturating; 13 | 14 | const SEED: u32 = 1; 15 | const ED_MULTIPLIER: u32 = 10; 16 | const ED_MULTIPLIER_2: u32 = 5; 17 | 18 | // Get Alice AccountId 19 | fn alice() -> T::AccountId { 20 | let alice = BridgeMasters::::get(); 21 | alice.get(0).unwrap().clone() 22 | } 23 | 24 | benchmarks! { 25 | transfer_token_to_bsc { 26 | let caller = alice::(); 27 | let owner_origin = SystemOrigin::Signed(caller.clone()); 28 | let balance = T::BridgeCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER - 1).into()); 29 | T::BridgeCurrency::make_free_balance_be(&caller, balance); 30 | let transfer_amount = T::BridgeCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER_2 - 1).into()); 31 | }: _( 32 | SystemOrigin::Signed(caller.clone()), 33 | H160::from_slice(b"0x6D1eee1CFeEAb71A4d"), 34 | transfer_amount 35 | ) 36 | 37 | transfer_token_to_realis { 38 | let caller = alice::(); 39 | let owner_origin = SystemOrigin::Signed(caller.clone()); 40 | let recipient: T::AccountId = account("recipient", 1, SEED); 41 | let pallet_id = RealisBridge::::account_id(); 42 | let balance = T::BridgeCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER - 1).into()); 43 | T::BridgeCurrency::make_free_balance_be(&recipient, balance); 44 | T::BridgeCurrency::make_free_balance_be(&pallet_id, balance); 45 | T::BridgeCurrency::make_free_balance_be(&caller, balance); 46 | let transfer_amount = T::BridgeCurrency::minimum_balance().saturating_mul((ED_MULTIPLIER_2 - 1).into()); 47 | }: _( 48 | SystemOrigin::Signed(caller.clone()), 49 | H160::from_slice(b"0x6D1eee1CFeEAb71A4d"), 50 | recipient, 51 | transfer_amount 52 | ) 53 | 54 | transfer_nft_to_bsc { 55 | let caller = alice::(); 56 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 57 | Nft::::mint( 58 | owner_origin.clone(), 59 | caller.clone(), 60 | b"QQ".to_vec(), 61 | U256([1, 0, 0, 0]), 62 | 1, 63 | Rarity::Common, 64 | b"QQ".to_vec(), 65 | )?; 66 | }: _( 67 | SystemOrigin::Signed(caller.clone()), 68 | H160::from_slice(b"0x6D1eee1CFeEAb71A4d"), 69 | U256([1, 0, 0, 0]) 70 | ) 71 | 72 | transfer_nft_to_realis { 73 | let caller = alice::(); 74 | let owner_origin: ::Origin = SystemOrigin::Signed(caller.clone()).into(); 75 | Nft::::mint( 76 | owner_origin.clone(), 77 | caller.clone(), 78 | b"QQ".to_vec(), 79 | U256([1, 0, 0, 0]), 80 | 1, 81 | Rarity::Common, 82 | b"QQ".to_vec(), 83 | )?; 84 | }: _( 85 | SystemOrigin::Signed(caller.clone()), 86 | H160::from_slice(b"0x6D1eee1CFeEAb71A4d"), 87 | caller.clone(), 88 | U256([1, 0, 0, 0]) 89 | ) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /frame/realis-bridge/src/mock.rs: -------------------------------------------------------------------------------- 1 | #![cfg(test)] 2 | 3 | use crate::*; 4 | use frame_support::{parameter_types, PalletId}; 5 | use sp_core::H256; 6 | use sp_runtime::traits::BlakeTwo256; 7 | use sp_runtime::{testing::Header, traits::IdentityLookup}; 8 | 9 | use crate::{self as realis_bridge, Config}; 10 | pub use pallet_balances as balances; 11 | 12 | pub type Block = sp_runtime::generic::Block; 13 | pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; 14 | 15 | frame_support::construct_runtime!( 16 | pub enum Test where 17 | Block = Block, 18 | NodeBlock = Block, 19 | UncheckedExtrinsic = UncheckedExtrinsic 20 | { 21 | System: frame_system::{Pallet, Call, Config, Storage, Event}, 22 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, 23 | Nft: pallet_nft::{Pallet, Call, Storage, Event}, 24 | RealisBridge: realis_bridge::{Pallet, Call, Event}, 25 | } 26 | ); 27 | 28 | parameter_types! { 29 | pub const BlockHashCount: u64 = 250; 30 | pub BlockWeights: frame_system::limits::BlockWeights = 31 | frame_system::limits::BlockWeights::simple_max( 32 | frame_support::weights::constants::WEIGHT_PER_SECOND * 2 33 | ); 34 | pub const MaxLocks: u32 = 1024; 35 | pub static ExistentialDeposit: u128 = 1; 36 | pub static Period: u64 = 5; 37 | pub static Offset: u64 = 0; 38 | } 39 | 40 | impl frame_system::Config for Test { 41 | type BaseCallFilter = frame_support::traits::AllowAll; 42 | type BlockWeights = (); 43 | type BlockLength = (); 44 | type Origin = Origin; 45 | type Call = Call; 46 | type Index = u64; 47 | type BlockNumber = u64; 48 | type Hash = H256; 49 | type Hashing = BlakeTwo256; 50 | type AccountId = u64; 51 | type Lookup = IdentityLookup; 52 | type Header = Header; 53 | type Event = Event; 54 | type BlockHashCount = BlockHashCount; 55 | type DbWeight = (); 56 | type Version = (); 57 | type PalletInfo = PalletInfo; 58 | type AccountData = pallet_balances::AccountData; 59 | type OnNewAccount = (); 60 | type OnKilledAccount = (); 61 | type SystemWeightInfo = (); 62 | type SS58Prefix = (); 63 | type OnSetCode = (); 64 | } 65 | 66 | impl pallet_balances::Config for Test { 67 | type MaxLocks = MaxLocks; 68 | type MaxReserves = (); 69 | type ReserveIdentifier = [u8; 8]; 70 | type Balance = u128; 71 | type Event = Event; 72 | type DustRemoval = (); 73 | type ExistentialDeposit = ExistentialDeposit; 74 | type AccountStore = System; 75 | type WeightInfo = (); 76 | } 77 | 78 | parameter_types! { 79 | pub const ExistentialDepositOfRealisTokens: u64 = 1; 80 | } 81 | 82 | impl pallet_nft::Config for Test { 83 | type Event = Event; 84 | type Balance = u128; 85 | type WeightInfo = pallet_nft::weights::SubstrateWeight; 86 | } 87 | 88 | parameter_types! { 89 | pub const RealisBridgePalletId: PalletId = PalletId(*b"rl/relbr"); 90 | } 91 | 92 | impl Config for Test { 93 | type Event = Event; 94 | type BridgeCurrency = pallet_balances::Pallet; 95 | type PalletId = RealisBridgePalletId; 96 | } 97 | -------------------------------------------------------------------------------- /frame/realis-bridge/src/tests.rs: -------------------------------------------------------------------------------- 1 | // use crate::{mock::*, Error}; 2 | // use frame_support::{assert_err, assert_ok}; 3 | // use primitive_types::U256; 4 | // use realis_primitives::*; 5 | // 6 | // #[test] 7 | -------------------------------------------------------------------------------- /frame/realis-bridge/src/weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Autogenerated weights for realis_bridge 19 | //! 20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 21 | //! DATE: 2021-11-25, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` 22 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 23 | 24 | // Executed Command: 25 | // ./target/release/realis 26 | // benchmark 27 | // --chain 28 | // dev 29 | // --execution 30 | // wasm 31 | // --wasm-execution 32 | // compiled 33 | // --pallet 34 | // realis-bridge 35 | // --extrinsic 36 | // * 37 | // --steps 38 | // 20 39 | // --repeat 40 | // 10 41 | // --raw 42 | // --output=./frame/realis-bridge/src/weights.rs 43 | // --template=./.maintain/frame-weight-template.hbs 44 | 45 | #![allow(unused_parens)] 46 | #![allow(unused_imports)] 47 | 48 | use frame_support::{ 49 | traits::Get, 50 | weights::{constants::RocksDbWeight, Weight}, 51 | }; 52 | use sp_std::marker::PhantomData; 53 | 54 | /// Weight functions needed for realis_bridge. 55 | pub trait WeightInfoBridge { 56 | fn transfer_token_to_bsc() -> Weight; 57 | fn transfer_token_to_realis() -> Weight; 58 | fn transfer_nft_to_bsc() -> Weight; 59 | fn transfer_nft_to_realis() -> Weight; 60 | } 61 | 62 | /// Weights for realis_bridge using the Substrate node and recommended hardware. 63 | pub struct SubstrateWeight(PhantomData); 64 | impl WeightInfoBridge for SubstrateWeight { 65 | fn transfer_token_to_bsc() -> Weight { 66 | (109_707_000 as Weight) 67 | .saturating_add(T::DbWeight::get().reads(2 as Weight)) 68 | .saturating_add(T::DbWeight::get().writes(2 as Weight)) 69 | } 70 | fn transfer_token_to_realis() -> Weight { 71 | (86_383_000 as Weight) 72 | .saturating_add(T::DbWeight::get().reads(3 as Weight)) 73 | .saturating_add(T::DbWeight::get().writes(2 as Weight)) 74 | } 75 | fn transfer_nft_to_bsc() -> Weight { 76 | (82_515_000 as Weight) 77 | .saturating_add(T::DbWeight::get().reads(5 as Weight)) 78 | .saturating_add(T::DbWeight::get().writes(5 as Weight)) 79 | } 80 | fn transfer_nft_to_realis() -> Weight { 81 | (77_216_000 as Weight) 82 | .saturating_add(T::DbWeight::get().reads(4 as Weight)) 83 | .saturating_add(T::DbWeight::get().writes(3 as Weight)) 84 | } 85 | } 86 | 87 | // For backwards compatibility and tests 88 | impl WeightInfoBridge for () { 89 | fn transfer_token_to_bsc() -> Weight { 90 | (109_707_000 as Weight) 91 | .saturating_add(RocksDbWeight::get().reads(2 as Weight)) 92 | .saturating_add(RocksDbWeight::get().writes(2 as Weight)) 93 | } 94 | fn transfer_token_to_realis() -> Weight { 95 | (86_383_000 as Weight) 96 | .saturating_add(RocksDbWeight::get().reads(3 as Weight)) 97 | .saturating_add(RocksDbWeight::get().writes(2 as Weight)) 98 | } 99 | fn transfer_nft_to_bsc() -> Weight { 100 | (82_515_000 as Weight) 101 | .saturating_add(RocksDbWeight::get().reads(5 as Weight)) 102 | .saturating_add(RocksDbWeight::get().writes(5 as Weight)) 103 | } 104 | fn transfer_nft_to_realis() -> Weight { 105 | (77_216_000 as Weight) 106 | .saturating_add(RocksDbWeight::get().reads(4 as Weight)) 107 | .saturating_add(RocksDbWeight::get().writes(3 as Weight)) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /frame/realis-game-api/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Substrate DevHub "] 3 | description = "FRAME pallet template for defining custom runtime logic." 4 | edition = "2018" 5 | homepage = "https://substrate.dev" 6 | license = "Unlicense" 7 | name = "realis-game-api" 8 | repository = "https://github.com/substrate-developer-hub/substrate-node-template/" 9 | version = "0.0.1" 10 | 11 | [package.metadata.docs.rs] 12 | targets = ["x86_64-unknown-linux-gnu"] 13 | 14 | [dependencies] 15 | serde = { version = "1.0.133", optional = true } 16 | codec = { package = "parity-scale-codec", version = "2.0.1", default-features = false, features = ["derive"] } 17 | frame-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 18 | frame-system = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 19 | sp-runtime = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 20 | sp-std = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 21 | pallet-balances = { default-features = false, git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 22 | #pallet-staking-reward-curve = { version = "3.0.0", default-features = false, path = "../staking-pool/reward-curve" } 23 | pallet-session = { default-features = false, features = ["historical"], git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9"} 24 | pallet-authorship = { default-features = false, git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 25 | sp-staking = { default-features = false, git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 26 | #frame-election-provider-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 27 | primitive-types = { version = "0.10.1", default-features = false } 28 | frame-benchmarking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", version = "4.0.0-dev", default-features = false, optional = true } 29 | node-primitives = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 30 | 31 | pallet-nft = { version = "0.0.2", default-features = false, path="../nft" } 32 | pallet-nft-delegate = { default-features = false, path="../nft-delegate"} 33 | marketplace = { version = "0.0.1", default-features = false, path="../marketplace" } 34 | pallet-staking = { version = "4.0.0-dev", default-features = false, path="../staking-pool" } 35 | realis-primitives = { version = "0.0.2", path = "../../primitives/realis", default-features = false} 36 | 37 | 38 | [dev-dependencies] 39 | pallet-timestamp = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 40 | sp-core = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 41 | sp-io = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 42 | #sp-runtime = { versiopallen = "2.0.0", default-features = false, path = "../../primitives/runtime" } 43 | 44 | 45 | [features] 46 | default = ["std"] 47 | std = [ 48 | "serde", 49 | "codec/std", 50 | "frame-benchmarking/std", 51 | "frame-support/std", 52 | "frame-system/std", 53 | "sp-runtime/std", 54 | "sp-std/std", 55 | "pallet-nft/std", 56 | "pallet-staking/std", 57 | "realis-primitives/std", 58 | "marketplace/std", 59 | "sp-staking/std", 60 | ] 61 | 62 | runtime-benchmarks = ["frame-benchmarking"] 63 | try-runtime = ["frame-support/try-runtime"] 64 | -------------------------------------------------------------------------------- /frame/realis-game-api/README.md: -------------------------------------------------------------------------------- 1 | NFT module for create a NFT-Tokens. 2 | 3 | You can burn and transfer your NFT-Tokens, only sudo account can mint NFT-Tokens. 4 | In order to see the number of tokens on the account, you need to go to the chain state, select the nft pallet, 5 | and select tokenForAccount. 6 | To view who the user is by token ID, you need to go to the chain state, select the nft pallet, and select AccountForToken, and write TokenId. 7 | 8 | License: Apache-2.0 -------------------------------------------------------------------------------- /frame/realis-game-api/src/tests.rs: -------------------------------------------------------------------------------- 1 | use crate::{mock::*, Config, Currency, Error}; 2 | use frame_support::{assert_err, assert_ok}; 3 | use pallet_nft as NFT; 4 | use primitive_types::U256; 5 | 6 | fn alice() -> T::AccountId { 7 | let alice = NFT::NftMasters::::get(); 8 | alice.get(0).unwrap().clone() 9 | } 10 | 11 | #[test] 12 | fn mint_some_type() { 13 | new_test_ext(vec![1]).execute_with(|| { 14 | assert_ok!(RealisGameApi::mint_nft( 15 | Origin::signed(1), 16 | 1, 17 | U256([1, 0, 0, 0]), 18 | 1 19 | )); 20 | }) 21 | } 22 | 23 | #[test] 24 | fn mint_existent_token() { 25 | new_test_ext(vec![1]).execute_with(|| { 26 | assert_ok!(RealisGameApi::mint_nft( 27 | Origin::signed(1), 28 | 1, 29 | U256([1, 0, 0, 0]), 30 | 1 31 | )); 32 | assert_err!( 33 | RealisGameApi::mint_nft(Origin::signed(1), 1, U256([1, 0, 0, 0]), 1), 34 | Error::::TokenExist 35 | ); 36 | }) 37 | } 38 | 39 | #[test] 40 | fn burn_none_existent_token() { 41 | new_test_ext(vec![1]).execute_with(|| { 42 | assert_err!( 43 | RealisGameApi::burn_nft(Origin::signed(1), U256([1, 0, 0, 0])), 44 | NFT::Error::::NonExistentToken 45 | ) 46 | }) 47 | } 48 | 49 | #[test] 50 | fn mint_and_burn() { 51 | new_test_ext(vec![1]).execute_with(|| { 52 | assert_ok!(RealisGameApi::mint_nft( 53 | Origin::signed(1), 54 | 1, 55 | U256([1, 0, 0, 0]), 56 | 1 57 | )); 58 | assert_ok!(RealisGameApi::burn_nft( 59 | Origin::signed(1), 60 | U256([1, 0, 0, 0]) 61 | )); 62 | }) 63 | } 64 | 65 | #[test] 66 | fn mint_1_2_burn_1_2() { 67 | new_test_ext(vec![1]).execute_with(|| { 68 | assert_ok!(RealisGameApi::mint_nft( 69 | Origin::signed(1), 70 | 1, 71 | U256([1, 0, 0, 0]), 72 | 1 73 | )); 74 | assert_ok!(RealisGameApi::mint_nft( 75 | Origin::signed(1), 76 | 1, 77 | U256([2, 0, 0, 0]), 78 | 1 79 | )); 80 | assert_ok!(RealisGameApi::burn_nft( 81 | Origin::signed(1), 82 | U256([1, 0, 0, 0]) 83 | )); 84 | assert_ok!(RealisGameApi::burn_nft( 85 | Origin::signed(1), 86 | U256([2, 0, 0, 0]) 87 | )); 88 | }) 89 | } 90 | 91 | #[test] 92 | fn mint_1_2_burn_2_1() { 93 | new_test_ext(vec![1]).execute_with(|| { 94 | assert_ok!(RealisGameApi::mint_nft( 95 | Origin::signed(1), 96 | 1, 97 | U256([1, 0, 0, 0]), 98 | 1 99 | )); 100 | assert_ok!(RealisGameApi::mint_nft( 101 | Origin::signed(1), 102 | 1, 103 | U256([2, 0, 0, 0]), 104 | 1 105 | )); 106 | assert_ok!(RealisGameApi::burn_nft( 107 | Origin::signed(1), 108 | U256([2, 0, 0, 0]) 109 | )); 110 | assert_ok!(RealisGameApi::burn_nft( 111 | Origin::signed(1), 112 | U256([1, 0, 0, 0]) 113 | )); 114 | }) 115 | } 116 | 117 | #[test] 118 | fn mint_transfer_burn_by_owner() { 119 | new_test_ext(vec![1, 2]).execute_with(|| { 120 | assert_ok!(RealisGameApi::mint_nft( 121 | Origin::signed(1), 122 | 1, 123 | U256([1, 0, 0, 0]), 124 | 1 125 | )); 126 | assert_ok!(RealisGameApi::transfer_nft( 127 | Origin::signed(1), 128 | 2, 129 | U256([1, 0, 0, 0]) 130 | )); 131 | assert_ok!(RealisGameApi::burn_nft( 132 | Origin::signed(2), 133 | U256([1, 0, 0, 0]) 134 | )); 135 | }) 136 | } 137 | 138 | #[test] 139 | fn mint_transfer_burn_not_by_owner() { 140 | new_test_ext(vec![1, 2]).execute_with(|| { 141 | assert_ok!(RealisGameApi::mint_nft( 142 | Origin::signed(1), 143 | 1, 144 | U256([1, 0, 0, 0]), 145 | 1 146 | )); 147 | assert_ok!(RealisGameApi::transfer_nft( 148 | Origin::signed(1), 149 | 2, 150 | U256([1, 0, 0, 0]) 151 | )); 152 | assert_err!( 153 | RealisGameApi::burn_nft(Origin::signed(1), U256([1, 0, 0, 0])), 154 | NFT::Error::::NotTokenOwner 155 | ); 156 | }) 157 | } 158 | 159 | #[test] 160 | fn mint_and_transfer() { 161 | new_test_ext(vec![1, 2]).execute_with(|| { 162 | assert_ok!(RealisGameApi::mint_nft( 163 | Origin::signed(1), 164 | 1, 165 | U256([1, 0, 0, 0]), 166 | 1 167 | )); 168 | assert_ok!(RealisGameApi::transfer_nft( 169 | Origin::signed(1), 170 | 2, 171 | U256([1, 0, 0, 0]) 172 | )); 173 | }) 174 | } 175 | 176 | #[test] 177 | fn mint_and_transfer_2_times() { 178 | new_test_ext(vec![1, 2, 3]).execute_with(|| { 179 | assert_ok!(RealisGameApi::mint_nft( 180 | Origin::signed(1), 181 | 1, 182 | U256([1, 0, 0, 0]), 183 | 1 184 | )); 185 | assert_ok!(RealisGameApi::transfer_nft( 186 | Origin::signed(1), 187 | 2, 188 | U256([1, 0, 0, 0]) 189 | )); 190 | assert_ok!(RealisGameApi::transfer_nft( 191 | Origin::signed(2), 192 | 3, 193 | U256([1, 0, 0, 0]) 194 | )); 195 | }) 196 | } 197 | 198 | #[test] 199 | fn mint_and_transfer_2_times_burn_by_owner() { 200 | new_test_ext(vec![1, 2, 3]).execute_with(|| { 201 | assert_ok!(RealisGameApi::mint_nft( 202 | Origin::signed(1), 203 | 1, 204 | U256([1, 0, 0, 0]), 205 | 1 206 | )); 207 | assert_ok!(RealisGameApi::transfer_nft( 208 | Origin::signed(1), 209 | 2, 210 | U256([1, 0, 0, 0]) 211 | )); 212 | assert_ok!(RealisGameApi::transfer_nft( 213 | Origin::signed(2), 214 | 3, 215 | U256([1, 0, 0, 0]) 216 | )); 217 | assert_ok!(RealisGameApi::burn_nft( 218 | Origin::signed(3), 219 | U256([1, 0, 0, 0]) 220 | )); 221 | }) 222 | } 223 | 224 | #[test] 225 | fn mint_and_transfer_2_times_burn_not_by_owner() { 226 | new_test_ext(vec![1, 2, 3]).execute_with(|| { 227 | assert_ok!(RealisGameApi::mint_nft( 228 | Origin::signed(1), 229 | 1, 230 | U256([1, 0, 0, 0]), 231 | 1 232 | )); 233 | assert_ok!(RealisGameApi::transfer_nft( 234 | Origin::signed(1), 235 | 2, 236 | U256([1, 0, 0, 0]) 237 | )); 238 | assert_ok!(RealisGameApi::transfer_nft( 239 | Origin::signed(2), 240 | 3, 241 | U256([1, 0, 0, 0]) 242 | )); 243 | assert_err!( 244 | RealisGameApi::burn_nft(Origin::signed(2), U256([1, 0, 0, 0])), 245 | NFT::Error::::NotTokenOwner 246 | ); 247 | }) 248 | } 249 | 250 | #[test] 251 | fn transfer_from_pallet() { 252 | new_test_ext(vec![1]).execute_with(|| { 253 | let caller = alice::(); 254 | let pallet_id = RealisGameApi::account_id(); 255 | Balances::make_free_balance_be(&pallet_id, 100); 256 | let transfer_amount = 50; 257 | 258 | assert_ok!(RealisGameApi::transfer_from_pallet( 259 | Origin::signed(caller.clone()), 260 | caller.clone(), 261 | transfer_amount 262 | )); 263 | }) 264 | } 265 | 266 | #[test] 267 | fn transfer_to_pallet() { 268 | new_test_ext(vec![1]).execute_with(|| { 269 | let caller = alice::(); 270 | Balances::make_free_balance_be(&caller, 100); 271 | let transfer_amount = 50; 272 | 273 | assert_ok!(RealisGameApi::transfer_to_pallet( 274 | Origin::signed(caller.clone()), 275 | caller.clone(), 276 | transfer_amount 277 | )); 278 | }) 279 | } 280 | 281 | #[test] 282 | fn transfer_from_ptp() { 283 | new_test_ext(vec![1, 2, 3]).execute_with(|| { 284 | let caller = alice::(); 285 | Balances::make_free_balance_be(&caller, 100); 286 | let transfer_amount = 50; 287 | 288 | assert_ok!(RealisGameApi::transfer_from_ptp( 289 | Origin::signed(caller.clone()), 290 | caller.clone(), 291 | 3, 292 | transfer_amount 293 | )); 294 | }) 295 | } 296 | 297 | #[test] 298 | fn spend_in_game() { 299 | new_test_ext(vec![1]).execute_with(|| { 300 | let caller = alice::(); 301 | Balances::make_free_balance_be(&caller, 100); 302 | let transfer_amount = 50; 303 | 304 | assert_ok!(RealisGameApi::spend_in_game( 305 | Origin::signed(caller.clone()), 306 | caller.clone(), 307 | transfer_amount 308 | )); 309 | }) 310 | } 311 | -------------------------------------------------------------------------------- /frame/staking-pool/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-staking" 3 | version = "4.0.0-dev" 4 | authors = ["Parity Technologies "] 5 | edition = "2018" 6 | license = "Apache-2.0" 7 | homepage = "https://substrate.dev" 8 | repository = "https://github.com/paritytech/substrate/" 9 | description = "FRAME pallet staking" 10 | readme = "README.md" 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | static_assertions = "1.1.0" 17 | serde_json = "1.0.79" 18 | serde = { version = "1.0.133" } 19 | codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } 20 | sp-std = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 21 | sp-io ={ git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 22 | sp-runtime = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 23 | sp-staking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 24 | frame-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 25 | frame-system = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 26 | pallet-session = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false, features = ["historical"]} 27 | pallet-authorship = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 28 | sp-application-crypto = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 29 | frame-election-provider-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 30 | log = { version = "0.4.14", default-features = false } 31 | paste = "1.0" 32 | 33 | # Optional imports for benchmarking 34 | frame-benchmarking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false, optional = true } 35 | rand_chacha = { version = "0.3", default-features = false, optional = true } 36 | 37 | [dev-dependencies] 38 | sp-storage = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 39 | sp-tracing = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 40 | sp-core = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 41 | pallet-balances = { default-features = false, git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 42 | pallet-timestamp = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 43 | pallet-staking-reward-curve = { version = "3.0.0", path = "./reward-curve" } 44 | substrate-test-utils = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 45 | frame-benchmarking = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 46 | frame-election-provider-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", features = ["runtime-benchmarks"] } 47 | rand_chacha = { version = "0.3" } 48 | parking_lot = "0.12.0" 49 | hex = "0.4" 50 | hex-literal = "0.3.4" 51 | 52 | [features] 53 | default = ["std"] 54 | std = [ 55 | "codec/std", 56 | "sp-std/std", 57 | "sp-io/std", 58 | "frame-support/std", 59 | "sp-runtime/std", 60 | "sp-staking/std", 61 | "pallet-session/std", 62 | "frame-system/std", 63 | "pallet-authorship/std", 64 | "sp-application-crypto/std", 65 | "frame-election-provider-support/std", 66 | "log/std", 67 | "serde/std", 68 | "frame-benchmarking/std", 69 | ] 70 | runtime-benchmarks = [ 71 | "frame-benchmarking", 72 | "frame-election-provider-support/runtime-benchmarks", 73 | "rand_chacha", 74 | ] 75 | try-runtime = ["frame-support/try-runtime"] 76 | -------------------------------------------------------------------------------- /frame/staking-pool/fuzzer/.gitignore: -------------------------------------------------------------------------------- 1 | hfuzz_target 2 | hfuzz_workspace 3 | -------------------------------------------------------------------------------- /frame/staking-pool/fuzzer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-staking-fuzz" 3 | version = "0.0.0" 4 | authors = ["Automatically generated"] 5 | publish = false 6 | edition = "2018" 7 | license = "Apache-2.0" 8 | homepage = "https://substrate.dev" 9 | repository = "https://github.com/paritytech/substrate/" 10 | description = "FRAME pallet staking fuzzing" 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | honggfuzz = "0.5" 17 | codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] } 18 | pallet-staking = { version = "4.0.0-dev", path = "../src", features = ["runtime-benchmarks"] } 19 | pallet-staking-reward-curve = { version = "3.0.0", path = "../reward-curve" } 20 | pallet-session = { version = "2.0.0-rc6", path = "../../session" } 21 | pallet-indices = { version = "2.0.0-rc6", path = "../../indices" } 22 | pallet-balances = { version = "2.0.0-rc6", path = "../../balances" } 23 | pallet-timestamp = { version = "2.0.0-rc6", path = "../../timestamp" } 24 | frame-system = { version = "2.0.0-rc6", path = "../../system" } 25 | frame-support = { version = "2.0.0-rc6", path = "../../support" } 26 | sp-std = { version = "2.0.0-rc6", path = "../../../primitives/std" } 27 | sp-io ={ version = "2.0.0-rc6", path = "../../../primitives/io" } 28 | sp-core = { version = "2.0.0-rc6", path = "../../../primitives/core" } 29 | sp-npos-elections = { version = "2.0.0-rc6", path = "../../../primitives/npos-elections" } 30 | sp-runtime = { version = "2.0.0-rc6", path = "../../../primitives/runtime" } 31 | 32 | [[bin]] 33 | name = "submit_solution" 34 | path = "src/submit_solution.rs" 35 | -------------------------------------------------------------------------------- /frame/staking-pool/fuzzer/src/mock.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2020-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Mock file for staking fuzzing. 19 | 20 | use frame_support::parameter_types; 21 | 22 | type AccountId = u64; 23 | type AccountIndex = u32; 24 | type BlockNumber = u64; 25 | type Balance = u64; 26 | 27 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; 28 | type Block = frame_system::mocking::MockBlock; 29 | 30 | frame_support::construct_runtime!( 31 | pub enum Test where 32 | Block = Block, 33 | NodeBlock = Block, 34 | UncheckedExtrinsic = UncheckedExtrinsic, 35 | { 36 | System: frame_system::{Pallet, Call, Config, Storage, Event}, 37 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, 38 | Staking: pallet_staking::{Pallet, Call, Config, Storage, Event, ValidateUnsigned}, 39 | Indices: pallet_indices::{Pallet, Call, Storage, Config, Event}, 40 | Session: pallet_session::{Pallet, Call, Storage, Event, Config}, 41 | } 42 | ); 43 | 44 | impl frame_system::Config for Test { 45 | type BaseCallFilter = frame_support::traits::Everything; 46 | type BlockWeights = (); 47 | type BlockLength = (); 48 | type DbWeight = (); 49 | type Origin = Origin; 50 | type Index = AccountIndex; 51 | type BlockNumber = BlockNumber; 52 | type Call = Call; 53 | type Hash = sp_core::H256; 54 | type Hashing = ::sp_runtime::traits::BlakeTwo256; 55 | type AccountId = AccountId; 56 | type Lookup = Indices; 57 | type Header = sp_runtime::testing::Header; 58 | type Event = Event; 59 | type BlockHashCount = (); 60 | type Version = (); 61 | type PalletInfo = PalletInfo; 62 | type AccountData = pallet_balances::AccountData; 63 | type OnNewAccount = (); 64 | type OnKilledAccount = (); 65 | type SystemWeightInfo = (); 66 | type SS58Prefix = (); 67 | type OnSetCode = (); 68 | } 69 | parameter_types! { 70 | pub const ExistentialDeposit: Balance = 10; 71 | } 72 | impl pallet_balances::Config for Test { 73 | type MaxLocks = (); 74 | type MaxReserves = (); 75 | type ReserveIdentifier = [u8; 8]; 76 | type Balance = Balance; 77 | type Event = Event; 78 | type DustRemoval = (); 79 | type ExistentialDeposit = ExistentialDeposit; 80 | type AccountStore = System; 81 | type WeightInfo = (); 82 | } 83 | impl pallet_indices::Config for Test { 84 | type AccountIndex = AccountIndex; 85 | type Event = Event; 86 | type Currency = Balances; 87 | type Deposit = (); 88 | type WeightInfo = (); 89 | } 90 | parameter_types! { 91 | pub const MinimumPeriod: u64 = 5; 92 | } 93 | impl pallet_timestamp::Config for Test { 94 | type Moment = u64; 95 | type OnTimestampSet = (); 96 | type MinimumPeriod = MinimumPeriod; 97 | type WeightInfo = (); 98 | } 99 | impl pallet_session::historical::Config for Test { 100 | type FullIdentification = pallet_staking::Exposure; 101 | type FullIdentificationOf = pallet_staking::ExposureOf; 102 | } 103 | 104 | sp_runtime::impl_opaque_keys! { 105 | pub struct SessionKeys { 106 | pub foo: sp_runtime::testing::UintAuthorityId, 107 | } 108 | } 109 | 110 | pub struct TestSessionHandler; 111 | impl pallet_session::SessionHandler for TestSessionHandler { 112 | const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[]; 113 | 114 | fn on_genesis_session(_validators: &[(AccountId, Ks)]) {} 115 | 116 | fn on_new_session( 117 | _: bool, 118 | _: &[(AccountId, Ks)], 119 | _: &[(AccountId, Ks)], 120 | ) {} 121 | 122 | fn on_disabled(_: usize) {} 123 | } 124 | 125 | impl pallet_session::Config for Test { 126 | type SessionManager = pallet_session::historical::NoteHistoricalRoot; 127 | type Keys = SessionKeys; 128 | type ShouldEndSession = pallet_session::PeriodicSessions<(), ()>; 129 | type NextSessionRotation = pallet_session::PeriodicSessions<(), ()>; 130 | type SessionHandler = TestSessionHandler; 131 | type Event = Event; 132 | type ValidatorId = AccountId; 133 | type ValidatorIdOf = pallet_staking::StashOf; 134 | type DisabledValidatorsThreshold = (); 135 | type WeightInfo = (); 136 | } 137 | pallet_staking_reward_curve::build! { 138 | const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!( 139 | min_inflation: 0_025_000, 140 | max_inflation: 0_100_000, 141 | ideal_stake: 0_500_000, 142 | falloff: 0_050_000, 143 | max_piece_count: 40, 144 | test_precision: 0_005_000, 145 | ); 146 | } 147 | parameter_types! { 148 | pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS; 149 | pub const MaxNominatorRewardedPerValidator: u32 = 64; 150 | pub const MaxIterations: u32 = 20; 151 | } 152 | 153 | pub type Extrinsic = sp_runtime::testing::TestXt; 154 | 155 | impl frame_system::offchain::SendTransactionTypes for Test 156 | where 157 | Call: From, 158 | { 159 | type OverarchingCall = Call; 160 | type Extrinsic = Extrinsic; 161 | } 162 | 163 | pub struct MockElectionProvider; 164 | impl frame_election_provider_support::ElectionProvider 165 | for MockElectionProvider 166 | { 167 | type Error = (); 168 | type DataProvider = pallet_staking::Module; 169 | 170 | fn elect() -> Result< 171 | (sp_npos_elections::Supports, frame_support::weights::Weight), 172 | Self::Error 173 | > { 174 | Err(()) 175 | } 176 | } 177 | 178 | impl pallet_staking::Config for Test { 179 | type Currency = Balances; 180 | type UnixTime = pallet_timestamp::Pallet; 181 | type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; 182 | type RewardRemainder = (); 183 | type Event = Event; 184 | type Slash = (); 185 | type Reward = (); 186 | type SessionsPerEra = (); 187 | type SlashDeferDuration = (); 188 | type SlashCancelOrigin = frame_system::EnsureRoot; 189 | type BondingDuration = (); 190 | type SessionInterface = Self; 191 | type EraPayout = pallet_staking::ConvertCurve; 192 | type NextNewSession = Session; 193 | type ElectionLookahead = (); 194 | type Call = Call; 195 | type MaxIterations = MaxIterations; 196 | type MinSolutionScoreBump = (); 197 | type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; 198 | type UnsignedPriority = (); 199 | type OffchainSolutionWeightLimit = (); 200 | type WeightInfo = (); 201 | type ElectionProvider = MockElectionProvider; 202 | } 203 | -------------------------------------------------------------------------------- /frame/staking-pool/fuzzer/src/submit_solution.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2020 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Fuzzing for staking pallet. 19 | //! 20 | //! HFUZZ_RUN_ARGS="-n 8" cargo hfuzz run submit_solution 21 | 22 | use honggfuzz::fuzz; 23 | 24 | use mock::Test; 25 | use pallet_staking::testing_utils::*; 26 | use frame_support::{assert_ok, storage::StorageValue, traits::UnfilteredDispatchable}; 27 | use frame_system::RawOrigin; 28 | use sp_runtime::DispatchError; 29 | use sp_core::offchain::{testing::TestOffchainExt, OffchainExt}; 30 | use pallet_staking::{EraElectionStatus, ElectionStatus, Module as Staking, Call as StakingCall}; 31 | 32 | mod mock; 33 | 34 | #[repr(u32)] 35 | #[allow(dead_code)] 36 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] 37 | enum Mode { 38 | /// Initial submission. This will be rather cheap. 39 | InitialSubmission, 40 | /// A better submission that will replace the previous ones. This is the most expensive. 41 | StrongerSubmission, 42 | /// A weak submission that will be rejected. This will be rather cheap. 43 | WeakerSubmission, 44 | } 45 | 46 | pub fn new_test_ext(iterations: u32) -> sp_io::TestExternalities { 47 | let mut ext: sp_io::TestExternalities = frame_system::GenesisConfig::default() 48 | .build_storage::() 49 | .map(Into::into) 50 | .expect("Failed to create test externalities."); 51 | 52 | let (offchain, offchain_state) = TestOffchainExt::new(); 53 | 54 | let mut seed = [0u8; 32]; 55 | seed[0..4].copy_from_slice(&iterations.to_le_bytes()); 56 | offchain_state.write().seed = seed; 57 | 58 | ext.register_extension(OffchainExt::new(offchain)); 59 | 60 | ext 61 | } 62 | 63 | fn main() { 64 | let to_range = |x: u32, a: u32, b: u32| { 65 | let collapsed = x % b; 66 | if collapsed >= a { 67 | collapsed 68 | } else { 69 | collapsed + a 70 | } 71 | }; 72 | loop { 73 | fuzz!(|data: (u32, u32, u32, u32, u32)| { 74 | let (mut num_validators, mut num_nominators, mut edge_per_voter, mut to_elect, mode_u32) = data; 75 | // always run with 5 iterations. 76 | let mut ext = new_test_ext(5); 77 | let mode: Mode = unsafe { std::mem::transmute(mode_u32) }; 78 | num_validators = to_range(num_validators, 50, 1000); 79 | num_nominators = to_range(num_nominators, 50, 2000); 80 | edge_per_voter = to_range(edge_per_voter, 1, 16); 81 | to_elect = to_range(to_elect, 20, num_validators); 82 | 83 | let do_reduce = true; 84 | 85 | println!("+++ instance with params {} / {} / {} / {} / {:?}({})", 86 | num_nominators, 87 | num_validators, 88 | edge_per_voter, 89 | to_elect, 90 | mode, 91 | mode_u32, 92 | ); 93 | 94 | ext.execute_with(|| { 95 | // initial setup 96 | init_active_era(); 97 | 98 | assert_ok!(create_validators_with_nominators_for_era::( 99 | num_validators, 100 | num_nominators, 101 | edge_per_voter as usize, 102 | true, 103 | None, 104 | )); 105 | 106 | >::put(ElectionStatus::Open(1)); 107 | assert!(>::create_stakers_snapshot().0); 108 | 109 | let origin = RawOrigin::Signed(create_funded_user::("fuzzer", 0, 100)); 110 | 111 | // stuff to submit 112 | let (winners, compact, score, size) = match mode { 113 | Mode::InitialSubmission => { 114 | /* No need to setup anything */ 115 | get_seq_phragmen_solution::(do_reduce) 116 | }, 117 | Mode::StrongerSubmission => { 118 | let (winners, compact, score, size) = get_weak_solution::(false); 119 | println!("Weak on chain score = {:?}", score); 120 | assert_ok!( 121 | >::submit_election_solution( 122 | origin.clone().into(), 123 | winners, 124 | compact, 125 | score, 126 | current_era::(), 127 | size, 128 | ) 129 | ); 130 | get_seq_phragmen_solution::(do_reduce) 131 | }, 132 | Mode::WeakerSubmission => { 133 | let (winners, compact, score, size) = get_seq_phragmen_solution::(do_reduce); 134 | println!("Strong on chain score = {:?}", score); 135 | assert_ok!( 136 | >::submit_election_solution( 137 | origin.clone().into(), 138 | winners, 139 | compact, 140 | score, 141 | current_era::(), 142 | size, 143 | ) 144 | ); 145 | get_weak_solution::(false) 146 | } 147 | }; 148 | 149 | // must have chosen correct number of winners. 150 | assert_eq!(winners.len() as u32, >::validator_count()); 151 | 152 | // final call and origin 153 | let call = StakingCall::::submit_election_solution( 154 | winners, 155 | compact, 156 | score, 157 | current_era::(), 158 | size, 159 | ); 160 | 161 | // actually submit 162 | match mode { 163 | Mode::WeakerSubmission => { 164 | assert_eq!( 165 | call.dispatch_bypass_filter(origin.into()).unwrap_err().error, 166 | DispatchError::Module { 167 | index: 0, 168 | error: 16, 169 | message: Some("OffchainElectionWeakSubmission"), 170 | }, 171 | ); 172 | }, 173 | // NOTE: so exhaustive pattern doesn't work here.. maybe some rust issue? 174 | // or due to `#[repr(u32)]`? 175 | Mode::InitialSubmission | Mode::StrongerSubmission => { 176 | assert_ok!(call.dispatch_bypass_filter(origin.into())); 177 | } 178 | }; 179 | }) 180 | }); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /frame/staking-pool/reward-curve/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-staking-reward-curve" 3 | version = "3.0.0" 4 | authors = ["Parity Technologies "] 5 | edition = "2018" 6 | license = "Apache-2.0" 7 | homepage = "https://substrate.dev" 8 | repository = "https://github.com/paritytech/substrate/" 9 | description = "Reward Curve for FRAME staking pallet" 10 | 11 | [package.metadata.docs.rs] 12 | targets = ["x86_64-unknown-linux-gnu"] 13 | 14 | [lib] 15 | proc-macro = true 16 | 17 | [dependencies] 18 | syn = { version = "1.0.58", features = ["full", "visit"] } 19 | quote = "1.0.3" 20 | proc-macro2 = "1.0.6" 21 | proc-macro-crate = "1.0.0" 22 | 23 | [dev-dependencies] 24 | sp-runtime = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9" } 25 | -------------------------------------------------------------------------------- /frame/staking-pool/reward-curve/src/log.rs: -------------------------------------------------------------------------------- 1 | use std::convert::TryInto; 2 | 3 | /// Simple u32 power of 2 function - simply uses a bit shift 4 | macro_rules! pow2 { 5 | ($n:expr) => { 6 | 1_u32 << $n 7 | }; 8 | } 9 | 10 | /// Returns the k_th per_million taylor term for a log2 function 11 | fn taylor_term(k: u32, y_num: u128, y_den: u128) -> u32 { 12 | let _2_div_ln_2: u128 = 2_885_390u128; 13 | 14 | if k == 0 { 15 | (_2_div_ln_2 * (y_num).pow(1) / (y_den).pow(1)) 16 | .try_into() 17 | .unwrap() 18 | } else { 19 | let mut res = _2_div_ln_2 * (y_num).pow(3) / (y_den).pow(3); 20 | for _ in 1..k { 21 | res = res * (y_num).pow(2) / (y_den).pow(2); 22 | } 23 | res /= 2 * k as u128 + 1; 24 | 25 | res.try_into().unwrap() 26 | } 27 | } 28 | 29 | /// Performs a log2 operation using a rational fraction 30 | /// 31 | /// result = log2(p/q) where p/q is bound to [1, 1_000_000] 32 | /// Where: 33 | /// * q represents the numerator of the rational fraction input 34 | /// * p represents the denominator of the rational fraction input 35 | /// * result represents a per-million output of log2 36 | pub fn log2(p: u32, q: u32) -> u32 { 37 | assert!(p >= q); // keep p/q bound to [1, inf) 38 | assert!(p <= u32::MAX / 2); 39 | 40 | // This restriction should not be mandatory. But function is only tested and used for this. 41 | assert!(p <= 1_000_000); 42 | assert!(q <= 1_000_000); 43 | 44 | // log2(1) = 0 45 | if p == q { 46 | return 0; 47 | } 48 | 49 | // find the power of 2 where q * 2^n <= p < q * 2^(n+1) 50 | let mut n = 0u32; 51 | while (p < pow2!(n) * q) || (p >= pow2!(n + 1) * q) { 52 | n += 1; 53 | assert!(n < 32); // cannot represent 2^32 in u32 54 | } 55 | assert!(p < pow2!(n + 1) * q); 56 | 57 | let y_num: u32 = p - pow2!(n) * q; 58 | let y_den: u32 = p + pow2!(n) * q; 59 | 60 | // Loop through each Taylor series coefficient until it reaches 10^-6 61 | let mut res = n * 1_000_000u32; 62 | let mut k = 0; 63 | loop { 64 | let term = taylor_term(k, y_num.into(), y_den.into()); 65 | if term == 0 { 66 | break; 67 | } 68 | 69 | res += term; 70 | k += 1; 71 | } 72 | 73 | res 74 | } 75 | 76 | #[test] 77 | fn test_log() { 78 | let div = 1_000; 79 | for p in 0..=div { 80 | for q in 1..=p { 81 | let p: u32 = (1_000_000 as u64 * p as u64 / div as u64) 82 | .try_into() 83 | .unwrap(); 84 | let q: u32 = (1_000_000 as u64 * q as u64 / div as u64) 85 | .try_into() 86 | .unwrap(); 87 | 88 | let res = -(log2(p, q) as i64); 89 | let expected = ((q as f64 / p as f64).log(2.0) * 1_000_000 as f64).round() as i64; 90 | assert!((res - expected).abs() <= 6); 91 | } 92 | } 93 | } 94 | 95 | #[test] 96 | #[should_panic] 97 | fn test_log_p_must_be_greater_than_q() { 98 | let p: u32 = 1_000; 99 | let q: u32 = 1_001; 100 | let _ = log2(p, q); 101 | } 102 | 103 | #[test] 104 | #[should_panic] 105 | fn test_log_p_upper_bound() { 106 | let p: u32 = 1_000_001; 107 | let q: u32 = 1_000_000; 108 | let _ = log2(p, q); 109 | } 110 | 111 | #[test] 112 | #[should_panic] 113 | fn test_log_q_limit() { 114 | let p: u32 = 1_000_000; 115 | let q: u32 = 0; 116 | let _ = log2(p, q); 117 | } 118 | 119 | #[test] 120 | fn test_log_of_one_boundary() { 121 | let p: u32 = 1_000_000; 122 | let q: u32 = 1_000_000; 123 | assert_eq!(log2(p, q), 0); 124 | } 125 | 126 | #[test] 127 | fn test_log_of_largest_input() { 128 | let p: u32 = 1_000_000; 129 | let q: u32 = 1; 130 | let expected = 19_931_568; 131 | let tolerance = 100; 132 | assert!((log2(p, q) as i32 - expected as i32).abs() < tolerance); 133 | } 134 | -------------------------------------------------------------------------------- /frame/staking-pool/reward-curve/tests/test.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2019-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Test crate for pallet-staking-reward-curve. Allows to test for procedural macro. 19 | //! See tests directory. 20 | 21 | mod test_small_falloff { 22 | pallet_staking_reward_curve::build! { 23 | const REWARD_CURVE: sp_runtime::curve::PiecewiseLinear<'static> = curve!( 24 | min_inflation: 0_020_000, 25 | max_inflation: 0_200_000, 26 | ideal_stake: 0_600_000, 27 | falloff: 0_010_000, 28 | max_piece_count: 200, 29 | test_precision: 0_005_000, 30 | ); 31 | } 32 | } 33 | 34 | mod test_big_falloff { 35 | pallet_staking_reward_curve::build! { 36 | const REWARD_CURVE: sp_runtime::curve::PiecewiseLinear<'static> = curve!( 37 | min_inflation: 0_100_000, 38 | max_inflation: 0_400_000, 39 | ideal_stake: 0_400_000, 40 | falloff: 1_000_000, 41 | max_piece_count: 40, 42 | test_precision: 0_005_000, 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /frame/staking-pool/reward-fn/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-staking-reward-fn" 3 | version = "3.0.0" 4 | authors = ["Parity Technologies "] 5 | edition = "2018" 6 | license = "Apache-2.0" 7 | homepage = "https://substrate.dev" 8 | repository = "https://github.com/RealisNetwork/substrate/" 9 | description = "Reward function for FRAME staking pallet" 10 | 11 | [package.metadata.docs.rs] 12 | targets = ["x86_64-unknown-linux-gnu"] 13 | 14 | [lib] 15 | 16 | [dependencies] 17 | sp-arithmetic = { version = "3.0.0", default-features = false, path = "../../../primitives/arithmetic" } 18 | log = { version = "0.4.14", default-features = false } 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "sp-arithmetic/std", 24 | "log/std", 25 | ] 26 | -------------------------------------------------------------------------------- /frame/staking-pool/reward-fn/src/lib.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #![cfg_attr(not(feature = "std"), no_std)] 19 | 20 | //! Useful function for inflation for nominated proof of stake. 21 | 22 | use core::convert::TryFrom; 23 | use sp_arithmetic::{ 24 | biguint::BigUint, 25 | traits::{SaturatedConversion, Zero}, 26 | PerThing, Perquintill, 27 | }; 28 | 29 | /// Compute yearly inflation using function 30 | /// 31 | /// ```ignore 32 | /// I(x) = for x between 0 and x_ideal: x / x_ideal, 33 | /// for x between x_ideal and 1: 2^((x_ideal - x) / d) 34 | /// ``` 35 | /// 36 | /// where: 37 | /// * x is the stake rate, i.e. fraction of total issued tokens that actively staked behind 38 | /// validators. 39 | /// * d is the falloff or `decay_rate` 40 | /// * x_ideal: the ideal stake rate. 41 | /// 42 | /// The result is meant to be scaled with minimum inflation and maximum inflation. 43 | /// 44 | /// (as detailed 45 | /// [here](https://research.web3.foundation/en/latest/polkadot/economics/1-token-economics.html#inflation-model-with-parachains)) 46 | /// 47 | /// Arguments are: 48 | /// * `stake`: The fraction of total issued tokens that actively staked behind validators. Known as 49 | /// `x` in the literature. Must be between 0 and 1. 50 | /// * `ideal_stake`: The fraction of total issued tokens that should be actively staked behind 51 | /// validators. Known as `x_ideal` in the literature. Must be between 0 and 1. 52 | /// * `falloff`: Known as `decay_rate` in the literature. A co-efficient dictating the strength of 53 | /// the global incentivization to get the `ideal_stake`. A higher number results in less typical 54 | /// inflation at the cost of greater volatility for validators. Must be more than 0.01. 55 | pub fn compute_inflation(stake: P, ideal_stake: P, falloff: P) -> P { 56 | if stake < ideal_stake { 57 | // ideal_stake is more than 0 because it is strictly more than stake 58 | return stake / ideal_stake 59 | } 60 | 61 | if falloff < P::from_percent(1.into()) { 62 | log::error!("Invalid inflation computation: falloff less than 1% is not supported"); 63 | return PerThing::zero() 64 | } 65 | 66 | let accuracy = { 67 | let mut a = BigUint::from(Into::::into(P::ACCURACY)); 68 | a.lstrip(); 69 | a 70 | }; 71 | 72 | let mut falloff = BigUint::from(falloff.deconstruct().into()); 73 | falloff.lstrip(); 74 | 75 | let ln2 = { 76 | /// `ln(2)` expressed in as perquintillionth. 77 | const LN2: u64 = 0_693_147_180_559_945_309; 78 | let ln2 = P::from_rational(LN2.into(), Perquintill::ACCURACY.into()); 79 | BigUint::from(ln2.deconstruct().into()) 80 | }; 81 | 82 | // falloff is stripped above. 83 | let ln2_div_d = div_by_stripped(ln2.mul(&accuracy), &falloff); 84 | 85 | let inpos_param = INPoSParam { 86 | x_ideal: BigUint::from(ideal_stake.deconstruct().into()), 87 | x: BigUint::from(stake.deconstruct().into()), 88 | accuracy, 89 | ln2_div_d, 90 | }; 91 | 92 | let res = compute_taylor_serie_part(&inpos_param); 93 | 94 | match u128::try_from(res.clone()) { 95 | Ok(res) if res <= Into::::into(P::ACCURACY) => P::from_parts(res.saturated_into()), 96 | // If result is beyond bounds there is nothing we can do 97 | _ => { 98 | log::error!("Invalid inflation computation: unexpected result {:?}", res); 99 | P::zero() 100 | }, 101 | } 102 | } 103 | 104 | /// Internal struct holding parameter info alongside other cached value. 105 | /// 106 | /// All expressed in part from `accuracy` 107 | struct INPoSParam { 108 | ln2_div_d: BigUint, 109 | x_ideal: BigUint, 110 | x: BigUint, 111 | /// Must be stripped and have no leading zeros. 112 | accuracy: BigUint, 113 | } 114 | 115 | /// Compute `2^((x_ideal - x) / d)` using taylor serie. 116 | /// 117 | /// x must be strictly more than x_ideal. 118 | /// 119 | /// result is expressed with accuracy `INPoSParam.accuracy` 120 | fn compute_taylor_serie_part(p: &INPoSParam) -> BigUint { 121 | // The last computed taylor term. 122 | let mut last_taylor_term = p.accuracy.clone(); 123 | 124 | // Whereas taylor sum is positive. 125 | let mut taylor_sum_positive = true; 126 | 127 | // The sum of all taylor term. 128 | let mut taylor_sum = last_taylor_term.clone(); 129 | 130 | for k in 1..300 { 131 | last_taylor_term = compute_taylor_term(k, &last_taylor_term, p); 132 | 133 | if last_taylor_term.is_zero() { 134 | break 135 | } 136 | 137 | let last_taylor_term_positive = k % 2 == 0; 138 | 139 | if taylor_sum_positive == last_taylor_term_positive { 140 | taylor_sum = taylor_sum.add(&last_taylor_term); 141 | } else { 142 | if taylor_sum >= last_taylor_term { 143 | taylor_sum = taylor_sum 144 | .sub(&last_taylor_term) 145 | // NOTE: Should never happen as checked above 146 | .unwrap_or_else(|e| e); 147 | } else { 148 | taylor_sum_positive = !taylor_sum_positive; 149 | taylor_sum = last_taylor_term 150 | .clone() 151 | .sub(&taylor_sum) 152 | // NOTE: Should never happen as checked above 153 | .unwrap_or_else(|e| e); 154 | } 155 | } 156 | } 157 | 158 | if !taylor_sum_positive { 159 | return BigUint::zero() 160 | } 161 | 162 | taylor_sum.lstrip(); 163 | taylor_sum 164 | } 165 | 166 | /// Return the absolute value of k-th taylor term of `2^((x_ideal - x))/d` i.e. 167 | /// `((x - x_ideal) * ln(2) / d)^k / k!` 168 | /// 169 | /// x must be strictly more x_ideal. 170 | /// 171 | /// We compute the term from the last term using this formula: 172 | /// 173 | /// `((x - x_ideal) * ln(2) / d)^k / k! == previous_term * (x - x_ideal) * ln(2) / d / k` 174 | /// 175 | /// `previous_taylor_term` and result are expressed with accuracy `INPoSParam.accuracy` 176 | fn compute_taylor_term(k: u32, previous_taylor_term: &BigUint, p: &INPoSParam) -> BigUint { 177 | let x_minus_x_ideal = 178 | p.x.clone() 179 | .sub(&p.x_ideal) 180 | // NOTE: Should never happen, as x must be more than x_ideal 181 | .unwrap_or_else(|_| BigUint::zero()); 182 | 183 | let res = previous_taylor_term.clone().mul(&x_minus_x_ideal).mul(&p.ln2_div_d).div_unit(k); 184 | 185 | // p.accuracy is stripped by definition. 186 | let res = div_by_stripped(res, &p.accuracy); 187 | let mut res = div_by_stripped(res, &p.accuracy); 188 | 189 | res.lstrip(); 190 | res 191 | } 192 | 193 | /// Compute a div b. 194 | /// 195 | /// requires `b` to be stripped and have no leading zeros. 196 | fn div_by_stripped(mut a: BigUint, b: &BigUint) -> BigUint { 197 | a.lstrip(); 198 | 199 | if b.len() == 0 { 200 | log::error!("Computation error: Invalid division"); 201 | return BigUint::zero() 202 | } 203 | 204 | if b.len() == 1 { 205 | return a.div_unit(b.checked_get(0).unwrap_or(1)) 206 | } 207 | 208 | if b.len() > a.len() { 209 | return BigUint::zero() 210 | } 211 | 212 | if b.len() == a.len() { 213 | // 100_000^2 is more than 2^32-1, thus `new_a` has more limbs than `b`. 214 | let mut new_a = a.mul(&BigUint::from(100_000u64.pow(2))); 215 | new_a.lstrip(); 216 | 217 | debug_assert!(new_a.len() > b.len()); 218 | return new_a 219 | .div(b, false) 220 | .map(|res| res.0) 221 | .unwrap_or_else(|| BigUint::zero()) 222 | .div_unit(100_000) 223 | .div_unit(100_000) 224 | } 225 | 226 | a.div(b, false).map(|res| res.0).unwrap_or_else(|| BigUint::zero()) 227 | } 228 | -------------------------------------------------------------------------------- /frame/staking-pool/reward-fn/tests/test.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | use sp_arithmetic::{PerThing, Perbill, PerU16, Percent, Perquintill}; 19 | 20 | /// This test the precision and panics if error too big error. 21 | /// 22 | /// error is asserted to be less or equal to 8/accuracy or 8*f64::EPSILON 23 | fn test_precision(stake: P, ideal_stake: P, falloff: P) { 24 | let accuracy_f64 = Into::::into(P::ACCURACY) as f64; 25 | let res = pallet_staking_reward_fn::compute_inflation(stake, ideal_stake, falloff); 26 | let res = Into::::into(res.deconstruct()) as f64 / accuracy_f64; 27 | 28 | let expect = float_i_npos(stake, ideal_stake, falloff); 29 | 30 | let error = (res - expect).abs(); 31 | 32 | if error > 8f64 / accuracy_f64 && error > 8.0 * f64::EPSILON { 33 | panic!( 34 | "stake: {:?}, ideal_stake: {:?}, falloff: {:?}, res: {}, expect: {}", 35 | stake, ideal_stake, falloff, res , expect 36 | ); 37 | } 38 | } 39 | 40 | /// compute the inflation using floats 41 | fn float_i_npos(stake: P, ideal_stake: P, falloff: P) -> f64 { 42 | let accuracy_f64 = Into::::into(P::ACCURACY) as f64; 43 | 44 | let ideal_stake = Into::::into(ideal_stake.deconstruct()) as f64 / accuracy_f64; 45 | let stake = Into::::into(stake.deconstruct()) as f64 / accuracy_f64; 46 | let falloff = Into::::into(falloff.deconstruct()) as f64 / accuracy_f64; 47 | 48 | let x_ideal = ideal_stake; 49 | let x = stake; 50 | let d = falloff; 51 | 52 | if x < x_ideal { 53 | x / x_ideal 54 | } else { 55 | 2_f64.powf((x_ideal - x) / d) 56 | } 57 | } 58 | 59 | #[test] 60 | fn test_precision_for_minimum_falloff() { 61 | fn test_falloff_precision_for_minimum_falloff() { 62 | for stake in 0..1_000 { 63 | let stake = P::from_rational(stake, 1_000); 64 | let ideal_stake = P::zero(); 65 | let falloff = P::from_rational(1, 100); 66 | test_precision(stake, ideal_stake, falloff); 67 | } 68 | } 69 | 70 | test_falloff_precision_for_minimum_falloff::(); 71 | 72 | test_falloff_precision_for_minimum_falloff::(); 73 | 74 | test_falloff_precision_for_minimum_falloff::(); 75 | 76 | test_falloff_precision_for_minimum_falloff::(); 77 | } 78 | 79 | #[test] 80 | fn compute_inflation_works() { 81 | fn compute_inflation_works() { 82 | for stake in 0..100 { 83 | for ideal_stake in 0..10 { 84 | for falloff in 1..10 { 85 | let stake = P::from_rational(stake, 100); 86 | let ideal_stake = P::from_rational(ideal_stake, 10); 87 | let falloff = P::from_rational(falloff, 100); 88 | test_precision(stake, ideal_stake, falloff); 89 | } 90 | } 91 | } 92 | } 93 | 94 | compute_inflation_works::(); 95 | 96 | compute_inflation_works::(); 97 | 98 | compute_inflation_works::(); 99 | 100 | compute_inflation_works::(); 101 | } 102 | -------------------------------------------------------------------------------- /frame/staking-pool/src/default_weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2017-2020 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Default weights of pallet-staking. 19 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6 20 | 21 | #![allow(unused_parens)] 22 | #![allow(unused_imports)] 23 | 24 | use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; 25 | 26 | impl crate::WeightInfo for () { 27 | fn bond() -> Weight { 28 | (144278000 as Weight) 29 | .saturating_add(DbWeight::get().reads(5 as Weight)) 30 | .saturating_add(DbWeight::get().writes(4 as Weight)) 31 | } 32 | fn bond_extra() -> Weight { 33 | (110715000 as Weight) 34 | .saturating_add(DbWeight::get().reads(4 as Weight)) 35 | .saturating_add(DbWeight::get().writes(2 as Weight)) 36 | } 37 | fn unbond() -> Weight { 38 | (99840000 as Weight) 39 | .saturating_add(DbWeight::get().reads(5 as Weight)) 40 | .saturating_add(DbWeight::get().writes(3 as Weight)) 41 | } 42 | fn withdraw_unbonded_update(s: u32, ) -> Weight { 43 | (100728000 as Weight) 44 | .saturating_add((63000 as Weight).saturating_mul(s as Weight)) 45 | .saturating_add(DbWeight::get().reads(5 as Weight)) 46 | .saturating_add(DbWeight::get().writes(3 as Weight)) 47 | } 48 | fn withdraw_unbonded_kill(s: u32, ) -> Weight { 49 | (168879000 as Weight) 50 | .saturating_add((6666000 as Weight).saturating_mul(s as Weight)) 51 | .saturating_add(DbWeight::get().reads(7 as Weight)) 52 | .saturating_add(DbWeight::get().writes(8 as Weight)) 53 | .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) 54 | } 55 | fn validate() -> Weight { 56 | (35539000 as Weight) 57 | .saturating_add(DbWeight::get().reads(2 as Weight)) 58 | .saturating_add(DbWeight::get().writes(2 as Weight)) 59 | } 60 | fn nominate(n: u32, ) -> Weight { 61 | (48596000 as Weight) 62 | .saturating_add((308000 as Weight).saturating_mul(n as Weight)) 63 | .saturating_add(DbWeight::get().reads(3 as Weight)) 64 | .saturating_add(DbWeight::get().writes(2 as Weight)) 65 | } 66 | fn chill() -> Weight { 67 | (35144000 as Weight) 68 | .saturating_add(DbWeight::get().reads(2 as Weight)) 69 | .saturating_add(DbWeight::get().writes(2 as Weight)) 70 | } 71 | fn set_payee() -> Weight { 72 | (24255000 as Weight) 73 | .saturating_add(DbWeight::get().reads(1 as Weight)) 74 | .saturating_add(DbWeight::get().writes(1 as Weight)) 75 | } 76 | fn set_controller() -> Weight { 77 | (52294000 as Weight) 78 | .saturating_add(DbWeight::get().reads(3 as Weight)) 79 | .saturating_add(DbWeight::get().writes(3 as Weight)) 80 | } 81 | fn set_validator_count() -> Weight { 82 | (5185000 as Weight) 83 | .saturating_add(DbWeight::get().writes(1 as Weight)) 84 | } 85 | fn force_no_eras() -> Weight { 86 | (5907000 as Weight) 87 | .saturating_add(DbWeight::get().writes(1 as Weight)) 88 | } 89 | fn force_new_era() -> Weight { 90 | (5917000 as Weight) 91 | .saturating_add(DbWeight::get().writes(1 as Weight)) 92 | } 93 | fn force_new_era_always() -> Weight { 94 | (5952000 as Weight) 95 | .saturating_add(DbWeight::get().writes(1 as Weight)) 96 | } 97 | fn set_invulnerables(v: u32, ) -> Weight { 98 | (6324000 as Weight) 99 | .saturating_add((9000 as Weight).saturating_mul(v as Weight)) 100 | .saturating_add(DbWeight::get().writes(1 as Weight)) 101 | } 102 | fn force_unstake(s: u32, ) -> Weight { 103 | (119691000 as Weight) 104 | .saturating_add((6681000 as Weight).saturating_mul(s as Weight)) 105 | .saturating_add(DbWeight::get().reads(4 as Weight)) 106 | .saturating_add(DbWeight::get().writes(8 as Weight)) 107 | .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) 108 | } 109 | fn cancel_deferred_slash(s: u32, ) -> Weight { 110 | (5820201000 as Weight) 111 | .saturating_add((34672000 as Weight).saturating_mul(s as Weight)) 112 | .saturating_add(DbWeight::get().reads(1 as Weight)) 113 | .saturating_add(DbWeight::get().writes(1 as Weight)) 114 | } 115 | fn payout_stakers_dead_controller(n: u32, ) -> Weight { 116 | (0 as Weight) 117 | .saturating_add((92486000 as Weight).saturating_mul(n as Weight)) 118 | .saturating_add(DbWeight::get().reads(4 as Weight)) 119 | .saturating_add(DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) 120 | .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(n as Weight))) 121 | } 122 | fn payout_stakers_alive_staked(n: u32, ) -> Weight { 123 | (0 as Weight) 124 | .saturating_add((117324000 as Weight).saturating_mul(n as Weight)) 125 | .saturating_add(DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) 126 | .saturating_add(DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) 127 | } 128 | fn rebond(l: u32, ) -> Weight { 129 | (71316000 as Weight) 130 | .saturating_add((142000 as Weight).saturating_mul(l as Weight)) 131 | .saturating_add(DbWeight::get().reads(4 as Weight)) 132 | .saturating_add(DbWeight::get().writes(3 as Weight)) 133 | } 134 | fn set_history_depth(e: u32, ) -> Weight { 135 | (0 as Weight) 136 | .saturating_add((51901000 as Weight).saturating_mul(e as Weight)) 137 | .saturating_add(DbWeight::get().reads(2 as Weight)) 138 | .saturating_add(DbWeight::get().writes(4 as Weight)) 139 | .saturating_add(DbWeight::get().writes((7 as Weight).saturating_mul(e as Weight))) 140 | } 141 | fn reap_stash(s: u32, ) -> Weight { 142 | (147166000 as Weight) 143 | .saturating_add((6661000 as Weight).saturating_mul(s as Weight)) 144 | .saturating_add(DbWeight::get().reads(4 as Weight)) 145 | .saturating_add(DbWeight::get().writes(8 as Weight)) 146 | .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) 147 | } 148 | fn new_era(v: u32, n: u32, ) -> Weight { 149 | (0 as Weight) 150 | .saturating_add((1440459000 as Weight).saturating_mul(v as Weight)) 151 | .saturating_add((182580000 as Weight).saturating_mul(n as Weight)) 152 | .saturating_add(DbWeight::get().reads(10 as Weight)) 153 | .saturating_add(DbWeight::get().reads((4 as Weight).saturating_mul(v as Weight))) 154 | .saturating_add(DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) 155 | .saturating_add(DbWeight::get().writes(8 as Weight)) 156 | .saturating_add(DbWeight::get().writes((3 as Weight).saturating_mul(v as Weight))) 157 | } 158 | fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight { 159 | (0 as Weight) 160 | .saturating_add((964000 as Weight).saturating_mul(v as Weight)) 161 | .saturating_add((432000 as Weight).saturating_mul(n as Weight)) 162 | .saturating_add((204294000 as Weight).saturating_mul(a as Weight)) 163 | .saturating_add((9546000 as Weight).saturating_mul(w as Weight)) 164 | .saturating_add(DbWeight::get().reads(6 as Weight)) 165 | .saturating_add(DbWeight::get().reads((4 as Weight).saturating_mul(a as Weight))) 166 | .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(w as Weight))) 167 | .saturating_add(DbWeight::get().writes(2 as Weight)) 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /frame/staking-pool/src/inflation.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2019-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! This module expose one function `P_NPoS` (Payout NPoS) or `compute_total_payout` which returns 19 | //! the total payout for the era given the era duration and the staking rate in NPoS. 20 | //! The staking rate in NPoS is the total amount of tokens staked by nominators and validators, 21 | //! divided by the total token supply. 22 | 23 | use sp_runtime::{curve::PiecewiseLinear, traits::AtLeast32BitUnsigned, Perbill}; 24 | 25 | /// The total payout to all validators (and their nominators) per era and maximum payout. 26 | /// 27 | /// Defined as such: 28 | /// `staker-payout = yearly_inflation(npos_token_staked / total_tokens) * total_tokens / 29 | /// era_per_year` `maximum-payout = max_yearly_inflation * total_tokens / era_per_year` 30 | /// 31 | /// `era_duration` is expressed in millisecond. 32 | pub fn compute_total_payout( 33 | yearly_inflation: &PiecewiseLinear<'static>, 34 | npos_token_staked: N, 35 | total_tokens: N, 36 | era_duration: u64, 37 | ) -> (N, N) 38 | where 39 | N: AtLeast32BitUnsigned + Clone, 40 | { 41 | // Milliseconds per year for the Julian year (365.25 days). 42 | const MILLISECONDS_PER_YEAR: u64 = 1000 * 3600 * 24 * 36525 / 100; 43 | 44 | let portion = Perbill::from_rational(era_duration as u64, MILLISECONDS_PER_YEAR); 45 | let payout = portion 46 | * yearly_inflation 47 | .calculate_for_fraction_times_denominator(npos_token_staked, total_tokens.clone()); 48 | let maximum = portion * (yearly_inflation.maximum * total_tokens); 49 | (payout, maximum) 50 | } 51 | 52 | #[cfg(test)] 53 | mod test { 54 | use sp_runtime::curve::PiecewiseLinear; 55 | 56 | pallet_staking_reward_curve::build! { 57 | const I_NPOS: PiecewiseLinear<'static> = curve!( 58 | min_inflation: 0_025_000, 59 | max_inflation: 0_100_000, 60 | ideal_stake: 0_500_000, 61 | falloff: 0_050_000, 62 | max_piece_count: 40, 63 | test_precision: 0_005_000, 64 | ); 65 | } 66 | 67 | #[test] 68 | fn npos_curve_is_sensible() { 69 | const YEAR: u64 = 365 * 24 * 60 * 60 * 1000; 70 | 71 | // check maximum inflation. 72 | // not 10_000 due to rounding error. 73 | assert_eq!( 74 | super::compute_total_payout(&I_NPOS, 0, 100_000u64, YEAR).1, 75 | 9_993 76 | ); 77 | 78 | // super::I_NPOS.calculate_for_fraction_times_denominator(25, 100) 79 | assert_eq!( 80 | super::compute_total_payout(&I_NPOS, 0, 100_000u64, YEAR).0, 81 | 2_498 82 | ); 83 | assert_eq!( 84 | super::compute_total_payout(&I_NPOS, 5_000, 100_000u64, YEAR).0, 85 | 3_248 86 | ); 87 | assert_eq!( 88 | super::compute_total_payout(&I_NPOS, 25_000, 100_000u64, YEAR).0, 89 | 6_246 90 | ); 91 | assert_eq!( 92 | super::compute_total_payout(&I_NPOS, 40_000, 100_000u64, YEAR).0, 93 | 8_494 94 | ); 95 | assert_eq!( 96 | super::compute_total_payout(&I_NPOS, 50_000, 100_000u64, YEAR).0, 97 | 9_993 98 | ); 99 | assert_eq!( 100 | super::compute_total_payout(&I_NPOS, 60_000, 100_000u64, YEAR).0, 101 | 4_379 102 | ); 103 | assert_eq!( 104 | super::compute_total_payout(&I_NPOS, 75_000, 100_000u64, YEAR).0, 105 | 2_733 106 | ); 107 | assert_eq!( 108 | super::compute_total_payout(&I_NPOS, 95_000, 100_000u64, YEAR).0, 109 | 2_513 110 | ); 111 | assert_eq!( 112 | super::compute_total_payout(&I_NPOS, 100_000, 100_000u64, YEAR).0, 113 | 2_505 114 | ); 115 | 116 | const DAY: u64 = 24 * 60 * 60 * 1000; 117 | assert_eq!( 118 | super::compute_total_payout(&I_NPOS, 25_000, 100_000u64, DAY).0, 119 | 17 120 | ); 121 | assert_eq!( 122 | super::compute_total_payout(&I_NPOS, 50_000, 100_000u64, DAY).0, 123 | 27 124 | ); 125 | assert_eq!( 126 | super::compute_total_payout(&I_NPOS, 75_000, 100_000u64, DAY).0, 127 | 7 128 | ); 129 | 130 | const SIX_HOURS: u64 = 6 * 60 * 60 * 1000; 131 | assert_eq!( 132 | super::compute_total_payout(&I_NPOS, 25_000, 100_000u64, SIX_HOURS).0, 133 | 4 134 | ); 135 | assert_eq!( 136 | super::compute_total_payout(&I_NPOS, 50_000, 100_000u64, SIX_HOURS).0, 137 | 7 138 | ); 139 | assert_eq!( 140 | super::compute_total_payout(&I_NPOS, 75_000, 100_000u64, SIX_HOURS).0, 141 | 2 142 | ); 143 | 144 | const HOUR: u64 = 60 * 60 * 1000; 145 | assert_eq!( 146 | super::compute_total_payout( 147 | &I_NPOS, 148 | 2_500_000_000_000_000_000_000_000_000u128, 149 | 5_000_000_000_000_000_000_000_000_000u128, 150 | HOUR 151 | ) 152 | .0, 153 | 57_038_500_000_000_000_000_000 154 | ); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /frame/staking-pool/src/migrations.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2020-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | 17 | //! Storage migrations for the Staking pallet. 18 | 19 | use super::*; 20 | 21 | pub mod v7 { 22 | use super::*; 23 | 24 | pub fn pre_migrate() -> Result<(), &'static str> { 25 | assert!( 26 | CounterForValidators::::get().is_zero(), 27 | "CounterForValidators already set." 28 | ); 29 | assert!( 30 | CounterForNominators::::get().is_zero(), 31 | "CounterForNominators already set." 32 | ); 33 | assert!(StorageVersion::::get() == Releases::V6_0_0); 34 | Ok(()) 35 | } 36 | 37 | pub fn migrate() -> Weight { 38 | log!(info, "Migrating staking to Releases::V7_0_0"); 39 | let validator_count = Validators::::iter().count() as u32; 40 | let nominator_count = Nominators::::iter().count() as u32; 41 | 42 | CounterForValidators::::put(validator_count); 43 | CounterForNominators::::put(nominator_count); 44 | 45 | StorageVersion::::put(Releases::V7_0_0); 46 | log!(info, "Completed staking migration to Releases::V7_0_0"); 47 | 48 | T::DbWeight::get().reads_writes(validator_count.saturating_add(nominator_count).into(), 2) 49 | } 50 | } 51 | 52 | pub mod v6 { 53 | use super::*; 54 | use frame_support::{generate_storage_alias, traits::Get, weights::Weight}; 55 | 56 | // NOTE: value type doesn't matter, we just set it to () here. 57 | generate_storage_alias!(Staking, SnapshotValidators => Value<()>); 58 | generate_storage_alias!(Staking, SnapshotNominators => Value<()>); 59 | generate_storage_alias!(Staking, QueuedElected => Value<()>); 60 | generate_storage_alias!(Staking, QueuedScore => Value<()>); 61 | generate_storage_alias!(Staking, EraElectionStatus => Value<()>); 62 | generate_storage_alias!(Staking, IsCurrentSessionFinal => Value<()>); 63 | 64 | /// check to execute prior to migration. 65 | pub fn pre_migrate() -> Result<(), &'static str> { 66 | // these may or may not exist. 67 | log!( 68 | info, 69 | "SnapshotValidators.exits()? {:?}", 70 | SnapshotValidators::exists() 71 | ); 72 | log!( 73 | info, 74 | "SnapshotNominators.exits()? {:?}", 75 | SnapshotNominators::exists() 76 | ); 77 | log!(info, "QueuedElected.exits()? {:?}", QueuedElected::exists()); 78 | log!(info, "QueuedScore.exits()? {:?}", QueuedScore::exists()); 79 | // these must exist. 80 | assert!( 81 | IsCurrentSessionFinal::exists(), 82 | "IsCurrentSessionFinal storage item not found!" 83 | ); 84 | assert!( 85 | EraElectionStatus::exists(), 86 | "EraElectionStatus storage item not found!" 87 | ); 88 | Ok(()) 89 | } 90 | 91 | /// Migrate storage to v6. 92 | pub fn migrate() -> Weight { 93 | log!(info, "Migrating staking to Releases::V6_0_0"); 94 | 95 | SnapshotValidators::kill(); 96 | SnapshotNominators::kill(); 97 | QueuedElected::kill(); 98 | QueuedScore::kill(); 99 | EraElectionStatus::kill(); 100 | IsCurrentSessionFinal::kill(); 101 | 102 | StorageVersion::::put(Releases::V6_0_0); 103 | log!(info, "Done."); 104 | T::DbWeight::get().writes(6 + 1) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /frame/staking-pool/src/testing_utils.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2020-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Testing utils for staking. Provides some common functions to setup staking state, such as 19 | //! bonding validators, nominators, and generating different types of solutions. 20 | 21 | use crate::{Pallet as Staking, *}; 22 | use frame_benchmarking::account; 23 | use frame_system::RawOrigin; 24 | use rand_chacha::{ 25 | rand_core::{RngCore, SeedableRng}, 26 | ChaChaRng, 27 | }; 28 | use sp_io::hashing::blake2_256; 29 | 30 | use frame_support::{pallet_prelude::*, traits::Currency}; 31 | use sp_runtime::{traits::StaticLookup, Perbill}; 32 | use sp_std::prelude::*; 33 | 34 | const SEED: u32 = 0; 35 | 36 | /// This function removes all validators and nominators from storage. 37 | pub fn clear_validators_and_nominators() { 38 | Validators::::remove_all(None); 39 | CounterForValidators::::kill(); 40 | Nominators::::remove_all(None); 41 | CounterForNominators::::kill(); 42 | } 43 | 44 | /// Grab a funded user. 45 | pub fn create_funded_user( 46 | string: &'static str, 47 | n: u32, 48 | balance_factor: u32, 49 | ) -> T::AccountId { 50 | let user = account(string, n, SEED); 51 | let balance = T::Currency::minimum_balance() * balance_factor.into(); 52 | T::Currency::make_free_balance_be(&user, balance); 53 | // ensure T::CurrencyToVote will work correctly. 54 | T::Currency::issue(balance); 55 | user 56 | } 57 | 58 | /// Create a stash and controller pair. 59 | pub fn create_stash_controller( 60 | n: u32, 61 | balance_factor: u32, 62 | destination: RewardDestination, 63 | ) -> Result<(T::AccountId, T::AccountId), &'static str> { 64 | let stash = create_funded_user::("stash", n, balance_factor); 65 | let controller = create_funded_user::("controller", n, balance_factor); 66 | let controller_lookup: ::Source = 67 | T::Lookup::unlookup(controller.clone()); 68 | let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into(); 69 | Staking::::bond( 70 | RawOrigin::Signed(stash.clone()).into(), 71 | controller_lookup, 72 | amount, 73 | destination, 74 | )?; 75 | return Ok((stash, controller)); 76 | } 77 | 78 | /// Create a stash and controller pair, where the controller is dead, and payouts go to controller. 79 | /// This is used to test worst case payout scenarios. 80 | pub fn create_stash_and_dead_controller( 81 | n: u32, 82 | balance_factor: u32, 83 | destination: RewardDestination, 84 | ) -> Result<(T::AccountId, T::AccountId), &'static str> { 85 | let stash = create_funded_user::("stash", n, balance_factor); 86 | // controller has no funds 87 | let controller = create_funded_user::("controller", n, 0); 88 | let controller_lookup: ::Source = 89 | T::Lookup::unlookup(controller.clone()); 90 | let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into(); 91 | Staking::::bond( 92 | RawOrigin::Signed(stash.clone()).into(), 93 | controller_lookup, 94 | amount, 95 | destination, 96 | )?; 97 | return Ok((stash, controller)); 98 | } 99 | 100 | /// create `max` validators. 101 | pub fn create_validators( 102 | max: u32, 103 | balance_factor: u32, 104 | ) -> Result::Source>, &'static str> { 105 | let mut validators: Vec<::Source> = Vec::with_capacity(max as usize); 106 | for i in 0..max { 107 | let (stash, controller) = 108 | create_stash_controller::(i, balance_factor, RewardDestination::Staked)?; 109 | let validator_prefs = ValidatorPrefs { 110 | commission: Perbill::from_percent(50), 111 | ..Default::default() 112 | }; 113 | Staking::::validate(RawOrigin::Signed(controller).into(), validator_prefs)?; 114 | let stash_lookup: ::Source = T::Lookup::unlookup(stash); 115 | validators.push(stash_lookup); 116 | } 117 | Ok(validators) 118 | } 119 | 120 | /// This function generates validators and nominators who are randomly nominating 121 | /// `edge_per_nominator` random validators (until `to_nominate` if provided). 122 | /// 123 | /// NOTE: This function will remove any existing validators or nominators to ensure 124 | /// we are working with a clean state. 125 | /// 126 | /// Parameters: 127 | /// - `validators`: number of bonded validators 128 | /// - `nominators`: number of bonded nominators. 129 | /// - `edge_per_nominator`: number of edge (vote) per nominator. 130 | /// - `randomize_stake`: whether to randomize the stakes. 131 | /// - `to_nominate`: if `Some(n)`, only the first `n` bonded validator are voted upon. Else, all of 132 | /// them are considered and `edge_per_nominator` random validators are voted for. 133 | /// 134 | /// Return the validators chosen to be nominated. 135 | pub fn create_validators_with_nominators_for_era( 136 | validators: u32, 137 | nominators: u32, 138 | edge_per_nominator: usize, 139 | randomize_stake: bool, 140 | to_nominate: Option, 141 | ) -> Result::Source>, &'static str> { 142 | clear_validators_and_nominators::(); 143 | 144 | let mut validators_stash: Vec<::Source> = 145 | Vec::with_capacity(validators as usize); 146 | let mut rng = ChaChaRng::from_seed(SEED.using_encoded(blake2_256)); 147 | 148 | // Create validators 149 | for i in 0..validators { 150 | let balance_factor = if randomize_stake { 151 | rng.next_u32() % 255 + 10 152 | } else { 153 | 100u32 154 | }; 155 | let (v_stash, v_controller) = 156 | create_stash_controller::(i, balance_factor, RewardDestination::Staked)?; 157 | let validator_prefs = ValidatorPrefs { 158 | commission: Perbill::from_percent(50), 159 | ..Default::default() 160 | }; 161 | Staking::::validate( 162 | RawOrigin::Signed(v_controller.clone()).into(), 163 | validator_prefs, 164 | )?; 165 | let stash_lookup: ::Source = 166 | T::Lookup::unlookup(v_stash.clone()); 167 | validators_stash.push(stash_lookup.clone()); 168 | } 169 | 170 | let to_nominate = to_nominate.unwrap_or(validators_stash.len() as u32) as usize; 171 | let validator_chosen = validators_stash[0..to_nominate].to_vec(); 172 | 173 | // Create nominators 174 | for j in 0..nominators { 175 | let balance_factor = if randomize_stake { 176 | rng.next_u32() % 255 + 10 177 | } else { 178 | 100u32 179 | }; 180 | let (_n_stash, n_controller) = 181 | create_stash_controller::(u32::MAX - j, balance_factor, RewardDestination::Staked)?; 182 | 183 | // Have them randomly validate 184 | let mut available_validators = validator_chosen.clone(); 185 | let mut selected_validators: Vec<::Source> = 186 | Vec::with_capacity(edge_per_nominator); 187 | 188 | for _ in 0..validators.min(edge_per_nominator as u32) { 189 | let selected = rng.next_u32() as usize % available_validators.len(); 190 | let validator = available_validators.remove(selected); 191 | selected_validators.push(validator); 192 | } 193 | Staking::::nominate( 194 | RawOrigin::Signed(n_controller.clone()).into(), 195 | selected_validators, 196 | )?; 197 | } 198 | 199 | ValidatorCount::::put(validators); 200 | 201 | Ok(validator_chosen) 202 | } 203 | 204 | /// get the current era. 205 | pub fn current_era() -> EraIndex { 206 | >::current_era().unwrap_or(0) 207 | } 208 | -------------------------------------------------------------------------------- /primitives/realis/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "realis-primitives" 3 | version = "0.0.2" 4 | edition = "2018" 5 | 6 | [dependencies] 7 | codec = { package = "parity-scale-codec", version = "2.0.1", default-features = false, features = ["derive"] } 8 | serde = { version = "1.0.133", default-features = false } 9 | primitive-types = { version = "0.10.1", default-features = false } 10 | derive_more = "0.99.17" 11 | sp-runtime = { version = "4.0.0-dev", git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false} 12 | frame-support = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 13 | frame-system = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 14 | sp-core = { git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 15 | sp-std = { package = "sp-std", git = "https://github.com/RealisNetwork/substrate", branch = "polkadot-v0.9.9", default-features = false } 16 | impl-trait-for-tuples = "0.2" 17 | serde_repr = "0.1.7" 18 | 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "codec/std", 24 | "serde/std", 25 | "primitive-types/std", 26 | "sp-runtime/std", 27 | "frame-support/std", 28 | "frame-system/std", 29 | "sp-core/std", 30 | "sp-std/std", 31 | ] 32 | -------------------------------------------------------------------------------- /primitives/realis/res/types.json: -------------------------------------------------------------------------------- 1 | { 2 | "TokenId": "U256", 3 | "Basic": "u8", 4 | "String": "Vec", 5 | "Token": { 6 | "id": "TokenId", 7 | "token_type": "TokenType" 8 | }, 9 | "TokenType": { 10 | "_enum": { 11 | "Basic": "(Basic, Rarity, String)" 12 | } 13 | }, 14 | "Status": { 15 | "_enum": [ 16 | "OnSell", 17 | "InDelegation", 18 | "Free" 19 | ] 20 | }, 21 | "Stackable": { 22 | "_enum": [ 23 | "Silver", 24 | "Gold", 25 | "Diamond" 26 | ] 27 | }, 28 | "Rarity": { 29 | "_enum": { 30 | "Common": 1, 31 | "Uncommon": 2, 32 | "Rare": 3, 33 | "Epic": 4, 34 | "Legendary": 5, 35 | "Relic": 6 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /primitives/realis/src/constants.rs: -------------------------------------------------------------------------------- 1 | pub const COMMISSION: u128 = 5; 2 | -------------------------------------------------------------------------------- /primitives/realis/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | 3 | pub mod constants; 4 | 5 | use frame_support::pallet_prelude::{Decode, Encode}; 6 | use primitive_types::U256; 7 | #[cfg(feature = "std")] 8 | use serde::{Deserialize, Serialize}; 9 | use sp_std::fmt::{Display, Formatter}; 10 | use sp_std::vec::Vec; 11 | 12 | pub type TokenId = U256; 13 | pub type String = Vec; 14 | 15 | #[derive(Encode, Decode, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)] 16 | pub struct Token { 17 | pub id: TokenId, 18 | pub token_type: TokenType, 19 | } 20 | 21 | #[derive(Encode, Decode, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)] 22 | #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] 23 | pub enum TokenType { 24 | Basic(Rarity, String, u32, String), 25 | } 26 | 27 | #[derive(Encode, Decode, Clone, Eq, PartialEq, PartialOrd, Ord, Debug, Copy)] 28 | #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] 29 | pub enum Status { 30 | OnSell, 31 | OnDelegateSell, 32 | InDelegation, 33 | Free, 34 | } 35 | 36 | #[derive(Encode, Decode, Clone, Eq, PartialEq, PartialOrd, Ord, Debug, Copy)] 37 | pub enum Stackable { 38 | Silver, 39 | Gold, 40 | Diamond, 41 | } 42 | 43 | #[derive(Encode, Decode, Clone, Eq, PartialEq, PartialOrd, Ord, Debug, Copy)] 44 | #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] 45 | pub enum Rarity { 46 | Common, 47 | Uncommon, 48 | Rare, 49 | Epic, 50 | Legendary, 51 | Relic, 52 | } 53 | 54 | impl Display for Rarity { 55 | fn fmt(&self, f: &mut Formatter<'_>) -> sp_std::fmt::Result { 56 | write!(f, "{:?}", self) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /scripts/benchmark_bridge.sh: -------------------------------------------------------------------------------- 1 | cargo build --release --features runtime-benchmarks 2 | 3 | ./target/release/realis benchmark \ 4 | --chain dev \ 5 | --execution wasm \ 6 | --wasm-execution compiled \ 7 | --pallet realis-bridge \ 8 | --extrinsic '*' \ 9 | --steps 20 \ 10 | --repeat 10 \ 11 | --raw \ 12 | --output=./frame/realis-bridge/src/weights.rs \ 13 | --template=./.maintain/frame-weight-template.hbs -------------------------------------------------------------------------------- /scripts/benchmark_marketplace.sh: -------------------------------------------------------------------------------- 1 | cargo build --release --features runtime-benchmarks 2 | 3 | ./target/release/realis benchmark \ 4 | --chain dev \ 5 | --execution wasm \ 6 | --wasm-execution compiled \ 7 | --pallet marketplace \ 8 | --extrinsic '*' \ 9 | --steps 20 \ 10 | --repeat 10 \ 11 | --raw \ 12 | --output=./frame/marketplace/src/weights.rs \ 13 | --template=./.maintain/frame-weight-template.hbs -------------------------------------------------------------------------------- /scripts/benchmark_nft.sh: -------------------------------------------------------------------------------- 1 | cargo build --release --features runtime-benchmarks 2 | 3 | ./target/release/realis benchmark \ 4 | --chain dev \ 5 | --execution wasm \ 6 | --wasm-execution compiled \ 7 | --pallet pallet-nft \ 8 | --extrinsic '*' \ 9 | --steps 20 \ 10 | --repeat 10 \ 11 | --raw \ 12 | --output=./frame/nft/src/weights.rs \ 13 | --template=./.maintain/frame-weight-template.hbs -------------------------------------------------------------------------------- /scripts/benchmark_nft_delegate.sh: -------------------------------------------------------------------------------- 1 | cargo build --release --features runtime-benchmarks 2 | 3 | ./target/release/realis benchmark \ 4 | --chain dev \ 5 | --execution wasm \ 6 | --wasm-execution compiled \ 7 | --pallet pallet-nft-delegate \ 8 | --extrinsic '*' \ 9 | --steps 20 \ 10 | --repeat 10 \ 11 | --raw \ 12 | --output=./frame/nft-delegate/src/weights.rs \ 13 | --template=./.maintain/frame-weight-template.hbs -------------------------------------------------------------------------------- /scripts/benchmark_realis.sh: -------------------------------------------------------------------------------- 1 | cargo build --release --features runtime-benchmarks 2 | 3 | ./target/release/realis benchmark \ 4 | --chain dev \ 5 | --execution wasm \ 6 | --wasm-execution compiled \ 7 | --pallet realis-game-api \ 8 | --extrinsic '*' \ 9 | --steps 20 \ 10 | --repeat 10 \ 11 | --raw \ 12 | --output=./frame/realis-game-api/src/weights.rs \ 13 | --template=./.maintain/frame-weight-template.hbs -------------------------------------------------------------------------------- /scripts/build_separately.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Build frames 4 | 5 | #echo "Start build pallet-dynamic-fee" 6 | #cargo build -p pallet-dynamic-fee 7 | #echo "Start build pallet-ethereum" 8 | #cargo build -p pallet-ethereum 9 | #echo "Start build pallet-evm" 10 | #cargo build -p pallet-evm 11 | 12 | echo "Start build pallet-nft" 13 | cargo build -p pallet-nft 14 | echo "Start build realis-game-api" 15 | cargo build -p realis-game-api 16 | echo "Start build realis-game-api-rpc" 17 | cargo build -p realis-game-api-rpc 18 | echo "Start build pallet-staking" 19 | cargo build -p pallet-staking 20 | 21 | # Build primitives 22 | 23 | #echo "Start build fp-consensus" 24 | #cargo build -p fp-consensus 25 | #echo "Start build fp-precompile" 26 | #cargo build -p fp-precompile 27 | echo "Start build realis-primitives" 28 | cargo build -p realis-primitives 29 | #echo "Start build fp-rpc" 30 | #cargo build -p fp-rpc 31 | #echo "Start build fp-storage" 32 | #cargo build -p fp-storage 33 | 34 | # Build 35 | 36 | echo "Start build runtime-common" 37 | cargo build -p runtime-common 38 | echo "Start build node-runtime" 39 | cargo build -p node-runtime 40 | echo "Start build node-cli" 41 | cargo build -p node-cli 42 | 43 | # Build whole project 44 | 45 | echo "Start build whole project" 46 | cargo build --release -------------------------------------------------------------------------------- /scripts/create_custom_spec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./target/release/realis build-spec --disable-default-bootnode --chain realis2 > customSpec.json 4 | -------------------------------------------------------------------------------- /scripts/create_realis_json.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./target/release/realis build-spec --chain=customSpec.json --raw --disable-default-bootnode > realis.json 4 | -------------------------------------------------------------------------------- /scripts/insert_aura_key_node01.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis key insert \ 2 | --base-path /tmp/node01 \ 3 | --chain customSpecRaw.json \ 4 | --scheme Sr25519 \ 5 | --suri "0x1e32c692fd0b8e8b5e02d96ed5403ca5aa1d4667d7e11f84eedc446d1c602b54" \ 6 | --password-interactive \ 7 | --key-type aura -------------------------------------------------------------------------------- /scripts/insert_aura_key_node02.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis key insert --base-path /tmp/node02 \ 2 | --chain customSpecRaw.json \ 3 | --scheme Sr25519 \ 4 | --suri "0x8b2fb92edf7bcf98d1682a45612cf0ca88607d3f5ada53ad82e93fc83c9cf867" \ 5 | --password-interactive \ 6 | --key-type aura -------------------------------------------------------------------------------- /scripts/insert_grandpa_key_node01.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis key insert --base-path /tmp/node01 \ 2 | --chain customSpecRaw.json \ 3 | --scheme Ed25519 \ 4 | --suri "0x1e32c692fd0b8e8b5e02d96ed5403ca5aa1d4667d7e11f84eedc446d1c602b54" \ 5 | --password-interactive \ 6 | --key-type gran -------------------------------------------------------------------------------- /scripts/insert_grandpa_key_node02.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis key insert --base-path /tmp/node02 \ 2 | --chain customSpecRaw.json \ 3 | --scheme Ed25519 \ 4 | --suri "0x8b2fb92edf7bcf98d1682a45612cf0ca88607d3f5ada53ad82e93fc83c9cf867" \ 5 | --password-interactive \ 6 | --key-type gran -------------------------------------------------------------------------------- /scripts/run_node01.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis \ 2 | --base-path /tmp/node01 \ 3 | --chain ./customSpecRaw.json \ 4 | --port 30333 \ 5 | --ws-port 9945 \ 6 | --rpc-port 9933 \ 7 | --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \ 8 | --validator \ 9 | --rpc-methods Unsafe \ 10 | --name MyNode01 -------------------------------------------------------------------------------- /scripts/run_node02.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis \ 2 | --base-path /tmp/node02 \ 3 | --chain ./customSpecRaw.json \ 4 | --port 30334 \ 5 | --ws-port 9946 \ 6 | --rpc-port 9934 \ 7 | --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \ 8 | --validator \ 9 | --rpc-methods Unsafe \ 10 | --name MyNode02 \ 11 | --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEdara2f9eg9dJHRmNWDQfEQUfSFjAx1qvRWwVrtWw1ts \ 12 | --password-interactive 13 | -------------------------------------------------------------------------------- /scripts/run_node_alice.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis \ 2 | --base-path /tmp/alice \ 3 | --chain local \ 4 | --alice \ 5 | --port 30333 \ 6 | --ws-port 9945 \ 7 | --rpc-port 9933 \ 8 | --node-key 0000000000000000000000000000000000000000000000000000000000000001 \ 9 | --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \ 10 | --validator -------------------------------------------------------------------------------- /scripts/run_node_bob.sh: -------------------------------------------------------------------------------- 1 | ./target/release/realis \ 2 | --base-path /tmp/bob \ 3 | --chain local \ 4 | --bob \ 5 | --port 30334 \ 6 | --ws-port 9946 \ 7 | --rpc-port 9934 \ 8 | --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \ 9 | --validator \ 10 | --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp -------------------------------------------------------------------------------- /types.json: -------------------------------------------------------------------------------- 1 | { 2 | "Rarity": { 3 | "_enum": { 4 | "Common": 1, 5 | "Uncommon": 2, 6 | "Rare": 3, 7 | "Epic": 4, 8 | "Legendary": 5, 9 | "Relic": 6 10 | } 11 | }, 12 | "Basic": "u8", 13 | "TokenId": "U256", 14 | "Stackable": { 15 | "_enum": [ 16 | "Silver", 17 | "Gold", 18 | "Diamond" 19 | ] 20 | }, 21 | "TokenType": { 22 | "_enum": { 23 | "Basic": "(Basic, Rarity)" 24 | } 25 | }, 26 | "Token": { 27 | "token_id": "TokenId", 28 | "token": "TokenType" 29 | }, 30 | "String": "Vec", 31 | "Status": { 32 | "_enum": [ 33 | "OnSell", 34 | "OnDelegateSell", 35 | "InDelegation", 36 | "Free" 37 | ] 38 | } 39 | } 40 | 41 | --------------------------------------------------------------------------------