├── .dockerignore ├── .editorconfig ├── .github └── workflows │ ├── build.yml │ ├── cargo-test.yml │ └── yarn.yml ├── .gitignore ├── .mergify.yml ├── .travis.yml ├── .travis ├── check-change └── check-mergify-merge ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── build.rs ├── clippy.toml ├── codechain ├── auto_self_nominate.rs ├── codechain.yml ├── config │ ├── chain_type.rs │ ├── mod.rs │ └── presets │ │ ├── config.dev.toml │ │ └── config.prod.toml ├── constants.rs ├── dummy_network_service.rs ├── json │ ├── mod.rs │ ├── password_entry.rs │ └── password_file.rs ├── main.rs ├── rpc.rs ├── rpc_apis.rs ├── run_node.rs └── subcommand │ ├── account_command.rs │ ├── convert_command.rs │ └── mod.rs ├── config └── simple_poa.toml ├── core ├── Cargo.toml ├── res │ ├── beagle.json │ ├── blake_pow.json │ ├── corgi.json │ ├── cuckoo.json │ ├── husky.json │ ├── mainnet.json │ ├── null.json │ ├── saluki.json │ ├── simple_poa.json │ ├── solo.json │ └── tendermint.json └── src │ ├── account_provider.rs │ ├── block.rs │ ├── blockchain │ ├── block_info.rs │ ├── blockchain.rs │ ├── body_db.rs │ ├── extras.rs │ ├── headerchain.rs │ ├── invoice_db.rs │ ├── mod.rs │ └── route.rs │ ├── blockchain_info.rs │ ├── client │ ├── chain_notify.rs │ ├── client.rs │ ├── config.rs │ ├── importer.rs │ ├── mod.rs │ └── test_client.rs │ ├── codechain_machine.rs │ ├── consensus │ ├── bit_set.rs │ ├── blake_pow │ │ ├── mod.rs │ │ └── params.rs │ ├── cuckoo │ │ ├── mod.rs │ │ └── params.rs │ ├── mod.rs │ ├── null_engine │ │ ├── mod.rs │ │ └── params.rs │ ├── signer.rs │ ├── simple_poa │ │ ├── mod.rs │ │ └── params.rs │ ├── solo │ │ ├── mod.rs │ │ └── params.rs │ ├── stake │ │ ├── action_data.rs │ │ ├── actions.rs │ │ ├── distribute.rs │ │ └── mod.rs │ ├── tendermint │ │ ├── DESIGN.md │ │ ├── backup.rs │ │ ├── chain_notify.rs │ │ ├── engine.rs │ │ ├── message.rs │ │ ├── mod.rs │ │ ├── network.rs │ │ ├── params.rs │ │ ├── types.rs │ │ ├── vote_collector.rs │ │ ├── vote_regression_checker.rs │ │ └── worker.rs │ └── validator_set │ │ ├── dynamic_validator.rs │ │ ├── mod.rs │ │ └── validator_list.rs │ ├── db.rs │ ├── db_version.rs │ ├── encoded.rs │ ├── error.rs │ ├── invoice.rs │ ├── lib.rs │ ├── miner │ ├── backup.rs │ ├── mem_pool.rs │ ├── mem_pool_benches.rs │ ├── mem_pool_types.rs │ ├── miner.rs │ ├── mod.rs │ ├── sealing_queue.rs │ ├── stratum.rs │ └── work_notify.rs │ ├── peer_db.rs │ ├── scheme │ ├── genesis.rs │ ├── mod.rs │ ├── pod_account.rs │ ├── pod_shard_metadata.rs │ ├── pod_state.rs │ ├── scheme.rs │ └── seal.rs │ ├── service.rs │ ├── tests │ ├── helpers.rs │ └── mod.rs │ ├── transaction.rs │ ├── types │ ├── block_status.rs │ ├── ids.rs │ ├── mod.rs │ └── verification_queue_info.rs │ ├── verification │ ├── mod.rs │ ├── queue │ │ ├── kind.rs │ │ └── mod.rs │ ├── verification.rs │ └── verifier.rs │ └── views │ ├── block.rs │ ├── body.rs │ ├── header.rs │ ├── mod.rs │ └── transaction.rs ├── discovery ├── Cargo.toml └── src │ ├── config.rs │ ├── extension.rs │ ├── lib.rs │ ├── message.rs │ └── node_id.rs ├── docker ├── README.md └── ubuntu │ └── Dockerfile ├── docker_push.sh ├── json ├── Cargo.toml └── src │ ├── bytes.rs │ ├── hash.rs │ ├── lib.rs │ ├── scheme │ ├── account.rs │ ├── blake_pow.rs │ ├── cuckoo.rs │ ├── engine.rs │ ├── genesis.rs │ ├── mod.rs │ ├── null_engine.rs │ ├── params.rs │ ├── scheme.rs │ ├── seal.rs │ ├── shard.rs │ ├── simple_poa.rs │ ├── solo.rs │ ├── state.rs │ └── tendermint.rs │ └── uint.rs ├── key ├── Cargo.toml ├── benches │ ├── ecdsa.rs │ ├── pay_and_transfer.rs │ ├── schnorr.rs │ └── tendermint.rs └── src │ ├── address.rs │ ├── ecdsa.rs │ ├── error.rs │ ├── exchange.rs │ ├── keypair.rs │ ├── lib.rs │ ├── network.rs │ ├── password.rs │ ├── platform_address.rs │ ├── private.rs │ ├── random.rs │ └── schnorr.rs ├── keystore ├── Cargo.toml ├── src │ ├── account │ │ ├── cipher.rs │ │ ├── crypto.rs │ │ ├── decrypted_account.rs │ │ ├── kdf.rs │ │ ├── mod.rs │ │ ├── safe_account.rs │ │ └── version.rs │ ├── accounts_dir │ │ ├── disk.rs │ │ ├── memory.rs │ │ └── mod.rs │ ├── ckeys.rs │ ├── error.rs │ ├── import.rs │ ├── json │ │ ├── bytes.rs │ │ ├── cipher.rs │ │ ├── crypto.rs │ │ ├── error.rs │ │ ├── hash.rs │ │ ├── id.rs │ │ ├── kdf.rs │ │ ├── key_file.rs │ │ ├── mod.rs │ │ └── version.rs │ ├── keystore.rs │ ├── lib.rs │ ├── random.rs │ └── secret_store.rs └── tests │ ├── api.rs │ ├── res │ ├── ciphertext │ │ ├── 30.json │ │ └── 31.json │ └── pat │ │ ├── p1.json │ │ └── p2.json │ └── util │ ├── mod.rs │ └── transient_dir.rs ├── logstash.conf ├── network ├── Cargo.toml └── src │ ├── addr.rs │ ├── client.rs │ ├── config.rs │ ├── control.rs │ ├── extension.rs │ ├── filters │ ├── control.rs │ ├── filter.rs │ ├── filters.rs │ └── mod.rs │ ├── lib.rs │ ├── node_id.rs │ ├── p2p │ ├── connection │ │ ├── established.rs │ │ ├── incoming.rs │ │ ├── message.rs │ │ ├── mod.rs │ │ └── outgoing.rs │ ├── handler.rs │ ├── listener.rs │ ├── message │ │ ├── extension.rs │ │ ├── message.rs │ │ ├── mod.rs │ │ ├── negotiation.rs │ │ └── signed_message.rs │ ├── mod.rs │ └── stream.rs │ ├── routing_table.rs │ ├── service.rs │ ├── session │ ├── mod.rs │ └── session.rs │ └── stream.rs ├── rpc ├── Cargo.toml └── src │ ├── lib.rs │ ├── rpc_server.rs │ └── v1 │ ├── errors.rs │ ├── impls │ ├── account.rs │ ├── chain.rs │ ├── devel.rs │ ├── engine.rs │ ├── mempool.rs │ ├── miner.rs │ ├── mod.rs │ └── net.rs │ ├── mod.rs │ ├── traits │ ├── account.rs │ ├── chain.rs │ ├── devel.rs │ ├── engine.rs │ ├── mempool.rs │ ├── miner.rs │ ├── mod.rs │ └── net.rs │ └── types │ ├── action.rs │ ├── asset.rs │ ├── asset_input.rs │ ├── asset_output.rs │ ├── asset_scheme.rs │ ├── block.rs │ ├── mem_pool.rs │ ├── mod.rs │ ├── text.rs │ ├── transaction.rs │ ├── unsigned_transaction.rs │ └── work.rs ├── rust-toolchain ├── rustfmt.toml ├── scripts └── test.sh ├── spec ├── Block-Synchronization-Extension.md ├── CodeChain-Account.md ├── CodeChain-Address.md ├── CodeChain-Coin.md ├── CodeChain-Virtual-Machine.md ├── Consensus.md ├── Digital-Signature.md ├── Discovery-Extension.md ├── Dynamic-Validator.md ├── Hash-Function.md ├── JSON-RPC.md ├── List-of-Network-Id.md ├── Merkle-Trie.md ├── Minimum-Fee.md ├── Network-Extension-Protocol.md ├── Node-Discovery-Protocol.md ├── Operate-Extension.md ├── P2P-Protocol.md ├── README.md ├── Script.md ├── Staking.md ├── State-Trie.md ├── Stratum.md ├── System-Extension.md ├── Tag-encoding.md ├── Transaction-Propagation-Extension.md ├── Transaction.md ├── Wire-Protocol.md └── disloyal-penalty-rate.png ├── state ├── Cargo.toml └── src │ ├── action_handler │ ├── hit.rs │ └── mod.rs │ ├── cache │ ├── global_cache.rs │ ├── lru_cache.rs │ ├── mod.rs │ ├── shard_cache.rs │ ├── top_cache.rs │ └── write_back.rs │ ├── checkpoint.rs │ ├── db │ ├── mod.rs │ └── state_db.rs │ ├── error.rs │ ├── impls │ ├── mod.rs │ ├── shard_level.rs │ ├── test_helper.rs │ └── top_level.rs │ ├── item │ ├── account.rs │ ├── action_data.rs │ ├── address.rs │ ├── asset.rs │ ├── asset_scheme.rs │ ├── metadata.rs │ ├── mod.rs │ ├── regular_account.rs │ ├── shard.rs │ └── text.rs │ ├── lib.rs │ ├── tests.rs │ └── traits.rs ├── stratum ├── Cargo.toml └── src │ ├── lib.rs │ └── traits.rs ├── sync ├── Cargo.toml └── src │ ├── block │ ├── downloader │ │ ├── body.rs │ │ ├── header.rs │ │ └── mod.rs │ ├── extension.rs │ ├── message │ │ ├── mod.rs │ │ ├── request.rs │ │ └── response.rs │ └── mod.rs │ ├── lib.rs │ ├── snapshot │ ├── error.rs │ ├── mod.rs │ ├── service.rs │ └── snapshot.rs │ └── transaction │ ├── extension.rs │ ├── message.rs │ └── mod.rs ├── test ├── .editorconfig ├── README.md ├── custom.minfee │ └── tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y │ │ ├── keys │ │ └── key │ │ └── password.json ├── package.json ├── src │ ├── config │ │ ├── mem-pool-min-fee1.toml │ │ └── mem-pool-min-fee2.toml │ ├── e2e.dynval │ │ ├── 1 │ │ │ ├── doubleVote.test.ts │ │ │ ├── dv.changeParams.test.ts │ │ │ ├── dv.era.test.ts │ │ │ ├── dv.m-m'.test.ts │ │ │ ├── dv.n'.test.ts │ │ │ ├── dv.n-1.test.ts │ │ │ └── dv.n.test.ts │ │ ├── 2 │ │ │ ├── autoselfnomination.test.ts │ │ │ ├── dv.n+1.test.ts │ │ │ ├── dv.nomination.test.ts │ │ │ ├── dv.oneblockoneterm.test.ts │ │ │ ├── dv.shutdown.test.ts │ │ │ └── jail.test.ts │ │ ├── dv.double-vote.test.ts │ │ └── setup.ts │ ├── e2e.long │ │ ├── account.test.ts │ │ ├── accountUnlock.test.ts │ │ ├── bootstrap.test.ts │ │ ├── discovery2.test.ts │ │ ├── discovery5.test.ts │ │ ├── expiration.test.ts │ │ ├── futureTransaction.test.ts │ │ ├── invalidBlockPropagation.helper.ts │ │ ├── invalidBlockPropagation0.test.ts │ │ ├── invalidBlockPropagation1.test.ts │ │ ├── invalidBlockPropagation2.test.ts │ │ ├── invalidBlockPropagation3.test.ts │ │ ├── invalidBlockPropagation4.test.ts │ │ ├── invalidBlockPropagation5.test.ts │ │ ├── invalidBlockPropagation6.test.ts │ │ ├── invalidBlockPropagation8.test.ts │ │ ├── invalidBlockPropagation9.test.ts │ │ ├── mempool.test.ts │ │ ├── mempoolMinfee.test.ts │ │ ├── onChainBlockValid.test.ts │ │ ├── onChainTx.test.ts │ │ ├── reward2.test.ts │ │ ├── staking.test.ts │ │ ├── sync2.test.ts │ │ ├── sync3.test.ts │ │ ├── sync5.test.ts │ │ ├── tendermint.test.ts │ │ └── timelock.test.ts │ ├── e2e │ │ ├── account.test.ts │ │ ├── basic.test.ts │ │ ├── burn.test.ts │ │ ├── chain.test.ts │ │ ├── changeAssetScheme.test.ts │ │ ├── changeParams.test.ts │ │ ├── customAction.test.ts │ │ ├── engine.test.ts │ │ ├── increaseAssetSupply.test.ts │ │ ├── ipc.test.ts │ │ ├── mempool.test.ts │ │ ├── mintAsset.test.ts │ │ ├── multisig.test.ts │ │ ├── network1.test.ts │ │ ├── network2.test.ts │ │ ├── partialSignature.test.ts │ │ ├── pay.test.ts │ │ ├── regularkey.test.ts │ │ ├── reward.test.ts │ │ ├── reward1.test.ts │ │ ├── shard.test.ts │ │ ├── staking.test.ts │ │ ├── storeRemove.test.ts │ │ ├── syncEmptyBlock.test.ts │ │ ├── termChange.test.ts │ │ ├── transactionResult.test.ts │ │ ├── transferAsset.test.ts │ │ ├── unwrap.test.ts │ │ ├── verification.test.ts │ │ └── wrap.test.ts │ ├── helper │ │ ├── chai-similar.test.ts │ │ ├── chai-similar.ts │ │ ├── constants.ts │ │ ├── error.ts │ │ ├── mock │ │ │ ├── blockSyncMessage.ts │ │ │ ├── cHeader.ts │ │ │ ├── example │ │ │ │ ├── send-block.ts │ │ │ │ └── send-tx.ts │ │ │ ├── index.ts │ │ │ ├── message.ts │ │ │ ├── p2pLayer.ts │ │ │ ├── tendermintMessage.ts │ │ │ ├── test │ │ │ │ ├── blockSyncMessage.test.ts │ │ │ │ ├── header.test.ts │ │ │ │ ├── message.test.ts │ │ │ │ └── txSyncMessage.test.ts │ │ │ └── transactionSyncMessage.ts │ │ ├── promise.ts │ │ ├── random.ts │ │ ├── rlp.ts │ │ └── spawn.ts │ ├── scheme │ │ ├── mempool.json │ │ ├── solo-block-reward-50.json │ │ ├── tendermint-dynval.json │ │ ├── tendermint-int.json │ │ └── tendermint-tps.json │ └── tendermint.test │ │ ├── local.ts │ │ └── remote.ts ├── tendermint.dynval │ ├── constants.ts │ ├── tccq80vewuacz704whqpcr9e5kjfmtlmpr5xggw66ty │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccq8ad6wxwhsk4aryazef5nawgw98zu6xpe5njs609 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccq8en43nfkkpjxn534gccpqejzhmx75lx2sxkyj6u │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccq8g96vn3tagkf4hrdzgf6l9nqded4l5j7c5qulst │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccq9e7k4nm2m3kxls3vqyxh9aast0ufys4ss4mk8lg │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccq9jj73ft3s4taqksv7fxy0qkhy978c9cqydsxy5y │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccqx8ltnh22s5a0xdfxf8j9zsg0c6ult03gvc6hcxy │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── tccqy0mn5x8y3shes2ncmsjna94nuffrt9msqz27ez6 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ └── tccqy5qjlvnv4jplzpkhvxe7pvdv2spmczfvyr7e0yk │ │ ├── keys │ │ └── key │ │ └── password.json ├── tendermint │ ├── keys │ │ ├── UTC--2018-11-21T06-43-26Z--0f1fa555-0819-3ec3-8336-8a832086e86d │ │ ├── UTC--2018-11-21T06-43-34Z--62b950a6-3fcd-20be-52ca-0e58a5912aab │ │ ├── UTC--2018-11-21T06-43-43Z--030d5252-e608-d19c-b456-3a675fc5169b │ │ └── UTC--2018-11-21T06-43-50Z--911357a2-fca3-0add-9245-6812bd95ad5a │ └── password.json ├── tsconfig.json ├── tslint.json ├── upload_logs.sh └── yarn.lock ├── types ├── Cargo.toml └── src │ ├── block_hash.rs │ ├── common_params.rs │ ├── errors │ ├── history_error.rs │ ├── mod.rs │ ├── runtime_error.rs │ └── syntax_error.rs │ ├── header.rs │ ├── lib.rs │ ├── tracker.rs │ ├── transaction │ ├── action.rs │ ├── asset_out_point.rs │ ├── incomplete_transaction.rs │ ├── input.rs │ ├── mod.rs │ ├── output.rs │ ├── partial_hashing.rs │ ├── shard.rs │ ├── timelock.rs │ └── transaction.rs │ ├── tx_hash.rs │ └── util │ ├── mod.rs │ ├── tag.rs │ └── unexpected.rs ├── util ├── io │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ ├── service.rs │ │ └── worker.rs ├── logger │ ├── Cargo.toml │ └── src │ │ ├── email.rs │ │ ├── lib.rs │ │ ├── logger.rs │ │ ├── macros.rs │ │ └── structured_logger.rs ├── panic_hook │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── table │ ├── Cargo.toml │ └── src │ │ └── lib.rs └── timer │ ├── Cargo.toml │ └── src │ ├── lib.rs │ └── timer.rs └── vm ├── Cargo.toml ├── src ├── decoder.rs ├── executor.rs ├── instruction.rs ├── lib.rs └── opcode.rs └── tests ├── chk_multi_sig.rs ├── chk_sig.rs ├── common └── mod.rs └── executor.rs /.dockerignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | /target/ 3 | /keys/ 4 | /db/ 5 | /docker/ 6 | /keystore.db 7 | /test/ -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*.rs] 3 | indent_style=space 4 | indent_size=4 5 | tab_width=8 6 | end_of_line=lf 7 | charset=utf-8 8 | trim_trailing_whitespace=true 9 | max_line_length=120 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 | charset=utf-8 18 | trim_trailing_whitespace=true 19 | insert_final_newline=true 20 | 21 | [.github/**/*.yml] 22 | indent_style=space 23 | indent_size=2 24 | tab_width=8 25 | end_of_line=lf 26 | charset=utf-8 27 | trim_trailing_whitespace=true 28 | insert_final_newline=true 29 | 30 | [.travis.yml] 31 | indent_style=space 32 | indent_size=2 33 | tab_width=8 34 | end_of_line=lf 35 | charset=utf-8 36 | 37 | [*.json] 38 | indent_style=space 39 | indent_size=2 40 | tab_width=4 41 | end_of_line=lf 42 | charset=utf-8 43 | trim_trailing_whitespace=true 44 | insert_final_newline=true 45 | 46 | 47 | [*.toml] 48 | indent_style=space 49 | indent_size=4 50 | tab_width=8 51 | end_of_line=lf 52 | charset=utf-8 53 | trim_trailing_whitespace=true 54 | insert_final_newline=true 55 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | name: build 4 | 5 | jobs: 6 | build: 7 | name: Actions - build 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [macOS-10.14, ubuntu-18.04] 12 | fail-fast: false 13 | steps: 14 | - uses: actions/checkout@v1 15 | with: 16 | fetch-depth: 1 17 | - uses: actions-rs/toolchain@v1 18 | with: 19 | toolchain: 1.40.0 20 | profile: minimal 21 | override: true 22 | - run: cargo fetch --verbose 23 | - run: cargo build --release 24 | - name: Archive 25 | working-directory: target/release 26 | run: | 27 | mkdir artifacts 28 | echo ${{github.sha}} ${{github.ref}} | tee artifacts/git-ref 29 | shasum -a 256 codechain | tee artifacts/sha256sums 30 | CODECHAIN_VERSION="$(./codechain --version | cut -d ' ' -f 2)" 31 | tar cvfz artifacts/codechain-${CODECHAIN_VERSION}-$(uname -m)-$(echo $(uname) | tr '[:upper:]' '[:lower:]').tar.gz codechain 32 | - uses: actions/upload-artifact@v1 33 | with: 34 | name: codechain-${{ matrix.os }} 35 | path: target/release/artifacts 36 | -------------------------------------------------------------------------------- /.github/workflows/cargo-test.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | name: cargo-test 4 | 5 | jobs: 6 | clippy: 7 | name: Actions - clippy 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v1 11 | with: 12 | fetch-depth: 1 13 | - uses: actions-rs/toolchain@v1 14 | with: 15 | toolchain: nightly-2019-12-19 16 | components: clippy 17 | profile: minimal 18 | override: true 19 | - run: cargo fetch --verbose 20 | - run: cargo clippy --all --all-targets -- -D warnings 21 | 22 | rustfmt: 23 | name: Actions - rustfmt 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v1 27 | with: 28 | fetch-depth: 1 29 | - uses: actions-rs/toolchain@v1 30 | with: 31 | toolchain: nightly-2019-12-19 32 | components: rustfmt 33 | profile: minimal 34 | override: true 35 | - run: cargo fmt -- --check 36 | 37 | unit-test: 38 | name: Actions - unit test 39 | runs-on: ${{ matrix.os }} 40 | strategy: 41 | matrix: 42 | os: [macOS-latest, ubuntu-latest] 43 | steps: 44 | - uses: actions/checkout@v1 45 | with: 46 | fetch-depth: 1 47 | - uses: actions-rs/toolchain@v1 48 | with: 49 | toolchain: 1.40.0 50 | profile: minimal 51 | override: true 52 | - run: cargo fetch --verbose 53 | - run: cargo build 54 | - run: cargo test --verbose --all 55 | env: 56 | RUST_BACKTRACE: 1 57 | -------------------------------------------------------------------------------- /.github/workflows/yarn.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | name: yarn 4 | 5 | jobs: 6 | lint: 7 | name: Actions - lint 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v1 11 | with: 12 | fetch-depth: 1 13 | - working-directory: ./test 14 | run: yarn 15 | - working-directory: ./test 16 | run: yarn lint 17 | - working-directory: ./test 18 | run: yarn test-mock 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Cargo lock in subs 2 | **/Cargo.lock 3 | 4 | # Generated by Cargo 5 | **/target/ 6 | 7 | **/*.rs.bk 8 | **/*.iml 9 | .idea/ 10 | .vscode/ 11 | /db/ 12 | /snapshot/ 13 | /log/ 14 | /keys/ 15 | /test/log/ 16 | 17 | # macOS 18 | .DS_store 19 | 20 | keystore.db 21 | 22 | # CodeChain uses node & yarn for tests 23 | node_modules/ 24 | yarn-error.log 25 | yarn.lock 26 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: Merge when CI passes and resolves all requested reviews 3 | conditions: 4 | - "#approved-reviews-by>=1" 5 | - "#review-requested=0" 6 | - "#changes-requested-reviews-by=0" 7 | - "status-success~=^Actions - " 8 | - status-success=continuous-integration/travis-ci/pr 9 | - base=master 10 | - label!=do-not-merge 11 | - "- title~=\\b(wip|WIP)\\b" 12 | actions: 13 | merge: 14 | method: rebase 15 | rebase_fallback: null 16 | strict: smart 17 | -------------------------------------------------------------------------------- /.travis/check-mergify-merge: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Everything that is normally printed to `stdout` in the script will be redirected to `stderr` 3 | # which will be visible in tty/Travis log. 4 | # Outputs that is printed to `fd 3` will be redirected to `stdout`, 5 | # which will be finally assigned to a variable `$SKIP` 6 | exec 3>&1 1>&2 # fd 3 = fd 1; fd 1 = fd 2 7 | 8 | function return_to_travis { 9 | STRATEGY="${1}" 10 | echo "${STRATEGY}" >&3 11 | exit 0 12 | } 13 | function skip_travis { return_to_travis "skip" ; } 14 | function noskip_travis { return_to_travis "noskip" ; } 15 | 16 | echo "TRAVIS_EVENT_TYPE=${TRAVIS_EVENT_TYPE}" 17 | echo "TRAVIS_BRANCH=${TRAVIS_BRANCH}" 18 | echo "TRAVIS_COMMIT=${TRAVIS_COMMIT}" 19 | 20 | set -xe 21 | 22 | case ${TRAVIS_EVENT_TYPE} in 23 | push) 24 | if [[ "${TRAVIS_BRANCH}" = master ]] 25 | then 26 | echo "Push on master" 27 | else 28 | echo "Don't skip testing for other than master" 29 | noskip_travis 30 | fi 31 | ;; 32 | *) 33 | echo "Don't skip for PR, api, cron event" 34 | noskip_travis 35 | ;; 36 | esac 37 | 38 | MERGIFY_COMMITTER="mergify[bot] " 39 | COMMITTER=$(git show --format="%cN <%cE>" --no-patch "${TRAVIS_COMMIT}") 40 | RESULT=$? 41 | if [[ "$RESULT" -ne 0 ]] 42 | then 43 | echo "Error: cannot get the committer" 44 | exit $RESULT 45 | fi 46 | 47 | if [[ "${COMMITTER}" = "${MERGIFY_COMMITTER}" ]] 48 | then 49 | echo "Skip check since it was checked in other PR" 50 | skip_travis 51 | else 52 | noskip_travis 53 | fi 54 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 1.0.0 2019-04-01 2 | * Initial release 3 | 4 | # 1.1.0 - 2019-04-04 5 | * Removed stakeholders who don't have stakes from trie ([#1439](https://github.com/CodeChain-io/codechain/pull/1439)) 6 | * Fixed the bug in AssetScheme related transactions ([#1442](https://github.com/CodeChain-io/codechain/pull/1442)) 7 | 8 | # 1.2.0 - 2019-04-19 9 | * Fixed the bug of version flag. 10 | * Added "commit-hash" command 11 | * Added "net_recentNetworkUsage" RPC 12 | * Added "chain_getMinTransactionFee" RPC 13 | * Reduced network traffic 14 | * Request the header only it need 15 | * Send new header to random peer instead of all. 16 | * Disabled Order and stake delegation by default 17 | * Enhanced unit tests and e2e tests 18 | 19 | # 1.3.0 - 2019-05-13 20 | * Fixed the broken commitHash RPC in a docker image #1443 21 | * Fixed the crash in Tendermint #1514 22 | * Added base-path option #236 23 | * Fixed the crash on exit #348 24 | * Reduced the booting time #1513 25 | 26 | # 1.4.0 - 2019-06-17 27 | * Do not prevote to the block with irrelevant generation time #1512 28 | * Change the name of verification threads 29 | * Add email alarm feature #1561 #1571 30 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | If you would like to contribute to CodeChain, please fork it, fix bugs or implement features, and [propose a pull request](https://github.com/CodeChain-io/codechain/compare). 2 | 3 | # Report bugs 4 | 5 | Create a [new issue](https://github.com/CodeChain-io/codechain/issues/new) in our repository and state: 6 | 7 | * What's your CodeChain version? 8 | * What's your operating system and version? 9 | * How did you install CodeChain? 10 | * Is your node fully synchronized? 11 | * Did you try turning it off and on again? 12 | * Also, try to include steps to reproduce the issue and expand on the **actual** versus **expected** behavior. 13 | 14 | # License 15 | 16 | By contributing to CodeChain, you agree that your contributions will be licensed under the AGPLv3 License. 17 | 18 | Each contributor has to [sign our Contributor License Agreement](https://www.clahub.com/agreements/CodeChain-io/codechain). The purpose of the CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen license. You can read and sign our full Contributor License Agreement before submitting a pull request. 19 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use vergen::{generate_cargo_keys, ConstantsFlags}; 18 | 19 | fn main() { 20 | generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate vergen constants!"); 21 | } 22 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | too-many-arguments-threshold = 10 2 | -------------------------------------------------------------------------------- /codechain/config/presets/config.dev.toml: -------------------------------------------------------------------------------- 1 | [codechain] 2 | quiet = false 3 | base_path = "." 4 | chain = "solo" 5 | 6 | [mining] 7 | mem_pool_mem_limit = 4 # MB 8 | mem_pool_size = 32768 9 | mem_pool_fee_bump_shift = 3 # 12.5% 10 | allow_create_shard = false 11 | notify_work = [] 12 | force_sealing = false 13 | reseal_on_txs = "all" 14 | reseal_min_period = 0 15 | reseal_max_period = 120000 16 | no_reseal_timer = false 17 | work_queue_size = 20 18 | self_nomination_enable = false 19 | allowed_past_gap = 30000 20 | allowed_future_gap = 5000 21 | 22 | [network] 23 | disable = false 24 | interface = "0.0.0.0" 25 | port = 3485 26 | max_peers = 30 27 | min_peers = 10 28 | bootstrap_addresses = [] 29 | sync = true 30 | transaction_relay = true 31 | discovery = true 32 | discovery_type = "unstructured" 33 | discovery_refresh = 60000 34 | discovery_bucket_size = 10 35 | # whitelist_path = "whitelist.txt" 36 | # blacklist_path = "blacklist.txt" 37 | 38 | [rpc] 39 | disable = false 40 | interface = "127.0.0.1" 41 | port = 8080 42 | 43 | [ipc] 44 | disable = false 45 | path = "/tmp/jsonrpc.ipc" 46 | 47 | [ws] 48 | disable = false 49 | interface = "127.0.0.1" 50 | port = 8081 51 | max_connections = 100 52 | 53 | [snapshot] 54 | disable = false 55 | path = "snapshot" 56 | 57 | [stratum] 58 | disable = false 59 | port = 8008 60 | 61 | [email_alarm] 62 | disable = true 63 | -------------------------------------------------------------------------------- /codechain/config/presets/config.prod.toml: -------------------------------------------------------------------------------- 1 | [codechain] 2 | quiet = false 3 | base_path = "." 4 | chain = "mainnet" 5 | 6 | [mining] 7 | mem_pool_mem_limit = 512 # MB 8 | mem_pool_size = 524288 9 | self_nomination_enable = false 10 | mem_pool_fee_bump_shift = 3 # 12.5% 11 | allow_create_shard = false 12 | notify_work = [] 13 | force_sealing = true 14 | reseal_on_txs = "all" 15 | reseal_min_period = 4000 16 | reseal_max_period = 120000 17 | no_reseal_timer = false 18 | work_queue_size = 20 19 | allowed_past_gap = 30000 20 | allowed_future_gap = 5000 21 | 22 | [network] 23 | disable = false 24 | interface = "0.0.0.0" 25 | port = 3485 26 | max_peers = 30 27 | min_peers = 10 28 | bootstrap_addresses = [] 29 | sync = true 30 | transaction_relay = true 31 | discovery = true 32 | discovery_type = "unstructured" 33 | discovery_refresh = 60000 34 | discovery_bucket_size = 10 35 | # whitelist_path = "whitelist.txt" 36 | # blacklist_path = "blacklist.txt" 37 | 38 | [rpc] 39 | disable = false 40 | interface = "127.0.0.1" 41 | port = 8080 42 | 43 | [ipc] 44 | disable = false 45 | path = "/tmp/jsonrpc.ipc" 46 | 47 | [ws] 48 | disable = true 49 | interface = "127.0.0.1" 50 | port = 8081 51 | max_connections = 100 52 | 53 | [snapshot] 54 | disable = true 55 | path = "snapshot" 56 | 57 | [stratum] 58 | disable = true 59 | port = 8008 60 | 61 | [email_alarm] 62 | disable = true 63 | -------------------------------------------------------------------------------- /codechain/constants.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | pub const DEFAULT_KEYS_PATH: &str = "keys"; 18 | pub const DEFAULT_DB_PATH: &str = "db"; 19 | -------------------------------------------------------------------------------- /codechain/json/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod password_entry; 18 | mod password_file; 19 | 20 | pub use self::password_entry::PasswordEntry; 21 | pub use self::password_file::PasswordFile; 22 | -------------------------------------------------------------------------------- /codechain/json/password_entry.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ckey::{Password, PlatformAddress}; 18 | 19 | #[derive(Debug, PartialEq, Serialize, Deserialize)] 20 | pub struct PasswordEntry { 21 | pub address: PlatformAddress, 22 | pub password: Password, 23 | } 24 | -------------------------------------------------------------------------------- /codechain/subcommand/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod account_command; 18 | mod convert_command; 19 | 20 | use self::account_command::run_account_command; 21 | use self::convert_command::run_convert_command; 22 | use clap::ArgMatches; 23 | 24 | pub fn run_subcommand(matches: &ArgMatches) -> Result<(), String> { 25 | let subcommand = matches.subcommand.as_ref().unwrap(); 26 | match subcommand.name.as_str() { 27 | "account" => run_account_command(&subcommand.matches), 28 | "convert" => run_convert_command(&subcommand.matches), 29 | "commit-hash" => { 30 | println!("{}", env!("VERGEN_SHA")); 31 | Ok(()) 32 | } 33 | _ => Err("Invalid subcommand".to_string()), 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /config/simple_poa.toml: -------------------------------------------------------------------------------- 1 | [codechain] 2 | chain = "simple_poa" 3 | 4 | [ipc] 5 | [rpc] 6 | [mining] 7 | [network] 8 | [snapshot] 9 | [stratum] 10 | -------------------------------------------------------------------------------- /core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-core" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 9 | codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2" } 10 | codechain-io = { path = "../util/io" } 11 | codechain-json = { path = "../json" } 12 | codechain-key = { path = "../key" } 13 | codechain-keystore = { path="../keystore" } 14 | codechain-logger = { path = "../util/logger" } 15 | codechain-network = { path = "../network" } 16 | codechain-state = { path = "../state" } 17 | codechain-timer = { path = "../util/timer" } 18 | codechain-types = { path = "../types" } 19 | codechain-stratum = { path = "../stratum" } 20 | codechain-vm = { path = "../vm" } 21 | crossbeam-channel = "0.3" 22 | cuckoo = { git = "https://github.com/CodeChain-io/rust-cuckoo.git", rev = "280cab9c" } 23 | hyper = { git = "https://github.com/paritytech/hyper", default-features = false } 24 | kvdb = "0.1" 25 | kvdb-rocksdb = "0.1" 26 | kvdb-memorydb = "0.1" 27 | linked-hash-map = "0.5" 28 | log = "0.4.6" 29 | lru-cache = "0.1.2" 30 | merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.4" } 31 | num-rational = "0.2.1" 32 | parking_lot = "0.11.0" 33 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 34 | rand = "0.6.1" 35 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 36 | rlp_compress = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" } 37 | rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" } 38 | snap = "0.2" 39 | table = { path = "../util/table" } 40 | 41 | [dev-dependencies] 42 | rand_xorshift = "0.1.0" 43 | 44 | [features] 45 | nightly = [] 46 | -------------------------------------------------------------------------------- /core/res/husky.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Husky", 3 | "engine": { 4 | "cuckoo": { 5 | "params": { 6 | "blockReward": "0x2540be400", 7 | "blockInterval": "30", 8 | "minScore": "0x1050", 9 | "maxVertex": "0x1000", 10 | "maxEdge": "0x800", 11 | "cycleLength": "8", 12 | "recommendedConfirmation": 6 13 | } 14 | } 15 | }, 16 | "params": { 17 | "maxAssetSchemeMetadataSize": "0x0400", 18 | "maxTransferMetadataSize": "0x0100", 19 | "maxTextContentSize": "0x0200", 20 | "maxExtraDataSize": "0x20", 21 | "networkID": "tc", 22 | "minPayCost" : 10, 23 | "minSetRegularKeyCost" : 10, 24 | "minCreateShardCost" : 10, 25 | "minSetShardOwnersCost" : 10, 26 | "minSetShardUsersCost" : 10, 27 | "minWrapCccCost" : 10, 28 | "minCustomCost" : 10, 29 | "minStoreCost" : 10, 30 | "minRemoveCost" : 10, 31 | "minMintAssetCost" : 10, 32 | "minTransferAssetCost" : 10, 33 | "minChangeAssetSchemeCost" : 10, 34 | "minIncreaseAssetSupplyCost" : 10, 35 | "minComposeAssetCost" : 10, 36 | "minDecomposeAssetCost" : 10, 37 | "minUnwrapCccCost" : 10, 38 | "maxBodySize": 4194304, 39 | "snapshotPeriod": 16384 40 | }, 41 | "genesis": { 42 | "seal": { 43 | "generic": "0x0" 44 | }, 45 | "score": "0x1050", 46 | "author": "tccqynz79luhx4cfakvcqe29rwaajnkzz6aev5deztu", 47 | "timestamp": "0x00", 48 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 49 | "extraData": "0x" 50 | }, 51 | "accounts": { 52 | "tccqynz79luhx4cfakvcqe29rwaajnkzz6aev5deztu": { "balance": "2100000000000000", "seq": "0" } 53 | }, 54 | "shards": { 55 | "0": { 56 | "seq": 0, 57 | "owners": ["tccqynz79luhx4cfakvcqe29rwaajnkzz6aev5deztu"], 58 | "users": [] 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /core/res/saluki.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Saluki", 3 | "engine": { 4 | "simplePoA": { 5 | "params": { 6 | "blockReward": "0x3b9aca00", 7 | "validators": [ 8 | "0x6253afef154b4ed8142f8927b7b6d242f570b027ebe51ed34e242415a94cae4de3d86e020e92e617df76fd2329023bf1374d7882b31e1656d6fed06676e0ceb7" 9 | ] 10 | } 11 | } 12 | }, 13 | "params": { 14 | "maxExtraDataSize": "0x20", 15 | "maxAssetSchemeMetadataSize": "0x0400", 16 | "maxTransferMetadataSize": "0x0100", 17 | "maxTextContentSize": "0x0200", 18 | "networkID": "sc", 19 | "minPayCost" : 10, 20 | "minSetRegularKeyCost" : 10, 21 | "minCreateShardCost" : 10, 22 | "minSetShardOwnersCost" : 10, 23 | "minSetShardUsersCost" : 10, 24 | "minWrapCccCost" : 10, 25 | "minCustomCost" : 10, 26 | "minStoreCost" : 10, 27 | "minRemoveCost" : 10, 28 | "minMintAssetCost" : 10, 29 | "minTransferAssetCost" : 10, 30 | "minChangeAssetSchemeCost" : 10, 31 | "minIncreaseAssetSupplyCost" : 10, 32 | "minComposeAssetCost" : 10, 33 | "minDecomposeAssetCost" : 10, 34 | "minUnwrapCccCost" : 10, 35 | "maxBodySize": 4194304, 36 | "snapshotPeriod": 16384 37 | }, 38 | "genesis": { 39 | "seal": { 40 | "generic": "0xc180" 41 | }, 42 | "score": "0x20000", 43 | "author": "sccqx74ftz8ct6yks4mq3u06g2wt07zxfqrss777pj2", 44 | "timestamp": "0x00", 45 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 46 | "extraData": "0x" 47 | }, 48 | "accounts": { 49 | "sccqx74ftz8ct6yks4mq3u06g2wt07zxfqrss777pj2": { "balance": "2100000000000000000", "seq": "0" } 50 | }, 51 | "shards": { 52 | "0": { 53 | "seq": 0, 54 | "owners": ["sccqx74ftz8ct6yks4mq3u06g2wt07zxfqrss777pj2"], 55 | "users": [] 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/blockchain/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod block_info; 18 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 19 | mod blockchain; 20 | mod body_db; 21 | mod extras; 22 | mod headerchain; 23 | mod invoice_db; 24 | mod route; 25 | 26 | pub use self::blockchain::{BlockChain, BlockProvider}; 27 | pub use self::body_db::BodyProvider; 28 | pub use self::extras::{BlockDetails, TransactionAddress, TransactionAddresses}; 29 | pub use self::headerchain::HeaderProvider; 30 | pub use self::invoice_db::InvoiceProvider; 31 | pub use self::route::ImportRoute; 32 | -------------------------------------------------------------------------------- /core/src/blockchain_info.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ctypes::{BlockHash, BlockNumber}; 18 | use primitives::U256; 19 | 20 | /// Information about the blockchain gathered together. 21 | #[derive(Clone, Debug)] 22 | pub struct BlockChainInfo { 23 | /// Score of the canonical chain. 24 | pub best_score: U256, 25 | /// The best score from proposal blocks. 26 | pub best_proposal_score: U256, 27 | /// Block queue score. 28 | pub pending_total_score: U256, 29 | /// Genesis block hash. 30 | pub genesis_hash: BlockHash, 31 | /// Best blockchain block hash. 32 | pub best_block_hash: BlockHash, 33 | /// Best blockchain proposal block hash. 34 | pub best_proposal_block_hash: BlockHash, 35 | /// Best blockchain block number. 36 | pub best_block_number: BlockNumber, 37 | /// Best blockchain block timestamp. 38 | pub best_block_timestamp: u64, 39 | } 40 | -------------------------------------------------------------------------------- /core/src/client/chain_notify.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ctypes::BlockHash; 18 | 19 | /// Represents what has to be handled by actor listening to chain events 20 | pub trait ChainNotify: Send + Sync { 21 | /// fires when chain has new headers. 22 | fn new_headers( 23 | &self, 24 | _imported: Vec, 25 | _invalid: Vec, 26 | _enacted: Vec, 27 | _retracted: Vec, 28 | _sealed: Vec, 29 | _new_best_proposal: Option, 30 | ) { 31 | // does nothing by default 32 | } 33 | 34 | /// fires when chain has new blocks. 35 | fn new_blocks( 36 | &self, 37 | _imported: Vec, 38 | _invalid: Vec, 39 | _enacted: Vec, 40 | _retracted: Vec, 41 | _sealed: Vec, 42 | ) { 43 | // does nothing by default 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /core/src/consensus/blake_pow/params.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cjson; 18 | use primitives::U256; 19 | 20 | pub struct BlakePoWParams { 21 | pub block_reward: u64, 22 | pub min_score: U256, 23 | pub block_interval: u64, 24 | pub recommmended_confirmation: u32, 25 | } 26 | 27 | impl From for BlakePoWParams { 28 | fn from(p: cjson::scheme::BlakePoWParams) -> Self { 29 | BlakePoWParams { 30 | block_reward: p.block_reward.map_or(0, Into::into), 31 | block_interval: p.block_interval.map_or(120, Into::into), 32 | min_score: p.min_score.map_or(U256::from(0x0002_0000), Into::into), 33 | recommmended_confirmation: p.recommended_confirmation.map_or(15, Into::into), 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/consensus/cuckoo/params.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cjson; 18 | use primitives::U256; 19 | 20 | pub struct CuckooParams { 21 | pub block_reward: u64, 22 | pub block_interval: u64, 23 | pub min_score: U256, 24 | pub max_vertex: usize, 25 | pub max_edge: usize, 26 | pub cycle_length: usize, 27 | pub recommmended_confirmation: u32, 28 | } 29 | 30 | impl From for CuckooParams { 31 | fn from(p: cjson::scheme::CuckooParams) -> Self { 32 | CuckooParams { 33 | block_reward: p.block_reward.map_or(0, Into::into), 34 | block_interval: p.block_interval.map_or(120, Into::into), 35 | min_score: p.min_score.map_or(U256::from(0x0002_0000), Into::into), 36 | max_vertex: p.max_vertex.map_or(1 << 30, Into::into), 37 | max_edge: p.max_edge.map_or(1 << 29, Into::into), 38 | cycle_length: p.cycle_length.map_or(42, Into::into), 39 | recommmended_confirmation: p.recommended_confirmation.map_or(15, Into::into), 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /core/src/consensus/null_engine/params.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cjson; 18 | 19 | /// Params for a null engine. 20 | #[derive(Clone, Default)] 21 | pub struct NullEngineParams { 22 | /// base reward for a block. 23 | pub block_reward: u64, 24 | } 25 | 26 | impl From for NullEngineParams { 27 | fn from(p: cjson::scheme::NullEngineParams) -> Self { 28 | NullEngineParams { 29 | block_reward: p.block_reward.map_or_else(Default::default, Into::into), 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/consensus/simple_poa/params.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cjson; 18 | use ckey::Public; 19 | 20 | #[derive(Debug, PartialEq)] 21 | pub struct SimplePoAParams { 22 | /// Valid signatories. 23 | pub validators: Vec, 24 | /// base reward for a block. 25 | pub block_reward: u64, 26 | } 27 | 28 | impl From for SimplePoAParams { 29 | fn from(p: cjson::scheme::SimplePoAParams) -> Self { 30 | SimplePoAParams { 31 | validators: p.validators, 32 | block_reward: p.block_reward.map_or_else(Default::default, Into::into), 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/consensus/solo/params.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cjson; 18 | use ckey::{Address, PlatformAddress}; 19 | use std::collections::HashMap; 20 | 21 | /// Params for a null engine. 22 | #[derive(Clone, Default)] 23 | pub struct SoloParams { 24 | /// base reward for a block. 25 | pub block_reward: u64, 26 | pub enable_hit_handler: bool, 27 | pub genesis_stakes: HashMap, 28 | } 29 | 30 | impl From for SoloParams { 31 | fn from(p: cjson::scheme::SoloParams) -> Self { 32 | SoloParams { 33 | block_reward: p.block_reward.map_or_else(Default::default, Into::into), 34 | enable_hit_handler: p.action_handlers.hit.is_some(), 35 | genesis_stakes: p 36 | .action_handlers 37 | .genesis_stakes 38 | .unwrap_or_default() 39 | .into_iter() 40 | .map(|(pa, amount)| (PlatformAddress::into_address(pa), amount)) 41 | .collect(), 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/consensus/tendermint/chain_notify.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::worker; 18 | use crate::client::ChainNotify; 19 | use crossbeam_channel as crossbeam; 20 | use ctypes::BlockHash; 21 | 22 | pub struct TendermintChainNotify { 23 | inner: crossbeam::Sender, 24 | } 25 | 26 | impl TendermintChainNotify { 27 | pub fn new(inner: crossbeam::Sender) -> Self { 28 | Self { 29 | inner, 30 | } 31 | } 32 | } 33 | 34 | impl ChainNotify for TendermintChainNotify { 35 | /// fires when chain has new blocks. 36 | fn new_blocks( 37 | &self, 38 | imported: Vec, 39 | _invalid: Vec, 40 | enacted: Vec, 41 | _retracted: Vec, 42 | _sealed: Vec, 43 | ) { 44 | self.inner 45 | .send(worker::Event::NewBlocks { 46 | imported, 47 | enacted, 48 | }) 49 | .unwrap(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/db_version.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | use crate::db; 17 | use kvdb::{DBTransaction, KeyValueDB}; 18 | 19 | pub const VERSION_KEY_PREFIX: &[u8] = b"version_"; 20 | /// Save the version of Tendermint backup where the key below is pointing 21 | pub const VERSION_KEY_TENDERMINT_BACKUP: &[u8] = b"version_tendermint-backup"; 22 | 23 | /// To support data values that are saved before the version scheme return 0 if the version does not exist 24 | pub fn get_version(db: &dyn KeyValueDB, key: &[u8]) -> u32 { 25 | let value = db.get(db::COL_EXTRA, key).expect("Low level database error. Some issue with disk?"); 26 | if let Some(bytes) = value { 27 | rlp::decode(&bytes).unwrap() 28 | } else { 29 | 0 30 | } 31 | } 32 | 33 | pub fn set_version(batch: &mut DBTransaction, key: &[u8], value: u32) { 34 | assert!( 35 | key.starts_with(VERSION_KEY_PREFIX), 36 | "Version keys should be prefixed with".to_owned() + std::str::from_utf8(VERSION_KEY_PREFIX).unwrap() 37 | ); 38 | batch.put(db::COL_EXTRA, key, &rlp::encode(&value)); 39 | } 40 | -------------------------------------------------------------------------------- /core/src/invoice.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ctypes::{Tracker, TxHash}; 18 | 19 | #[derive(Clone, Debug, PartialEq)] 20 | pub struct Invoice { 21 | pub tracker: Option, 22 | pub hash: TxHash, 23 | pub error: Option, 24 | } 25 | -------------------------------------------------------------------------------- /core/src/scheme/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod genesis; 18 | mod pod_account; 19 | mod pod_shard_metadata; 20 | mod pod_state; 21 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 22 | mod scheme; 23 | mod seal; 24 | 25 | pub use self::genesis::Genesis; 26 | pub use self::scheme::Scheme; 27 | -------------------------------------------------------------------------------- /core/src/scheme/pod_shard_metadata.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cjson; 18 | use ckey::{Address, PlatformAddress}; 19 | use std::fmt; 20 | 21 | #[derive(Clone, Debug, Eq, PartialEq)] 22 | pub struct PodShardMetadata { 23 | pub owners: Vec
, 24 | pub users: Vec
, 25 | pub seq: u64, 26 | } 27 | 28 | impl From for PodShardMetadata { 29 | fn from(s: cjson::scheme::Shard) -> Self { 30 | Self { 31 | seq: s.seq.map(Into::into).unwrap_or(0), 32 | owners: s.owners.into_iter().map(PlatformAddress::into_address).collect(), 33 | users: s.users.unwrap_or_else(Vec::new).into_iter().map(PlatformAddress::into_address).collect(), 34 | } 35 | } 36 | } 37 | 38 | impl fmt::Display for PodShardMetadata { 39 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 40 | write!(f, "(#seq={}; owners={:#?}; users={:#?})", self.seq, self.owners, self.users) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /core/src/tests/helpers.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::scheme::Scheme; 18 | use cstate::StateDB; 19 | use ctypes::{BlockHash, Header}; 20 | use primitives::{Bytes, U256}; 21 | use rlp::{self, RlpStream}; 22 | 23 | pub fn create_test_block(header: &Header) -> Bytes { 24 | let mut rlp = RlpStream::new_list(2); 25 | rlp.append(header); 26 | rlp.append_raw(&rlp::EMPTY_LIST_RLP, 1); 27 | rlp.out() 28 | } 29 | 30 | pub fn get_good_dummy_block() -> Bytes { 31 | let (_, bytes) = get_good_dummy_block_hash(); 32 | bytes 33 | } 34 | 35 | pub fn get_good_dummy_block_hash() -> (BlockHash, Bytes) { 36 | let mut block_header = Header::new(); 37 | let test_scheme = Scheme::new_test(); 38 | block_header.set_score(U256::from(0x20000)); 39 | block_header.set_timestamp(40); 40 | block_header.set_number(1); 41 | block_header.set_parent_hash(test_scheme.genesis_header().hash()); 42 | 43 | (block_header.hash(), create_test_block(&block_header)) 44 | } 45 | 46 | pub fn get_temp_state_db() -> StateDB { 47 | StateDB::new_with_memorydb() 48 | } 49 | -------------------------------------------------------------------------------- /core/src/tests/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | pub mod helpers; 18 | -------------------------------------------------------------------------------- /core/src/types/block_status.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | /// General block status 18 | #[derive(Debug, Eq, PartialEq)] 19 | pub enum BlockStatus { 20 | /// Part of the blockchain. 21 | InChain, 22 | /// Queued for import. 23 | Queued, 24 | /// Known as bad. 25 | Bad, 26 | /// Pending block. 27 | Pending, 28 | /// Unknown. 29 | Unknown, 30 | } 31 | -------------------------------------------------------------------------------- /core/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod block_status; 18 | mod ids; 19 | mod verification_queue_info; 20 | 21 | pub use self::block_status::BlockStatus; 22 | pub use self::ids::{BlockId, TransactionId}; 23 | pub use self::verification_queue_info::VerificationQueueInfo; 24 | -------------------------------------------------------------------------------- /core/src/verification/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | pub mod queue; 18 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 19 | mod verification; 20 | mod verifier; 21 | 22 | pub use self::queue::{BlockQueue, Config as QueueConfig}; 23 | pub use self::verification::*; 24 | pub use self::verifier::Verifier; 25 | -------------------------------------------------------------------------------- /core/src/views/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod block; 18 | mod body; 19 | mod header; 20 | mod transaction; 21 | 22 | pub use self::block::BlockView; 23 | pub use self::body::BodyView; 24 | pub use self::header::HeaderView; 25 | pub use self::transaction::TransactionView; 26 | -------------------------------------------------------------------------------- /discovery/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-discovery" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 9 | codechain-key = { path = "../key" } 10 | codechain-logger = { path = "../util/logger" } 11 | codechain-network = { path = "../network" } 12 | codechain-timer = { path = "../util/timer" } 13 | log = "0.4.6" 14 | never-type = "0.1.0" 15 | parking_lot = "0.11.0" 16 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 17 | rand = "0.6.1" 18 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 19 | time = "0.1" 20 | 21 | [dev-dependencies] 22 | lazy_static = "1.2" 23 | -------------------------------------------------------------------------------- /discovery/src/config.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | pub struct Config { 18 | pub bucket_size: u8, 19 | pub t_refresh: u32, 20 | } 21 | 22 | use super::K; 23 | use super::T_REFRESH; 24 | 25 | impl Config { 26 | pub fn new(bucket_size: Option, t_refresh: Option) -> Self { 27 | Self { 28 | bucket_size: bucket_size.unwrap_or(K), 29 | t_refresh: t_refresh.unwrap_or(T_REFRESH), 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /discovery/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | #![allow(deprecated)] 18 | 19 | #[macro_use] 20 | extern crate log; 21 | extern crate never_type; 22 | extern crate parking_lot; 23 | extern crate primitives; 24 | extern crate rand; 25 | extern crate rlp; 26 | extern crate time; 27 | 28 | extern crate codechain_crypto as ccrypto; 29 | extern crate codechain_key as ckey; 30 | #[macro_use] 31 | extern crate codechain_logger as clogger; 32 | extern crate codechain_network as cnetwork; 33 | extern crate codechain_timer as ctimer; 34 | 35 | mod config; 36 | mod extension; 37 | mod message; 38 | mod node_id; 39 | 40 | const K: u8 = 16; 41 | const T_REFRESH: u32 = 60_000; 42 | 43 | pub use crate::config::Config; 44 | pub use crate::extension::Extension as Discovery; 45 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # Docker support 2 | 3 | ## Ubuntu 4 | `docker build -f docker/ubuntu/Dockerfile --tag kodebox/codechain:branch_or_tag_name .` 5 | -------------------------------------------------------------------------------- /docker/ubuntu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 as builder 2 | WORKDIR /build 3 | 4 | # install tools and dependencies 5 | RUN apt-get update && \ 6 | apt-get install -y \ 7 | g++ \ 8 | build-essential \ 9 | curl \ 10 | git \ 11 | file \ 12 | binutils \ 13 | libssl-dev \ 14 | pkg-config \ 15 | libudev-dev \ 16 | cmake 17 | 18 | # install rustup 19 | RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y 20 | 21 | # rustup directory 22 | ENV PATH /root/.cargo/bin:$PATH 23 | 24 | # show backtraces 25 | ENV RUST_BACKTRACE 1 26 | 27 | # show tools 28 | RUN rustc -vV && \ 29 | cargo -V && \ 30 | gcc -v &&\ 31 | g++ -v 32 | 33 | # build codechain 34 | ADD . /build/codechain 35 | RUN cd codechain && \ 36 | cargo build --release --verbose && \ 37 | ls /build/codechain/target/release/codechain && \ 38 | strip /build/codechain/target/release/codechain 39 | 40 | RUN file /build/codechain/target/release/codechain 41 | 42 | 43 | FROM ubuntu:18.04 44 | WORKDIR /app/codechain 45 | RUN apt-get update && apt-get install -y libssl-dev 46 | COPY --from=builder /build/codechain/target/release/codechain ./target/release/codechain 47 | COPY --from=builder /build/codechain/codechain/config/presets/ ./codechain/config/presets 48 | 49 | # show backtraces 50 | ENV RUST_BACKTRACE 1 51 | 52 | EXPOSE 3485 8080 53 | ENTRYPOINT ["target/release/codechain"] 54 | -------------------------------------------------------------------------------- /docker_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker build -f docker/ubuntu/Dockerfile --tag kodebox/codechain:$TRAVIS_COMMIT . 3 | echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 4 | docker push kodebox/codechain:$TRAVIS_COMMIT 5 | -------------------------------------------------------------------------------- /json/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-json" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | codechain-key = { path = "../key" } 9 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 10 | rustc-hex = "1.0" 11 | serde = "1.0" 12 | serde_json = "1.0" 13 | serde_derive = "1.0" 14 | -------------------------------------------------------------------------------- /json/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate codechain_key as ckey; 18 | extern crate primitives; 19 | extern crate rustc_hex; 20 | extern crate serde; 21 | extern crate serde_json; 22 | #[macro_use] 23 | extern crate serde_derive; 24 | 25 | pub mod bytes; 26 | pub mod hash; 27 | pub mod scheme; 28 | pub mod uint; 29 | -------------------------------------------------------------------------------- /json/src/scheme/account.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::uint::Uint; 18 | 19 | /// Scheme account. 20 | #[derive(Debug, PartialEq, Deserialize)] 21 | pub struct Account { 22 | /// Balance. 23 | pub balance: Option, 24 | /// Seq. 25 | pub seq: Option, 26 | } 27 | 28 | impl Account { 29 | /// Returns true if account does not have seq and balance 30 | pub fn is_empty(&self) -> bool { 31 | self.balance.is_none() && self.seq.is_none() 32 | } 33 | } 34 | 35 | #[cfg(test)] 36 | mod tests { 37 | use serde_json; 38 | 39 | use super::Account; 40 | 41 | #[test] 42 | fn account_deserialization() { 43 | let s = r#"{ 44 | "balance": "1", 45 | "seq": "0" 46 | }"#; 47 | let deserialized: Account = serde_json::from_str(s).unwrap(); 48 | assert!(!deserialized.is_empty()); 49 | assert_eq!(deserialized.balance, Some(1.into())); 50 | assert_eq!(deserialized.seq, Some(0.into())); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /json/src/scheme/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod account; 18 | mod blake_pow; 19 | mod cuckoo; 20 | mod engine; 21 | mod genesis; 22 | mod null_engine; 23 | mod params; 24 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 25 | mod scheme; 26 | mod seal; 27 | mod shard; 28 | mod simple_poa; 29 | mod solo; 30 | mod state; 31 | mod tendermint; 32 | 33 | pub use self::account::Account; 34 | pub use self::blake_pow::{BlakePoW, BlakePoWParams}; 35 | pub use self::cuckoo::{Cuckoo, CuckooParams}; 36 | pub use self::engine::Engine; 37 | pub use self::genesis::Genesis; 38 | pub use self::null_engine::{NullEngine, NullEngineParams}; 39 | pub use self::params::Params; 40 | pub use self::scheme::Scheme; 41 | pub use self::seal::{Seal, TendermintSeal}; 42 | pub use self::shard::Shard; 43 | pub use self::simple_poa::{SimplePoA, SimplePoAParams}; 44 | pub use self::solo::{Solo, SoloParams}; 45 | pub use self::state::{Accounts, Shards}; 46 | pub use self::tendermint::{Tendermint, TendermintParams}; 47 | -------------------------------------------------------------------------------- /json/src/scheme/null_engine.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::uint::Uint; 18 | 19 | /// Authority params deserialization. 20 | #[derive(Debug, PartialEq, Deserialize)] 21 | #[serde(rename_all = "camelCase")] 22 | pub struct NullEngineParams { 23 | /// Block reward. 24 | pub block_reward: Option, 25 | } 26 | 27 | /// Null engine descriptor 28 | #[derive(Debug, PartialEq, Deserialize)] 29 | pub struct NullEngine { 30 | pub params: NullEngineParams, 31 | } 32 | 33 | #[cfg(test)] 34 | mod tests { 35 | use serde_json; 36 | 37 | use super::*; 38 | 39 | #[test] 40 | fn null_engine_deserialization() { 41 | let s = r#"{ 42 | "params": { 43 | "blockReward": "0x0d" 44 | } 45 | }"#; 46 | 47 | let deserialized: NullEngine = serde_json::from_str(s).unwrap(); 48 | assert_eq!(deserialized.params.block_reward, Some(0x0d.into())); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /json/src/scheme/state.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::{Account, Shard}; 18 | use ckey::PlatformAddress; 19 | use std::collections::BTreeMap; 20 | 21 | pub type Accounts = BTreeMap; 22 | pub type Shards = BTreeMap; 23 | -------------------------------------------------------------------------------- /key/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-key" 3 | version = "0.1.0" 4 | authors = ["debris ", "CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rand = "0.6.1" 9 | rustc-hex = "1.0" 10 | rustc-serialize = "0.3" 11 | lazy_static = "1.2" 12 | bech32 = "0.2.2" 13 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 14 | never-type = "0.1.0" 15 | parking_lot = "0.11.0" 16 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 17 | rand_xorshift = "0.1.0" 18 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 19 | secp256k1 = { git = "https://github.com/CodeChain-io/rust-secp256k1.git", version = "0.6" } 20 | serde = "1.0" 21 | serde_derive = "1.0" 22 | serde_json = "1.0" 23 | -------------------------------------------------------------------------------- /key/benches/ecdsa.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | #![feature(test)] 18 | 19 | extern crate codechain_key as ckey; 20 | extern crate test; 21 | 22 | use ckey::{recover, sign, verify, Generator, Message, Random}; 23 | use test::Bencher; 24 | 25 | #[bench] 26 | fn ecdsa_sign(b: &mut Bencher) { 27 | b.iter(|| { 28 | let key_pair = Random.generate().unwrap(); 29 | let message = Message::random(); 30 | let _signature = sign(key_pair.private(), &message).unwrap(); 31 | }) 32 | } 33 | 34 | #[bench] 35 | fn ecdsa_sign_and_verify(b: &mut Bencher) { 36 | b.iter(|| { 37 | let key_pair = Random.generate().unwrap(); 38 | let message = Message::random(); 39 | let signature = sign(key_pair.private(), &message).unwrap(); 40 | assert_eq!(Ok(true), verify(key_pair.public(), &signature, &message)); 41 | }) 42 | } 43 | 44 | #[bench] 45 | fn ecdsa_sign_and_recover(b: &mut Bencher) { 46 | b.iter(|| { 47 | let key_pair = Random.generate().unwrap(); 48 | let message = Message::random(); 49 | let signature = sign(key_pair.private(), &message).unwrap(); 50 | assert_eq!(Ok(*key_pair.public()), recover(&signature, &message)); 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /key/benches/schnorr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | #![feature(test)] 18 | 19 | extern crate codechain_key as ckey; 20 | extern crate test; 21 | 22 | use ckey::{recover_schnorr, sign_schnorr, verify_schnorr, Generator, Message, Random}; 23 | use test::Bencher; 24 | 25 | #[bench] 26 | fn schnorr_sign(b: &mut Bencher) { 27 | b.iter(|| { 28 | let key_pair = Random.generate().unwrap(); 29 | let message = Message::random(); 30 | let _signature = sign_schnorr(key_pair.private(), &message).unwrap(); 31 | }); 32 | } 33 | 34 | #[bench] 35 | fn schnorr_sign_and_verify(b: &mut Bencher) { 36 | b.iter(|| { 37 | let key_pair = Random.generate().unwrap(); 38 | let message = Message::random(); 39 | let signature = sign_schnorr(key_pair.private(), &message).unwrap(); 40 | assert_eq!(Ok(true), verify_schnorr(key_pair.public(), &signature, &message)); 41 | }); 42 | } 43 | 44 | #[bench] 45 | fn schnorr_sign_and_recover(b: &mut Bencher) { 46 | b.iter(|| { 47 | let key_pair = Random.generate().unwrap(); 48 | let message = Message::random(); 49 | let signature = sign_schnorr(key_pair.private(), &message).unwrap(); 50 | assert_eq!(Ok(*key_pair.public()), recover_schnorr(&signature, &message)); 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /keystore/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-keystore" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team ", "Parity Technologies "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | log = "0.4.6" 9 | libc = "0.2" 10 | rand = "0.6.1" 11 | codechain-json = { path = "../json" } 12 | codechain-key = { path = "../key" } 13 | codechain-types = { path = "../types" } 14 | serde = "1.0" 15 | serde_json = "1.0" 16 | serde_derive = "1.0" 17 | rustc-hex = "1.0" 18 | time = "0.1.34" 19 | parking_lot = "0.11.0" 20 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 21 | smallvec = "0.4" 22 | tempdir = "0.3" 23 | 24 | [dev-dependencies] 25 | matches = "0.1" 26 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 27 | 28 | [lib] 29 | -------------------------------------------------------------------------------- /keystore/src/account/cipher.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | use crate::json; 18 | 19 | #[derive(Debug, PartialEq, Clone)] 20 | pub struct Aes128Ctr { 21 | pub iv: [u8; 16], 22 | } 23 | 24 | #[derive(Debug, PartialEq, Clone)] 25 | pub enum Cipher { 26 | Aes128Ctr(Aes128Ctr), 27 | } 28 | 29 | impl From for Aes128Ctr { 30 | fn from(json: json::Aes128Ctr) -> Self { 31 | Aes128Ctr { 32 | iv: json.iv.into(), 33 | } 34 | } 35 | } 36 | 37 | impl From for json::Aes128Ctr { 38 | fn from(aes: Aes128Ctr) -> Self { 39 | Self { 40 | iv: From::from(aes.iv), 41 | } 42 | } 43 | } 44 | 45 | impl From for Cipher { 46 | fn from(json: json::Cipher) -> Self { 47 | match json { 48 | json::Cipher::Aes128Ctr(params) => Cipher::Aes128Ctr(From::from(params)), 49 | } 50 | } 51 | } 52 | 53 | impl From for json::Cipher { 54 | fn from(cipher: Cipher) -> Self { 55 | match cipher { 56 | Cipher::Aes128Ctr(params) => json::Cipher::Aes128Ctr(params.into()), 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /keystore/src/account/decrypted_account.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019. Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ckey::{ 18 | sign, sign_schnorr, Error as KeyError, KeyPair, Message, Private, Public, SchnorrSignature, Secret, Signature, 19 | }; 20 | 21 | /// An opaque wrapper for secret. 22 | #[derive(Clone)] 23 | pub struct DecryptedAccount { 24 | secret: Secret, 25 | } 26 | 27 | impl DecryptedAccount { 28 | pub fn new(secret: Secret) -> DecryptedAccount { 29 | DecryptedAccount { 30 | secret, 31 | } 32 | } 33 | 34 | /// Sign a message. 35 | pub fn sign(&self, message: &Message) -> Result { 36 | sign(&Private::from(self.secret), message) 37 | } 38 | 39 | /// Sign a message with Schnorr scheme. 40 | pub fn sign_schnorr(&self, message: &Message) -> Result { 41 | sign_schnorr(&Private::from(self.secret), message) 42 | } 43 | 44 | /// Derive public key. 45 | pub fn public(&self) -> Result { 46 | Ok(*KeyPair::from_private(Private::from(self.secret))?.public()) 47 | } 48 | } 49 | 50 | impl Drop for DecryptedAccount { 51 | fn drop(&mut self) { 52 | self.secret = Secret::default(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /keystore/src/account/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | mod cipher; 18 | mod crypto; 19 | mod decrypted_account; 20 | mod kdf; 21 | mod safe_account; 22 | mod version; 23 | 24 | pub use self::cipher::{Aes128Ctr, Cipher}; 25 | pub use self::crypto::Crypto; 26 | pub use self::decrypted_account::DecryptedAccount; 27 | pub use self::kdf::{Kdf, Pbkdf2, Prf, Scrypt}; 28 | pub use self::safe_account::SafeAccount; 29 | pub use self::version::Version; 30 | -------------------------------------------------------------------------------- /keystore/src/account/version.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | use crate::json; 18 | 19 | #[derive(Debug, PartialEq, Clone, Copy)] 20 | pub enum Version { 21 | V3, 22 | } 23 | 24 | impl From for Version { 25 | fn from(json: json::Version) -> Self { 26 | match json { 27 | json::Version::V3 => Version::V3, 28 | } 29 | } 30 | } 31 | 32 | impl From for json::Version { 33 | fn from(version: Version) -> Self { 34 | match version { 35 | Version::V3 => json::Version::V3, 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /keystore/src/ckeys.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | pub use ckey::*; 18 | 19 | use crate::json; 20 | 21 | impl From
for json::H160 { 22 | fn from(addr: Address) -> Self { 23 | let a: [u8; 20] = addr.into(); 24 | From::from(a) 25 | } 26 | } 27 | 28 | impl From for Address { 29 | fn from(json: json::H160) -> Self { 30 | let a: [u8; 20] = json.into(); 31 | From::from(a) 32 | } 33 | } 34 | 35 | impl<'a> From<&'a json::H160> for Address { 36 | fn from(json: &'a json::H160) -> Self { 37 | let mut a = [0u8; 20]; 38 | a.copy_from_slice(json); 39 | From::from(a) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /keystore/src/json/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | use std::fmt; 18 | 19 | #[derive(Debug, PartialEq)] 20 | pub enum Error { 21 | UnsupportedCipher, 22 | InvalidCipherParams, 23 | UnsupportedKdf, 24 | InvalidUuid, 25 | UnsupportedVersion, 26 | InvalidCiphertext, 27 | InvalidH256, 28 | InvalidPrf, 29 | } 30 | 31 | impl fmt::Display for Error { 32 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 33 | match *self { 34 | Error::InvalidUuid => write!(f, "Invalid Uuid"), 35 | Error::UnsupportedVersion => write!(f, "Unsupported version"), 36 | Error::UnsupportedKdf => write!(f, "Unsupported kdf"), 37 | Error::InvalidCiphertext => write!(f, "Invalid ciphertext"), 38 | Error::UnsupportedCipher => write!(f, "Unsupported cipher"), 39 | Error::InvalidCipherParams => write!(f, "Invalid cipher params"), 40 | Error::InvalidH256 => write!(f, "Invalid hash"), 41 | Error::InvalidPrf => write!(f, "Invalid prf"), 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /keystore/src/json/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | //! Contract interface specification. 18 | 19 | mod cipher; 20 | mod crypto; 21 | mod error; 22 | mod hash; 23 | mod id; 24 | mod kdf; 25 | mod key_file; 26 | mod version; 27 | 28 | pub use self::cipher::{Aes128Ctr, Cipher, CipherSer, CipherSerParams}; 29 | pub use self::crypto::{CipherText, Crypto}; 30 | pub use self::error::Error; 31 | pub use self::hash::{H128, H160, H256}; 32 | pub use self::id::Uuid; 33 | pub use self::kdf::{Kdf, KdfSer, KdfSerParams, Pbkdf2, Prf, Scrypt}; 34 | pub use self::key_file::{KeyFile, OpaqueKeyFile}; 35 | pub use self::version::Version; 36 | -------------------------------------------------------------------------------- /keystore/src/random.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | use rand::distributions::Alphanumeric; 18 | use rand::rngs::OsRng; 19 | use rand::{Rng, RngCore}; 20 | 21 | pub trait Random { 22 | fn random() -> Self 23 | where 24 | Self: Sized; 25 | } 26 | 27 | impl Random for [u8; 16] { 28 | fn random() -> Self { 29 | let mut result = [0u8; 16]; 30 | let mut rng = OsRng::new().unwrap(); 31 | rng.fill_bytes(&mut result); 32 | result 33 | } 34 | } 35 | 36 | impl Random for [u8; 32] { 37 | fn random() -> Self { 38 | let mut result = [0u8; 32]; 39 | let mut rng = OsRng::new().unwrap(); 40 | rng.fill_bytes(&mut result); 41 | result 42 | } 43 | } 44 | 45 | /// Generate a random string of given length. 46 | pub fn random_string(length: usize) -> String { 47 | let mut rng = OsRng::new().expect("Not able to operate without random source."); 48 | rng.sample_iter(&Alphanumeric).take(length).collect() 49 | } 50 | -------------------------------------------------------------------------------- /keystore/tests/res/ciphertext/30.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "e72a7999-abbe-7341-9970-577eb835c147", 3 | "version": 3, 4 | "crypto": { 5 | "cipher": "aes-128-ctr", 6 | "cipherparams": { 7 | "iv": "1b6b306d952fc5ec3c060ff69b9b086a" 8 | }, 9 | "ciphertext": "9f5709992055df537e76fbf9d2d89f711f13417f3ee0fe26e5d015862e151f62", 10 | "kdf": "pbkdf2", 11 | "kdfparams": { 12 | "c": 10240, 13 | "dklen": 32, 14 | "prf": "hmac-sha256", 15 | "salt": "bb96ab3330eb9b77e2e4797d03d4b4d4755aa9a94ec0cd558606d0320d689296" 16 | }, 17 | "mac": "4e96e9d0f81ac5e7136bbf232f1b1fcc9e0c5f59bf056a1af3716c27347692b5" 18 | }, 19 | "address": "8267cb8df20e1dc57fef31322e16bddd83d4cc3d", 20 | "name": "", 21 | "meta": "{}" 22 | } 23 | -------------------------------------------------------------------------------- /keystore/tests/res/ciphertext/31.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "1b18d902-b0cc-7582-e4dc-e9bd755983ea", 3 | "version": 3, 4 | "crypto": { 5 | "cipher": "aes-128-ctr", 6 | "cipherparams": { 7 | "iv": "fac569f6899216659a8c9c93a250ccf2" 8 | }, 9 | "ciphertext": "ed1840def903f2b3e838e9997a10f8bfd07b931351fac1e9ccc445abc9d5e655", 10 | "kdf": "pbkdf2", 11 | "kdfparams": { 12 | "c": 10240, 13 | "dklen": 32, 14 | "prf": "hmac-sha256", 15 | "salt": "5fafaa10a1e04c6a32a6998646a7e4e6b2182f2e4d80026d6ee5c4f55297d0f0" 16 | }, 17 | "mac": "16b8f5365792727a31f156e3823466a30f8cc202828ca7988bd50289a4ed65e1" 18 | }, 19 | "address": "77a477c745390977a72f44437ac1dac19b705571", 20 | "name": "", 21 | "meta": "{}" 22 | } 23 | -------------------------------------------------------------------------------- /keystore/tests/res/pat/p1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "e72a7999-abbe-7341-9970-577eb835c147", 3 | "version": 3, 4 | "crypto": { 5 | "cipher": "aes-128-ctr", 6 | "cipherparams": { 7 | "iv": "1b6b306d952fc5ec3c060ff69b9b086a" 8 | }, 9 | "ciphertext": "9f5709992055df537e76fbf9d2d89f711f13417f3ee0fe26e5d015862e151f62", 10 | "kdf": "pbkdf2", 11 | "kdfparams": { 12 | "c": 10240, 13 | "dklen": 32, 14 | "prf": "hmac-sha256", 15 | "salt": "bb96ab3330eb9b77e2e4797d03d4b4d4755aa9a94ec0cd558606d0320d689296" 16 | }, 17 | "mac": "4e96e9d0f81ac5e7136bbf232f1b1fcc9e0c5f59bf056a1af3716c27347692b5" 18 | }, 19 | "address": "3fc74504d2b491d73079975e302279540bf6e44e", 20 | "name": "", 21 | "meta": "{}" 22 | } 23 | -------------------------------------------------------------------------------- /keystore/tests/res/pat/p2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "1b18d902-b0cc-7582-e4dc-e9bd755983ea", 3 | "version": 3, 4 | "crypto": { 5 | "cipher": "aes-128-ctr", 6 | "cipherparams": { 7 | "iv": "fac569f6899216659a8c9c93a250ccf2" 8 | }, 9 | "ciphertext": "ed1840def903f2b3e838e9997a10f8bfd07b931351fac1e9ccc445abc9d5e655", 10 | "kdf": "pbkdf2", 11 | "kdfparams": { 12 | "c": 10240, 13 | "dklen": 32, 14 | "prf": "hmac-sha256", 15 | "salt": "5fafaa10a1e04c6a32a6998646a7e4e6b2182f2e4d80026d6ee5c4f55297d0f0" 16 | }, 17 | "mac": "16b8f5365792727a31f156e3823466a30f8cc202828ca7988bd50289a4ed65e1" 18 | }, 19 | "address": "41178717678e402bdb663d98fe47669d93b29603", 20 | "name": "", 21 | "meta": "{}" 22 | } 23 | -------------------------------------------------------------------------------- /keystore/tests/util/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2017 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | mod transient_dir; 18 | 19 | pub use self::transient_dir::TransientDir; 20 | -------------------------------------------------------------------------------- /logstash.conf: -------------------------------------------------------------------------------- 1 | input { 2 | file { 3 | id => "0" 4 | path => "/var/tmp/codechain/codechain.log.*" 5 | start_position => beginning 6 | } 7 | } 8 | 9 | filter { 10 | grok { 11 | match => { 12 | "message" => "#%{INSTANCE:instance}\s+%{TIMESTAMP:timestamp}\s+%{THREAD:thread}\s+%{LEVEL:level}\s+%{TARGET:target}\s+%{MESSAGE:message}" 13 | } 14 | overwrite => [ "message" ] 15 | # remove_field => [ "@timestamp" ] 16 | pattern_definitions => { 17 | "INSTANCE" => "\d+" 18 | "TIMESTAMP" => "\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}" 19 | "THREAD" => ".+" 20 | "LEVEL" => "OFF|ERROR|WARN|INFO|DEBUG|TRACE" 21 | "TARGET" => "[\w.]+" 22 | "MESSAGE" => ".*$" 23 | } 24 | } 25 | date { 26 | match => [ "timestamp", "yyyy-MM-dd HH:mm:ss" ] 27 | remove_field => [ "timestamp" ] 28 | } 29 | } 30 | 31 | output { 32 | elasticsearch { 33 | hosts => [ "localhost:9200" ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /network/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-network" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 9 | codechain-io = { path = "../util/io" } 10 | codechain-key = { path = "../key" } 11 | codechain-logger = { path = "../util/logger" } 12 | codechain-timer = { path = "../util/timer" } 13 | codechain-types = { path = "../types" } 14 | crossbeam-channel = "0.3" 15 | finally-block = "0.1" 16 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 17 | log = "0.4.6" 18 | kvdb = "0.1" 19 | mio = "0.6.16" 20 | never-type = "0.1.0" 21 | parking_lot = "0.11.0" 22 | rand = "0.6.1" 23 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 24 | rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" } 25 | table = { path = "../util/table" } 26 | time = "0.1" 27 | token-generator = "0.1.0" 28 | cidr = "0.0.4" 29 | -------------------------------------------------------------------------------- /network/src/config.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::filters::FilterEntry; 18 | use crate::SocketAddr; 19 | 20 | pub struct Config { 21 | pub address: String, 22 | pub port: u16, 23 | pub bootstrap_addresses: Vec, 24 | pub min_peers: usize, 25 | pub max_peers: usize, 26 | pub whitelist: Vec, 27 | pub blacklist: Vec, 28 | } 29 | -------------------------------------------------------------------------------- /network/src/filters/control.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::filter::FilterEntry; 18 | use cidr::IpCidr; 19 | use std::net::IpAddr; 20 | 21 | pub trait Control: Send + Sync { 22 | fn add_to_whitelist(&self, addr: IpCidr, tag: Option); 23 | fn remove_from_whitelist(&self, addr: &IpCidr); 24 | 25 | fn add_to_blacklist(&self, addr: IpCidr, tag: Option); 26 | fn remove_from_blacklist(&self, addr: &IpCidr); 27 | 28 | fn enable_whitelist(&self); 29 | fn disable_whitelist(&self); 30 | fn enable_blacklist(&self); 31 | fn disable_blacklist(&self); 32 | 33 | fn get_whitelist(&self) -> (Vec, bool); 34 | fn get_blacklist(&self) -> (Vec, bool); 35 | 36 | fn is_allowed(&self, addr: &IpAddr) -> bool; 37 | } 38 | -------------------------------------------------------------------------------- /network/src/filters/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod control; 18 | mod filter; 19 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 20 | mod filters; 21 | 22 | pub use self::control::Control as FiltersControl; 23 | pub use self::filter::FilterEntry; 24 | pub use self::filters::Filters; 25 | -------------------------------------------------------------------------------- /network/src/node_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::SocketAddr; 18 | use std::fmt; 19 | use std::net::IpAddr; 20 | 21 | #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq, RlpEncodableWrapper, RlpDecodableWrapper)] 22 | pub struct NodeId { 23 | addr: SocketAddr, 24 | } 25 | 26 | impl NodeId { 27 | pub fn new(ip: IpAddr, port: u16) -> Self { 28 | Self { 29 | addr: SocketAddr::new(ip, port), 30 | } 31 | } 32 | } 33 | 34 | impl fmt::Display for NodeId { 35 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 36 | let internal = &self.addr; 37 | let port = internal.port(); 38 | match internal.ip() { 39 | IpAddr::V4(ip) if ip.is_loopback() => write!(f, "Local V4:{}", port), 40 | IpAddr::V4(ip) if ip.is_private() => write!(f, "Private {}:{}", ip, port), 41 | IpAddr::V4(ip) => write!(f, "Global {}:{}", ip, port), 42 | IpAddr::V6(_) => unimplemented!(), 43 | } 44 | } 45 | } 46 | 47 | pub trait IntoSocketAddr { 48 | fn into_addr(self) -> SocketAddr; 49 | } 50 | 51 | impl IntoSocketAddr for NodeId { 52 | fn into_addr(self) -> SocketAddr { 53 | self.addr 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /network/src/p2p/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod connection; 18 | mod handler; 19 | mod listener; 20 | mod message; 21 | mod stream; 22 | 23 | pub use self::handler::{Handler, ManagingPeerdb, Message}; 24 | use self::message::{ExtensionMessage, Message as NetworkMessage, NegotiationMessage, SignedMessage}; 25 | -------------------------------------------------------------------------------- /network/src/session/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 18 | mod session; 19 | 20 | pub type Nonce = u128; 21 | pub use self::session::Session; 22 | -------------------------------------------------------------------------------- /rpc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-rpc" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [lib] 8 | 9 | [dependencies] 10 | cidr = "0.0.4" 11 | codechain-core = { path = "../core" } 12 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 13 | codechain-json = { path = "../json" } 14 | codechain-key = { path = "../key" } 15 | codechain-keystore = { path = "../keystore" } 16 | codechain-logger = { path = "../util/logger" } 17 | codechain-network = { path = "../network" } 18 | codechain-state = { path = "../state" } 19 | codechain-sync = { path = "../sync" } 20 | codechain-types = { path = "../types" } 21 | codechain-vm = { path = "../vm" } 22 | kvdb = "0.1" 23 | kvdb-rocksdb = "0.1" 24 | lazy_static = "1.2" 25 | log = "0.4.6" 26 | parking_lot = "0.11.0" 27 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 28 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 29 | serde = "1.0" 30 | serde_json = "1.0" 31 | serde_derive = "1.0" 32 | rand = "0.6.1" 33 | rustc-hex = "1.0" 34 | rustc-serialize = "0.3" 35 | time = "0.1" 36 | tokio-core = "0.1.17" 37 | jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 38 | jsonrpc-derive = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 39 | jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 40 | jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 41 | jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 42 | -------------------------------------------------------------------------------- /rpc/src/v1/impls/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod account; 18 | mod chain; 19 | mod devel; 20 | mod engine; 21 | mod mempool; 22 | mod miner; 23 | mod net; 24 | 25 | pub use self::account::AccountClient; 26 | pub use self::chain::ChainClient; 27 | pub use self::devel::DevelClient; 28 | pub use self::engine::EngineClient; 29 | pub use self::mempool::MempoolClient; 30 | pub use self::miner::MinerClient; 31 | pub use self::net::NetClient; 32 | -------------------------------------------------------------------------------- /rpc/src/v1/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod errors; 18 | mod impls; 19 | mod traits; 20 | mod types; 21 | 22 | pub use self::impls::*; 23 | pub use self::traits::*; 24 | -------------------------------------------------------------------------------- /rpc/src/v1/traits/devel.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::super::types::TPSTestSetting; 18 | use cjson::bytes::Bytes; 19 | use ctypes::BlockHash; 20 | use jsonrpc_core::Result; 21 | use primitives::H256; 22 | use std::net::SocketAddr; 23 | 24 | #[rpc(server)] 25 | pub trait Devel { 26 | #[rpc(name = "devel_getStateTrieKeys")] 27 | fn get_state_trie_keys(&self, offset: usize, limit: usize) -> Result>; 28 | 29 | #[rpc(name = "devel_getStateTrieValue")] 30 | fn get_state_trie_value(&self, key: H256) -> Result>; 31 | 32 | #[rpc(name = "devel_startSealing")] 33 | fn start_sealing(&self) -> Result<()>; 34 | 35 | #[rpc(name = "devel_stopSealing")] 36 | fn stop_sealing(&self) -> Result<()>; 37 | 38 | #[rpc(name = "devel_getBlockSyncPeers")] 39 | fn get_block_sync_peers(&self) -> Result>; 40 | 41 | #[rpc(name = "devel_getPeerBestBlockHashes")] 42 | fn get_peer_best_block_hashes(&self) -> Result>; 43 | 44 | #[rpc(name = "devel_getTargetBlockHashes")] 45 | fn get_target_block_hashes(&self) -> Result>; 46 | 47 | #[rpc(name = "devel_testTPS")] 48 | fn test_tps(&self, setting: TPSTestSetting) -> Result; 49 | } 50 | -------------------------------------------------------------------------------- /rpc/src/v1/traits/engine.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cjson::bytes::{Bytes, WithoutPrefix}; 18 | use ckey::PlatformAddress; 19 | use jsonrpc_core::Result; 20 | 21 | #[rpc(server)] 22 | pub trait Engine { 23 | /// Gets the reward of the given block number 24 | #[rpc(name = "engine_getBlockReward")] 25 | fn get_block_reward(&self, block_number: u64) -> Result; 26 | 27 | /// Gets coinbase's account id 28 | #[rpc(name = "engine_getCoinbase")] 29 | fn get_coinbase(&self) -> Result>; 30 | 31 | /// Gets the recommended minimum confirmations 32 | #[rpc(name = "engine_getRecommendedConfirmation")] 33 | fn get_recommended_confirmation(&self) -> Result; 34 | 35 | /// Gets custom action data for given custom action handler id and rlp encoded key. 36 | #[rpc(name = "engine_getCustomActionData")] 37 | fn get_custom_action_data( 38 | &self, 39 | handler_id: u64, 40 | key_fragment: Bytes, 41 | block_number: Option, 42 | ) -> Result>>; 43 | } 44 | -------------------------------------------------------------------------------- /rpc/src/v1/traits/miner.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::super::types::Work; 18 | use cjson::bytes::Bytes; 19 | use ctypes::BlockHash; 20 | use jsonrpc_core::Result; 21 | 22 | #[rpc(server)] 23 | pub trait Miner { 24 | #[rpc(name = "miner_getWork")] 25 | fn get_work(&self) -> Result; 26 | 27 | #[rpc(name = "miner_submitWork")] 28 | fn submit_work(&self, pow_hash: BlockHash, seal: Vec) -> Result; 29 | } 30 | -------------------------------------------------------------------------------- /rpc/src/v1/traits/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod account; 18 | mod chain; 19 | mod devel; 20 | mod engine; 21 | mod mempool; 22 | mod miner; 23 | mod net; 24 | 25 | pub use self::account::Account; 26 | pub use self::chain::Chain; 27 | pub use self::devel::Devel; 28 | pub use self::engine::Engine; 29 | pub use self::mempool::Mempool; 30 | pub use self::miner::Miner; 31 | pub use self::net::Net; 32 | -------------------------------------------------------------------------------- /rpc/src/v1/types/text.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ckey::{NetworkId, PlatformAddress}; 18 | use cstate::Text as TextType; 19 | 20 | #[derive(Debug, Serialize)] 21 | #[serde(rename_all = "camelCase")] 22 | pub struct Text { 23 | pub content: String, 24 | pub certifier: PlatformAddress, 25 | } 26 | 27 | impl Text { 28 | pub fn from_core(from: TextType, network_id: NetworkId) -> Self { 29 | Self { 30 | content: from.content().to_string(), 31 | certifier: PlatformAddress::new_v1(network_id, *from.certifier()), 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rpc/src/v1/types/unsigned_transaction.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::super::errors; 18 | use super::Action; 19 | use cjson::uint::Uint; 20 | use ckey::NetworkId; 21 | use ctypes::transaction::IncompleteTransaction; 22 | use jsonrpc_core::Error; 23 | use std::convert::{TryFrom, TryInto}; 24 | 25 | #[derive(Debug, Deserialize)] 26 | #[serde(rename_all = "camelCase")] 27 | pub struct UnsignedTransaction { 28 | pub seq: Option, 29 | pub fee: Uint, 30 | pub network_id: NetworkId, 31 | pub action: Action, 32 | } 33 | 34 | impl TryFrom for (IncompleteTransaction, Option) { 35 | type Error = Error; 36 | fn try_from(tx: UnsignedTransaction) -> Result { 37 | Ok(( 38 | IncompleteTransaction { 39 | fee: tx.fee.into(), 40 | network_id: tx.network_id, 41 | action: tx.action.try_into().map_err(errors::conversion)?, 42 | }, 43 | tx.seq, 44 | )) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rpc/src/v1/types/work.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use primitives::{H256, U256}; 18 | 19 | #[derive(Debug, Serialize)] 20 | #[serde(rename_all = "camelCase")] 21 | pub struct Work { 22 | pub pow_hash: H256, 23 | pub target: U256, 24 | } 25 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | 1.40.0 2 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | indent_style = "Block" 2 | use_small_heuristics = "Off" # "Default" 3 | binop_separator = "Front" 4 | # combine_control_expr = true 5 | comment_width = 120 # 80 6 | condense_wildcard_suffixes = true # false 7 | control_brace_style = "AlwaysSameLine" 8 | # disable_all_formatting = false 9 | error_on_line_overflow = false # true 10 | # error_on_unformatted = false 11 | fn_args_layout = "Tall" 12 | brace_style = "PreferSameLine" # "SameLineWhere" 13 | empty_item_single_line = true 14 | enum_discrim_align_threshold = 0 15 | fn_single_line = false 16 | # where_single_line = false 17 | force_explicit_abi = true 18 | format_strings = false 19 | format_macro_matchers = false 20 | format_macro_bodies = true 21 | hard_tabs = false 22 | imports_indent = "Block" # "Visual" 23 | imports_layout = "Mixed" 24 | merge_imports = false 25 | match_block_trailing_comma = false 26 | max_width = 120 # 100 27 | merge_derives = true 28 | # force_multiline_blocks = false 29 | newline_style = "Unix" 30 | normalize_comments = false 31 | remove_nested_parens = true 32 | reorder_imports = true 33 | reorder_modules = true 34 | # reorder_impl_items = false 35 | # report_todo = "Never" 36 | # report_fixme = "Never" 37 | space_after_colon = true 38 | space_before_colon = false 39 | struct_field_align_threshold = 0 40 | spaces_around_ranges = false 41 | ## struct_lit_single_line = true 42 | tab_spaces = 4 43 | trailing_comma = "Vertical" 44 | trailing_semicolon = false # true 45 | # type_punctuation_density = "Wide" 46 | use_field_init_shorthand = true # false 47 | use_try_shorthand = true # false 48 | # format_code_in_doc_comments = false 49 | wrap_comments = false 50 | match_arm_blocks = true 51 | overflow_delimited_expr = true 52 | blank_lines_upper_bound = 2 # 1 53 | blank_lines_lower_bound = 0 54 | # required_version 55 | hide_parse_errors = false 56 | color = "Always" # "Auto" 57 | unstable_features = false 58 | # license_template_path 59 | # ignore 60 | edition = "2018" 61 | # version 62 | normalize_doc_attributes = true # false 63 | inline_attribute_width = 0 64 | -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -eq 0 ]; then 4 | echo "USAGE :" 5 | echo " test NUM_CLIENTS [OPTIONS]" 6 | exit 1 7 | fi 8 | 9 | NUM_CLIENTS=$1 10 | OTHER_OPTIONS=${@:2} 11 | 12 | BASE_DIR=$(cd "$(dirname "$0")"/.. && pwd) 13 | LOG_DIR="/var/tmp/codechain" 14 | DB_DIR=${BASE_DIR}/db 15 | 16 | CODECHAIN_PORT_START=3484 17 | RPC_PORT_START=8080 18 | 19 | mkdir -p ${LOG_DIR} 20 | mkdir -p ${DB_DIR} 21 | 22 | run_server() { 23 | if [ $1 -eq 0 ]; then 24 | BOOTSTRAP="" 25 | else 26 | BOOTSTRAP="--bootstrap-addresses 127.0.0.1:${CODECHAIN_PORT_START}" 27 | fi 28 | cd ${BASE_DIR} 29 | cargo run -- \ 30 | --db-path ${DB_DIR}/db$1 \ 31 | --port $((${CODECHAIN_PORT_START} + $1)) \ 32 | --jsonrpc-port $((${RPC_PORT_START} + $1)) \ 33 | --secret-key "`printf "%064x" $(($1 + 1))`" \ 34 | ${BOOTSTRAP} \ 35 | ${OTHER_OPTIONS} \ 36 | >> ${LOG_DIR}/codechain.log.$1 2>&1 & 37 | } 38 | 39 | echo "Building..." 40 | cd ${BASE_DIR} 41 | cargo build 42 | 43 | run_server 0 44 | 45 | echo "Waiting for startup...." 46 | 47 | if [ -x /usr/bin/expect ]; then 48 | /usr/bin/expect <) 8 | 9 | ``` 10 | Request(limit) 11 | 12 | limit := u64 13 | ``` 14 | 15 | ## Response (<-) 16 | 17 | ``` 18 | Response(Contacts) 19 | 20 | Contacts := nil 21 | | Contact . Contacts 22 | Contact := SocketAddr 23 | ``` 24 | -------------------------------------------------------------------------------- /spec/Hash-Function.md: -------------------------------------------------------------------------------- 1 | CodeChain uses [BLAKE2](https://blake2.net/). 2 | 3 | SHA256, used in Bitcoin, has a number of technical shortcomings due to its Merkle-Damgård construction. These vulnerabilities led to the SHA3 competition for a new hash function based on a different fundamental construction. 4 | 5 | CodeChain has chosen BLAKE-256 as its hash function, a finalist for the competition. The hash function is based around a HAIFA construction that incorporates a variation of the ChaCha stream cipher by Bernstein. The hash function is notable for its high performance on x86-64 microarchitecture, being faster for short messages than SHA256 despite being considered to have a much higher security margin at 14-rounds. 6 | -------------------------------------------------------------------------------- /spec/List-of-Network-Id.md: -------------------------------------------------------------------------------- 1 | A network id is included in [Transaction](Transaction.md) to prevent a replay attack. Also, the first 3 characters of [CodeChain Address](CodeChain-Address.md) indicates the network id, which prevents transactions to a wrong address. 2 | 3 | * CodeChain mainnet: `CC` 4 | * Corgi testnet: `WC` 5 | * Local test node: `TC` 6 | -------------------------------------------------------------------------------- /spec/Minimum-Fee.md: -------------------------------------------------------------------------------- 1 | Transactions have a different minimum fee per type. 2 | 3 | The current minimum fee of transaction is defined as: 4 | 5 | | Transaction | Minimum fee([CCC](CodeChain-Coin.md)) | 6 | |---------------------|-----------------:| 7 | | Pay | 100 | 8 | | SetRegularKey | 10,000 | 9 | | Store | 5,000 | 10 | | Remove | 5,000 | 11 | | MintAsset | 100,000 | 12 | | TransferAsset | 100 | 13 | | ChangeAssetScheme | 100,000 | 14 | | IncreaseAssetSupply | 100,000 | 15 | | WrapCCC | 100,000 | 16 | | UnwrapCCC | 100 | 17 | -------------------------------------------------------------------------------- /spec/Network-Extension-Protocol.md: -------------------------------------------------------------------------------- 1 | All p2p communications, including block propagation and consensus, which are indispensable in a blockchain, are implemented in the extension. 2 | 3 | * [System Extension](System-Extension.md) 4 | * [Operate Extension](Operate-Extension.md) 5 | * [Discovery Extension](Discovery-Extension.md) 6 | * [Block Synchronization Extension](Block-Synchronization-Extension.md) 7 | * [Transaction Propagation Extension](Transaction-Propagation-Extension.md) 8 | 9 | -------------------------------------------------------------------------------- /spec/Node-Discovery-Protocol.md: -------------------------------------------------------------------------------- 1 | Although node discovery is an indispensable part of a p2p network, the node discovery protocol is not a part of CodeChain's base protocol. Instead of defining it as a base protocol, CodeChain defines it as an extension to make it easily replaceable. This kind of extension is called a **discovery protocol**. 2 | 3 | It is also possible to run without node discovery protocol. In this case, the server only tries to connect to fixed servers. 4 | 5 | # Kademlia 6 | 7 | Kademlia is one of the discovery protocols that CodeChain provides. This is a subset of the kademlia DHT protocol. 8 | 9 | ## Node Identification 10 | 11 | The kademlia protocol uses 256-bits to distinguish a node. This 256-bit identification is called `NodeId`. CodeChain uses the BLAKE2b hash of the IP address to make them uniformly distributed and prevent a [Sybil attack](https://en.wikipedia.org/wiki/Sybil_attack). 12 | 13 | ## Xor Distance 14 | 15 | The kademlia protocol uses xor distance. Xor distance is symmetric. In other words, the distance from node A to node B is the same as the distance from node B to node A. This property is important because when node A is one of the closest nodes of node B, node B is also probably one of the closest nodes to node A. It reduces the load for managing networks. 16 | 17 | ## Message 18 | 19 | Because CodeChain doesn’t need features related to distributed storage, kademlia-discovery does not have `STORAGE` and `FIND_VALUE` messages. In addition, there is no need to check the heartbeat since CodeChain uses TCP. Thus, CodeChain has only `FIND_NODE` and `NODE` message. 20 | 21 | Every request has a message id. The corresponding response must epoch this id. The message id should not be reused until the response is received or the session is closed. 22 | -------------------------------------------------------------------------------- /spec/Operate-Extension.md: -------------------------------------------------------------------------------- 1 | * Name := “operate” 2 | * Version := 0 3 | * Encrypt := optional 4 | * Indispensable := true 5 | 6 | # Messages 7 | 8 | ## Ping (->) 9 | 10 | ## Pong (<->) 11 | 12 | ## AskAvailableExtensions (->) 13 | 14 | ## Extension (<-) 15 | 16 | ``` 17 | Extension([extension-name . extension-version]*) 18 | ``` 19 | -------------------------------------------------------------------------------- /spec/README.md: -------------------------------------------------------------------------------- 1 | # CodeChain 2 | CodeChain is a programmable blockchain supporting multiple asset types. You can instantly create new digital assets and use them for your services. 3 | 4 | # Specification 5 | * [CodeChain Account](CodeChain-Account.md) 6 | * [CodeChain Address](CodeChain-Address.md) 7 | * [CodeChain Coin](CodeChain-Coin.md) 8 | * [Transaction](Transaction.md) 9 | * [Asset Exchange Protocol](Asset-Exchange-Protocol.md) 10 | * [Consensus](Consensus.md) 11 | * [Script](Script.md) 12 | * [CodeChain Virtual Machine](CodeChain-Virtual-Machine.md) 13 | * [State Trie](State-Trie.md) 14 | * Network Protocol 15 | * [Session Initiation Protocol](Session-Initiation-Protocol.md) 16 | * [P2P Protocol](P2P-Protocol.md) 17 | * [Network Extension Protocol](Network-Extension-Protocol.md) 18 | * [Node Discovery Protocol](Node-Discovery-Protocol.md) 19 | * [List of Network Id](List-of-Network-Id.md) 20 | * [Wire Protocol](Wire-Protocol.md) 21 | * Cryptography 22 | * [Hash Function](Hash-Function.md) 23 | * [Merkle Trie](Merkle-Trie.md) 24 | * [Digital Signature](Digital-Signature.md) 25 | * [JSON RPC](JSON-RPC.md) 26 | * [Stratum](Stratum.md) 27 | * Custom Action 28 | * [Staking](Staking.md) -------------------------------------------------------------------------------- /spec/State-Trie.md: -------------------------------------------------------------------------------- 1 | CodeChain has three kinds of states. The states are `Account`, `AssetScheme` and `Asset`. They are distinguished by their address but they share one global state trie. 2 | 3 | # Account 4 | 5 | ```rust 6 | struct Account { 7 | balance: U256, 8 | seq: U256, 9 | regular_key: Option 10 | } 11 | ``` 12 | 13 | # AssetScheme 14 | 15 | ```rust 16 | struct AssetScheme { 17 | metadata: String, 18 | amount: u64, 19 | registrar: Option
, 20 | } 21 | ``` 22 | 23 | # Asset 24 | 25 | ```rust 26 | struct Asset { 27 | asset_type: H256, 28 | script_hash: H256, 29 | parameters: Vec, 30 | amount: u64, 31 | } 32 | ``` 33 | 34 | asset_type = BLAKE2b(OutPoint pointing to AssetMint)[0..32]. 35 | -------------------------------------------------------------------------------- /spec/System-Extension.md: -------------------------------------------------------------------------------- 1 | * Name := “system” 2 | * Version := 0 3 | * Encrypt := optional 4 | * Indispensable := true 5 | * Privileged := true 6 | 7 | # Messages 8 | 9 | ## AddBlackList (->) 10 | 11 | ``` 12 | AddBlackList(admin’s-signature) 13 | ``` 14 | -------------------------------------------------------------------------------- /spec/Tag-encoding.md: -------------------------------------------------------------------------------- 1 | # Tag encoding 2 | 3 | ![img](https://cdn-images-1.medium.com/max/880/0*YripqzIkBK6EoNLz) 4 | 5 | The tag consists of one byte of prefix and a dynamic length output filter. First, the one-byte prefix includes the output scheme bit, input scheme bit and output filter length. The tag should follow the rules below. Not doing so will make the instruction fail. 6 | 7 | 1. The filter length has to be zero if the output scheme is one. 8 | 9 | 2. 6bit of filter length is the same as the byte length of the output filter following it. 10 | 11 | 3. Trailing zero bytes are not allowed. If it exists, the instruction will fail. (for example, `0x0000000011010100` is an invalid output filter) 12 | 13 | After confirming that the inserted tag follows above rules, signing input proceeds. If the input scheme bit is zero, then only the executing input is signed by ECDSA secret key, which is owned by the user. On the other hand, if the input scheme bit is one, then all of the inputs in the transaction are signed. The output scheme bit is interpreted in a similar way, but a little differently when it is zero. When the output scheme bit is one, all of the outputs in the transaction will be signed. In contrast, if the output scheme bit is zero, a special filtering rule will be applied to outputs in the transaction. Let's see the output filter as a bit array in which each bit has a number sequentially. Each bit is matched with the output's index, so if the matched bit is zero, then the output will be signed; otherwise, it will not be signed. 14 | 15 | -------------------------------------------------------------------------------- /spec/Transaction-Propagation-Extension.md: -------------------------------------------------------------------------------- 1 | * Name := “transaction-propagation” 2 | * Version := 0 3 | * Encrypt := never 4 | 5 | # Messages 6 | 7 | ## Transactions (<->) 8 | 9 | ``` 10 | Transactions(tx_0, …) 11 | ``` 12 | 13 | This message MUST contain one or more items. To avoid spamming, sender SHOULD NOT include transaction that is expected to be known by receiver. Snappy algorithm is used to compress the content. 14 | -------------------------------------------------------------------------------- /spec/disloyal-penalty-rate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeChain-io/codechain/9964d028e0b4c51443e59526a1aa4708f4d99b38/spec/disloyal-penalty-rate.png -------------------------------------------------------------------------------- /state/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-state" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 9 | codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2" } 10 | codechain-logger = { path = "../util/logger" } 11 | codechain-key = { path = "../key" } 12 | codechain-types = { path = "../types" } 13 | codechain-vm = { path = "../vm" } 14 | kvdb = "0.1" 15 | kvdb-memorydb = "0.1" 16 | log = "0.4.6" 17 | lru-cache = "0.1.1" 18 | merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.4" } 19 | parking_lot = "0.11.0" 20 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 21 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 22 | rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" } 23 | rustc-hex = "1.0" 24 | -------------------------------------------------------------------------------- /state/src/cache/lru_cache.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::CacheableItem; 18 | use lru_cache::LruCache as LruCacheImpl; 19 | 20 | pub struct LruCache { 21 | cache: LruCacheImpl, 22 | } 23 | 24 | impl LruCache { 25 | pub fn new(capacity: usize) -> Self { 26 | Self { 27 | cache: LruCacheImpl::new(capacity), 28 | } 29 | } 30 | 31 | pub fn clear(&mut self) { 32 | self.cache.clear() 33 | } 34 | 35 | /// Returns an iterator over the cache's key-value pairs in least- to most-recently-used order. 36 | pub fn iter(&self) -> impl Iterator { 37 | self.cache.iter() 38 | } 39 | 40 | pub fn insert(&mut self, k: Item::Address, v: Item) -> Option { 41 | self.cache.insert(k, v) 42 | } 43 | 44 | pub fn remove(&mut self, k: &Item::Address) -> Option { 45 | self.cache.remove(&k) 46 | } 47 | } 48 | 49 | impl Clone for LruCache { 50 | fn clone(&self) -> Self { 51 | Self { 52 | cache: self.cache.clone(), 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /state/src/cache/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use rlp::{Decodable, Encodable}; 18 | use std::fmt; 19 | use std::hash::Hash; 20 | 21 | mod global_cache; 22 | mod lru_cache; 23 | mod shard_cache; 24 | mod top_cache; 25 | mod write_back; 26 | 27 | pub use self::global_cache::GlobalCache; 28 | pub use self::shard_cache::ShardCache; 29 | pub use self::top_cache::TopCache; 30 | pub use self::write_back::WriteBack; 31 | 32 | pub trait CacheableItem: Clone + Default + fmt::Debug + Decodable + Encodable { 33 | type Address: AsRef<[u8]> + Clone + Copy + fmt::Debug + Eq + Hash; 34 | fn is_null(&self) -> bool; 35 | } 36 | -------------------------------------------------------------------------------- /state/src/checkpoint.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | pub type CheckpointId = usize; 18 | 19 | pub trait StateWithCheckpoint { 20 | /// Create a recoverable checkpoint of this state. 21 | fn create_checkpoint(&mut self, id: CheckpointId); 22 | /// Merge last checkpoint with previous. 23 | fn discard_checkpoint(&mut self, id: CheckpointId); 24 | /// Revert to the last checkpoint and discard it. 25 | fn revert_to_checkpoint(&mut self, id: CheckpointId); 26 | } 27 | -------------------------------------------------------------------------------- /state/src/db/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod state_db; 18 | 19 | pub use self::state_db::StateDB; 20 | -------------------------------------------------------------------------------- /state/src/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ctypes::errors::RuntimeError; 18 | use merkle_trie::TrieError; 19 | use std::fmt; 20 | 21 | #[derive(Clone, Debug, PartialEq)] 22 | pub enum Error { 23 | Trie(TrieError), 24 | Runtime(RuntimeError), 25 | } 26 | 27 | impl fmt::Display for Error { 28 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 29 | match self { 30 | Error::Trie(err) => err.fmt(f), 31 | Error::Runtime(err) => err.fmt(f), 32 | } 33 | } 34 | } 35 | 36 | impl From for Error { 37 | fn from(err: TrieError) -> Self { 38 | Error::Trie(err) 39 | } 40 | } 41 | 42 | impl From for Error { 43 | fn from(err: RuntimeError) -> Self { 44 | Error::Runtime(err) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /state/src/impls/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | #[cfg(test)] 18 | mod test_helper; // It must be placed above other modules 19 | 20 | mod shard_level; 21 | mod top_level; 22 | 23 | pub use self::shard_level::ShardLevelState; 24 | pub use self::top_level::TopLevelState; 25 | -------------------------------------------------------------------------------- /state/src/item/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | #[macro_use] 18 | mod address; 19 | 20 | pub mod account; 21 | pub mod action_data; 22 | pub mod asset; 23 | pub mod asset_scheme; 24 | pub mod metadata; 25 | pub mod regular_account; 26 | pub mod shard; 27 | pub mod text; 28 | 29 | #[derive(Clone, Copy)] 30 | #[repr(u8)] 31 | enum Prefix { 32 | OwnedAsset = b'A', 33 | Account = b'C', 34 | Shard = b'H', 35 | Metadata = b'M', 36 | RegularAccount = b'R', 37 | AssetScheme = b'S', 38 | Text = b'T', 39 | } 40 | -------------------------------------------------------------------------------- /stratum/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | description = "CodeChain stratum lib" 3 | name = "codechain-stratum" 4 | version = "1.11.0" 5 | license = "GPL-3.0" 6 | authors = ["Parity Technologies ", "CodeChain Team "] 7 | edition = "2018" 8 | 9 | [dependencies] 10 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 11 | codechain-logger = { path = "../util/logger" } 12 | codechain-json = { path = "../json" } 13 | jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 14 | jsonrpc-derive = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 15 | jsonrpc-tcp-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 16 | log = "0.4.6" 17 | parking_lot = "0.11.0" 18 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 19 | 20 | [dev-dependencies] 21 | env_logger = "0.6.0" 22 | tokio-core = "0.1.17" 23 | tokio-io = "0.1.10" 24 | -------------------------------------------------------------------------------- /sync/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-sync" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [lib] 8 | 9 | [dependencies] 10 | codechain-core = { path = "../core" } 11 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 12 | codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2" } 13 | codechain-key = { path = "../key" } 14 | codechain-logger = { path = "../util/logger" } 15 | codechain-network = { path = "../network" } 16 | codechain-state = { path = "../state" } 17 | codechain-timer = { path = "../util/timer" } 18 | codechain-types = { path = "../types" } 19 | kvdb = "0.1" 20 | log = "0.4.6" 21 | merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.4" } 22 | never-type = "0.1.0" 23 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 24 | rand = "0.6.1" 25 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 26 | snap = "0.2" 27 | token-generator = "0.1.0" 28 | 29 | [dev-dependencies] 30 | kvdb-memorydb = "0.1" 31 | tempfile = "3.0.4" 32 | trie-standardmap = { git = "https://github.com/CodeChain-io/trie-standardmap.git", version = "0.3" } 33 | -------------------------------------------------------------------------------- /sync/src/block/downloader/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod body; 18 | mod header; 19 | 20 | pub use self::body::BodyDownloader; 21 | pub use self::header::HeaderDownloader; 22 | -------------------------------------------------------------------------------- /sync/src/block/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod downloader; 18 | mod extension; 19 | mod message; 20 | 21 | pub use self::extension::{BlockSyncSender, Event as BlockSyncEvent, Extension as BlockSyncExtension}; 22 | -------------------------------------------------------------------------------- /sync/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate codechain_core as ccore; 18 | extern crate codechain_db as cdb; 19 | #[macro_use] 20 | extern crate codechain_logger as clogger; 21 | extern crate codechain_network as cnetwork; 22 | extern crate codechain_state as cstate; 23 | extern crate codechain_timer as ctimer; 24 | extern crate codechain_types as ctypes; 25 | 26 | extern crate kvdb; 27 | #[cfg(test)] 28 | extern crate kvdb_memorydb; 29 | #[macro_use] 30 | extern crate log; 31 | extern crate never_type; 32 | extern crate primitives; 33 | extern crate rand; 34 | extern crate rlp; 35 | extern crate snap; 36 | #[cfg(test)] 37 | extern crate tempfile; 38 | extern crate token_generator; 39 | #[cfg(test)] 40 | extern crate trie_standardmap; 41 | 42 | mod block; 43 | mod snapshot; 44 | mod transaction; 45 | 46 | pub use crate::block::{BlockSyncEvent, BlockSyncExtension, BlockSyncSender}; 47 | pub use crate::snapshot::SnapshotService; 48 | pub use crate::transaction::TransactionSyncExtension; 49 | 50 | #[cfg(test)] 51 | extern crate codechain_key as ckey; 52 | -------------------------------------------------------------------------------- /sync/src/snapshot/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use cdb::DatabaseError; 18 | use primitives::H256; 19 | use std::fmt::{Display, Formatter, Result as FormatResult}; 20 | use std::io::{Error as FileError, ErrorKind}; 21 | 22 | #[derive(Debug)] 23 | pub enum Error { 24 | NodeNotFound(H256), 25 | SyncError(String), 26 | FileError(ErrorKind), 27 | Database(DatabaseError), 28 | } 29 | 30 | impl From for Error { 31 | fn from(error: FileError) -> Self { 32 | Error::FileError(error.kind()) 33 | } 34 | } 35 | 36 | impl From for Error { 37 | fn from(error: DatabaseError) -> Self { 38 | Error::Database(error) 39 | } 40 | } 41 | 42 | impl Display for Error { 43 | fn fmt(&self, f: &mut Formatter) -> FormatResult { 44 | match self { 45 | Error::NodeNotFound(key) => write!(f, "State node not found: {:x}", key), 46 | Error::SyncError(reason) => write!(f, "Sync error: {}", reason), 47 | Error::FileError(kind) => write!(f, "File system error: {:?}", kind), 48 | Error::Database(error) => write!(f, "DB error: {}", error), 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sync/src/snapshot/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod error; 18 | mod service; 19 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 20 | mod snapshot; 21 | 22 | pub use self::service::Service as SnapshotService; 23 | -------------------------------------------------------------------------------- /sync/src/transaction/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod extension; 18 | mod message; 19 | 20 | pub use self::extension::Extension as TransactionSyncExtension; 21 | -------------------------------------------------------------------------------- /test/.editorconfig: -------------------------------------------------------------------------------- 1 | [src/**.{ts,tsx,json,js,jsx}] 2 | trim_trailing_whitespace = true 3 | insert_final_newline = true 4 | indent_style = space 5 | indent_size = 4 6 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | End-to-end tests(a.k.a. e2e tests) are for testing CodeChain application as a whole. Related files are located in this directory, and written in TypeScript. 2 | 3 | # Installing Dependencies 4 | 5 | [yarn](https://yarnpkg.com/lang/en/) is the package manager we use. To install dependencies, run the following command in the `test` directory: 6 | ``` 7 | yarn install 8 | ``` 9 | 10 | # Building CodeChain executable 11 | 12 | (We're going to automate this step in the near future) 13 | 14 | Currently, it requires you to compile CodeChain in advance to run the tests. The e2e tests will directly execute the binary in `target/debug` directory or `target/release` directory. 15 | 16 | ```sh 17 | # debug 18 | cargo build 19 | ``` 20 | 21 | ```sh 22 | # release 23 | cargo build --release 24 | ``` 25 | 26 | # Running Tests 27 | 28 | To run e2e tests, run following command in e2e test directory. 29 | ```sh 30 | # debug 31 | yarn start 32 | ``` 33 | 34 | ``` 35 | # release 36 | NODE_ENV=production yarn start 37 | ``` 38 | 39 | # Writing Test 40 | 41 | Simple e2e test that sends a transaction and gets an invoice from CodeChain is implemented at `src/e2e/basic.test.ts`. It would be a good starting point for implementing new tests. 42 | 43 | Writing an e2e test involves spawning a new CodeChain process and attaching SDK to it. Helper class for automating this process is defined under `src/helper/spawn.ts`, named `CodeChain`. Some important functions are described below: 44 | 45 | ### constructor 46 | Assigns globally unique instance id to this object. Many parameters that need to avoid conflict(such as a port number) are derived from this instance id. 47 | 48 | ### start 49 | Spawns a new CodeChain node, and returns Promise that resolves when initialization is completed. 50 | 51 | ### clean 52 | Kills a process and cleanup files created while running this node. 53 | -------------------------------------------------------------------------------- /test/custom.minfee/tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"ebedec2785dabd7d1380da0f4ca6619125248fa751526d6d17801e5cc777d3b3","cipherparams":{"iv":"4646508b38209c36e40b0aa24e669981"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"d9d54532d8172a461565ab51a8df1ae89d478c2c50750de186f655a33a393fd6","c":10240,"prf":"hmac-sha256"},"mac":"a0c4a20033e5a2e3f3bbc28f3c545b82b939604d45993072518281b710bb93d2"},"id":"b56516a4-734f-435f-83b3-b58ebfcad054","version":3,"address":"e2edea1225bf66d78bb6af2de5d0ee30860ad486","meta":"{}"} -------------------------------------------------------------------------------- /test/custom.minfee/tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/src/config/mem-pool-min-fee1.toml: -------------------------------------------------------------------------------- 1 | [codechain] 2 | 3 | [mining] 4 | min_pay_transaction_cost = 150 5 | self_nomination_enable = false 6 | 7 | [network] 8 | 9 | [rpc] 10 | 11 | [ipc] 12 | 13 | [ws] 14 | 15 | [snapshot] 16 | 17 | [stratum] 18 | 19 | [email_alarm] 20 | -------------------------------------------------------------------------------- /test/src/config/mem-pool-min-fee2.toml: -------------------------------------------------------------------------------- 1 | [codechain] 2 | 3 | [mining] 4 | min_pay_transaction_cost = 200 5 | self_nomination_enable = false 6 | 7 | [network] 8 | 9 | [rpc] 10 | 11 | [ipc] 12 | 13 | [ws] 14 | 15 | [snapshot] 16 | 17 | [stratum] 18 | 19 | [email_alarm] 20 | -------------------------------------------------------------------------------- /test/src/e2e.long/discovery2.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import "mocha"; 18 | import CodeChain from "../helper/spawn"; 19 | 20 | describe("discovery2 nodes", function() { 21 | let nodeA: CodeChain; 22 | let nodeB: CodeChain; 23 | 24 | beforeEach(async function() { 25 | nodeA = new CodeChain(); 26 | nodeB = new CodeChain(); 27 | await Promise.all([nodeA.start(), nodeB.start()]); 28 | }); 29 | 30 | // FIXME: Connection establishment is too slow. 31 | // See https://github.com/CodeChain-io/codechain/issues/760 32 | it("should be able to connect", async function() { 33 | await nodeA.connect(nodeB); 34 | }); 35 | 36 | afterEach(async function() { 37 | if (this.currentTest!.state === "failed") { 38 | nodeA.keepLogs(); 39 | nodeB.keepLogs(); 40 | } 41 | await Promise.all([nodeA.clean(), nodeB.clean()]); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation0.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H256 } from "codechain-primitives/lib"; 18 | import "mocha"; 19 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 20 | 21 | const INVALID_PARENT = new H256( 22 | "0x1111111111111111111111111111111111111111111111111111111111111111" 23 | ); 24 | const params = { 25 | tparent: INVALID_PARENT 26 | }; 27 | createTestSuite(0, "OnChain invalid parent block propagation test", params); 28 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation1.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import "mocha"; 18 | 19 | describe.skip("invalid block propagation 1", async function() { 20 | // FIXME 21 | it("OnChain invalid timestamp block propagation test", async function() {}).timeout( 22 | 30_000 23 | ); 24 | }); 25 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation2.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { U256 } from "codechain-primitives/lib"; 18 | import "mocha"; 19 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 20 | 21 | const INVALID_NUMBER = new U256(2); 22 | const params = { 23 | tnumber: INVALID_NUMBER 24 | }; 25 | createTestSuite(2, "OnChain invalid number block propagation test", params); 26 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation3.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H160 } from "codechain-primitives/lib"; 18 | import "mocha"; 19 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 20 | 21 | const INVALID_AUTHOR = new H160("0xffffffffffffffffffffffffffffffffffffffff"); 22 | const params = { 23 | tauthor: INVALID_AUTHOR 24 | }; 25 | createTestSuite(3, "OnChain invalid author block propagation test", params); 26 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation4.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import "mocha"; 18 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 19 | 20 | const INVALID_EXTRADATA = Buffer.from("DEADBEEF"); 21 | const params = { 22 | textraData: INVALID_EXTRADATA 23 | }; 24 | createTestSuite(4, "OnChain invalid extraData block propagation test", params); 25 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation5.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H256 } from "codechain-primitives/lib"; 18 | import "mocha"; 19 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 20 | 21 | const INVALID_TRANSACTIONS_ROOT = new H256( 22 | "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 23 | ); 24 | const params = { 25 | ttransactionRoot: INVALID_TRANSACTIONS_ROOT 26 | }; 27 | createTestSuite( 28 | 5, 29 | "OnChain invalid transactionRoot block propagation test", 30 | params 31 | ); 32 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation6.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H256 } from "codechain-primitives/lib"; 18 | import "mocha"; 19 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 20 | 21 | const INVALID_STATEROOT = new H256( 22 | "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 23 | ); 24 | const params = { 25 | tstateRoot: INVALID_STATEROOT 26 | }; 27 | createTestSuite(6, "OnChain invalid stateRoot block propagation test", params); 28 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation8.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { U256 } from "codechain-primitives/lib"; 18 | import "mocha"; 19 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 20 | 21 | const INVALID_SCORE = new U256(9999999999999999999999999999999999999999); 22 | const params = { 23 | tscore: INVALID_SCORE 24 | }; 25 | createTestSuite(8, "OnChain invalid score block propagation test", params); 26 | -------------------------------------------------------------------------------- /test/src/e2e.long/invalidBlockPropagation9.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import "mocha"; 18 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 19 | 20 | const INVALID_SEAL = [Buffer.from("DEADBEEF")]; 21 | const params = { 22 | tseal: INVALID_SEAL 23 | }; 24 | createTestSuite(9, "OnChain invalid score seal propagation test", params); 25 | -------------------------------------------------------------------------------- /test/src/e2e/basic.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { expect } from "chai"; 18 | import "mocha"; 19 | import CodeChain from "../helper/spawn"; 20 | 21 | describe("solo - 1 node", function() { 22 | let node: CodeChain; 23 | before(async function() { 24 | node = new CodeChain(); 25 | await node.start(); 26 | }); 27 | 28 | it("ping", async function() { 29 | expect(await node.sdk.rpc.node.ping()).to.equal("pong"); 30 | }); 31 | 32 | it("getNodeVersion", async function() { 33 | expect(await node.sdk.rpc.node.getNodeVersion()).to.match( 34 | /^[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9.]*)?$/ 35 | ); 36 | }); 37 | 38 | it("getCommitHash", async function() { 39 | expect(await node.sdk.rpc.node.getCommitHash()).to.match( 40 | /^[a-fA-F0-9]{40}$/ 41 | ); 42 | }); 43 | 44 | afterEach(function() { 45 | if (this.currentTest!.state === "failed") { 46 | node.keepLogs(); 47 | } 48 | }); 49 | 50 | after(async function() { 51 | await node.clean(); 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /test/src/e2e/engine.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | import { expect } from "chai"; 18 | import "mocha"; 19 | import CodeChain from "../helper/spawn"; 20 | 21 | describe("engine", function() { 22 | let node: CodeChain; 23 | before(async function() { 24 | node = new CodeChain(); 25 | await node.start(); 26 | }); 27 | 28 | it("getCoinbase", async function() { 29 | // TODO: Coinbase is not defined in solo mode, so it always returns null. Need to test in other modes. 30 | expect( 31 | await node.sdk.rpc.sendRpcRequest("engine_getCoinbase", []) 32 | ).to.be.a("null"); 33 | }); 34 | 35 | it("getRecommendedConfirmation", async function() { 36 | // TODO: The rcommended confirmation of solo is always 1. Need to test in other modes. 37 | expect( 38 | await node.sdk.rpc.sendRpcRequest( 39 | "engine_getRecommendedConfirmation", 40 | [] 41 | ) 42 | ).to.equal(1); 43 | }); 44 | 45 | afterEach(function() { 46 | if (this.currentTest!.state === "failed") { 47 | node.keepLogs(); 48 | } 49 | }); 50 | 51 | after(async function() { 52 | await node.clean(); 53 | }); 54 | }); 55 | -------------------------------------------------------------------------------- /test/src/helper/mock/example/send-block.ts: -------------------------------------------------------------------------------- 1 | import { Mock } from "../"; 2 | 3 | async function sendBlock() { 4 | const mock = new Mock("0.0.0.0", 3485, "tc"); 5 | mock.setLog(); 6 | await mock.establish(); 7 | // Genesis block 8 | const header = mock.soloGenesisBlockHeader(); 9 | 10 | // Block 1 11 | const header1 = mock.soloBlock1(header.hashing()); 12 | 13 | // Block 2 14 | const header2 = mock.soloBlock2(header1.hashing()); 15 | 16 | await mock.sendEncodedBlock( 17 | [ 18 | header.toEncodeObject(), 19 | header1.toEncodeObject(), 20 | header2.toEncodeObject() 21 | ], 22 | [[], []], 23 | header2.hashing(), 24 | header2.getScore() 25 | ); 26 | 27 | await mock.end(); 28 | } 29 | 30 | sendBlock(); 31 | -------------------------------------------------------------------------------- /test/src/helper/mock/example/send-tx.ts: -------------------------------------------------------------------------------- 1 | import { Mock } from ".."; 2 | 3 | const SDK = require("codechain-sdk"); 4 | 5 | async function sendTransaction() { 6 | const mock = new Mock("0.0.0.0", 3485, "tc"); 7 | mock.setLog(); 8 | await mock.establish(); 9 | 10 | const sdk = new SDK({ 11 | server: process.env.CODECHAIN_RPC_HTTP || "http://localhost:8080", 12 | networkId: process.env.CODECHAIN_NETWORK_ID || "tc" 13 | }); 14 | const ACCOUNT_SECRET = 15 | process.env.ACCOUNT_SECRET || 16 | "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; 17 | const unsigned = sdk.core.createPayTransaction({ 18 | recipient: "tccqruq09sfgax77nj4gukjcuq69uzeyv0jcs7vzngg", 19 | amount: 10000 20 | }); 21 | const signed = unsigned.sign({ 22 | secret: ACCOUNT_SECRET, 23 | fee: 10, 24 | nonce: 0 25 | }); 26 | 27 | await mock.sendEncodedTransaction([signed.toEncodeObject()]); 28 | 29 | await mock.end(); 30 | } 31 | sendTransaction(); 32 | -------------------------------------------------------------------------------- /test/src/helper/mock/test/blockSyncMessage.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { U256 } from "codechain-primitives"; 3 | import "mocha"; 4 | import * as BlockSyncMessage from "../blockSyncMessage"; 5 | 6 | describe("Check BlockSyncMessage RLP encoding", function() { 7 | it("RequestBodyMessage RLP encoding test", function() { 8 | const message = new BlockSyncMessage.RequestMessage({ 9 | type: "bodies", 10 | data: [] 11 | }); 12 | const msg = new BlockSyncMessage.BlockSyncMessage({ 13 | type: "request", 14 | id: new U256(10), 15 | message 16 | }); 17 | expect(msg.rlpBytes().toString("hex")).deep.equal("c3040ac0"); 18 | }); 19 | 20 | it("ResponseBodyMessage RLP encoding test", function() { 21 | const message = new BlockSyncMessage.ResponseMessage({ 22 | type: "bodies", 23 | data: [[]] 24 | }); 25 | const msg = new BlockSyncMessage.BlockSyncMessage({ 26 | type: "response", 27 | id: new U256(10), 28 | message 29 | }); 30 | expect(msg.rlpBytes().toString("hex")).deep.equal("c8050ac5840204c1c0"); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /test/src/helper/mock/test/txSyncMessage.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import "mocha"; 3 | import * as TxSyncMessage from "../transactionSyncMessage"; 4 | 5 | describe("Check TransactionSyncMessage RLP encoding", function() { 6 | it("TransactionSyncMessage RLP encoding test", function() { 7 | const msg = new TxSyncMessage.TransactionSyncMessage({ 8 | type: "transactions", 9 | data: [] 10 | }); 11 | expect(msg.rlpBytes().toString("hex")).deep.equal("830100c0"); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /test/src/helper/random.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | export function makeRandomPassphrase() { 18 | let text = ""; 19 | const possible = 20 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "; 21 | for (let i = 0; i < 40; i++) { 22 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 23 | } 24 | return text; 25 | } 26 | 27 | export function makeRandomH256() { 28 | let text = ""; 29 | const possible = "0123456789abcdef"; 30 | for (let i = 0; i < 64; i++) { 31 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 32 | } 33 | return text; 34 | } 35 | -------------------------------------------------------------------------------- /test/src/helper/rlp.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | export function readOptionalRlp( 18 | bytes: [] | [Buffer], 19 | decoder: (b: Buffer) => T 20 | ) { 21 | if (bytes.length === 0) { 22 | return null; 23 | } else { 24 | return decoder(bytes[0]); 25 | } 26 | } 27 | 28 | export function readUIntRLP(bytes: Buffer) { 29 | if (bytes.length === 0) { 30 | return 0; 31 | } else { 32 | return bytes.readUIntBE(0, bytes.length); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq80vewuacz704whqpcr9e5kjfmtlmpr5xggw66ty/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"a321aa735d04e27151b632f0fc3e15f77a932ce73831d63af83e792e706b5684","cipherparams":{"iv":"9f75fe08134623cbd600841b1ffe4d26"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"dafea7373eb40519f48c81fe2a398ff71786520123ed1ee7c92f470e6c33a9e9","c":10240,"prf":"hmac-sha256"},"mac":"131c5fbbdb103236bf890c312dd4d34c06b853d767b71ed6f5812ef123323a77"},"id":"e504a11a-9f71-4831-873a-d0bb0430633d","version":3,"address":"deccbb9dc0bcfabae00e065cd2d24ed7fd847432","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq80vewuacz704whqpcr9e5kjfmtlmpr5xggw66ty/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq80vewuacz704whqpcr9e5kjfmtlmpr5xggw66ty", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"ebedec2785dabd7d1380da0f4ca6619125248fa751526d6d17801e5cc777d3b3","cipherparams":{"iv":"4646508b38209c36e40b0aa24e669981"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"d9d54532d8172a461565ab51a8df1ae89d478c2c50750de186f655a33a393fd6","c":10240,"prf":"hmac-sha256"},"mac":"a0c4a20033e5a2e3f3bbc28f3c545b82b939604d45993072518281b710bb93d2"},"id":"b56516a4-734f-435f-83b3-b58ebfcad054","version":3,"address":"e2edea1225bf66d78bb6af2de5d0ee30860ad486","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq83wm6sjyklkd4utk6hjmewsaccgvzk5sck8cs2y", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq8ad6wxwhsk4aryazef5nawgw98zu6xpe5njs609/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"095de0ab3b2f5d2e64e0dd2b7a1cdcef5d84c5a4fb02d36058d2429d04d8ccf6","cipherparams":{"iv":"09fd87fb48982a82f1f01ff8ca2f6a16"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"8a6a01efde49ff63218047bcf6e81de1848e9e0b9ee8eb2b3027b2ef7bac7e5f","c":10240,"prf":"hmac-sha256"},"mac":"e3bef07eb28dc11366bdddb4ecbbc5da123c3f762fd43b17158eb249bd140891"},"id":"32e20732-ae99-4d44-a32c-292cadf0cf46","version":3,"address":"fadd38cebc2d5e8c9d165349f5c8714e2e68c1cd","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq8ad6wxwhsk4aryazef5nawgw98zu6xpe5njs609/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq8ad6wxwhsk4aryazef5nawgw98zu6xpe5njs609", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq8en43nfkkpjxn534gccpqejzhmx75lx2sxkyj6u/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"433b84a93034d9b18d61f9bfff3fca4f7bc10a52caa114749a2724d5ddc9d68f","cipherparams":{"iv":"58d75fa62c81221ccbab2e9fefc01f88"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"344f456bb6a3f43f94f4804422a8f1c768ca67d0594ef0363df05168378d2b4a","c":10240,"prf":"hmac-sha256"},"mac":"8b0d146ce0b3c528200f37eafbb6b80ad2bbcbe6eb58b29111759c8a5f5ca7fb"},"id":"2c74ed73-606a-41f0-955d-d6f41c84019d","version":3,"address":"f33ac669b583234e91aa3180833215f66f53e654","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq8en43nfkkpjxn534gccpqejzhmx75lx2sxkyj6u/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq8en43nfkkpjxn534gccpqejzhmx75lx2sxkyj6u", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq8g96vn3tagkf4hrdzgf6l9nqded4l5j7c5qulst/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"84044b3827938a0ff2ee21a59386b2d7df22e6bded6e865510a7eb4841cb2bd1","cipherparams":{"iv":"b8cca0d480552ce8139f2342ba7c32bb"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"b97e4071e98ab9ec8ca941671688273c229d43b4692247403aea7de2f8c7b0ba","c":10240,"prf":"hmac-sha256"},"mac":"fb16703eb11d29e7cb8d486714a6f10bc24d3634d192d3e12f66f2c3b2af1983"},"id":"f507f78a-ac4a-47a1-b42b-3203b2349b5a","version":3,"address":"d05d32715f5164d6e368909d7cb30372dafe92f6","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq8g96vn3tagkf4hrdzgf6l9nqded4l5j7c5qulst/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq8g96vn3tagkf4hrdzgf6l9nqded4l5j7c5qulst", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq9e7k4nm2m3kxls3vqyxh9aast0ufys4ss4mk8lg/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"23c05eb7e941154ee5b1b232631664d8f7b62579fbca074b097825a71f1efc1b","cipherparams":{"iv":"26eb7c07c758aed165c8077d28b76669"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"f4c9cdfb5becc621d2de267e9d14a8eeb57356b0a4edc5e855bd7aa831b3c673","c":10240,"prf":"hmac-sha256"},"mac":"7d8366474fbca7f9dbbd839148a5014f723a27d45f3dc69fcdd249a1fa78db69"},"id":"35c673ca-713e-4b20-b48f-77ad7c5b9abf","version":3,"address":"73eb567b56e3637e1160086b97bd82dfc4921584","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq9e7k4nm2m3kxls3vqyxh9aast0ufys4ss4mk8lg/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq9e7k4nm2m3kxls3vqyxh9aast0ufys4ss4mk8lg", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq9jj73ft3s4taqksv7fxy0qkhy978c9cqydsxy5y/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"5401b6d0ce0a7d158d75b7031ff9f68bd082a737b981d379edd5eda37b8f7b4f","cipherparams":{"iv":"1542bda141e5e90fbc904b28a580bc4c"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"706dd92cd646d52b67fca77b573a1e51dae2f261f8a92af367625596ce6d2049","c":10240,"prf":"hmac-sha256"},"mac":"16a6c610206fe351ac0cb80ae3a04869ab011da201cbbc52fe7c7491bc9c61ef"},"id":"173cef58-5633-4512-a4cf-78faee0ded60","version":3,"address":"652f452b8c2abe82d06792623c16b90be3e0b801","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccq9jj73ft3s4taqksv7fxy0qkhy978c9cqydsxy5y/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq9jj73ft3s4taqksv7fxy0qkhy978c9cqydsxy5y", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccqx8ltnh22s5a0xdfxf8j9zsg0c6ult03gvc6hcxy/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"693d83a45c3f058d4001bed70ce5f5b6f1ba6036c3c5bb1ebd5f84a183fd459f","cipherparams":{"iv":"a7350ff2d893fcf8faaf88e84db52049"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"527e54e10358db46f22383eace189439a6e880bd3335f51d34a33a6b9f101116","c":10240,"prf":"hmac-sha256"},"mac":"909386f796de824ca54eb58cade6d347f73823ea1ebf5e95680b78b53aa9d3e5"},"id":"18c83e32-265c-4b2e-a0ff-86bb4ae25293","version":3,"address":"8ff5ceea5429d799a9324f228a087e35cfadf143","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccqx8ltnh22s5a0xdfxf8j9zsg0c6ult03gvc6hcxy/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccqx8ltnh22s5a0xdfxf8j9zsg0c6ult03gvc6hcxy", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccqy0mn5x8y3shes2ncmsjna94nuffrt9msqz27ez6/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"9e7edad510dcfde4cf2e035f86a1f31856eb9ca924f7403b055ddc05d8307ec8","cipherparams":{"iv":"7d10c63c431dded65e885ec5821d9c21"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"78f0fa078cdfd8bed60a2ae95ed54389a3d6f9a8a9465de06c3081334b6d5699","c":10240,"prf":"hmac-sha256"},"mac":"f9917c912e318bb10ccc502ba92ce32c304c64f6909f188daa442c2138b3e21f"},"id":"6dfa14e4-9a23-435f-9185-7c03fa0775d5","version":3,"address":"1fb9d0c724617cc153c6e129f4b59f1291acbb80","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccqy0mn5x8y3shes2ncmsjna94nuffrt9msqz27ez6/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccqy0mn5x8y3shes2ncmsjna94nuffrt9msqz27ez6", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tccqy5qjlvnv4jplzpkhvxe7pvdv2spmczfvyr7e0yk/keys/key: -------------------------------------------------------------------------------- 1 | {"crypto":{"ciphertext":"7aa75cc975591341df8add7623d33f9b120f8a2b36ae0910b9ffcf481e3b9f60","cipherparams":{"iv":"6a767469be40ec796467e7d8e9305570"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"a9865dd8e16e23493895f386acd7915fbdce12ee43b21988e42c1ecc32d87bd2","c":10240,"prf":"hmac-sha256"},"mac":"3625fe7f662427620c2be6ac5588e1440d3871561bf8be136ec74c5dd71effd1"},"id":"6ff7b374-d896-4958-843f-606f89168fc7","version":3,"address":"28097d9365641f8836bb0d9f058d62a01de04961","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint.dynval/tccqy5qjlvnv4jplzpkhvxe7pvdv2spmczfvyr7e0yk/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccqy5qjlvnv4jplzpkhvxe7pvdv2spmczfvyr7e0yk", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2018-11-21T06-43-26Z--0f1fa555-0819-3ec3-8336-8a832086e86d: -------------------------------------------------------------------------------- 1 | {"id":"0f1fa555-0819-3ec3-8336-8a832086e86d","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"eccbf8812b99c5f65d6dbc15d5e6d8fc"},"ciphertext":"007554bd6ba281d0454e7499dd5d9acd5e87ead37548b6e71e088d96642bd388","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"91d502ff70f4966105d03e820ae794e6a6a656c92105bc58273ec38ce3c1b6a2"},"mac":"33683e52450cce42c5e39c475e90c73e23324220620e2ec7a0cb51247f5a55a8"},"address":"6a8e5ec34cdb3cde78ebf4dfd8d84f00f437fddb","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2018-11-21T06-43-34Z--62b950a6-3fcd-20be-52ca-0e58a5912aab: -------------------------------------------------------------------------------- 1 | {"id":"62b950a6-3fcd-20be-52ca-0e58a5912aab","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"9cf0c3bc2ffc08443cb747d8837c03a6"},"ciphertext":"3608171497a4f1df75f968492e84a74cc7407a012c83a73b98cd390f61e33ce6","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"72b19260a1c048ce3cf1b12e2857919f35f76cfb8d7ef927056b41e644d0536d"},"mac":"77dafe8a2b059c270a19b16c53ff99625052ec8ddd0e22e1a7c51d3f12a1ac8e"},"address":"c25b8e91fccd3b8b137b5faa7f86f656252ba2ee","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2018-11-21T06-43-43Z--030d5252-e608-d19c-b456-3a675fc5169b: -------------------------------------------------------------------------------- 1 | {"id":"030d5252-e608-d19c-b456-3a675fc5169b","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"f795d4ef6580c6da9560b4481daf12c1"},"ciphertext":"f8337a83cf22d0bfe3d10c45b66e360c20bab2b48d61ad262d8d59cc5679536f","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"c9865dc97087f8ed1839e2ecbd967c828eba27ea74bd68d2da6a286331b34450"},"mac":"5eb6cfe5707d1298d96e0be0d64aad5bcd54e476da41242cfc2d56cbc70e6ecd"},"address":"d32d7cd32af1703400c9624ea3ba488d7a0e6d17","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2018-11-21T06-43-50Z--911357a2-fca3-0add-9245-6812bd95ad5a: -------------------------------------------------------------------------------- 1 | {"id":"911357a2-fca3-0add-9245-6812bd95ad5a","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"ccd94083c9d0e4feb82e34f8a1e4d496"},"ciphertext":"b4496302711cdbf2e7c354db4ed7e55166c2fc74a210a1fe51eedc4e60d63910","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"b0c930a2312a997a0ca6b1bc3f5ab43b5d082a09f6dd4cec7d42f7e9b683da13"},"mac":"afa9102e44788b605ce4c0bcf96a35b117a7a9edb3c064e3ee4de0dbb328782a"},"address":"49acbedaea4afa1c00adea94856536fab532d927","meta":"{}"} -------------------------------------------------------------------------------- /test/tendermint/password.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "address": "tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f", 4 | "password": "" 5 | }, { 6 | "address": "tccq8p9hr53lnxnhzcn0d065lux7etz22azaca786tt", 7 | "password": "" 8 | }, { 9 | "address": "tccq8fj6lxn9tchqdqqe93yaga6fzxh5rndzu8k2gdw", 10 | "password": "" 11 | }, { 12 | "address": "tccq9y6e0k6af9058qq4h4ffpt9xmat2vkeyue23j8y", 13 | "password": "" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "types": ["node"], 5 | "module": "commonjs", 6 | "lib": ["es2018"], 7 | "declaration": true, 8 | "outDir": "lib", 9 | "strict": true 10 | }, 11 | "include": ["./src/**/*"], 12 | "exclude": ["./src/**/*.test.ts"] 13 | } 14 | -------------------------------------------------------------------------------- /test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["tslint:recommended", "tslint-config-prettier", "tslint-no-unused-expression-chai"], 3 | "rules": { 4 | "interface-name": false, 5 | "variable-name": [true, "check-format", "allow-leading-underscore", "allow-pascal-case"], 6 | "no-console": false, 7 | "object-literal-sort-keys": false, 8 | "only-arrow-functions": false, 9 | "no-var-requires": false, 10 | "max-classes-per-file": false, 11 | "triple-equals": [true, "allow-null-check", "allow-undefined-check"], 12 | "no-bitwise": false, 13 | "array-type": false 14 | }, 15 | "jsRules": { 16 | "no-console": false, 17 | "object-literal-sort-keys": false 18 | }, 19 | "linterOptions": { 20 | "exclude": ["node_modules/**/*.ts", "/lib/*"] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/upload_logs.sh: -------------------------------------------------------------------------------- 1 | if [ -d "./log" ]; then 2 | cd ./log 3 | count=$(git ls-files -o | wc -l) 4 | echo "Log file list: " 5 | git ls-files -o 6 | 7 | for (( i=1; i<="$count";i++ )); do 8 | file=$(echo $(git ls-files -o | sed "${i}q;d")) 9 | echo "uploading $file" 10 | if [ -z $TRANSFER_SH_URL ]; then 11 | echo "uploaded $file at $(curl --upload-file $file https://transfer.sh/)"; 12 | else 13 | echo "uploaded $file at $(curl --upload-file $file -u $TRANSFER_SH_USER:$TRANSFER_SH_PASSWORD $TRANSFER_SH_URL)"; 14 | fi 15 | done 16 | fi 17 | -------------------------------------------------------------------------------- /types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-types" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 9 | codechain-json = { path = "../json" } 10 | codechain-key = { path = "../key" } 11 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 12 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 13 | rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" } 14 | serde = "1.0" 15 | serde_derive = "1.0" 16 | 17 | [dev-dependencies] 18 | serde_json = "1.0" 19 | -------------------------------------------------------------------------------- /types/src/errors/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019. Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use rlp::{DecoderError, Encodable, Rlp, RlpStream}; 18 | 19 | mod history_error; 20 | mod runtime_error; 21 | mod syntax_error; 22 | 23 | pub use self::history_error::Error as HistoryError; 24 | pub use self::runtime_error::{Error as RuntimeError, UnlockFailureReason}; 25 | pub use self::syntax_error::Error as SyntaxError; 26 | 27 | trait TaggedRlp { 28 | type Tag: Encodable + Copy; 29 | 30 | fn length_of(tag: Self::Tag) -> Result; 31 | 32 | fn new_tagged_list(s: &mut RlpStream, tag: Self::Tag) -> &mut RlpStream { 33 | s.begin_list(Self::length_of(tag).unwrap()).append(&tag) 34 | } 35 | 36 | fn check_size(rlp: &Rlp, tag: Self::Tag) -> Result<(), DecoderError> { 37 | let item_count = rlp.item_count()?; 38 | let expected = Self::length_of(tag)?; 39 | if item_count != expected { 40 | return Err(DecoderError::RlpInvalidLength { 41 | expected, 42 | got: item_count, 43 | }) 44 | } 45 | Ok(()) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /types/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate codechain_crypto as ccrypto; 18 | extern crate codechain_json as cjson; 19 | extern crate codechain_key as ckey; 20 | extern crate primitives; 21 | extern crate rlp; 22 | #[macro_use] 23 | extern crate rlp_derive; 24 | extern crate serde; 25 | #[macro_use] 26 | extern crate serde_derive; 27 | #[cfg(test)] 28 | extern crate serde_json; 29 | 30 | mod block_hash; 31 | mod common_params; 32 | mod tracker; 33 | mod tx_hash; 34 | 35 | pub mod errors; 36 | pub mod header; 37 | pub mod transaction; 38 | pub mod util; 39 | 40 | pub type BlockNumber = u64; 41 | pub type ShardId = u16; 42 | 43 | pub use block_hash::BlockHash; 44 | pub use common_params::CommonParams; 45 | pub use header::Header; 46 | pub use tracker::Tracker; 47 | pub use tx_hash::TxHash; 48 | -------------------------------------------------------------------------------- /types/src/transaction/asset_out_point.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::ShardId; 18 | use crate::Tracker; 19 | use primitives::H160; 20 | 21 | #[derive(Debug, Clone, Eq, PartialEq, RlpDecodable, RlpEncodable)] 22 | pub struct AssetOutPoint { 23 | pub tracker: Tracker, 24 | pub index: usize, 25 | pub asset_type: H160, 26 | pub shard_id: ShardId, 27 | pub quantity: u64, 28 | } 29 | -------------------------------------------------------------------------------- /types/src/transaction/incomplete_transaction.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::{Action, Transaction}; 18 | use ckey::NetworkId; 19 | 20 | #[derive(Debug, Clone, PartialEq, Eq)] 21 | pub struct IncompleteTransaction { 22 | /// Quantity of CCC to be paid as a cost for distributing this transaction to the network. 23 | pub fee: u64, 24 | /// Network Id 25 | pub network_id: NetworkId, 26 | 27 | pub action: Action, 28 | } 29 | 30 | impl IncompleteTransaction { 31 | pub fn complete(self, seq: u64) -> Transaction { 32 | Transaction { 33 | seq, 34 | fee: self.fee, 35 | network_id: self.network_id, 36 | action: self.action, 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /types/src/transaction/input.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::{AssetOutPoint, Timelock}; 18 | use primitives::Bytes; 19 | 20 | #[derive(Debug, Clone, Eq, PartialEq, RlpDecodable, RlpEncodable)] 21 | pub struct AssetTransferInput { 22 | pub prev_out: AssetOutPoint, 23 | pub timelock: Option, 24 | pub lock_script: Bytes, 25 | pub unlock_script: Bytes, 26 | } 27 | -------------------------------------------------------------------------------- /types/src/transaction/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | mod action; 18 | mod asset_out_point; 19 | mod incomplete_transaction; 20 | mod input; 21 | mod output; 22 | mod partial_hashing; 23 | mod shard; 24 | mod timelock; 25 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 26 | mod transaction; 27 | 28 | pub use self::action::Action; 29 | pub use self::asset_out_point::AssetOutPoint; 30 | pub use self::incomplete_transaction::IncompleteTransaction; 31 | pub use self::input::AssetTransferInput; 32 | pub use self::output::{AssetMintOutput, AssetTransferOutput}; 33 | pub use self::partial_hashing::{HashingError, PartialHashing}; 34 | pub use self::shard::{AssetWrapCCCOutput, ShardTransaction}; 35 | pub use self::timelock::Timelock; 36 | pub use self::transaction::Transaction; 37 | -------------------------------------------------------------------------------- /types/src/transaction/output.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::ShardId; 18 | use primitives::{Bytes, H160}; 19 | 20 | #[derive(Debug, Clone, Eq, PartialEq, RlpDecodable, RlpEncodable)] 21 | pub struct AssetTransferOutput { 22 | pub lock_script_hash: H160, 23 | pub parameters: Vec, 24 | pub asset_type: H160, 25 | pub shard_id: ShardId, 26 | pub quantity: u64, 27 | } 28 | 29 | #[derive(Default, Debug, Clone, PartialEq, Eq)] 30 | pub struct AssetMintOutput { 31 | pub lock_script_hash: H160, 32 | pub parameters: Vec, 33 | pub supply: u64, 34 | } 35 | -------------------------------------------------------------------------------- /types/src/transaction/partial_hashing.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::AssetTransferInput; 18 | use crate::util::tag::Tag; 19 | use primitives::H256; 20 | 21 | pub trait PartialHashing { 22 | fn hash_partially(&self, tag: Tag, cur: &AssetTransferInput, burn: bool) -> Result; 23 | } 24 | 25 | #[derive(Debug, PartialEq)] 26 | pub enum HashingError { 27 | InvalidFilter, 28 | } 29 | -------------------------------------------------------------------------------- /types/src/util/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | pub mod tag; 18 | pub mod unexpected; 19 | -------------------------------------------------------------------------------- /util/io/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | description = "CodeChain IO library" 3 | homepage = "http://parity.io" 4 | license = "GPL-3.0" 5 | name = "codechain-io" 6 | version = "1.9.0" 7 | authors = ["Parity Technologies ", "CodeChain Team "] 8 | edition = "2018" 9 | 10 | [dependencies] 11 | codechain-logger = { path = "../logger" } 12 | mio = "0.6.16" 13 | crossbeam = "0.5.0" 14 | parking_lot = "0.11.0" 15 | log = "0.4.6" 16 | -------------------------------------------------------------------------------- /util/logger/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-logger" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | atty = "0.2" 9 | colored = "1.6" 10 | env_logger = "0.6.0" 11 | lazy_static = "1.2" 12 | log = "0.4.6" 13 | parking_lot = "0.11.0" 14 | sendgrid = "0.8.1" 15 | serde = "1.0" 16 | serde_derive = "1.0" 17 | serde_json = "1.0" 18 | time = "0.1" 19 | 20 | -------------------------------------------------------------------------------- /util/logger/src/email.rs: -------------------------------------------------------------------------------- 1 | use ::sendgrid::v3 as sendgrid; 2 | 3 | #[derive(Clone)] 4 | pub struct EmailAlarm { 5 | to: String, 6 | sendgrid_key: String, 7 | network_id: String, 8 | } 9 | 10 | impl EmailAlarm { 11 | pub fn new(to: String, sendgrid_key: String, network_id: String) -> Self { 12 | Self { 13 | to, 14 | sendgrid_key, 15 | network_id, 16 | } 17 | } 18 | 19 | pub fn send(&self, log: &str) { 20 | let p = sendgrid::Personalization::new().add_to(sendgrid::Email::new().set_email(&self.to)); 21 | let now = time::now_utc(); 22 | let now = now.rfc3339(); 23 | let m = sendgrid::Message::new() 24 | .set_from(sendgrid::Email::new().set_email("no-reply@codechain.io")) 25 | .set_subject(&format!("[error][{}][codechain] Error from CodeChain-{}", self.network_id, now)) 26 | .add_content(sendgrid::Content::new().set_content_type("text/html").set_value(log)) 27 | .add_personalization(p); 28 | let sender = sendgrid::Sender::new(self.sendgrid_key.clone()); 29 | let send_result = sender.send(&m); 30 | if let Err(err) = send_result { 31 | eprintln!("Sent an email, but failed. returned error is {}", err); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /util/logger/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate atty; 18 | extern crate colored; 19 | extern crate env_logger; 20 | extern crate lazy_static; 21 | extern crate log; 22 | extern crate parking_lot; 23 | extern crate sendgrid; 24 | extern crate serde; 25 | extern crate serde_derive; 26 | extern crate serde_json; 27 | extern crate time; 28 | 29 | mod email; 30 | mod logger; 31 | mod macros; 32 | mod structured_logger; 33 | 34 | use log::SetLoggerError; 35 | 36 | pub use logger::Config as LoggerConfig; 37 | use logger::Logger; 38 | 39 | pub use log::Level; 40 | 41 | pub fn init(config: &LoggerConfig, email_alarm: Option) -> Result<(), SetLoggerError> { 42 | let logger = Logger::new(config, email_alarm); 43 | log::set_max_level(logger.filter()); 44 | log::set_boxed_logger(Box::new(logger)) 45 | } 46 | 47 | use lazy_static::lazy_static; 48 | use structured_logger::StructuredLogger; 49 | 50 | lazy_static! { 51 | pub static ref SLOGGER: StructuredLogger = StructuredLogger::create(); 52 | } 53 | 54 | pub use email::EmailAlarm; 55 | -------------------------------------------------------------------------------- /util/panic_hook/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | description = "Parity custom panic hook" 3 | homepage = "http://parity.io" 4 | license = "GPL-3.0" 5 | name = "panic_hook" 6 | version = "0.1.0" 7 | authors = ["Parity Technologies ", "CodeChain Team "] 8 | edition = "2018" 9 | 10 | [dependencies] 11 | backtrace = "0.3.2" 12 | codechain-logger = { path = "../logger" } 13 | my_internet_ip = "0.1.1" 14 | get_if_addrs = "0.5.3" 15 | -------------------------------------------------------------------------------- /util/table/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "table" 3 | version = "0.1.0" 4 | authors = ["Parity Technologies "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /util/timer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-timer" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [lib] 8 | 9 | [dependencies] 10 | parking_lot = "0.11.0" 11 | log = "0.4.6" 12 | codechain-logger = { path = "../logger" } 13 | -------------------------------------------------------------------------------- /util/timer/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate parking_lot; 18 | #[macro_use] 19 | extern crate log; 20 | #[macro_use] 21 | extern crate codechain_logger as clogger; 22 | 23 | mod timer; 24 | 25 | pub use crate::timer::{ 26 | ScheduleError as TimerScheduleError, TimeoutHandler, TimerApi, TimerLoop, TimerName, TimerToken, 27 | }; 28 | -------------------------------------------------------------------------------- /vm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-vm" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [lib] 8 | 9 | [dependencies] 10 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" } 11 | codechain-key = { path = "../key" } 12 | codechain-types = { path = "../types" } 13 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" } 14 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" } 15 | 16 | [dev-dependencies] 17 | secp256k1 = { git = "https://github.com/CodeChain-io/rust-secp256k1.git", version = "0.6" } 18 | -------------------------------------------------------------------------------- /vm/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate codechain_crypto as ccrypto; 18 | extern crate codechain_key as ckey; 19 | extern crate codechain_types as ctypes; 20 | extern crate primitives; 21 | 22 | extern crate rlp; 23 | #[cfg(test)] 24 | extern crate secp256k1; 25 | 26 | mod decoder; 27 | mod executor; 28 | mod instruction; 29 | mod opcode; 30 | 31 | pub use crate::decoder::{decode, DecoderError}; 32 | pub use crate::executor::{execute, ChainTimeInfo, Config as VMConfig, RuntimeError, ScriptResult, TimelockType}; 33 | pub use crate::instruction::Instruction; 34 | -------------------------------------------------------------------------------- /vm/src/opcode.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | pub const NOP: u8 = 0x00; 18 | pub const BURN: u8 = 0x01; 19 | pub const SUCCESS: u8 = 0x02; 20 | pub const FAIL: u8 = 0x03; 21 | pub const NOT: u8 = 0x10; 22 | pub const EQ: u8 = 0x11; 23 | pub const JMP: u8 = 0x20; 24 | pub const JNZ: u8 = 0x21; 25 | pub const JZ: u8 = 0x22; 26 | pub const PUSH: u8 = 0x30; 27 | pub const POP: u8 = 0x31; 28 | pub const PUSHB: u8 = 0x32; 29 | pub const DUP: u8 = 0x33; 30 | pub const SWAP: u8 = 0x34; 31 | pub const COPY: u8 = 0x35; 32 | pub const DROP: u8 = 0x36; 33 | pub const CHKSIG: u8 = 0x80; 34 | pub const CHKMULTISIG: u8 = 0x81; 35 | pub const BLAKE256: u8 = 0x90; 36 | pub const SHA256: u8 = 0x91; 37 | pub const RIPEMD160: u8 = 0x92; 38 | pub const KECCAK256: u8 = 0x93; 39 | pub const BLAKE160: u8 = 0x94; 40 | pub const CHKTIMELOCK: u8 = 0xb0; 41 | -------------------------------------------------------------------------------- /vm/tests/common/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 Kodebox, Inc. 2 | // This file is part of CodeChain. 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Affero General Public License as 6 | // published by the Free Software Foundation, either version 3 of the 7 | // License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Affero General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Affero General Public License 15 | // along with this program. If not, see . 16 | 17 | use ctypes::{BlockNumber, Tracker}; 18 | use cvm::ChainTimeInfo; 19 | 20 | pub struct TestClient { 21 | block_age: Option, 22 | time_age: Option, 23 | } 24 | 25 | impl TestClient { 26 | pub fn new(block_age: Option, time_age: Option) -> Self { 27 | TestClient { 28 | block_age, 29 | time_age, 30 | } 31 | } 32 | } 33 | 34 | impl Default for TestClient { 35 | fn default() -> Self { 36 | Self::new(Some(0), Some(0)) 37 | } 38 | } 39 | 40 | impl ChainTimeInfo for TestClient { 41 | fn transaction_block_age(&self, _: &Tracker, _parent_block_number: BlockNumber) -> Option { 42 | self.block_age 43 | } 44 | 45 | fn transaction_time_age(&self, _: &Tracker, _parent_timestamp: u64) -> Option { 46 | self.time_age 47 | } 48 | } 49 | --------------------------------------------------------------------------------