├── .dockerignore ├── .editorconfig ├── .github └── workflows │ ├── build.yml │ └── cargo-test.yml ├── .gitignore ├── .mergify.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── build.rs ├── clippy.toml ├── config.tendermint-solo.ini ├── coordinator ├── Cargo.toml └── src │ ├── app_desc.rs │ ├── app_desc │ ├── deserialize.rs │ ├── engine.rs │ ├── genesis.rs │ ├── params.rs │ ├── tendermint.rs │ └── validator.rs │ ├── context.rs │ ├── context │ ├── chain_history_access.rs │ ├── mem_pool_access.rs │ ├── storage_access.rs │ └── sub_storage_access.rs │ ├── desc_common.rs │ ├── desc_common │ └── params.rs │ ├── engine.rs │ ├── header.rs │ ├── lib.rs │ ├── link_desc.rs │ ├── link_desc │ ├── params.rs │ └── validator.rs │ ├── linkable.rs │ ├── module.rs │ ├── test_coordinator.rs │ ├── transaction.rs │ ├── types.rs │ ├── types │ └── event.rs │ ├── values.rs │ ├── weaver.rs │ └── weaver │ └── test.rs ├── core ├── Cargo.toml ├── res │ ├── null.json │ ├── solo.json │ └── tendermint.json └── src │ ├── account_provider.rs │ ├── block.rs │ ├── blockchain │ ├── block_info.rs │ ├── blockchain.rs │ ├── body_db.rs │ ├── event_db.rs │ ├── extras.rs │ ├── headerchain.rs │ ├── mod.rs │ ├── route.rs │ └── update_result.rs │ ├── blockchain_info.rs │ ├── client │ ├── chain_notify.rs │ ├── client.rs │ ├── config.rs │ ├── importer.rs │ ├── mod.rs │ ├── snapshot_notify.rs │ └── test_client.rs │ ├── consensus │ ├── bit_set.rs │ ├── mod.rs │ ├── null_engine │ │ └── mod.rs │ ├── signer.rs │ ├── solo │ │ └── mod.rs │ ├── tendermint │ │ ├── DESIGN.md │ │ ├── backup.rs │ │ ├── chain_notify.rs │ │ ├── engine.rs │ │ ├── evidence_collector.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 │ ├── db.rs │ ├── db_version.rs │ ├── encoded.rs │ ├── error.rs │ ├── event.rs │ ├── genesis.rs │ ├── lib.rs │ ├── miner │ ├── backup.rs │ ├── mem_pool.rs │ ├── mem_pool_types.rs │ ├── miner.rs │ └── mod.rs │ ├── peer_db.rs │ ├── service.rs │ ├── tests │ ├── helpers.rs │ └── mod.rs │ ├── transaction.rs │ ├── types │ ├── block_status.rs │ ├── mod.rs │ ├── transaction_id.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 ├── demo ├── README.md ├── app-desc.toml ├── config0.ini ├── config1.ini ├── config2.ini ├── config3.ini ├── keys │ ├── UTC--2020-03-05T06-22-17Z--15737bb2-a003-24dd-4f38-9a42b2f1a5c1 │ ├── UTC--2020-03-05T06-23-41Z--84597567-cca7-15c1-1e67-ba4d7d74c9cf │ ├── UTC--2020-03-05T06-24-42Z--8a4d1282-551c-30f4-4e51-4f7d1836b482 │ └── UTC--2020-03-05T06-25-04Z--3a427683-d4d6-7a73-e776-fd15df5b1396 ├── link-desc.toml └── password.json ├── discovery ├── Cargo.toml └── src │ ├── config.rs │ ├── extension.rs │ ├── lib.rs │ ├── message.rs │ └── node_id.rs ├── docker ├── README.md └── ubuntu │ └── Dockerfile ├── docker_push.sh ├── foundry ├── config │ ├── mod.rs │ └── presets │ │ ├── config.dev.ini │ │ └── config.prod.ini ├── constants.rs ├── dummy_network_service.rs ├── json │ ├── mod.rs │ ├── password_entry.rs │ └── password_file.rs ├── lib.rs ├── main.rs ├── run_node.rs └── subcommand.rs ├── graphql-engine ├── Cargo.toml └── src │ ├── block.rs │ ├── header.rs │ └── lib.rs ├── graphql-types ├── Cargo.toml └── src │ └── lib.rs ├── graphql ├── Cargo.toml ├── src │ ├── graphiql.rs │ ├── handler.rs │ └── lib.rs └── tests │ ├── common │ └── mod.rs │ └── integration_test.rs ├── informer ├── Cargo.toml └── src │ ├── handler │ ├── mod.rs │ ├── rpc_ws_handler.rs │ └── subscription.rs │ ├── informer_service │ ├── informer_service_handler.rs │ ├── mod.rs │ └── rate_limiter.rs │ ├── lib.rs │ └── rpc_server.rs ├── informer_courier ├── Cargo.toml └── src │ ├── event_types.rs │ ├── informer_notify.rs │ └── lib.rs ├── integration-test ├── Cargo.toml ├── README.md ├── config.tendermint-solo.ini ├── keys │ ├── UTC--2020-03-05T06-22-17Z--15737bb2-a003-24dd-4f38-9a42b2f1a5c1 │ ├── UTC--2020-03-05T06-23-41Z--84597567-cca7-15c1-1e67-ba4d7d74c9cf │ ├── UTC--2020-03-05T06-24-42Z--8a4d1282-551c-30f4-4e51-4f7d1836b482 │ └── UTC--2020-03-05T06-25-04Z--3a427683-d4d6-7a73-e776-fd15df5b1396 ├── password.json ├── src │ └── lib.rs └── tests │ ├── integration_test.rs │ └── multi.rs ├── json ├── Cargo.toml └── src │ ├── bytes.rs │ ├── hash.rs │ ├── lib.rs │ └── uint.rs ├── key ├── Cargo.toml ├── benches │ ├── ed25519.rs │ ├── pay_and_transfer.rs │ └── tendermint.rs └── src │ ├── ed25519 │ ├── keypair.rs │ ├── mod.rs │ ├── private.rs │ ├── public.rs │ └── signature.rs │ ├── encryption.rs │ ├── encryption │ ├── keypair.rs │ ├── private.rs │ └── public.rs │ ├── error.rs │ ├── keypair.rs │ ├── lib.rs │ ├── network.rs │ ├── password.rs │ ├── platform_address.rs │ ├── platform_address │ ├── checksum.rs │ └── version.rs │ ├── random.rs │ └── x25519 │ ├── exchange.rs │ ├── keypair.rs │ ├── mod.rs │ ├── private.rs │ └── public.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 │ ├── bin │ │ └── sign.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 ├── module ├── Cargo.toml ├── src │ ├── impls.rs │ ├── impls │ │ └── process.rs │ ├── lib.rs │ ├── link.rs │ ├── link │ │ └── base.rs │ └── sandbox.rs └── tests │ └── intergration_test.rs ├── 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 │ ├── chain.rs │ ├── devel.rs │ ├── mempool.rs │ ├── mod.rs │ ├── net.rs │ └── snapshot.rs │ ├── mod.rs │ ├── traits │ ├── chain.rs │ ├── devel.rs │ ├── mempool.rs │ ├── mod.rs │ ├── net.rs │ └── snapshot.rs │ └── types │ ├── action.rs │ ├── asset_output.rs │ ├── asset_scheme.rs │ ├── block.rs │ ├── mod.rs │ ├── transaction.rs │ ├── unsigned_transaction.rs │ └── work.rs ├── rust-toolchain ├── rustfmt.toml ├── spec ├── Block-Synchronization-Extension.md ├── Digital-Signature.md ├── Discovery-Extension.md ├── Foundry-Address.md ├── GraphQL.md ├── Hash-Function.md ├── JSON-RPC.md ├── Merkle-Trie.md ├── Network-Extension-Protocol.md ├── Node-Discovery-Protocol.md ├── Operate-Extension.md ├── P2P-Protocol.md ├── README.md ├── Stratum.md ├── System-Extension.md ├── Tag-encoding.md ├── Transaction-Propagation-Extension.md ├── Transaction.md └── Wire-Protocol.md ├── state ├── Cargo.toml └── src │ ├── cache │ ├── global_cache.rs │ ├── lru_cache.rs │ ├── mod.rs │ ├── module_cache.rs │ ├── top_cache.rs │ └── write_back.rs │ ├── checkpoint.rs │ ├── db │ ├── mod.rs │ └── state_db.rs │ ├── error.rs │ ├── impls │ ├── mod.rs │ ├── module_level.rs │ ├── test_helper.rs │ └── top_level.rs │ ├── item │ ├── action_data.rs │ ├── address.rs │ ├── metadata.rs │ ├── mod.rs │ ├── module.rs │ ├── module_datum.rs │ ├── stake.rs │ └── validator_set.rs │ ├── lib.rs │ ├── stake │ └── mod.rs │ ├── tests.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 │ └── transaction │ ├── extension.rs │ ├── message.rs │ └── mod.rs ├── test ├── .editorconfig ├── .gitignore ├── README.md ├── custom.minfee │ └── tccq9td7gtgjhu08ud9hs7uml0pj4lt36mdwyft72tl │ │ ├── keys │ │ └── key │ │ └── password.json ├── package.json ├── src │ ├── e2e.long │ │ ├── account.test.ts │ │ ├── accountUnlock.test.ts │ │ ├── bootstrap.test.ts │ │ ├── discovery2.test.ts │ │ ├── discovery5.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 │ │ ├── invalidBlockPropagation9.test.ts │ │ ├── mempool.test.ts │ │ ├── onChainBlockValid.test.ts │ │ ├── onChainHeaderValid.test.ts │ │ ├── onChainTx.test.ts │ │ ├── reward2.test.ts │ │ ├── sync2.test.ts │ │ ├── sync3.test.ts │ │ ├── sync5.test.ts │ │ └── tendermint.test.ts │ ├── e2e │ │ ├── account.test.ts │ │ ├── basic.test.ts │ │ ├── chain.test.ts │ │ ├── informer.test.ts │ │ ├── informer2.test.ts │ │ ├── ipc.test.ts │ │ ├── mempool.test.ts │ │ ├── network1.test.ts │ │ ├── network2.test.ts │ │ ├── pay.test.ts │ │ ├── reward.test.ts │ │ ├── snapshot.test.ts │ │ ├── syncEmptyBlock.test.ts │ │ └── verification.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 │ ├── primitives │ │ ├── README.md │ │ ├── src │ │ │ ├── address │ │ │ │ ├── address.ts │ │ │ │ └── checksum.ts │ │ │ ├── hash.ts │ │ │ ├── index.ts │ │ │ ├── key │ │ │ │ ├── ed25519.ts │ │ │ │ ├── key.ts │ │ │ │ └── keyExchange.ts │ │ │ ├── utility.ts │ │ │ └── value │ │ │ │ ├── H128.ts │ │ │ │ ├── H256.ts │ │ │ │ ├── H512.ts │ │ │ │ ├── U128.ts │ │ │ │ ├── U256.ts │ │ │ │ └── U64.ts │ │ └── test │ │ │ ├── Hxxx.test.ts │ │ │ ├── Uxxx.test.ts │ │ │ ├── address.test.ts │ │ │ ├── hash.test.ts │ │ │ ├── key.test.ts │ │ │ ├── keyExchange.test.ts │ │ │ └── utility.test.ts │ ├── scheme │ │ ├── mempool.json │ │ ├── solo.json │ │ ├── tendermint-int.json │ │ └── tendermint-tps.json │ ├── sdk │ │ ├── __test__ │ │ │ ├── SignatureTag.spec.ts │ │ │ └── blake.spec.ts │ │ ├── core │ │ │ ├── Block.ts │ │ │ ├── SignedTransaction.ts │ │ │ ├── Text.ts │ │ │ ├── Transaction.ts │ │ │ ├── __test__ │ │ │ │ ├── Block.spec.ts │ │ │ │ └── SignedTransaction.spec.ts │ │ │ ├── classes.ts │ │ │ ├── index.ts │ │ │ ├── transaction │ │ │ │ ├── ChangeParams.ts │ │ │ │ ├── DelegateCCS.ts │ │ │ │ ├── Pay.ts │ │ │ │ ├── Redelegate.ts │ │ │ │ ├── ReportDoubleVote.ts │ │ │ │ ├── Revoke.ts │ │ │ │ ├── SelfNominate.ts │ │ │ │ ├── TransferCCS.ts │ │ │ │ ├── __test__ │ │ │ │ │ └── Pay.spec.ts │ │ │ │ └── json.ts │ │ │ └── types.ts │ │ ├── index.ts │ │ ├── key │ │ │ ├── KeyStore.ts │ │ │ ├── LocalKeyStore.ts │ │ │ ├── MemoryKeyStore.ts │ │ │ ├── RemoteKeyStore.ts │ │ │ ├── __test__ │ │ │ │ ├── LocalKeyStore.spec.ts │ │ │ │ └── MemoryKeyStore.spec.ts │ │ │ ├── classes.ts │ │ │ └── index.ts │ │ └── utils.ts │ └── tendermint.test │ │ ├── local.ts │ │ └── remote.ts ├── tendermint.dynval │ ├── 74ft6vs4-6hnNHtCB4Drxl25ZZEi0i0pDf-daeZMq-Ys3kgqKOUtc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── 7zfgtdtf43Cq3OiFal90JIQBg2MbmaJMqrfQpQ98qOCjyR-BsWctc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── 8y5y8f2cmHGhSPvEdPgq0ckxQLmiS3wuiUQViBa6tvgoxfRQJGEtc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── 9w0t888bwJQ6KiY1g16erHoJXsZYBRkMDf6t2q0g8By_DykEV9Itc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── be408xc5EctYW80ArkfkEEdJh9TYEp3hMF1I1Yhr5itP9Q8oSvMtc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── brnv7hjvbOFhgKognQNJ-OtnAs9dBh6Bhe9upHKNhu4rIKhQZA0tc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── constants.ts │ ├── ejr942sfGmscSzhJgY2GDHm7B6dIJo_oa67IisBx2dxZLCG6Wr8tc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── rn3rnhr3s9Q_CLfiEx3HrRuSnXTDsteFheb2XqKG2Me44sESOxYtc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ ├── snapshot-config.yml │ ├── tcqfztsg3H1ZitrqRhvzyFrnJ66dZT0xXwcJmiANX770mz_9XSUtc0 │ │ ├── keys │ │ │ └── key │ │ └── password.json │ └── xek9jzmhvHcp-RxX9XXJVV23kKl574FD6ilIjzteSY48LACx05Etc0 │ │ ├── keys │ │ └── key │ │ └── password.json ├── tendermint │ ├── keys │ │ ├── UTC--2020-03-05T06-22-17Z--15737bb2-a003-24dd-4f38-9a42b2f1a5c1 │ │ ├── UTC--2020-03-05T06-23-41Z--84597567-cca7-15c1-1e67-ba4d7d74c9cf │ │ ├── UTC--2020-03-05T06-24-42Z--8a4d1282-551c-30f4-4e51-4f7d1836b482 │ │ └── UTC--2020-03-05T06-25-04Z--3a427683-d4d6-7a73-e776-fd15df5b1396 │ └── password.json ├── tsconfig.json ├── tslint.json ├── upload_logs.sh └── yarn.lock ├── timestamp ├── Cargo.toml ├── README.md ├── app-desc.toml ├── link-desc.toml ├── src │ ├── account │ │ ├── graphql.rs │ │ ├── mod.rs │ │ ├── module.rs │ │ ├── services.rs │ │ ├── state_machine.rs │ │ └── types.rs │ ├── bin │ │ ├── account.rs │ │ ├── sorting.rs │ │ ├── staking.rs │ │ ├── stamp.rs │ │ └── token.rs │ ├── common.rs │ ├── common │ │ ├── state_machine.rs │ │ └── state_manager.rs │ ├── lib.rs │ ├── sorting │ │ ├── mod.rs │ │ ├── module.rs │ │ └── services.rs │ ├── staking │ │ ├── mod.rs │ │ ├── module.rs │ │ └── services.rs │ ├── stamp │ │ ├── mod.rs │ │ ├── module.rs │ │ ├── services.rs │ │ └── types.rs │ ├── token │ │ ├── graphql.rs │ │ ├── mod.rs │ │ ├── module.rs │ │ ├── services.rs │ │ ├── state_machine.rs │ │ └── types.rs │ └── util │ │ └── mod.rs └── tests │ ├── common │ ├── mod.rs │ └── query.graphql │ └── integration_test.rs ├── types ├── Cargo.toml └── src │ ├── block_hash.rs │ ├── block_id.rs │ ├── chain_params.rs │ ├── errors │ ├── history_error.rs │ ├── mod.rs │ ├── runtime_error.rs │ └── syntax_error.rs │ ├── header.rs │ ├── lib.rs │ ├── sync_header.rs │ ├── transaction │ ├── approval.rs │ ├── mod.rs │ ├── partial_hashing.rs │ └── validator.rs │ ├── tx_hash.rs │ ├── util │ ├── mod.rs │ ├── tag.rs │ └── unexpected.rs │ └── validator_set.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 /.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.47.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 foundry | tee artifacts/sha256sums 30 | FOUNDRY_VERSION="$(./foundry --version | cut -d ' ' -f 2)" 31 | tar cvfz artifacts/foundry-${FOUNDRY_VERSION}-$(uname -m)-$(echo $(uname) | tr '[:upper:]' '[:lower:]').tar.gz foundry 32 | - uses: actions/upload-artifact@v1 33 | with: 34 | name: foundry-${{ matrix.os }} 35 | path: target/release/artifacts -------------------------------------------------------------------------------- /.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 | # integration test 21 | /integration-test/db/ 22 | /integration-test/logs/ 23 | 24 | # demo 25 | /demo/db* 26 | /demo/foundry -------------------------------------------------------------------------------- /.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 | - base=master 9 | - label!=do-not-merge 10 | - "- title~=\\b(wip|WIP)\\b" 11 | actions: 12 | merge: 13 | method: rebase 14 | rebase_fallback: null 15 | strict: smart 16 | -------------------------------------------------------------------------------- /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 GPLv3 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 | -------------------------------------------------------------------------------- /config.tendermint-solo.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeChain-io/foundry/58cd0832f9db09ace91035344db7168063ecfa7a/config.tendermint-solo.ini -------------------------------------------------------------------------------- /coordinator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "coordinator" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 9 | ckey = { package = "codechain-key", path = "../key" } 10 | cmodule = { package = "codechain-module", path = "../module" } 11 | codechain-logger = { path = "../util/logger" } 12 | ctypes = { package = "codechain-types", path = "../types" } 13 | remote-trait-object = "0.4.0" 14 | foundry-process-sandbox = { version = "0.2.1", git = "https://github.com/CodeChain-io/foundry-sandbox.git", tag = "v0.2.1" } 15 | foundry-module-rt = { version = "0.2.2", git = "https://github.com/CodeChain-io/module-rt.git", tag = "v0.2.2" } 16 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 17 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 18 | parking_lot = "0.11.0" 19 | serde = { version = "1.0", features = ["derive"] } 20 | serde_yaml = "0.8" 21 | toml = "0.4" 22 | erased-serde = "0.3" 23 | rustc-hex = "2" 24 | hex = { version = "0.4.2", features = ["serde"] } 25 | regex = "1" 26 | once_cell = "1" 27 | linkme = "0.2.2" 28 | log = "0.4.6" 29 | thiserror = "1" 30 | handlebars = "3.3" 31 | anyhow = "1" 32 | serde_cbor = "0.11.1" 33 | intertrait = "0.2.0" 34 | 35 | [dev-dependencies] 36 | unindent = "0.1.6" 37 | -------------------------------------------------------------------------------- /coordinator/src/context.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod chain_history_access; 18 | mod mem_pool_access; 19 | mod storage_access; 20 | mod sub_storage_access; 21 | 22 | pub use chain_history_access::ChainHistoryAccess; 23 | pub use mem_pool_access::MemPoolAccess; 24 | pub use storage_access::StorageAccess; 25 | pub use sub_storage_access::SubStorageAccess; 26 | 27 | /// A `Context` provides the interface against the system services such as moulde substorage access, 28 | /// mempool access 29 | pub trait Context: SubStorageAccess + MemPoolAccess {} 30 | -------------------------------------------------------------------------------- /coordinator/src/context/chain_history_access.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::header::Header; 18 | use ctypes::BlockId; 19 | 20 | pub trait ChainHistoryAccess { 21 | fn get_block_header(&self, block_id: BlockId) -> Option
; 22 | } 23 | -------------------------------------------------------------------------------- /coordinator/src/context/mem_pool_access.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::transaction::Transaction; 18 | use ctypes::TxHash; 19 | 20 | pub trait MemPoolAccess { 21 | fn inject_transactions(&self, txs: Vec) -> Vec>; 22 | } 23 | -------------------------------------------------------------------------------- /coordinator/src/context/storage_access.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::context::SubStorageAccess; 18 | pub use ctypes::StorageId; 19 | 20 | // Interface between host and the coordinator 21 | pub trait StorageAccess: Send { 22 | /// Returns a subspace of the given `storage_id` in the underlying storage. 23 | fn sub_storage(&mut self, storage_id: StorageId) -> Box; 24 | 25 | fn max_body_size(&self) -> u64; 26 | 27 | /// Create a recoverable checkpoint of this state 28 | fn create_checkpoint(&mut self); 29 | /// Revert to the last checkpoint and discard it 30 | fn revert_to_the_checkpoint(&mut self); 31 | /// Merge last checkpoint with the previous 32 | fn discard_checkpoint(&mut self); 33 | } 34 | -------------------------------------------------------------------------------- /coordinator/src/context/sub_storage_access.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use remote_trait_object::{service, Service}; 18 | 19 | // Interface between each module and the coordinator 20 | #[service] 21 | pub trait SubStorageAccess: Service { 22 | fn get(&self, key: &[u8]) -> Option>; 23 | fn set(&mut self, key: &[u8], value: Vec); 24 | fn has(&self, key: &[u8]) -> bool; 25 | fn remove(&mut self, key: &[u8]); 26 | } 27 | -------------------------------------------------------------------------------- /core/res/null.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Null", 3 | "genesis": { 4 | "seal": { 5 | "generic": "0x0" 6 | }, 7 | "author": "fjjh0000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtc0", 8 | "timestamp": "0x00", 9 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 10 | "extraData": "0x" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/res/solo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Solo", 3 | "genesis": { 4 | "seal": { 5 | "generic": "0x0" 6 | }, 7 | "author": "fjjh0000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtc0", 8 | "timestamp": "0x00", 9 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 10 | "extraData": "0x" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/res/tendermint.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Tendermint", 3 | "genesis": { 4 | "seal": { 5 | "tendermint": { 6 | "prev_view": "0x0", 7 | "cur_view": "0x0", 8 | "precommits": [ 9 | "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 10 | ] 11 | } 12 | }, 13 | "author": "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0", 14 | "timestamp": "0x00", 15 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 16 | "extraData": "0x" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 event_db; 22 | mod extras; 23 | mod headerchain; 24 | mod route; 25 | mod update_result; 26 | 27 | pub use self::blockchain::{BlockChain, BlockProvider}; 28 | pub use self::body_db::BodyProvider; 29 | pub use self::event_db::EventProvider; 30 | pub use self::extras::{BlockDetails, TransactionAddress}; 31 | pub use self::headerchain::HeaderProvider; 32 | pub use self::update_result::ChainUpdateResult; 33 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use ctypes::{BlockHash, BlockNumber}; 18 | 19 | /// Information about the blockchain gathered together. 20 | #[derive(Clone, Debug)] 21 | pub struct BlockChainInfo { 22 | /// Genesis block hash. 23 | pub genesis_hash: BlockHash, 24 | /// Best blockchain block hash. 25 | pub best_block_hash: BlockHash, 26 | /// Best blockchain proposal block hash. 27 | pub best_proposal_block_hash: BlockHash, 28 | /// Best blockchain block number. 29 | pub best_block_number: BlockNumber, 30 | /// Best blockchain block timestamp. 31 | pub best_block_timestamp: u64, 32 | } 33 | -------------------------------------------------------------------------------- /core/src/client/chain_notify.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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(&self, _imported: Vec, _enacted: Vec, _new_best_proposal: Option) { 23 | // does nothing by default 24 | } 25 | 26 | /// fires when chain has new blocks. 27 | fn new_blocks(&self, _imported: Vec, _invalid: Vec, _enacted: Vec) { 28 | // does nothing by default 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/consensus/null_engine/mod.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::ConsensusEngine; 18 | use crate::consensus::{EngineError, EngineType}; 19 | use ckey::Ed25519Public as Public; 20 | 21 | /// An engine which does not provide any consensus mechanism and does not seal blocks. 22 | #[derive(Default)] 23 | pub struct NullEngine; 24 | 25 | impl ConsensusEngine for NullEngine { 26 | fn seals_internally(&self) -> bool { 27 | true 28 | } 29 | 30 | fn engine_type(&self) -> EngineType { 31 | EngineType::Solo 32 | } 33 | 34 | fn possible_authors(&self, _block_number: Option) -> Result>, EngineError> { 35 | Ok(None) 36 | } 37 | 38 | fn current_validator_set( 39 | &self, 40 | _block_number: Option, 41 | ) -> Result, EngineError> { 42 | Ok(None) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/consensus/tendermint/chain_notify.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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(&self, imported: Vec, _invalid: Vec, enacted: Vec) { 37 | self.inner 38 | .send(worker::Event::NewBlocks { 39 | imported, 40 | enacted, 41 | }) 42 | .unwrap(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/consensus/tendermint/evidence_collector.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::vote_collector::DoubleVote; 18 | use std::mem::take; 19 | 20 | pub type Evidence = DoubleVote; // This may be generalized in the future 21 | 22 | #[derive(Default)] 23 | pub struct EvidenceCollector { 24 | evidences: Vec, 25 | } 26 | 27 | impl EvidenceCollector { 28 | pub fn insert_double_vote(&mut self, double_vote: DoubleVote) { 29 | self.evidences.push(double_vote); 30 | } 31 | 32 | pub fn fetch_evidences(&mut self) -> Vec { 33 | take(&mut self.evidences) 34 | } 35 | 36 | pub fn remove_published_evidences(&mut self, published: Vec) { 37 | self.evidences.retain(|e| !published.contains(e)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod block_status; 18 | mod transaction_id; 19 | mod verification_queue_info; 20 | 21 | pub use self::block_status::BlockStatus; 22 | pub use self::transaction_id::TransactionId; 23 | pub use self::verification_queue_info::VerificationQueueInfo; 24 | -------------------------------------------------------------------------------- /core/src/types/transaction_id.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use ctypes::{BlockId, TransactionIndex, TxHash}; 18 | 19 | /// Uniquely identifies transaction. 20 | #[derive(Debug, PartialEq, Clone, Hash, Eq)] 21 | pub enum TransactionId { 22 | /// Transaction's blake256. 23 | Hash(TxHash), 24 | /// Block id and transaction index within this block. 25 | /// Querying by block position is always faster. 26 | Location(BlockId, TransactionIndex), 27 | } 28 | 29 | impl From for TransactionId { 30 | fn from(hash: TxHash) -> Self { 31 | TransactionId::Hash(hash) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/src/verification/mod.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod block; 18 | mod body; 19 | mod header; 20 | 21 | pub use self::block::BlockView; 22 | pub use self::body::BodyView; 23 | pub use self::header::HeaderView; 24 | -------------------------------------------------------------------------------- /demo/config0.ini: -------------------------------------------------------------------------------- 1 | [Defaults] 2 | base_path = "." 3 | password_path = "./password.json" 4 | 5 | # MB 6 | mem_pool_mem_limit = 4 7 | mem_pool_size = 32768 8 | reseal_on_txs = "all" 9 | reseal_min_period = 0 10 | allowed_past_gap = 30000 11 | allowed_future_gap = 5000 12 | engine_signer = "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0" 13 | 14 | network_enable = true 15 | interface = "0.0.0.0" 16 | port = 3030 17 | max_peers = 30 18 | min_peers = 10 19 | bootstrap_addresses = "127.0.0.1:3031,127.0.0.1:3032,127.0.0.1:3033" 20 | 21 | sync_enable = true 22 | tx_relay_enable = true 23 | discovery = true 24 | discovery_type = "unstructured" 25 | discovery_refresh = 60000 26 | discovery_bucket_size = 10 27 | # whitelist_path = "whitelist.txt" 28 | # blacklist_path = "blacklist.txt" 29 | 30 | graphql_port = 4040 31 | 32 | jsonrpc_enable = false 33 | 34 | ipc_enable = false 35 | 36 | informer_enable = false 37 | 38 | ws_enable = false 39 | 40 | snapshot_enable = false 41 | 42 | email_alarm_enable = false 43 | -------------------------------------------------------------------------------- /demo/config1.ini: -------------------------------------------------------------------------------- 1 | [Defaults] 2 | base_path = "." 3 | password_path = "./password.json" 4 | 5 | # MB 6 | mem_pool_mem_limit = 4 7 | mem_pool_size = 32768 8 | reseal_on_txs = "all" 9 | reseal_min_period = 0 10 | allowed_past_gap = 30000 11 | allowed_future_gap = 5000 12 | engine_signer = "szff1322BHP3gsOuwFPDf-K8zvqSmNz4rj3CJirlQKFKWA_3c-Ytc0" 13 | 14 | network_enable = true 15 | interface = "0.0.0.0" 16 | port = 3031 17 | max_peers = 30 18 | min_peers = 10 19 | bootstrap_addresses = "127.0.0.1:3030,127.0.0.1:3032,127.0.0.1:3033" 20 | 21 | sync_enable = true 22 | tx_relay_enable = true 23 | discovery = true 24 | discovery_type = "unstructured" 25 | discovery_refresh = 60000 26 | discovery_bucket_size = 10 27 | # whitelist_path = "whitelist.txt" 28 | # blacklist_path = "blacklist.txt" 29 | 30 | graphql_port = 4041 31 | 32 | jsonrpc_enable = false 33 | 34 | ipc_enable = false 35 | 36 | informer_enable = false 37 | 38 | ws_enable = false 39 | 40 | snapshot_enable = false 41 | 42 | email_alarm_enable = false 43 | -------------------------------------------------------------------------------- /demo/config2.ini: -------------------------------------------------------------------------------- 1 | [Defaults] 2 | base_path = "." 3 | password_path = "./password.json" 4 | 5 | # MB 6 | mem_pool_mem_limit = 4 7 | mem_pool_size = 32768 8 | reseal_on_txs = "all" 9 | reseal_min_period = 0 10 | allowed_past_gap = 30000 11 | allowed_future_gap = 5000 12 | engine_signer = "qwfj0xwkJQLV5iEGeaGeRfPA-TJX56Mnuq9fQD9coasmhanhck4tc0" 13 | 14 | network_enable = true 15 | interface = "0.0.0.0" 16 | port = 3032 17 | max_peers = 30 18 | min_peers = 10 19 | bootstrap_addresses = "127.0.0.1:3031,127.0.0.1:3030,127.0.0.1:3033" 20 | 21 | sync_enable = true 22 | tx_relay_enable = true 23 | discovery = true 24 | discovery_type = "unstructured" 25 | discovery_refresh = 60000 26 | discovery_bucket_size = 10 27 | # whitelist_path = "whitelist.txt" 28 | # blacklist_path = "blacklist.txt" 29 | 30 | graphql_port = 4042 31 | 32 | jsonrpc_enable = false 33 | 34 | ipc_enable = false 35 | 36 | informer_enable = false 37 | 38 | ws_enable = false 39 | 40 | snapshot_enable = false 41 | 42 | email_alarm_enable = false 43 | -------------------------------------------------------------------------------- /demo/config3.ini: -------------------------------------------------------------------------------- 1 | [Defaults] 2 | base_path = "." 3 | password_path = "./password.json" 4 | 5 | # MB 6 | mem_pool_mem_limit = 4 7 | mem_pool_size = 32768 8 | reseal_on_txs = "all" 9 | reseal_min_period = 0 10 | allowed_past_gap = 30000 11 | allowed_future_gap = 5000 12 | engine_signer = "dbqtds3w6QnzEf0RXuQS7c_N6IzFBzcBAfdjWme5y0U5DxzLS14tc0" 13 | 14 | network_enable = true 15 | interface = "0.0.0.0" 16 | port = 3033 17 | max_peers = 30 18 | min_peers = 10 19 | bootstrap_addresses = "127.0.0.1:3031,127.0.0.1:3030,127.0.0.1:3032" 20 | 21 | sync_enable = true 22 | tx_relay_enable = true 23 | discovery = true 24 | discovery_type = "unstructured" 25 | discovery_refresh = 60000 26 | discovery_bucket_size = 10 27 | # whitelist_path = "whitelist.txt" 28 | # blacklist_path = "blacklist.txt" 29 | 30 | graphql_port = 4043 31 | 32 | jsonrpc_enable = false 33 | 34 | ipc_enable = false 35 | 36 | informer_enable = false 37 | 38 | ws_enable = false 39 | 40 | snapshot_enable = false 41 | 42 | email_alarm_enable = false 43 | -------------------------------------------------------------------------------- /demo/keys/UTC--2020-03-05T06-22-17Z--15737bb2-a003-24dd-4f38-9a42b2f1a5c1: -------------------------------------------------------------------------------- 1 | {"id":"15737bb2-a003-24dd-4f38-9a42b2f1a5c1","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"e7258e1090900aa0e14efa15b82fd951"},"ciphertext":"50dba0aba05af919cc26281d7a650f3705c2b12f8b4b1c57fc53e991dc4acc71e48f53bade9da676c25f3e46b0384b9cccd286c94d26ae1b057cf5557c0ca055","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"5abacddd15947f7b729ab3b0250b4d0cf7401cc4888466f42052518d87fb5e71"},"mac":"a86a1e44ac394e315361c3bf05143704212db3b75cdb8a70af2167c5d9d5908e"},"pubkey":"0a6902c51384a15d1062cac3a4e62c8d0c2eb02b4de7fa0a304ce4f88ea482d0","meta":"{}"} 2 | -------------------------------------------------------------------------------- /demo/keys/UTC--2020-03-05T06-23-41Z--84597567-cca7-15c1-1e67-ba4d7d74c9cf: -------------------------------------------------------------------------------- 1 | {"id":"84597567-cca7-15c1-1e67-ba4d7d74c9cf","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"786e31c275e51eba4615ec70c7a1776d"},"ciphertext":"2e800890f66191e2546eae77be5bd05e154cfe4f84b5ae0f25fc6f26f0209695de11e7b266395f88876ff41f56998fc2065c9f9338aa76aa4e6b20a0d3e7b05c","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"cd7bc6a9b192bb6da9774899fd4eea9a6676f1b4d943d51dd0c664ade49fae18"},"mac":"a594d1f3878bfa8c664bbdd0f90cc5f96fb72ddf41b50fa2b508f800130c2e9f"},"pubkey":"0473f782c3aec053c37fe2bccefa9298dcf8ae3dc2262ae540a14a580ff773e6","meta":"{}"} 2 | -------------------------------------------------------------------------------- /demo/keys/UTC--2020-03-05T06-24-42Z--8a4d1282-551c-30f4-4e51-4f7d1836b482: -------------------------------------------------------------------------------- 1 | {"id":"8a4d1282-551c-30f4-4e51-4f7d1836b482","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"119d4e88b899c0c168d45e8b0ae7944e"},"ciphertext":"f54ccdd40de8e7c34931102c9b7006132dbf352d906b95c9b4b5c0e24d3cbd94dedf5c76b4f0d4b9839d02f6e01d292e22278905fa429c493be523c49d0c7848","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"78c39a2e181ea071fb5a3a0cb8681311cdcf35f2f850974dd0abf8053751080e"},"mac":"6fdb483a72477e07fb68b2b96870a5534f40931dc290f682aea1c2496edd51d2"},"pubkey":"2502d5e6210679a19e45f3c0f93257e7a327baaf5f403f5ca1ab2685a9e1724e","meta":"{}"} 2 | -------------------------------------------------------------------------------- /demo/keys/UTC--2020-03-05T06-25-04Z--3a427683-d4d6-7a73-e776-fd15df5b1396: -------------------------------------------------------------------------------- 1 | {"id":"3a427683-d4d6-7a73-e776-fd15df5b1396","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"2e0d3e79e28d235e87c92476cc23695c"},"ciphertext":"a31a552aaa17e02476d34f9619105eb1024a4e2c2feee47ac3b35e9b11b22d4c5a2bc9f6ea6bfa260f230fc4842d963424503af3f3bcd11240b83a44a849fe54","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"d80628d63d7a42f92e30db09d4d628d8e7a615361e396ef6f8191f7abdaee17f"},"mac":"04f169d217b8d1b2fc1e437ac250443151f6cc68011b28668a89505a0bd3dae3"},"pubkey":"e909f311fd115ee412edcfcde88cc507370101f7635a67b9cb45390f1ccb4b5e","meta":"{}"} 2 | -------------------------------------------------------------------------------- /demo/password.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "address": "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0", 4 | "password": "" 5 | }, { 6 | "address": "szff1322BHP3gsOuwFPDf-K8zvqSmNz4rj3CJirlQKFKWA_3c-Ytc0", 7 | "password": "" 8 | }, { 9 | "address": "qwfj0xwkJQLV5iEGeaGeRfPA-TJX56Mnuq9fQD9coasmhanhck4tc0", 10 | "password": "" 11 | }, { 12 | "address": "dbqtds3w6QnzEf0RXuQS7c_N6IzFBzcBAfdjWme5y0U5DxzLS14tc0", 13 | "password": "" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /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 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 9 | codechain-logger = { path = "../util/logger" } 10 | cnetwork = { package = "codechain-network", path = "../network" } 11 | ctimer = { package = "codechain-timer", path = "../util/timer" } 12 | log = "0.4.6" 13 | never-type = "0.1.0" 14 | parking_lot = "0.11.0" 15 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 16 | rand = "0.6.1" 17 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 18 | time = "0.1" 19 | 20 | [dev-dependencies] 21 | lazy_static = "1.2" 22 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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-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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #![allow(deprecated)] 18 | 19 | #[macro_use] 20 | extern crate log; 21 | #[macro_use] 22 | extern crate codechain_logger as clogger; 23 | 24 | mod config; 25 | mod extension; 26 | mod message; 27 | mod node_id; 28 | 29 | const K: u8 = 16; 30 | const T_REFRESH: u32 = 60_000; 31 | 32 | pub use crate::config::Config; 33 | pub use crate::extension::Extension as Discovery; 34 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # Docker support 2 | 3 | ## Ubuntu 4 | `docker build -f docker/ubuntu/Dockerfile --tag codechain-io/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 | 17 | # install rustup 18 | RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y 19 | 20 | # rustup directory 21 | ENV PATH /root/.cargo/bin:$PATH 22 | 23 | # show backtraces 24 | ENV RUST_BACKTRACE 1 25 | 26 | # show tools 27 | RUN rustc -vV && \ 28 | cargo -V && \ 29 | gcc -v &&\ 30 | g++ -v 31 | 32 | # build codechain 33 | ADD . /build/codechain 34 | RUN cd codechain && \ 35 | cargo build --release --verbose && \ 36 | ls /build/codechain/target/release/codechain && \ 37 | strip /build/codechain/target/release/codechain 38 | 39 | RUN file /build/codechain/target/release/codechain 40 | 41 | 42 | FROM ubuntu:18.04 43 | WORKDIR /app/codechain 44 | RUN apt-get update && apt-get install -y libssl-dev 45 | COPY --from=builder /build/codechain/target/release/codechain ./target/release/codechain 46 | COPY --from=builder /build/codechain/codechain/config/presets/ ./codechain/config/presets 47 | 48 | # show backtraces 49 | ENV RUST_BACKTRACE 1 50 | 51 | EXPOSE 3485 8080 52 | ENTRYPOINT ["target/release/codechain"] 53 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /foundry/config/presets/config.dev.ini: -------------------------------------------------------------------------------- 1 | [Defaults] 2 | base_path = "." 3 | 4 | # MB 5 | mem_pool_mem_limit = 4 6 | mem_pool_size = 32768 7 | reseal_on_txs = "all" 8 | reseal_min_period = 0 9 | allowed_past_gap = 30000 10 | allowed_future_gap = 5000 11 | 12 | network_enable = true 13 | interface = "0.0.0.0" 14 | port = 3485 15 | max_peers = 30 16 | min_peers = 10 17 | # bootstrap_addresses = "127.0.0.1:3485" 18 | sync_enable = true 19 | tx_relay_enable = true 20 | discovery_enable = true 21 | discovery_type = "unstructured" 22 | discovery_refresh = 60000 23 | discovery_bucket_size = 10 24 | # whitelist_path = "whitelist.txt" 25 | # blacklist_path = "blacklist.txt" 26 | 27 | ipc_enable = true 28 | ipc_path = "/tmp/jsonrpc.ipc" 29 | 30 | jsonrpc_enable = true 31 | jsonrpc_interface = "127.0.0.1" 32 | jsonrpc_port = 8080 33 | 34 | ws_enable = true 35 | ws_interface = "127.0.0.1" 36 | ws_port = 8081 37 | ws_max_connections = 100 38 | 39 | graphql_port = 4040 40 | 41 | informer_enable = true 42 | informer_interface = "127.0.0.1" 43 | informer_port = 7070 44 | informer_max_connections = 100 45 | 46 | snapshot_enable = true 47 | snapshot_path = "snapshot" 48 | # blocks. About a week 49 | snapshot_expiration = 100000 50 | 51 | email_alarm_enable = false 52 | -------------------------------------------------------------------------------- /foundry/config/presets/config.prod.ini: -------------------------------------------------------------------------------- 1 | [Defaults] 2 | base_path = "." 3 | 4 | # MB 5 | mem_pool_mem_limit = 512 6 | mem_pool_size = 524288 7 | reseal_on_txs = "all" 8 | reseal_min_period = 4000 9 | allowed_past_gap = 30000 10 | allowed_future_gap = 5000 11 | 12 | network_enable = true 13 | interface = "0.0.0.0" 14 | port = 3485 15 | max_peers = 30 16 | min_peers = 10 17 | # bootstrap_addresses = "127.0.0.1:3485" 18 | sync_enable = true 19 | tx_relay_enable = true 20 | discovery_enable = true 21 | discovery_type = "unstructured" 22 | discovery_refresh = 60000 23 | discovery_bucket_size = 10 24 | # whitelist_path = "whitelist.txt" 25 | # blacklist_path = "blacklist.txt" 26 | 27 | jsonrpc_enable = true 28 | jsonrpc_interface = "127.0.0.1" 29 | jsonrpc_port = 8080 30 | 31 | graphql_port = 4040 32 | 33 | informer_enable = true 34 | informer_interface = "127.0.0.1" 35 | informer_port = 7070 36 | informer_max_connections = 100 37 | 38 | ipc_enable = true 39 | ipc_path = "/tmp/jsonrpc.ipc" 40 | 41 | ipc_disable = true 42 | ipc_interface = "127.0.0.1" 43 | ipc_port = 7070 44 | ipc_max_connections = 100 45 | 46 | ws_enable = false 47 | ws_interface = "127.0.0.1" 48 | ws_port = 8081 49 | ws_max_connections = 100 50 | 51 | snapshot_enable = false 52 | snapshot_path = "snapshot" 53 | # blocks. About a week 54 | snapshot_expiration = 100000 55 | 56 | email_alarm_enable = false 57 | -------------------------------------------------------------------------------- /foundry/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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 | -------------------------------------------------------------------------------- /foundry/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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 | -------------------------------------------------------------------------------- /foundry/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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use ckey::{Password, PlatformAddress}; 18 | use serde::{Deserialize, Serialize}; 19 | 20 | #[derive(Debug, PartialEq, Serialize, Deserialize)] 21 | pub struct PasswordEntry { 22 | pub address: PlatformAddress, 23 | pub password: Password, 24 | } 25 | -------------------------------------------------------------------------------- /foundry/subcommand.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use clap::ArgMatches; 18 | 19 | pub fn run_subcommand(matches: &ArgMatches<'_>) -> Result<(), String> { 20 | let subcommand = matches.subcommand.as_ref().unwrap(); 21 | match subcommand.name.as_str() { 22 | "commit-hash" => { 23 | println!("{}", env!("VERGEN_SHA")); 24 | Ok(()) 25 | } 26 | _ => Err("Invalid subcommand.rs".into()), 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /graphql-engine/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "foundry-graphql-engine" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | coordinator = { path = "../coordinator" } 9 | ccore = { package = "codechain-core", path = "../core" } 10 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 11 | clogger = { package = "codechain-logger", path = "../util/logger" } 12 | ckey = {package = "codechain-key", path = "../key" } 13 | ctypes = { package = "codechain-types", path = "../types" } 14 | log = "0.4.6" 15 | parking_lot = "0.11.0" 16 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 17 | serde = { version = "1.0.111", features = ["derive"] } 18 | serde_json = "1.0" 19 | remote-trait-object = "0.4.0" 20 | async-graphql = "2.0.5" 21 | tokio = {version = "0.2.21", features = ["sync", "time", "rt-threaded", "macros", "uds"]} 22 | hex = "0.4.2" 23 | crossbeam = "0.7" 24 | foundry-graphql-types = { version = "0.1.0", path = "../graphql-types"} -------------------------------------------------------------------------------- /graphql-engine/src/header.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use ccore::HeaderView; 18 | 19 | pub struct Header { 20 | header: Vec, 21 | } 22 | 23 | impl Header { 24 | /// `header` must be RLP-encoded. 25 | pub fn new(header: Vec) -> Self { 26 | Self { 27 | header, 28 | } 29 | } 30 | } 31 | 32 | #[async_graphql::Object] 33 | impl Header { 34 | async fn number(&self) -> u64 { 35 | let view = HeaderView::new(&self.header); 36 | view.number() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /graphql-types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "foundry-graphql-types" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 9 | ckey = {package = "codechain-key", path = "../key" } 10 | ctypes = { package = "codechain-types", path = "../types" } 11 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 12 | serde = { version = "1.0.111", features = ["derive"] } 13 | serde_cbor = "0.11.1" 14 | serde_json = "1.0" 15 | remote-trait-object = "0.4.0" 16 | async-graphql = "2.0.5" 17 | hex = "0.4.2" 18 | -------------------------------------------------------------------------------- /graphql/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "foundry-graphql" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | remote-trait-object = "0.4" 9 | actix-web = "3.0" 10 | actix-service = "1.0" 11 | actix-rt = "1.1.1" 12 | actix-http = "2.0" 13 | async-graphql = "2.0.5" 14 | futures = "0.3.5" 15 | tokio = "0.2.20" 16 | serde_json = "1.0.53" 17 | serde_derive = "1.0.110" 18 | serde = "1.0.110" 19 | coordinator = {path = "../coordinator"} 20 | crossbeam = "0.7" 21 | ctypes = { package = "codechain-types", path = "../types" } 22 | 23 | [dev-dependencies] 24 | -------------------------------------------------------------------------------- /graphql/src/handler.rs: -------------------------------------------------------------------------------- 1 | /// This will be used in both tests and 2 | /// various GraphQL resolver for thehost level(chain, mempool, net...) 3 | /// which will be implemented in this crate as well. 4 | pub fn handle_gql_query( 5 | runtime: &tokio::runtime::Handle, 6 | root: T, 7 | query: &str, 8 | variables: &str, 9 | ) -> String { 10 | let variables = if let Ok(s) = (|| -> Result<_, ()> { 11 | Ok(async_graphql::context::Variables::from_json(serde_json::from_str(variables).map_err(|_| ())?)) 12 | })() { 13 | s 14 | } else { 15 | return "Failed to parse JSON".to_owned() 16 | }; 17 | 18 | let schema = async_graphql::Schema::new(root, async_graphql::EmptyMutation, async_graphql::EmptySubscription); 19 | let request = async_graphql::Request::new(query).variables(variables); 20 | let res = schema.execute(request); 21 | serde_json::to_string(&runtime.block_on(res)).unwrap() 22 | } 23 | -------------------------------------------------------------------------------- /informer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-informer" 3 | version = "0.1.0" 4 | authors = ["MSNTCS "] 5 | edition = "2018" 6 | 7 | [lib] 8 | 9 | [dependencies] 10 | cidr = "0.0.4" 11 | codechain-logger = { path = "../util/logger" } 12 | kvdb = "0.1" 13 | lazy_static = "1.2" 14 | crossbeam-channel = "0.4" 15 | parking_lot = "0.11.0" 16 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 17 | cinfo_courier = { package = "codechain_informer_courier", path = "../informer_courier" } 18 | ccore = { package = "codechain-core", path = "../core" } 19 | ctypes = { package = "codechain-types", path = "../types" } 20 | crpc = { package = "codechain-rpc", path = "../rpc" } 21 | tokio = { version = "0.2.13", features = ["full"] } 22 | serde = "1.0" 23 | log = "0.4.6" 24 | serde_json = "1.0" 25 | serde_derive = "1.0" 26 | rand = "0.6.1" 27 | rustc-hex = "1.0" 28 | rustc-serialize = "0.3" 29 | time = "0.1" 30 | jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 31 | jsonrpc-derive = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 32 | jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 33 | jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 34 | jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 35 | jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 36 | 37 | -------------------------------------------------------------------------------- /informer/src/handler/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod rpc_ws_handler; 18 | mod subscription; 19 | 20 | pub use rpc_ws_handler::{Handler, InformerConfig, Registration}; 21 | pub use subscription::Subscription; 22 | -------------------------------------------------------------------------------- /informer/src/informer_service/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod informer_service_handler; 18 | mod rate_limiter; 19 | 20 | pub use informer_service_handler::{ColdEvents, InformerService}; 21 | pub use rate_limiter::RateLimiter; 22 | -------------------------------------------------------------------------------- /informer/src/rpc_server.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::{PubSubHandler, RequestContext, Session, WsError, WsServer, WsServerBuilder}; 18 | use std::net::SocketAddr; 19 | use std::sync::Arc; 20 | 21 | pub fn start_ws( 22 | addr: &SocketAddr, 23 | handler: PubSubHandler>, 24 | max_connections: usize, 25 | ) -> Result { 26 | WsServerBuilder::with_meta_extractor(handler, |context: &RequestContext| Arc::new(Session::new(context.sender()))) 27 | .max_connections(max_connections) 28 | .start(addr) 29 | } 30 | -------------------------------------------------------------------------------- /informer_courier/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain_informer_courier" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | crossbeam-channel = "0.4" 9 | serde = "1.0" 10 | serde_json = "1.0" 11 | serde_derive = "1.0" 12 | -------------------------------------------------------------------------------- /informer_courier/src/event_types.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #[derive(Clone)] 18 | pub enum EventTags { 19 | PeerAdded, 20 | ColdBlockGenerationNumerical(u64), 21 | ColdBlockGenerationHash(String), 22 | } 23 | 24 | #[derive(Serialize)] 25 | pub enum Events { 26 | PeerAdded(String, String, usize), 27 | } 28 | -------------------------------------------------------------------------------- /informer_courier/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #[macro_use] 18 | extern crate serde_derive; 19 | 20 | mod event_types; 21 | pub mod informer_notify; 22 | 23 | pub use event_types::{EventTags, Events}; 24 | pub use informer_notify::InformerEventSender; 25 | -------------------------------------------------------------------------------- /integration-test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "foundry-integration-test" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | awc = "2.0.0" 9 | actix-rt = "1.1.1" 10 | chrono = "0.4" 11 | futures = "0.3.5" 12 | tokio = {version = "0.2.21", features = ["sync", "time", "rt-threaded", "macros"]} 13 | serde_json = "1.0.53" 14 | serde_cbor = "0.11.1" 15 | serde_derive = "1.0.110" 16 | serde = "1.0.110" 17 | coordinator = {path = "../coordinator"} 18 | ctypes = { package = "codechain-types", path = "../types" } 19 | hex = "0.4.2" 20 | ckey = {package = "codechain-key", path = "../key" } 21 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 22 | rand = "0.7" 23 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 24 | 25 | [features] 26 | integration-test = [] -------------------------------------------------------------------------------- /integration-test/README.md: -------------------------------------------------------------------------------- 1 | # Foundry Integration Test 2 | 3 | ## How to Run 4 | 5 | Run 6 | 7 | ```shell 8 | cargo build 9 | cargo test -p foundry-integration-test --manifest-path ./integration-test/Cargo.toml --features integration-test -- --test-threads=1 10 | ``` 11 | 12 | ## Future Plan 13 | 14 | It might be re-written in JS later. 15 | -------------------------------------------------------------------------------- /integration-test/config.tendermint-solo.ini: -------------------------------------------------------------------------------- 1 | [Defaults] 2 | base_path = "." 3 | password_path = "./password.json" 4 | 5 | # MB 6 | mem_pool_mem_limit = 4 7 | mem_pool_size = 32768 8 | reseal_on_txs = "all" 9 | reseal_min_period = 0 10 | allowed_past_gap = 30000 11 | allowed_future_gap = 5000 12 | engine_signer = "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0" 13 | 14 | network_enable = true 15 | interface = "0.0.0.0" 16 | port = 3485 17 | max_peers = 30 18 | min_peers = 10 19 | # bootstrap_addresses = "" 20 | sync_enable = true 21 | tx_relay_enable = true 22 | discovery_enable = true 23 | discovery_type = "unstructured" 24 | discovery_refresh = 60000 25 | discovery_bucket_size = 10 26 | # whitelist_path = "whitelist.txt" 27 | # blacklist_path = "blacklist.txt" 28 | 29 | jsonrpc_enable = true 30 | jsonrpc_interface = "127.0.0.1" 31 | jsonrpc_port = 8080 32 | 33 | graphql_port = 4040 34 | 35 | ipc_enable = false 36 | ipc_path = "/tmp/jsonrpc.ipc" 37 | 38 | informer_enable = false 39 | informer_interface = "127.0.0.1" 40 | informer_port = 7070 41 | informer_max_connections = 100 42 | 43 | ws_disable = true 44 | ws_interface = "127.0.0.1" 45 | ws_port = 8081 46 | ws_max_connections = 100 47 | 48 | snapshot_enable = true 49 | snapshot_path = "snapshot" 50 | # blocks. About a week 51 | snapshot_expiration = 100000 52 | 53 | email_alarm_enable = false 54 | -------------------------------------------------------------------------------- /integration-test/keys/UTC--2020-03-05T06-22-17Z--15737bb2-a003-24dd-4f38-9a42b2f1a5c1: -------------------------------------------------------------------------------- 1 | {"id":"15737bb2-a003-24dd-4f38-9a42b2f1a5c1","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"e7258e1090900aa0e14efa15b82fd951"},"ciphertext":"50dba0aba05af919cc26281d7a650f3705c2b12f8b4b1c57fc53e991dc4acc71e48f53bade9da676c25f3e46b0384b9cccd286c94d26ae1b057cf5557c0ca055","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"5abacddd15947f7b729ab3b0250b4d0cf7401cc4888466f42052518d87fb5e71"},"mac":"a86a1e44ac394e315361c3bf05143704212db3b75cdb8a70af2167c5d9d5908e"},"pubkey":"0a6902c51384a15d1062cac3a4e62c8d0c2eb02b4de7fa0a304ce4f88ea482d0","meta":"{}"} 2 | -------------------------------------------------------------------------------- /integration-test/keys/UTC--2020-03-05T06-23-41Z--84597567-cca7-15c1-1e67-ba4d7d74c9cf: -------------------------------------------------------------------------------- 1 | {"id":"84597567-cca7-15c1-1e67-ba4d7d74c9cf","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"786e31c275e51eba4615ec70c7a1776d"},"ciphertext":"2e800890f66191e2546eae77be5bd05e154cfe4f84b5ae0f25fc6f26f0209695de11e7b266395f88876ff41f56998fc2065c9f9338aa76aa4e6b20a0d3e7b05c","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"cd7bc6a9b192bb6da9774899fd4eea9a6676f1b4d943d51dd0c664ade49fae18"},"mac":"a594d1f3878bfa8c664bbdd0f90cc5f96fb72ddf41b50fa2b508f800130c2e9f"},"pubkey":"0473f782c3aec053c37fe2bccefa9298dcf8ae3dc2262ae540a14a580ff773e6","meta":"{}"} 2 | -------------------------------------------------------------------------------- /integration-test/keys/UTC--2020-03-05T06-24-42Z--8a4d1282-551c-30f4-4e51-4f7d1836b482: -------------------------------------------------------------------------------- 1 | {"id":"8a4d1282-551c-30f4-4e51-4f7d1836b482","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"119d4e88b899c0c168d45e8b0ae7944e"},"ciphertext":"f54ccdd40de8e7c34931102c9b7006132dbf352d906b95c9b4b5c0e24d3cbd94dedf5c76b4f0d4b9839d02f6e01d292e22278905fa429c493be523c49d0c7848","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"78c39a2e181ea071fb5a3a0cb8681311cdcf35f2f850974dd0abf8053751080e"},"mac":"6fdb483a72477e07fb68b2b96870a5534f40931dc290f682aea1c2496edd51d2"},"pubkey":"2502d5e6210679a19e45f3c0f93257e7a327baaf5f403f5ca1ab2685a9e1724e","meta":"{}"} 2 | -------------------------------------------------------------------------------- /integration-test/keys/UTC--2020-03-05T06-25-04Z--3a427683-d4d6-7a73-e776-fd15df5b1396: -------------------------------------------------------------------------------- 1 | {"id":"3a427683-d4d6-7a73-e776-fd15df5b1396","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"2e0d3e79e28d235e87c92476cc23695c"},"ciphertext":"a31a552aaa17e02476d34f9619105eb1024a4e2c2feee47ac3b35e9b11b22d4c5a2bc9f6ea6bfa260f230fc4842d963424503af3f3bcd11240b83a44a849fe54","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"d80628d63d7a42f92e30db09d4d628d8e7a615361e396ef6f8191f7abdaee17f"},"mac":"04f169d217b8d1b2fc1e437ac250443151f6cc68011b28668a89505a0bd3dae3"},"pubkey":"e909f311fd115ee412edcfcde88cc507370101f7635a67b9cb45390f1ccb4b5e","meta":"{}"} 2 | -------------------------------------------------------------------------------- /integration-test/password.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "address": "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0", 4 | "password": "" 5 | }, { 6 | "address": "szff1322BHP3gsOuwFPDf-K8zvqSmNz4rj3CJirlQKFKWA_3c-Ytc0", 7 | "password": "" 8 | }, { 9 | "address": "qwfj0xwkJQLV5iEGeaGeRfPA-TJX56Mnuq9fQD9coasmhanhck4tc0", 10 | "password": "" 11 | }, { 12 | "address": "dbqtds3w6QnzEf0RXuQS7c_N6IzFBzcBAfdjWme5y0U5DxzLS14tc0", 13 | "password": "" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /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 | ckey = { package = "codechain-key", path = "../key" } 9 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 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, 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate serde_derive; 18 | 19 | pub mod bytes; 20 | pub mod hash; 21 | pub mod uint; 22 | -------------------------------------------------------------------------------- /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 | base64 = "0.12" 13 | codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 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.5", tag = "v0.5.1" } 17 | rand_xorshift = "0.1.0" 18 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 19 | sodiumoxide = "0.2.5" 20 | serde = "1.0" 21 | serde_derive = "1.0" 22 | serde_json = "1.0" 23 | 24 | [dev-dependencies] 25 | criterion = "0.3" 26 | 27 | [[bench]] 28 | name = "ed25519" 29 | harness = false 30 | 31 | [[bench]] 32 | name = "pay_and_transfer" 33 | harness = false 34 | 35 | [[bench]] 36 | name = "tendermint" 37 | harness = false -------------------------------------------------------------------------------- /key/src/ed25519/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod keypair; 18 | mod private; 19 | mod public; 20 | mod signature; 21 | 22 | pub use keypair::KeyPair; 23 | pub use private::Private; 24 | pub use public::Public; 25 | pub use signature::{sign, verify, Ed25519Signature as Signature, SIGNATUREBYTES as SIGNATURE_LENGTH}; 26 | -------------------------------------------------------------------------------- /key/src/encryption/private.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::public::Public; 18 | use sodiumoxide::crypto::box_::SecretKey; 19 | 20 | #[derive(Debug, Clone, PartialEq)] 21 | pub struct Private(pub(crate) SecretKey); 22 | 23 | impl Private { 24 | pub fn from_slice(slice: &[u8]) -> Option { 25 | SecretKey::from_slice(slice).map(Self) 26 | } 27 | 28 | pub fn public_key(&self) -> Public { 29 | self.0.public_key().into() 30 | } 31 | } 32 | 33 | impl AsRef<[u8]> for Private { 34 | fn as_ref(&self) -> &[u8] { 35 | self.0.as_ref() 36 | } 37 | } 38 | 39 | impl From for Private { 40 | fn from(k: SecretKey) -> Self { 41 | Private(k) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /key/src/encryption/public.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use sodiumoxide::crypto::box_::PublicKey; 18 | 19 | #[derive(Clone, Eq, PartialEq, Debug)] 20 | pub struct Public(pub(crate) PublicKey); 21 | 22 | impl Public { 23 | pub fn from_slice(slice: &[u8]) -> Option { 24 | PublicKey::from_slice(slice).map(Self) 25 | } 26 | } 27 | 28 | impl AsRef<[u8]> for Public { 29 | fn as_ref(&self) -> &[u8] { 30 | self.0.as_ref() 31 | } 32 | } 33 | 34 | impl From for Public { 35 | fn from(k: PublicKey) -> Self { 36 | Public(k) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /key/src/keypair.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | pub trait KeyPair { 18 | type Private; 19 | type Public; 20 | 21 | /// Create a pair from secret key 22 | fn from_private(private: Self::Private) -> Self; 23 | 24 | fn from_keypair(private: Self::Private, public: Self::Public) -> Self; 25 | 26 | fn private(&self) -> &Self::Private; 27 | 28 | fn public(&self) -> &Self::Public; 29 | } 30 | -------------------------------------------------------------------------------- /key/src/x25519/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod exchange; 18 | mod keypair; 19 | mod private; 20 | mod public; 21 | 22 | pub use exchange::exchange; 23 | pub use keypair::KeyPair; 24 | pub use private::Private; 25 | pub use public::Public; 26 | -------------------------------------------------------------------------------- /key/src/x25519/private.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::public::Public; 18 | use sodiumoxide::crypto::scalarmult::{scalarmult_base, Scalar}; 19 | 20 | #[derive(Debug, Clone, PartialEq)] 21 | // The inner type Scalar clears its memory when it is dropped 22 | pub struct Private(pub(crate) Scalar); 23 | 24 | impl Private { 25 | pub fn from_slice(slice: &[u8]) -> Option { 26 | Scalar::from_slice(slice).map(Self) 27 | } 28 | 29 | pub fn public_key(&self) -> Public { 30 | let Private(scalar) = self; 31 | scalarmult_base(scalar).into() 32 | } 33 | } 34 | 35 | impl AsRef<[u8]> for Private { 36 | fn as_ref(&self) -> &[u8] { 37 | self.0.as_ref() 38 | } 39 | } 40 | 41 | impl From for Private { 42 | fn from(k: Scalar) -> Self { 43 | Private(k) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /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 | cjson = { package = "codechain-json", path = "../json" } 12 | ckey = { package = "codechain-key", path = "../key" } 13 | ctypes = { package = "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 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 21 | smallvec = "0.4" 22 | tempdir = "0.3" 23 | hex = "0.4.2" 24 | 25 | [dev-dependencies] 26 | matches = "0.1" 27 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 28 | 29 | [[bin]] 30 | path = "./src/bin/sign.rs" 31 | name = "sign" -------------------------------------------------------------------------------- /keystore/src/account/decrypted_account.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019-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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use ckey::{sign, Ed25519Private as Private, Ed25519Public as Public, Error as KeyError, Message, Signature}; 18 | 19 | /// An opaque wrapper for secret. The inner data of Private implements Drop trait to clear memory. 20 | #[derive(Clone)] 21 | pub struct DecryptedAccount { 22 | secret: Private, 23 | } 24 | 25 | impl DecryptedAccount { 26 | pub fn new(secret: Private) -> DecryptedAccount { 27 | DecryptedAccount { 28 | secret, 29 | } 30 | } 31 | 32 | /// Sign a message. 33 | pub fn sign(&self, message: &Message) -> Result { 34 | Ok(sign(message.as_ref(), &self.secret)) 35 | } 36 | 37 | /// Derive public key. 38 | pub fn public(&self) -> Result { 39 | Ok(self.secret.public_key()) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /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/bin/sign.rs: -------------------------------------------------------------------------------- 1 | use ckey::Ed25519Private as Private; 2 | 3 | // FIXME: Use a safer way to receive the private key instead of CLI 4 | fn main() -> Result<(), String> { 5 | let args: Vec = std::env::args().collect(); 6 | if args.len() != 3 { 7 | return Err(format!("Wrong number of arguments; Expected 2, but given {}", args.len() - 1)) 8 | } 9 | 10 | let private = Private::from_slice(&hex::decode(&args[1]).map_err(|_| "Failed to parse private key".to_owned())?) 11 | .ok_or_else(|| "Invalid private key".to_owned())?; 12 | let data = hex::decode(&args[2]).map_err(|_| "Failed to parse data".to_owned())?; 13 | let signature: Vec = ckey::sign(&data, &private).as_ref().to_vec(); 14 | 15 | println!("{}", hex::encode(signature)); 16 | 17 | Ok(()) 18 | } 19 | -------------------------------------------------------------------------------- /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/tests/res/ciphertext/30.json: -------------------------------------------------------------------------------- 1 | { 2 | "id":"c1083ad6-8dc6-a0de-375c-b75e6cbbb4a9", 3 | "version": 3, 4 | "crypto": { 5 | "cipher": "aes-128-ctr", 6 | "cipherparams": { 7 | "iv":"948927fac39b5ce07e08c5b81f9e2441" 8 | }, 9 | "ciphertext": "4845318ddcf4a3be606aeca8fa24d4e21cc48ec1e2de46b7fe967a7384ef7beaf6c31b9028f4b73765c0bd8a088d5b73bc90c75781bb492f3dd54fddfd893525", 10 | "kdf": "pbkdf2", 11 | "kdfparams": { 12 | "c": 10240, 13 | "dklen": 32, 14 | "prf": "hmac-sha256", 15 | "salt": "e2b2d03ef854b4d293d016844e126adb255e339fdc342ef777be8592054785bc" 16 | }, 17 | "mac": "936b8c048ecfdfdb7a52058200bb4b6a131bafb899659f671f380e21df13a90c" 18 | }, 19 | "pubkey": "800a29dbeab141ada7923517e945bf4594917473809547bc0bb2e47cd39ac94b", 20 | "name": "", 21 | "meta": "{}" 22 | } 23 | -------------------------------------------------------------------------------- /keystore/tests/res/ciphertext/31.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "4540e943-58d5-971e-bc43-a82bfbdc478a", 3 | "version": 3, 4 | "crypto": { 5 | "cipher": "aes-128-ctr", 6 | "cipherparams": { 7 | "iv": "7eef1e345cd8bf4db880dcb8c2496511" 8 | }, 9 | "ciphertext": "3dc273315db46994330f76025ff78ce51cefb4e89e3334fb13a8707a108382a505f0eff8a0dd92ca04ee63c5fe0847b5497bd89b7e7e1bd46194a6a602c30632", 10 | "kdf": "pbkdf2", 11 | "kdfparams": { 12 | "c": 10240, 13 | "dklen": 32, 14 | "prf": "hmac-sha256", 15 | "salt": "416051144ecce708e9250cd077bcd2ec5b0e3b36146b100a7d15ef238caf7d94" 16 | }, 17 | "mac": "ea06d74da6c7c5ea6fe3621e6f6936abedde259a5e6b6ca8caf908cf3e785401" 18 | }, 19 | "pubkey": "9f3f180b63b95559a95735385e35cd973c3d4e9f81bbf0faa61cf6159841feb5", 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 | "pubkey": "800a29dbeab141ada7923517e945bf4594917473809547bc0bb2e47cd39ac94b", 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 | "pubkey": "9f3f180b63b95559a95735385e35cd973c3d4e9f81bbf0faa61cf6159841feb5", 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 | -------------------------------------------------------------------------------- /module/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "codechain-module" 3 | version = "0.1.0" 4 | authors = ["CodeChain Team "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 9 | thiserror = "1.0.15" 10 | linkme = "0.2.1" 11 | once_cell = "1.3.1" 12 | serde = { version = "1.0.105", features = ["derive"] } 13 | serde_cbor = "0.11.1" 14 | erased-serde = "0.3.11" 15 | intertrait = "0.2.0" 16 | remote-trait-object = "0.4.0" 17 | foundry-process-sandbox = { version = "0.2.1", git = "https://github.com/CodeChain-io/foundry-sandbox.git", tag = "v0.2.1" } 18 | foundry-module-rt = { version = "0.2.2", git = "https://github.com/CodeChain-io/module-rt.git", tag = "v0.2.2" } 19 | parking_lot = "0.11.0" 20 | crossbeam = "0.7" 21 | anyhow = "1" 22 | -------------------------------------------------------------------------------- /module/src/impls.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License 15 | // along with this program. If not, see . 16 | 17 | pub mod process; 18 | -------------------------------------------------------------------------------- /module/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate foundry_process_sandbox as fproc_sndbx; 18 | use linkme::distributed_slice; 19 | 20 | pub mod impls; 21 | pub mod link; 22 | pub mod sandbox; 23 | 24 | #[distributed_slice] 25 | pub static MODULE_INITS: [fn()] = [..]; 26 | 27 | pub fn init_modules() { 28 | for init in MODULE_INITS { 29 | init(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /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 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 9 | cio = { package = "codechain-io", path = "../util/io" } 10 | ckey = { package = "codechain-key", path = "../key" } 11 | codechain-logger = { path = "../util/logger" } 12 | cinfo_courier = { package = "codechain_informer_courier", path = "../informer_courier" } 13 | ctimer = { package = "codechain-timer", path = "../util/timer" } 14 | crossbeam-channel = "0.4" 15 | finally-block = "0.1" 16 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 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.5", tag = "v0.5.0"} 24 | rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::net::Ipv4Addr; 18 | 19 | use crate::filters::FilterEntry; 20 | use crate::SocketAddr; 21 | 22 | pub struct Config { 23 | pub address: Ipv4Addr, 24 | pub port: u16, 25 | pub bootstrap_addresses: Vec, 26 | pub min_peers: usize, 27 | pub max_peers: usize, 28 | pub whitelist: Vec, 29 | pub blacklist: Vec, 30 | } 31 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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/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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 | coordinator = { path = "../coordinator" } 12 | codechain-core = { path = "../core" } 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 | kvdb = "0.1" 22 | lazy_static = "1.2" 23 | log = "0.4.6" 24 | parking_lot = "0.11.0" 25 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 26 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 27 | serde = "1.0" 28 | serde_json = "1.0" 29 | serde_derive = "1.0" 30 | rand = "0.6.1" 31 | rustc-hex = "1.0" 32 | rustc-serialize = "0.3" 33 | time = "0.1" 34 | jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 35 | jsonrpc-derive = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 36 | jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 37 | jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 38 | jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.3" } 39 | -------------------------------------------------------------------------------- /rpc/src/v1/impls/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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod chain; 18 | mod devel; 19 | mod mempool; 20 | mod net; 21 | mod snapshot; 22 | 23 | pub use self::chain::ChainClient; 24 | pub use self::devel::DevelClient; 25 | pub use self::mempool::MempoolClient; 26 | pub use self::net::NetClient; 27 | pub use self::snapshot::SnapshotClient; 28 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #[allow(unused)] 18 | mod errors; 19 | mod impls; 20 | mod traits; 21 | #[allow(unused)] 22 | mod types; 23 | 24 | pub use self::impls::*; 25 | pub use self::traits::*; 26 | pub use self::types::Block; 27 | -------------------------------------------------------------------------------- /rpc/src/v1/traits/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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod chain; 18 | mod devel; 19 | mod mempool; 20 | mod net; 21 | mod snapshot; 22 | 23 | pub use self::chain::Chain; 24 | pub use self::devel::Devel; 25 | pub use self::mempool::Mempool; 26 | pub use self::net::Net; 27 | pub use self::snapshot::Snapshot; 28 | -------------------------------------------------------------------------------- /rpc/src/v1/traits/snapshot.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::super::types::BlockNumberAndHash; 18 | use jsonrpc_core::Result; 19 | 20 | #[rpc(server)] 21 | pub trait Snapshot { 22 | /// Gets list of block numbers and block hashes of the snapshots. 23 | #[rpc(name = "snapshot_getList")] 24 | fn get_snapshot_list(&self) -> Result>; 25 | } 26 | -------------------------------------------------------------------------------- /rpc/src/v1/types/action.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::super::errors::ConversionError; 18 | use cjson::uint::Uint; 19 | use ckey::{Error as KeyError, NetworkId, PlatformAddress}; 20 | use ctypes::transaction::{Action as ActionType, Approval}; 21 | use primitives::Bytes; 22 | use rlp::Encodable; 23 | use std::convert::TryFrom; 24 | 25 | #[derive(Debug, Deserialize, Serialize, PartialEq)] 26 | #[serde(rename_all = "camelCase", tag = "type")] 27 | pub enum Action { 28 | } 29 | 30 | impl Action { 31 | pub fn from_core(from: ActionType, network_id: NetworkId) -> Self { 32 | Action 33 | } 34 | } 35 | 36 | impl TryFrom for ActionType { 37 | type Error = ConversionError; 38 | fn try_from(from: Action) -> Result { 39 | Ok(ActionType) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /rpc/src/v1/types/asset_output.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /rpc/src/v1/types/asset_scheme.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use super::super::errors; 18 | use cjson::uint::Uint; 19 | use ckey::NetworkId; 20 | use jsonrpc_core::Error; 21 | use std::convert::{TryFrom, TryInto}; 22 | 23 | #[derive(Debug, Deserialize)] 24 | #[serde(rename_all = "camelCase")] 25 | pub struct UnsignedTransaction { 26 | pub network_id: NetworkId, 27 | } 28 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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.47.0 2 | -------------------------------------------------------------------------------- /spec/Digital-Signature.md: -------------------------------------------------------------------------------- 1 | # Curve 2 | 3 | Foundry uses [Curve25519/Edward25519](https://cr.yp.to/ecdh/curve25519-20060209.pdf) because it provides the efficient algorithms for key exchange and signing. 4 | 5 | # Signature Algorithm 6 | 7 | Foundry uses [Ed25519 signature](https://ed25519.cr.yp.to/ed25519-20110926.pdf) as its digital signature algorithm instead of more conventional ECDSA. Ed25519 scheme is a EdDSA digital signature scheme applied to the Edward25519 elliptic curve. 8 | 9 | Ed25519 signature has a couple of [nice properties](https://ed25519.cr.yp.to/) -------------------------------------------------------------------------------- /spec/Discovery-Extension.md: -------------------------------------------------------------------------------- 1 | * Name := "discovery" 2 | * Version := 0 3 | * Encrypt := optional 4 | 5 | # Messages 6 | 7 | ## Request (->) 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/GraphQL.md: -------------------------------------------------------------------------------- 1 | # GraphQL 2 | 3 | The only interface to access to the running Foundry node is [GraphQL](https://graphql.org/). 4 | There are `N+1` GraphQL endpoints opened in a single Foundry node, where `N` is the modules, and `1` is the consensus engine. 5 | Each can be found in either `localhost:${port}/${module_name}/graphql` or `localhost:${port}/engine/graphql`. 6 | 7 | Queries for modules don't specify the block number by themselves. 8 | You should provide it in the HTTP header if you want to specify the block number. 9 | Use `"number": _` for that. (This is because of federation - tentative) 10 | Note that the latest block will be chosen if you don't specify any. 11 | 12 | You can also use [GraphiQL](https://github.com/graphql/graphiql), an offical IDE for GraphQL. 13 | To access to it, use `/__graphql` instead of `/graphql`. -------------------------------------------------------------------------------- /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/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/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 | # Foundry 2 | Foundry is a framework for building blockchain applications. The goal of the Foundry is to allow developers to easily create custom blockchains from scratch that can natively interoperate with other blockchains. 3 | 4 | # Specification 5 | * [Foundry Address](Foundry-Address.md) 6 | * [Transaction](Transaction.md) 7 | * Network Protocol 8 | * [Session Initiation Protocol](Session-Initiation-Protocol.md) 9 | * [P2P Protocol](P2P-Protocol.md) 10 | * [Network Extension Protocol](Network-Extension-Protocol.md) 11 | * [Node Discovery Protocol](Node-Discovery-Protocol.md) 12 | * [Wire Protocol](Wire-Protocol.md) 13 | * Cryptography 14 | * [Hash Function](Hash-Function.md) 15 | * [Merkle Trie](Merkle-Trie.md) 16 | * [Digital Signature](Digital-Signature.md) 17 | * [JSON RPC](JSON-RPC.md) 18 | * [Stratum](Stratum.md) 19 | * Custom Action 20 | * [Staking](Staking.md) 21 | -------------------------------------------------------------------------------- /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 Ed25519 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 | -------------------------------------------------------------------------------- /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.3", tag = "v0.3.0" } 9 | codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2", tag = "v0.2.0" } 10 | codechain-logger = { path = "../util/logger" } 11 | codechain-key = { path = "../key" } 12 | codechain-types = { path = "../types" } 13 | coordinator = { path = "../coordinator" } 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.1", tag = "v0.4.1" } 19 | parking_lot = "0.11.0" 20 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 21 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 22 | rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 23 | rustc-hex = "1.0" 24 | remote-trait-object = "0.4.2" 25 | 26 | [dev-dependencies] 27 | rand = "0.6.1" 28 | rand_xorshift = "0.1.0" 29 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 module_cache; 24 | mod top_cache; 25 | mod write_back; 26 | 27 | pub use self::global_cache::GlobalCache; 28 | pub use self::module_cache::ModuleCache; 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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-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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 module_level; 21 | mod top_level; 22 | 23 | pub use self::module_level::ModuleLevelState; 24 | pub use self::top_level::TopLevelState; 25 | -------------------------------------------------------------------------------- /state/src/item/mod.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #[macro_use] 18 | mod address; 19 | 20 | pub mod action_data; 21 | pub mod metadata; 22 | pub mod module; 23 | pub mod module_datum; 24 | pub mod stake; 25 | pub mod validator_set; 26 | 27 | #[derive(Clone, Copy)] 28 | #[repr(u8)] 29 | enum Prefix { 30 | Metadata = b'M', 31 | ModuleDatum = b'S', 32 | Module = b'U', 33 | } 34 | -------------------------------------------------------------------------------- /state/src/stake/mod.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use ccrypto::blake256; 18 | use primitives::H256; 19 | use rlp::{Encodable, RlpStream}; 20 | 21 | pub struct StakeKeyBuilder { 22 | rlp: RlpStream, 23 | } 24 | 25 | impl StakeKeyBuilder { 26 | fn prepare() -> StakeKeyBuilder { 27 | let mut rlp = RlpStream::new_list(2); 28 | rlp.append(&"Stake"); 29 | StakeKeyBuilder { 30 | rlp, 31 | } 32 | } 33 | 34 | pub fn new(fragment_length: usize) -> StakeKeyBuilder { 35 | let mut builder = Self::prepare(); 36 | builder.rlp.begin_list(fragment_length); 37 | builder 38 | } 39 | 40 | pub fn append(mut self, e: &E) -> StakeKeyBuilder 41 | where 42 | E: Encodable, { 43 | self.rlp.append(e); 44 | self 45 | } 46 | 47 | pub fn into_key(self) -> H256 { 48 | blake256(self.rlp.as_raw()) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /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.3", tag = "v0.3.0" } 12 | codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2", tag = "v0.2.0" } 13 | coordinator = { path = "../coordinator" } 14 | codechain-key = { path = "../key" } 15 | codechain-logger = { path = "../util/logger" } 16 | codechain-network = { path = "../network" } 17 | codechain-state = { path = "../state" } 18 | codechain-timer = { path = "../util/timer" } 19 | codechain-types = { path = "../types" } 20 | kvdb = "0.1" 21 | log = "0.4.6" 22 | merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.4.1", tag = "v0.4.1" } 23 | never-type = "0.1.0" 24 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 25 | rand = "0.6.1" 26 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 27 | snap = "0.2" 28 | token-generator = "0.1.0" 29 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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, 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 | #[macro_use] 26 | extern crate log; 27 | 28 | mod block; 29 | pub mod snapshot; 30 | mod transaction; 31 | 32 | pub use crate::block::{BlockSyncEvent, BlockSyncExtension, BlockSyncSender}; 33 | pub use crate::transaction::TransactionSyncExtension; 34 | 35 | #[cfg(test)] 36 | extern crate codechain_key as ckey; 37 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | yarn-error.log 3 | keystore.db 4 | yarn.lock 5 | -------------------------------------------------------------------------------- /test/custom.minfee/tccq9td7gtgjhu08ud9hs7uml0pj4lt36mdwyft72tl/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"b61ee760-d106-38b4-7f61-4999364c8d44","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"cef277a5b0b63ac898d8392b859815c1"},"ciphertext":"4fe56e47a5e53e23430782477a8ca1c4d8a7ebdb1af3fb8a54e81ee4f6fb8da3516ae723010d8cd4fa0f34374c73e517bfde210fc198752a99f357ca77f2a076","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"4c78c16d3bd42677f7805c1366e6dfc8a37ac877aa921b2e00bc0a8dd17f043a"},"mac":"05a7054dcbc07a5594d61bd1610fdc00bc932550c6ec311d45250f730b25f314"},"address":"56df216895f8f3f1a5bc3dcdfde1957eb8eb6d71","meta":"{}"} -------------------------------------------------------------------------------- /test/custom.minfee/tccq9td7gtgjhu08ud9hs7uml0pj4lt36mdwyft72tl/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tccq9td7gtgjhu08ud9hs7uml0pj4lt36mdwyft72tl", "password": "" }] 2 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H256 } from "../primitives/src"; 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | import { U256 } from "../primitives/src"; 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H256 } from "../primitives/src"; 18 | import "mocha"; 19 | import { createTestSuite } from "./invalidBlockPropagation.helper"; 20 | 21 | const INVALID_AUTHOR = new H256( 22 | "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 23 | ); 24 | const params = { 25 | tauthor: INVALID_AUTHOR 26 | }; 27 | createTestSuite(3, "OnChain invalid author block propagation test", params); 28 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H256 } from "../primitives/src"; 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | import { H256 } from "../primitives/src"; 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/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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 seal propagation test", params); 25 | -------------------------------------------------------------------------------- /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 | ); 25 | 26 | await mock.end(); 27 | } 28 | 29 | sendBlock(); 30 | -------------------------------------------------------------------------------- /test/src/helper/mock/example/send-tx.ts: -------------------------------------------------------------------------------- 1 | import { Mock } from ".."; 2 | import { SDK } from "../../../sdk"; 3 | 4 | async function sendTransaction() { 5 | const mock = new Mock("0.0.0.0", 3485, "tc"); 6 | mock.setLog(); 7 | await mock.establish(); 8 | 9 | const sdk = new SDK({ 10 | networkId: process.env.CODECHAIN_NETWORK_ID || "tc" 11 | }); 12 | const ACCOUNT_SECRET = 13 | process.env.ACCOUNT_SECRET || 14 | "9af28f6fd6a1170dbee2cb8c34abab0408e6d811d212cdcde23f72473eb0d97ad7a6d266837c1c591383b90d835068b9ed58dd3bcebd6e285911f58e40ce413c"; 15 | const unsigned = sdk.core.createPayTransaction({ 16 | recipient: "fys3db1kOrI_rXyaTx9U2_RP-SlNK1q0LRXxYeQGBI1av35drZQtc0", 17 | quantity: 10000 18 | }); 19 | const signed = unsigned.sign({ 20 | secret: ACCOUNT_SECRET, 21 | fee: 10, 22 | seq: 0 23 | }); 24 | 25 | await mock.sendEncodedTransaction([signed.toEncodeObject()]); 26 | 27 | await mock.end(); 28 | } 29 | sendTransaction(); 30 | -------------------------------------------------------------------------------- /test/src/helper/mock/test/blockSyncMessage.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { U256 } from "../../../primitives/src"; 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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/src/primitives/README.md: -------------------------------------------------------------------------------- 1 | # foundry-primitives-js [![Build Status](https://travis-ci.org/CodeChain-io/foundry-primitives-js.svg?branch=master)](https://travis-ci.org/CodeChain-io/foundry-primitives-js) 2 | 3 | JavaScript functions and classes for Foundry primitives 4 | 5 | ## Installing a package 6 | 7 | ```sh 8 | # npm 9 | npm install foundry-primitives 10 | # yarn 11 | yarn add foundry-primitives 12 | ``` 13 | 14 | ## Getting started 15 | 16 | ```javascript 17 | // Using require 18 | var primitives = require("foundry-primitives"); 19 | var H256 = primitives.H256; 20 | var blake256 = primitives.blake256; 21 | 22 | // Using import 23 | import { blake256, H256 } from "foundry-primitives"; 24 | ``` 25 | 26 | ## Functions 27 | 28 | - blake256 29 | - blake256WithKey 30 | - ripemd160 31 | - signEd25519 32 | - verifyEd25519 33 | - generatePrivateKey 34 | - getPublicFromPrivate 35 | - toHex 36 | - toArray 37 | - getAccountIdFromPrivate 38 | - getAccountIdFromPublic 39 | 40 | ## Classes 41 | 42 | - H128, H256, H512 43 | - U64, U128, U256 44 | - Address 45 | 46 | ## API Documentation 47 | 48 | [https://codechain-io.github.io/foundry-primitives-js](https://codechain-io.github.io/foundry-primitives-js) 49 | -------------------------------------------------------------------------------- /test/src/primitives/src/address/checksum.ts: -------------------------------------------------------------------------------- 1 | import { H256 } from ".."; 2 | 3 | /** 4 | * @hidden 5 | */ 6 | const ALPHABET = "0123456789bcdefghjkmnpqrstuvwxyz"; 7 | 8 | // FIXME: any 9 | /** 10 | * @hidden 11 | */ 12 | function convert(data: number[], inBits: number, outBits: number): number[] { 13 | let value = 0; 14 | let bits = 0; 15 | const maxV = (1 << outBits) - 1; 16 | 17 | const result = []; 18 | for (const datum of data) { 19 | value = (value << inBits) | datum; 20 | bits += inBits; 21 | 22 | while (bits >= outBits) { 23 | bits -= outBits; 24 | result.push((value >> bits) & maxV); 25 | } 26 | } 27 | 28 | if (bits > 0) { 29 | result.push((value << (outBits - bits)) & maxV); 30 | } 31 | 32 | return result; 33 | } 34 | 35 | // FIXME: any 36 | /** 37 | * @hidden 38 | */ 39 | export function calculate( 40 | pubkey: H256, 41 | networkId: string, 42 | version: number 43 | ): string { 44 | const bytes = [0, 0, 0, 0, 0]; 45 | const pubkeyHex = Buffer.from(pubkey.value, "hex"); 46 | for (let i = 0; i < 6; i += 1) { 47 | for (let j = 0; j < 5; j += 1) { 48 | bytes[j] ^= pubkeyHex[i * 5 + j]; 49 | } 50 | } 51 | 52 | bytes[3] ^= pubkeyHex[30]; 53 | bytes[4] ^= pubkeyHex[31]; 54 | 55 | bytes[0] ^= networkId.charCodeAt(0); 56 | bytes[1] ^= networkId.charCodeAt(1); 57 | bytes[2] ^= version; 58 | 59 | const rearranged = convert(bytes, 8, 5); 60 | return "".concat(...rearranged.map(code => ALPHABET.charAt(code))); 61 | } 62 | -------------------------------------------------------------------------------- /test/src/primitives/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Address, AddressValue } from "./address/address"; 2 | 3 | export { H128, H128Value } from "./value/H128"; 4 | export { H256, H256Value } from "./value/H256"; 5 | export { H512, H512Value } from "./value/H512"; 6 | 7 | export { U64, U64Value } from "./value/U64"; 8 | export { U128, U128Value } from "./value/U128"; 9 | export { U256, U256Value } from "./value/U256"; 10 | 11 | export { 12 | blake128, 13 | blake128WithKey, 14 | blake160, 15 | blake160WithKey, 16 | blake256, 17 | blake256WithKey, 18 | ripemd160 19 | } from "./hash"; 20 | 21 | export { generatePrivateKey, getPublicFromPrivate } from "./key/key"; 22 | export { 23 | exchange, 24 | x25519GetPublicFromPrivate, 25 | X25519Private, 26 | X25519Public 27 | } from "./key/keyExchange"; 28 | export { Ed25519Signature, signEd25519, verifyEd25519 } from "./key/ed25519"; 29 | 30 | export { toHex, toArray, toLocaleString } from "./utility"; 31 | -------------------------------------------------------------------------------- /test/src/primitives/src/key/ed25519.ts: -------------------------------------------------------------------------------- 1 | import * as _ from "lodash"; 2 | import nacl = require("tweetnacl"); 3 | import { toArray, toHex } from "../utility"; 4 | 5 | export type Ed25519Signature = string; 6 | 7 | /** 8 | * Gets EdDSA(Ed25519) signature for message from private key. 9 | * @param message 32 byte hexadecimal string 10 | * @param priv 64 byte hexadecimal string of private key 11 | * @returns 64 byte hexadecimal string of Ed25519 signature 12 | */ 13 | export const signEd25519 = ( 14 | message: string, 15 | priv: string 16 | ): Ed25519Signature => { 17 | return toHex( 18 | Buffer.from(nacl.sign.detached(toArray(message), toArray(priv))) 19 | ); 20 | }; 21 | 22 | /** 23 | * Checks if the signature from signEd25519 is valid. 24 | * @param message 32 byte hexadecimal string 25 | * @param signature 64 byte hexadecimal string of Ed25519 signature 26 | * @param pub 32 byte hexadecimal string of public key 27 | * @returns if signature is valid, true. Else false. 28 | */ 29 | export const verifyEd25519 = ( 30 | message: string, 31 | signature: Ed25519Signature, 32 | pub: string 33 | ): boolean => { 34 | return nacl.sign.detached.verify( 35 | toArray(message), 36 | toArray(signature), 37 | toArray(pub) 38 | ); 39 | }; 40 | -------------------------------------------------------------------------------- /test/src/primitives/src/key/key.ts: -------------------------------------------------------------------------------- 1 | import nacl = require("tweetnacl"); 2 | import { toArray, toHex } from "../utility"; 3 | 4 | /** 5 | * Generates a private key. 6 | * @returns 64 byte hexadecimal string of private key 7 | */ 8 | export const generatePrivateKey = (): string => { 9 | return toHex(Buffer.from(nacl.sign.keyPair().secretKey)); 10 | }; 11 | 12 | /** 13 | * Gets public key from private key. 14 | * @param priv 64 byte hexadecimal string of private key 15 | * @returns 32 byte hexadecimal string of public key 16 | */ 17 | export const getPublicFromPrivate = (priv: string): string => { 18 | return toHex( 19 | Buffer.from(nacl.sign.keyPair.fromSecretKey(toArray(priv)).publicKey) 20 | ); 21 | }; 22 | -------------------------------------------------------------------------------- /test/src/primitives/src/key/keyExchange.ts: -------------------------------------------------------------------------------- 1 | import { toArray, toHex } from "../utility"; 2 | 3 | /** 4 | * @hidden 5 | */ 6 | const nacl = require("tweetnacl"); 7 | 8 | export type X25519Public = string; 9 | export type X25519Private = string; 10 | 11 | /** 12 | * Gets an ECDH session key for encryption and decryption between two parties 13 | * @param otherPublic 32 byte hexadecimal string of the other side public key 14 | * @param myPrivate 32 byte hexadecimal string of my side private key 15 | * @returns 32 byte hexadecimal string of the shared secret 16 | */ 17 | export const exchange = ( 18 | otherPublic: X25519Public, 19 | myPrivate: X25519Private 20 | ): string => { 21 | const groupElement = toArray(otherPublic); 22 | const scalar = toArray(myPrivate); 23 | const sharedSecret = nacl.scalarMult(scalar, groupElement); 24 | return toHex(sharedSecret); 25 | }; 26 | 27 | /** 28 | * Gets the X25519 public key(on Curve25519) for a private key 29 | * @param x25519Private 32 byte hexadecimal string of a secret key 30 | * @returns 32 byte hexadecimal string of the public key 31 | */ 32 | export const x25519GetPublicFromPrivate = (x25519Private: string): string => { 33 | const scalar = toArray(x25519Private); 34 | const x25519Public = nacl.scalarMult.base(scalar); 35 | return toHex(x25519Public); 36 | }; 37 | -------------------------------------------------------------------------------- /test/src/primitives/src/utility.ts: -------------------------------------------------------------------------------- 1 | import BigNumber from "bignumber.js"; 2 | 3 | /** 4 | * @hidden 5 | */ 6 | const toHexByte = (byte: number) => 7 | byte < 0x10 ? `0${byte.toString(16)}` : byte.toString(16); 8 | 9 | /** 10 | * Converts buffer to hexadecimal string. 11 | * @param buffer arbritrary length of data 12 | * @returns hexadecimal string 13 | */ 14 | export const toHex = (buffer: Buffer): string => { 15 | return Array.from(buffer) 16 | .map(toHexByte) 17 | .join(""); 18 | }; 19 | 20 | /** 21 | * Converts hexadecimal string to Uint8Array. 22 | * @param string arbritrary length of data 23 | * @returns Uint8Array 24 | */ 25 | export const toArray = (hex: string): Uint8Array => { 26 | return Uint8Array.from(Buffer.from(hex, "hex")); 27 | }; 28 | 29 | /** 30 | * Converts BigNumber to formatted number string 31 | * Default decimalSeparator is point: "." 32 | * Default groupSeparator is comma; "," 33 | * Default groupSize is 3 34 | * @param num BigNumber object 35 | * @returns formatted number string 36 | */ 37 | export const toLocaleString = (num: BigNumber): string => { 38 | return num.toFormat(); 39 | }; 40 | -------------------------------------------------------------------------------- /test/src/primitives/test/keyExchange.test.ts: -------------------------------------------------------------------------------- 1 | import { exchange, x25519GetPublicFromPrivate } from "../src"; 2 | import "mocha"; 3 | import { expect } from "chai"; 4 | 5 | describe("exchange", () => { 6 | // The testing oracle is generated from "libsodium-wrappers" 7 | const AliceX25519Sk = 8 | "49023b9f7f997d3c8f1763f762a2f79d3d0fc5d4204ee25bf05ef57ca190d91b"; 9 | const AliceX25519Pk = 10 | "687d59b5c23877b6e822e3459d5a9a45e801a6a3752cdada2dfa7c76eaadb36f"; 11 | const BobX25519Pk = 12 | "f039531944bb30f89df41dedfb3ae1a385bc3052bec473060a57f3b2ec248c64"; 13 | const BobX25519Sk = 14 | "e16af6bbf808b73137ec93b7d26ec2ca59e8e5367ced0cbee11553e8b316a564"; 15 | 16 | const shared_secret = 17 | "3e57e4716cbb9ffbcedce8c9b1516fe8b43dd6688020523b62e9142fc2cc5879"; 18 | 19 | it("Alice-side", () => { 20 | expect(exchange(BobX25519Pk, AliceX25519Sk)).equal(shared_secret); 21 | }); 22 | 23 | it("Bob-side", () => { 24 | expect(exchange(AliceX25519Pk, BobX25519Sk)).equal(shared_secret); 25 | }); 26 | }); 27 | 28 | it("x25519GetPublicFromPrivate", () => { 29 | // The testing oracle is generated from "libsodium-wrappers" 30 | const x25519Sk = 31 | "49023b9f7f997d3c8f1763f762a2f79d3d0fc5d4204ee25bf05ef57ca190d91b"; 32 | const x25519Pk = 33 | "687d59b5c23877b6e822e3459d5a9a45e801a6a3752cdada2dfa7c76eaadb36f"; 34 | 35 | expect(x25519GetPublicFromPrivate(x25519Sk)).equal(x25519Pk); 36 | }); 37 | -------------------------------------------------------------------------------- /test/src/primitives/test/utility.test.ts: -------------------------------------------------------------------------------- 1 | import BigNumber from "bignumber.js"; 2 | import { 3 | generatePrivateKey, 4 | getPublicFromPrivate, 5 | toHex, 6 | toLocaleString 7 | } from "../src"; 8 | import "mocha"; 9 | import { expect } from "chai"; 10 | 11 | ([ 12 | [[0x00, 0x01, 0x02], "000102"], 13 | [[0xff, 0xfe, 0xfd], "fffefd"], 14 | [[0xde, 0xad, 0xbe, 0xef], "deadbeef"], 15 | [[0x62, 0x75, 0x66, 0x66, 0x65, 0x72], "627566666572"] 16 | ] as [number[], string][]).forEach(args => { 17 | const [input, output] = args; 18 | it(`toHex ${input} ${output}`, () => { 19 | const buffer = new Buffer(input); 20 | expect(toHex(buffer)).equal(output); 21 | }); 22 | }); 23 | 24 | it("getPublicFromPrivate", () => { 25 | const priv = generatePrivateKey(); 26 | const pubkey = getPublicFromPrivate(priv); 27 | expect(/^[0-9a-fA-F]{64}$/.test(pubkey)).true; 28 | }); 29 | 30 | it("toLocaleString", () => { 31 | expect(toLocaleString(new BigNumber(1234567))).equal("1,234,567"); 32 | expect(toLocaleString(new BigNumber(123))).equal("123"); 33 | expect( 34 | toLocaleString(new BigNumber("1234123412341234.1234123412341234")) 35 | ).equal("1,234,123,412,341,234.1234123412341234"); 36 | expect(toLocaleString(new BigNumber("-1234234.234134234"))).equal( 37 | "-1,234,234.234134234" 38 | ); 39 | }); 40 | -------------------------------------------------------------------------------- /test/src/scheme/mempool.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Solo" 3 | } 4 | -------------------------------------------------------------------------------- /test/src/scheme/solo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Solo", 3 | "genesis": { 4 | "seal": { 5 | "generic": "0x0" 6 | }, 7 | "author": "fjjh0000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtc0", 8 | "timestamp": "0x00", 9 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 10 | "extraData": "0x" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/src/scheme/tendermint-int.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Tendermint", 3 | "genesis": { 4 | "seal": { 5 | "tendermint": { 6 | "prev_view": "0x0", 7 | "cur_view": "0x0", 8 | "precommits": [ 9 | "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 10 | ] 11 | } 12 | }, 13 | "author": "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0", 14 | "timestamp": "0x00", 15 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 16 | "extraData": "0x" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/src/scheme/tendermint-tps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Tendermint", 3 | "genesis": { 4 | "seal": { 5 | "tendermint": { 6 | "prev_view": "0x0", 7 | "cur_view": "0x0", 8 | "precommits": [ 9 | "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 10 | ] 11 | } 12 | }, 13 | "author": "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0", 14 | "timestamp": "0x00", 15 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 16 | "extraData": "0x" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/src/sdk/__test__/blake.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import "mocha"; 3 | import { blake256 } from "../utils"; 4 | 5 | it("result of blake256 is 64 hex decimal", () => { 6 | const hash = blake256("some string"); 7 | expect(hash.length).to.equal(64); 8 | }); 9 | -------------------------------------------------------------------------------- /test/src/sdk/core/Text.ts: -------------------------------------------------------------------------------- 1 | import { Address } from "../../primitives/src"; 2 | 3 | export interface TextJSON { 4 | content: string; 5 | certifier: string; 6 | } 7 | 8 | /** 9 | * Object used when getting a text by chain_getText. 10 | */ 11 | export class Text { 12 | public static fromJSON(data: TextJSON) { 13 | const { content, certifier } = data; 14 | return new Text({ 15 | content, 16 | certifier: Address.ensure(certifier) 17 | }); 18 | } 19 | 20 | public readonly content: string; 21 | public readonly certifier: Address; 22 | 23 | constructor(data: { content: string; certifier: Address }) { 24 | const { content, certifier } = data; 25 | this.content = content; 26 | this.certifier = certifier; 27 | } 28 | 29 | public toJSON(): TextJSON { 30 | const { content, certifier } = this; 31 | return { 32 | content, 33 | certifier: certifier.value 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/src/sdk/core/classes.ts: -------------------------------------------------------------------------------- 1 | import { H128, H128Value } from "../../primitives/src"; 2 | export { H256, H256Value } from "../../primitives/src"; 3 | export { H512, H512Value } from "../../primitives/src"; 4 | export { U64, U64Value } from "../../primitives/src"; 5 | export { U256, U256Value } from "../../primitives/src"; 6 | 7 | export { Block } from "./Block"; 8 | export { Transaction } from "./Transaction"; 9 | export { SignedTransaction } from "./SignedTransaction"; 10 | 11 | export { Pay } from "./transaction/Pay"; 12 | 13 | export { Address, AddressValue } from "../../primitives/src"; 14 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/ChangeParams.ts: -------------------------------------------------------------------------------- 1 | import { U64 } from "../classes"; 2 | import { Transaction } from "../Transaction"; 3 | import { NetworkId } from "../types"; 4 | 5 | export interface ChangeParamsActionJSON { 6 | metadataSeq: string; 7 | params: (number | string)[]; 8 | approvals: any[]; 9 | } 10 | 11 | export class ChangeParams extends Transaction { 12 | private readonly metadataSeq: U64; 13 | private readonly params: (number | string)[]; 14 | private readonly approvals: any[]; 15 | 16 | public constructor( 17 | metadataSeq: U64, 18 | params: (number | string)[], 19 | approvals: any[], 20 | networkId: NetworkId 21 | ) { 22 | super(networkId); 23 | this.metadataSeq = metadataSeq; 24 | this.approvals = approvals; 25 | this.params = params; 26 | } 27 | 28 | public type(): string { 29 | return "changeParams"; 30 | } 31 | 32 | protected actionToEncodeObject(): any[] { 33 | return [ 34 | 0xff, 35 | this.metadataSeq.toEncodeObject(), 36 | this.params, 37 | ...this.approvals 38 | ]; 39 | } 40 | 41 | protected actionToJSON(): ChangeParamsActionJSON { 42 | return { 43 | metadataSeq: this.metadataSeq.toJSON(), 44 | params: this.params, 45 | approvals: this.approvals 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/DelegateCCS.ts: -------------------------------------------------------------------------------- 1 | import { Address, U64 } from "../classes"; 2 | import { Transaction } from "../Transaction"; 3 | import { NetworkId } from "../types"; 4 | 5 | export interface DelegateCCSActionJSON { 6 | address: string; 7 | quantity: string; 8 | } 9 | 10 | export class DelegateCCS extends Transaction { 11 | private readonly address: Address; 12 | private readonly quantity: U64; 13 | 14 | public constructor(address: Address, quantity: U64, networkId: NetworkId) { 15 | super(networkId); 16 | this.address = address; 17 | this.quantity = quantity; 18 | } 19 | 20 | public type(): string { 21 | return "delegateCCS"; 22 | } 23 | 24 | protected actionToEncodeObject(): any[] { 25 | return [ 26 | 0x22, 27 | this.address.getPubKey().toEncodeObject(), 28 | this.quantity.toEncodeObject() 29 | ]; 30 | } 31 | 32 | protected actionToJSON(): DelegateCCSActionJSON { 33 | return { 34 | address: this.address.value, 35 | quantity: this.quantity.toJSON() 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/Pay.ts: -------------------------------------------------------------------------------- 1 | import { Address, U64 } from "../classes"; 2 | import { Transaction } from "../Transaction"; 3 | import { NetworkId } from "../types"; 4 | 5 | export interface PayActionJSON { 6 | receiver: string; 7 | quantity: string; 8 | } 9 | 10 | export class Pay extends Transaction { 11 | private readonly receiver: Address; 12 | private readonly quantity: U64; 13 | 14 | public constructor(receiver: Address, quantity: U64, networkId: NetworkId) { 15 | super(networkId); 16 | this.receiver = receiver; 17 | this.quantity = quantity; 18 | } 19 | 20 | public type(): string { 21 | return "pay"; 22 | } 23 | 24 | protected actionToEncodeObject(): any[] { 25 | return [ 26 | 2, 27 | this.receiver.getPubKey().toEncodeObject(), 28 | this.quantity.toEncodeObject() 29 | ]; 30 | } 31 | 32 | protected actionToJSON(): PayActionJSON { 33 | return { 34 | receiver: this.receiver.value, 35 | quantity: this.quantity.toJSON() 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/Redelegate.ts: -------------------------------------------------------------------------------- 1 | import { Address, U64 } from "../classes"; 2 | import { Transaction } from "../Transaction"; 3 | import { NetworkId } from "../types"; 4 | 5 | export interface RedelegateActionJSON { 6 | prevDelegator: string; 7 | nextDelegator: string; 8 | quantity: string; 9 | } 10 | 11 | export class Redelegate extends Transaction { 12 | private readonly prevDelegator: Address; 13 | private readonly nextDelegator: Address; 14 | private readonly quantity: U64; 15 | 16 | public constructor( 17 | prevDelegator: Address, 18 | nextDelegator: Address, 19 | quantity: U64, 20 | networkId: NetworkId 21 | ) { 22 | super(networkId); 23 | this.prevDelegator = prevDelegator; 24 | this.nextDelegator = nextDelegator; 25 | this.quantity = quantity; 26 | } 27 | 28 | public type(): string { 29 | return "redelegate"; 30 | } 31 | 32 | protected actionToEncodeObject(): any[] { 33 | return [ 34 | 0x26, 35 | this.prevDelegator.getPubKey().toEncodeObject(), 36 | this.nextDelegator.getPubKey().toEncodeObject(), 37 | this.quantity.toEncodeObject() 38 | ]; 39 | } 40 | 41 | protected actionToJSON(): RedelegateActionJSON { 42 | return { 43 | prevDelegator: this.prevDelegator.value, 44 | nextDelegator: this.nextDelegator.value, 45 | quantity: this.quantity.toJSON() 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/ReportDoubleVote.ts: -------------------------------------------------------------------------------- 1 | import { Transaction } from "../Transaction"; 2 | import { NetworkId } from "../types"; 3 | 4 | export interface ReportDoubleVoteActionJSON { 5 | message1: number[]; 6 | message2: number[]; 7 | } 8 | 9 | export class ReportDoubleVote extends Transaction { 10 | private readonly message1: Buffer; 11 | private readonly message2: Buffer; 12 | 13 | public constructor( 14 | message1: Buffer, 15 | message2: Buffer, 16 | networkId: NetworkId 17 | ) { 18 | super(networkId); 19 | this.message1 = message1; 20 | this.message2 = message2; 21 | } 22 | 23 | public type(): string { 24 | return "reportDoubleVote"; 25 | } 26 | 27 | protected actionToEncodeObject(): any[] { 28 | return [0x25, this.message1, this.message2]; 29 | } 30 | 31 | protected actionToJSON(): ReportDoubleVoteActionJSON { 32 | return { 33 | message1: [...this.message1], 34 | message2: [...this.message2] 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/Revoke.ts: -------------------------------------------------------------------------------- 1 | import { Address, U64 } from "../classes"; 2 | import { Transaction } from "../Transaction"; 3 | import { NetworkId } from "../types"; 4 | 5 | export interface RevokeActionJSON { 6 | address: string; 7 | quantity: string; 8 | } 9 | 10 | export class Revoke extends Transaction { 11 | private readonly address: Address; 12 | private readonly quantity: U64; 13 | 14 | public constructor(address: Address, quantity: U64, networkId: NetworkId) { 15 | super(networkId); 16 | this.address = address; 17 | this.quantity = quantity; 18 | } 19 | 20 | public type(): string { 21 | return "revoke"; 22 | } 23 | 24 | protected actionToEncodeObject(): any[] { 25 | return [ 26 | 0x23, 27 | this.address.getPubKey().toEncodeObject(), 28 | this.quantity.toEncodeObject() 29 | ]; 30 | } 31 | 32 | protected actionToJSON(): RevokeActionJSON { 33 | return { 34 | address: this.address.value, 35 | quantity: this.quantity.toJSON() 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/SelfNominate.ts: -------------------------------------------------------------------------------- 1 | import { U64 } from "../classes"; 2 | import { Transaction } from "../Transaction"; 3 | import { NetworkId } from "../types"; 4 | 5 | export interface SelfNominateActionJSON { 6 | deposit: string; 7 | metadata: number[]; 8 | } 9 | 10 | export class SelfNominate extends Transaction { 11 | private readonly deposit: U64; 12 | private readonly metadata: Buffer; 13 | 14 | public constructor(deposit: U64, metadata: Buffer, networkId: NetworkId) { 15 | super(networkId); 16 | this.deposit = deposit; 17 | this.metadata = metadata; 18 | } 19 | 20 | public type(): string { 21 | return "selfNominate"; 22 | } 23 | 24 | protected actionToEncodeObject(): any[] { 25 | return [0x24, this.deposit.toEncodeObject(), this.metadata]; 26 | } 27 | 28 | protected actionToJSON(): SelfNominateActionJSON { 29 | return { 30 | deposit: this.deposit.toJSON(), 31 | metadata: [...this.metadata] 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/src/sdk/core/transaction/TransferCCS.ts: -------------------------------------------------------------------------------- 1 | import { Address, U64 } from "../classes"; 2 | import { Transaction } from "../Transaction"; 3 | import { NetworkId } from "../types"; 4 | 5 | export interface TransferCCSActionJSON { 6 | address: string; 7 | quantity: string; 8 | } 9 | 10 | export class TransferCCS extends Transaction { 11 | private readonly address: Address; 12 | private readonly quantity: U64; 13 | 14 | public constructor(address: Address, quantity: U64, networkId: NetworkId) { 15 | super(networkId); 16 | this.address = address; 17 | this.quantity = quantity; 18 | } 19 | 20 | public type(): string { 21 | return "transferCCS"; 22 | } 23 | 24 | protected actionToEncodeObject(): any[] { 25 | return [ 26 | 0x21, 27 | this.address.getPubKey().toEncodeObject(), 28 | this.quantity.toEncodeObject() 29 | ]; 30 | } 31 | 32 | protected actionToJSON(): TransferCCSActionJSON { 33 | return { 34 | address: this.address.value, 35 | quantity: this.quantity.toJSON() 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/src/sdk/core/types.ts: -------------------------------------------------------------------------------- 1 | import { U64 } from "../../primitives/src"; 2 | 3 | export type NetworkId = string; 4 | 5 | export interface CommonParams { 6 | maxExtraDataSize: U64; 7 | networkID: NetworkId; 8 | maxBodySize: U64; 9 | snapshotPeriod: U64; 10 | } 11 | -------------------------------------------------------------------------------- /test/src/sdk/key/KeyStore.ts: -------------------------------------------------------------------------------- 1 | export interface KeyManagementAPI { 2 | getKeyList(): Promise; 3 | createKey(params?: { passphrase?: string }): Promise; 4 | removeKey(params: { key: string }): Promise; 5 | exportRawKey(params: { key: string; passphrase?: string }): Promise; 6 | getPublicKey(params: { 7 | key: string; 8 | passphrase?: string; 9 | }): Promise; 10 | sign(params: { 11 | key: string; 12 | message: string; 13 | passphrase?: string; 14 | }): Promise; 15 | } 16 | 17 | export type KeyStore = KeyManagementAPI; 18 | -------------------------------------------------------------------------------- /test/src/sdk/key/classes.ts: -------------------------------------------------------------------------------- 1 | export { RemoteKeyStore } from "./RemoteKeyStore"; 2 | export { LocalKeyStore } from "./LocalKeyStore"; 3 | -------------------------------------------------------------------------------- /test/tendermint.dynval/74ft6vs4-6hnNHtCB4Drxl25ZZEi0i0pDf-daeZMq-Ys3kgqKOUtc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"2102a483-94ed-14bc-9b8a-22c02add4e90","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"643fb412584d538a73e99a38de1f4ff7"},"ciphertext":"e0e565dfe5b4a5003d887cbd9121c29f9da209a0da04eb0ec34a12bf6437880f65c0e8a6465965adaf5c4d8a614589e17d3ae89c94d03dfc0e927ac7a414e040","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"53c53fe01110aed3e35dc7ce8874e4af57e09b0f910fb5ede6d4ff69d52d8adc"},"mac":"b58cce0c57a141dfd12b08e12c3686d9c84b0a769b8415d99bcd555cc9d10551"},"pubkey":"fba867347b420780ebc65db9659122d22d290dff9d69e64cabe62cde482a28e5","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/74ft6vs4-6hnNHtCB4Drxl25ZZEi0i0pDf-daeZMq-Ys3kgqKOUtc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "74ft6vs4-6hnNHtCB4Drxl25ZZEi0i0pDf-daeZMq-Ys3kgqKOUtc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/7zfgtdtf43Cq3OiFal90JIQBg2MbmaJMqrfQpQ98qOCjyR-BsWctc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"1c699a6d-8f88-922d-66b6-97698656c485","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"e17bcd2348c62ca8d2b8c6435731a34d"},"ciphertext":"3423217c8dd69c458354e70b24ea92e71be8fc9676c4ef04e73395f49966e54ecda3908f0523dfc85582b5d04cb4c66bf464a21bdf7698721f78445bbac18483","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"e637c490e94a1565c8f8acce28f80687617c89d7b880b6cefa0f5ab31a0c2451"},"mac":"1492786387a6b229d71cd6c66e212093b9cb0df38bd74a291faa0ad13045b4eb"},"pubkey":"e370aadce8856a5f7424840183631b99a24caab7d0a50f7ca8e0a3c91f81b167","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/7zfgtdtf43Cq3OiFal90JIQBg2MbmaJMqrfQpQ98qOCjyR-BsWctc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "7zfgtdtf43Cq3OiFal90JIQBg2MbmaJMqrfQpQ98qOCjyR-BsWctc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/8y5y8f2cmHGhSPvEdPgq0ckxQLmiS3wuiUQViBa6tvgoxfRQJGEtc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"330d749b-f40b-78ff-b732-ee355ed04575","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"02af34cb9888b7f4c9bd95b20524653b"},"ciphertext":"4738a1efa05efef46092318b6bd202513c7730ca91b9570acffb7a568d837d201c89bf0d9bf6e10e21539e1c91af482d633b34a5c745c4053ef216cafc944d0a","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"8c678c237dcf5067b81f07952f6e70f967bf2d8d6c731ff700ec8e3192a55698"},"mac":"31075a62dec88c7e76e677711dd5722c7e80db6e638c9eba728f36896383e855"},"pubkey":"9871a148fbc474f82ad1c93140b9a24b7c2e8944158816bab6f828c5f4502461","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/8y5y8f2cmHGhSPvEdPgq0ckxQLmiS3wuiUQViBa6tvgoxfRQJGEtc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "8y5y8f2cmHGhSPvEdPgq0ckxQLmiS3wuiUQViBa6tvgoxfRQJGEtc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/9w0t888bwJQ6KiY1g16erHoJXsZYBRkMDf6t2q0g8By_DykEV9Itc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"3140e9a4-29bc-0ef1-bcce-bd20ed66224f","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"0663329316ef8d96f537d3a67727bbb7"},"ciphertext":"2ff99801f9cd12037bd95453aabd61b767ee79b3396d74ffacc119fe6c8b70944d4898e9f38259ca0637fb9c6bb711d871664776a3985d6b9fedb2a277e253a9","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"090db7b7d11f1efac2ed9b7b4fd0ad67326db1e49e159f4736b3c65b5b19ac1a"},"mac":"6f1c6754091bedbdbbaba859822e26ea9b3bc4d953f367cae293bef85a4d8ab9"},"pubkey":"c0943a2a2635835e9eac7a095ec65805190c0dfeaddaad20f01cbf0f290457d2","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/9w0t888bwJQ6KiY1g16erHoJXsZYBRkMDf6t2q0g8By_DykEV9Itc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "9w0t888bwJQ6KiY1g16erHoJXsZYBRkMDf6t2q0g8By_DykEV9Itc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/be408xc5EctYW80ArkfkEEdJh9TYEp3hMF1I1Yhr5itP9Q8oSvMtc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"b61ee760-d106-38b4-7f61-4999364c8d44","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"cef277a5b0b63ac898d8392b859815c1"},"ciphertext":"4fe56e47a5e53e23430782477a8ca1c4d8a7ebdb1af3fb8a54e81ee4f6fb8da3516ae723010d8cd4fa0f34374c73e517bfde210fc198752a99f357ca77f2a076","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"4c78c16d3bd42677f7805c1366e6dfc8a37ac877aa921b2e00bc0a8dd17f043a"},"mac":"05a7054dcbc07a5594d61bd1610fdc00bc932550c6ec311d45250f730b25f314"},"pubkey":"11cb585bcd00ae47e410474987d4d8129de1305d48d5886be62b4ff50f284af3","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/be408xc5EctYW80ArkfkEEdJh9TYEp3hMF1I1Yhr5itP9Q8oSvMtc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "be408xc5EctYW80ArkfkEEdJh9TYEp3hMF1I1Yhr5itP9Q8oSvMtc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/brnv7hjvbOFhgKognQNJ-OtnAs9dBh6Bhe9upHKNhu4rIKhQZA0tc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"349974d7-b3b8-c3f5-47cc-f27ff53d0b93","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"55d96f79303d9d49df807ced0b81a323"},"ciphertext":"3dce6970e40c3046fe37031c5d433c09315d09f31697c0c9785538bb7dd236e6ac521d06b47e17320f831bbe6e972d44408977e810b71109a7f4ecca885ff98f","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"421ef9d102f7b936702af38962cf84a4f31a3449f022b02cd12548b7573edb03"},"mac":"ec02cee38d3f533bf0ed84e25640cda369175cd69b670086a88fdef2b7132c25"},"pubkey":"6ce16180aa209d0349f8eb6702cf5d061e8185ef6ea4728d86ee2b20a850640d","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/brnv7hjvbOFhgKognQNJ-OtnAs9dBh6Bhe9upHKNhu4rIKhQZA0tc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "brnv7hjvbOFhgKognQNJ-OtnAs9dBh6Bhe9upHKNhu4rIKhQZA0tc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/ejr942sfGmscSzhJgY2GDHm7B6dIJo_oa67IisBx2dxZLCG6Wr8tc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"b07fa3ed-22bd-a600-427e-d5f74f66b037","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"d4afbbcaaf029a9260b9a8c51f79bff5"},"ciphertext":"af10d0e0117ab5ac24bec71a7d63bf82163a863274f0d2e7e677b6fe246223b9d2e4784773601a3a11679c7f716656f2bd5742416e0e8ab3fbc33d3479ae211f","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"542aeae65caeeaf790e92188f46b9d33efdb1d102ba98ddad1746efb2df49972"},"mac":"cc06f1c244fe17ad0dc874cbdaffa7a87b46ab2da425085d43cdf9e78c40964c"},"pubkey":"1a6b1c4b3849818d860c79bb07a748268fe86baec88ac071d9dc592c21ba5abf","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/ejr942sfGmscSzhJgY2GDHm7B6dIJo_oa67IisBx2dxZLCG6Wr8tc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "ejr942sfGmscSzhJgY2GDHm7B6dIJo_oa67IisBx2dxZLCG6Wr8tc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/rn3rnhr3s9Q_CLfiEx3HrRuSnXTDsteFheb2XqKG2Me44sESOxYtc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"2bbbb44f-86a4-9600-5ed8-9f45ad83f9ae","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"7a919c7b7b653dab8c713bf29e13e280"},"ciphertext":"818aed16953abb79a0c30d804ce48d60b1fb335105e67785f00770d352ef1628343ddccb3a12837687b3d2d00cd63a4ce77d21dd87cb1612dc151dad18fc1552","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"9510a88a99a86692016394cf9c4f56fcb4462957a8422500704377501fd0c048"},"mac":"c8cef0ba02bf8ff1a9ab8448a36eee4a91a551d382fe4a6d808e7606ca4ab9ad"},"pubkey":"b3d43f08b7e2131dc7ad1b929d74c3b2d78585e6f65ea286d8c7b8e2c1123b16","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/rn3rnhr3s9Q_CLfiEx3HrRuSnXTDsteFheb2XqKG2Me44sESOxYtc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "rn3rnhr3s9Q_CLfiEx3HrRuSnXTDsteFheb2XqKG2Me44sESOxYtc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/snapshot-config.yml: -------------------------------------------------------------------------------- 1 | [codechain] 2 | 3 | [mining] 4 | self_nomination_enable = false 5 | 6 | [network] 7 | 8 | [rpc] 9 | 10 | [ipc] 11 | 12 | [informer] 13 | 14 | [ws] 15 | 16 | [snapshot] 17 | disable = false 18 | 19 | [email_alarm] 20 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tcqfztsg3H1ZitrqRhvzyFrnJ66dZT0xXwcJmiANX770mz_9XSUtc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"eb71fd12-f3fc-84ac-078c-90c16fe7974f","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"ccc8106b98d77cf8a9fa2635811f32db"},"ciphertext":"2b906d3a6e1bc0fc7fc3301343035f3cc83546c142a875f168720cce16078386196ee47fe0e41d10a617b57dff92b3eda1069c7dd772afc03869db746233cd0c","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"2df3eecbc89adfbf63c4f88f1f4089d03705c2516ba234d8d94447b484e22c13"},"mac":"aa8b78fcf9456b450c231b2d4a03ada71e08b8a27f633b7e9b86bd868c48c998"},"pubkey":"dc7d598adaea461bf3c85ae727ae9d653d315f07099a200d5fbef49b3ffd5d25","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/tcqfztsg3H1ZitrqRhvzyFrnJ66dZT0xXwcJmiANX770mz_9XSUtc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "tcqfztsg3H1ZitrqRhvzyFrnJ66dZT0xXwcJmiANX770mz_9XSUtc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/xek9jzmhvHcp-RxX9XXJVV23kKl574FD6ilIjzteSY48LACx05Etc0/keys/key: -------------------------------------------------------------------------------- 1 | {"id":"84c6d30c-619d-27a9-565d-73a2f74074f2","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"7eb48ff827aeecf07da7375272ffb96b"},"ciphertext":"0a69c6df8f6a469fb0619828d629e6e3ca79953f74cc1c856ba01f44dc9a6d052a4a705859e4c07fe16bb1b716597661976970b081a8ee900d6016f58de215c7","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"084c6aff2b6752dde9b1dccd640560d02bf244e4110a8d44aa3a87c6553d0201"},"mac":"ceb4a412897f4ad066f8672e6a334214a8685b8715b1a5135b41018739a9303c"},"pubkey":"bc7729f91c57f575c9555db790a979ef8143ea29488f3b5e498e3c2c00b1d391","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint.dynval/xek9jzmhvHcp-RxX9XXJVV23kKl574FD6ilIjzteSY48LACx05Etc0/password.json: -------------------------------------------------------------------------------- 1 | [{ "address": "xek9jzmhvHcp-RxX9XXJVV23kKl574FD6ilIjzteSY48LACx05Etc0", "password": "" }] 2 | -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2020-03-05T06-22-17Z--15737bb2-a003-24dd-4f38-9a42b2f1a5c1: -------------------------------------------------------------------------------- 1 | {"id":"15737bb2-a003-24dd-4f38-9a42b2f1a5c1","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"e7258e1090900aa0e14efa15b82fd951"},"ciphertext":"50dba0aba05af919cc26281d7a650f3705c2b12f8b4b1c57fc53e991dc4acc71e48f53bade9da676c25f3e46b0384b9cccd286c94d26ae1b057cf5557c0ca055","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"5abacddd15947f7b729ab3b0250b4d0cf7401cc4888466f42052518d87fb5e71"},"mac":"a86a1e44ac394e315361c3bf05143704212db3b75cdb8a70af2167c5d9d5908e"},"pubkey":"0a6902c51384a15d1062cac3a4e62c8d0c2eb02b4de7fa0a304ce4f88ea482d0","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2020-03-05T06-23-41Z--84597567-cca7-15c1-1e67-ba4d7d74c9cf: -------------------------------------------------------------------------------- 1 | {"id":"84597567-cca7-15c1-1e67-ba4d7d74c9cf","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"786e31c275e51eba4615ec70c7a1776d"},"ciphertext":"2e800890f66191e2546eae77be5bd05e154cfe4f84b5ae0f25fc6f26f0209695de11e7b266395f88876ff41f56998fc2065c9f9338aa76aa4e6b20a0d3e7b05c","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"cd7bc6a9b192bb6da9774899fd4eea9a6676f1b4d943d51dd0c664ade49fae18"},"mac":"a594d1f3878bfa8c664bbdd0f90cc5f96fb72ddf41b50fa2b508f800130c2e9f"},"pubkey":"0473f782c3aec053c37fe2bccefa9298dcf8ae3dc2262ae540a14a580ff773e6","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2020-03-05T06-24-42Z--8a4d1282-551c-30f4-4e51-4f7d1836b482: -------------------------------------------------------------------------------- 1 | {"id":"8a4d1282-551c-30f4-4e51-4f7d1836b482","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"119d4e88b899c0c168d45e8b0ae7944e"},"ciphertext":"f54ccdd40de8e7c34931102c9b7006132dbf352d906b95c9b4b5c0e24d3cbd94dedf5c76b4f0d4b9839d02f6e01d292e22278905fa429c493be523c49d0c7848","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"78c39a2e181ea071fb5a3a0cb8681311cdcf35f2f850974dd0abf8053751080e"},"mac":"6fdb483a72477e07fb68b2b96870a5534f40931dc290f682aea1c2496edd51d2"},"pubkey":"2502d5e6210679a19e45f3c0f93257e7a327baaf5f403f5ca1ab2685a9e1724e","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint/keys/UTC--2020-03-05T06-25-04Z--3a427683-d4d6-7a73-e776-fd15df5b1396: -------------------------------------------------------------------------------- 1 | {"id":"3a427683-d4d6-7a73-e776-fd15df5b1396","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"2e0d3e79e28d235e87c92476cc23695c"},"ciphertext":"a31a552aaa17e02476d34f9619105eb1024a4e2c2feee47ac3b35e9b11b22d4c5a2bc9f6ea6bfa260f230fc4842d963424503af3f3bcd11240b83a44a849fe54","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"d80628d63d7a42f92e30db09d4d628d8e7a615361e396ef6f8191f7abdaee17f"},"mac":"04f169d217b8d1b2fc1e437ac250443151f6cc68011b28668a89505a0bd3dae3"},"pubkey":"e909f311fd115ee412edcfcde88cc507370101f7635a67b9cb45390f1ccb4b5e","meta":"{}"} 2 | -------------------------------------------------------------------------------- /test/tendermint/password.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "address": "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0", 4 | "password": "" 5 | }, { 6 | "address": "szff1322BHP3gsOuwFPDf-K8zvqSmNz4rj3CJirlQKFKWA_3c-Ytc0", 7 | "password": "" 8 | }, { 9 | "address": "qwfj0xwkJQLV5iEGeaGeRfPA-TJX56Mnuq9fQD9coasmhanhck4tc0", 10 | "password": "" 11 | }, { 12 | "address": "dbqtds3w6QnzEf0RXuQS7c_N6IzFBzcBAfdjWme5y0U5DxzLS14tc0", 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 | "resolveJsonModule": true, 10 | "strict": true 11 | }, 12 | "include": ["./src/**/*"], 13 | "exclude": ["./src/**/*.test.ts"] 14 | } 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /timestamp/app-desc.toml: -------------------------------------------------------------------------------- 1 | default-sandboxer = "single-process" 2 | 3 | [modules.module-account] 4 | hash = "a010000000012345678901234567890123456789012345678901234567890123" 5 | 6 | [modules.module-account.tags] 7 | previliged = true 8 | 9 | [modules.module-staking] 10 | hash = "a020000000012345678901234567890123456789012345678901234567890123" 11 | genesis-config = ["0a6902c51384a15d1062cac3a4e62c8d0c2eb02b4de7fa0a304ce4f88ea482d0"] 12 | 13 | [modules.module-staking.tags] 14 | previliged = true 15 | 16 | [modules.module-stamp] 17 | hash = "a030000000012345678901234567890123456789012345678901234567890123" 18 | genesis-config = {} 19 | 20 | [modules.module-stamp.tags] 21 | previliged = true 22 | 23 | [modules.module-token] 24 | hash = "a040000000012345678901234567890123456789012345678901234567890123" 25 | 26 | [modules.module-token.init-config] 27 | thread-pool-size = "@{{thread-pool-size}}" 28 | 29 | [modules.module-token.tags] 30 | previliged = true 31 | 32 | [modules.module-sorting] 33 | hash = "a050000000012345678901234567890123456789012345678901234567890123" 34 | transactions = ["get-account-and-seq"] 35 | 36 | [modules.module-sorting.tags] 37 | previliged = true 38 | 39 | [host] 40 | 41 | [host.engine] 42 | type = "tendermint" 43 | 44 | [host.engine.params] 45 | timeoutPropose = 3000 46 | timeoutProposeDelta = 1000 47 | timeoutPrevote = 1000 48 | timeoutPrevoteDelta = 1000 49 | timeoutPrecommit = 1000 50 | timeoutPrecommitDelta = 1000 51 | timeoutCommit = 1000 52 | 53 | [transactions] 54 | hello = "module-account" 55 | stamp = "module-stamp" 56 | token-transfer = "module-token" 57 | 58 | [param-defaults] 59 | thread-pool-size = "16" 60 | -------------------------------------------------------------------------------- /timestamp/src/bin/account.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let args = std::env::args().collect(); 3 | foundry_module_rt::start::< 4 | foundry_process_sandbox::ipc::unix_socket::DomainSocket, 5 | foundry_timestamp::account::Module, 6 | >(args); 7 | } 8 | -------------------------------------------------------------------------------- /timestamp/src/bin/sorting.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let args = std::env::args().collect(); 3 | foundry_module_rt::start::< 4 | foundry_process_sandbox::ipc::unix_socket::DomainSocket, 5 | foundry_timestamp::sorting::Module, 6 | >(args); 7 | } 8 | -------------------------------------------------------------------------------- /timestamp/src/bin/staking.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let args = std::env::args().collect(); 3 | foundry_module_rt::start::< 4 | foundry_process_sandbox::ipc::unix_socket::DomainSocket, 5 | foundry_timestamp::staking::Module, 6 | >(args); 7 | } 8 | -------------------------------------------------------------------------------- /timestamp/src/bin/stamp.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let args = std::env::args().collect(); 3 | foundry_module_rt::start::( 4 | args, 5 | ); 6 | } 7 | -------------------------------------------------------------------------------- /timestamp/src/bin/token.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let args = std::env::args().collect(); 3 | foundry_module_rt::start::( 4 | args, 5 | ); 6 | } 7 | -------------------------------------------------------------------------------- /timestamp/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License 15 | // along with this program. If not, see . 16 | 17 | pub mod account; 18 | pub mod common; 19 | pub mod sorting; 20 | pub mod staking; 21 | pub mod stamp; 22 | pub mod token; 23 | pub mod util; 24 | -------------------------------------------------------------------------------- /timestamp/tests/common/query.graphql: -------------------------------------------------------------------------------- 1 | query Test($public: String) { 2 | account(public: $public) { 3 | seq 4 | } 5 | } -------------------------------------------------------------------------------- /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 | ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" } 9 | cjson = { package = "codechain-json", path = "../json" } 10 | ckey = { package = "codechain-key", path = "../key" } 11 | primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" } 12 | rand = "0.6.1" 13 | rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 14 | rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.5", tag = "v0.5.0"} 15 | serde = "1.0" 16 | serde_derive = "1.0" 17 | 18 | [dev-dependencies] 19 | serde_json = "1.0" 20 | -------------------------------------------------------------------------------- /types/src/block_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::{BlockHash, BlockNumber}; 18 | 19 | /// Uniquely identifies block. 20 | #[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)] 21 | pub enum BlockId { 22 | /// Block's blake256. 23 | /// Querying by hash is always faster. 24 | Hash(BlockHash), 25 | /// Block number within canon blockchain. 26 | Number(BlockNumber), 27 | /// Earliest block (genesis). 28 | Earliest, 29 | /// Latest mined block. 30 | Latest, 31 | /// Parent of latest mined block. 32 | ParentOfLatest, 33 | } 34 | 35 | impl From for BlockId { 36 | fn from(hash: BlockHash) -> Self { 37 | BlockId::Hash(hash) 38 | } 39 | } 40 | 41 | impl From for BlockId { 42 | fn from(number: BlockNumber) -> Self { 43 | BlockId::Number(number) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /types/src/transaction/approval.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use ckey::{Ed25519Public as Public, Signature}; 18 | 19 | #[derive(Clone, Debug, Eq, PartialEq, RlpEncodable, RlpDecodable, Serialize, Deserialize)] 20 | pub struct Approval { 21 | signature: Signature, 22 | signer_public: Public, 23 | } 24 | 25 | impl Approval { 26 | pub fn new(signature: Signature, signer_public: Public) -> Self { 27 | Self { 28 | signature, 29 | signer_public, 30 | } 31 | } 32 | pub fn signature(&self) -> &Signature { 33 | &self.signature 34 | } 35 | 36 | pub fn signer_public(&self) -> &Public { 37 | &self.signer_public 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /types/src/transaction/mod.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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod approval; 18 | mod partial_hashing; 19 | #[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))] 20 | mod validator; 21 | 22 | pub use self::approval::Approval; 23 | pub use self::partial_hashing::{HashingError, PartialHashing}; 24 | pub use self::validator::Validator; 25 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use crate::util::tag::Tag; 18 | use primitives::H256; 19 | 20 | pub trait PartialHashing { 21 | fn hash_partially(&self, tag: Tag, burn: bool) -> Result; 22 | } 23 | 24 | #[derive(Debug, PartialEq)] 25 | pub enum HashingError { 26 | InvalidFilter, 27 | } 28 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU 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, 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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod email; 18 | mod logger; 19 | mod macros; 20 | mod structured_logger; 21 | 22 | pub use email::EmailAlarm; 23 | use lazy_static::lazy_static; 24 | pub use log::Level; 25 | use log::SetLoggerError; 26 | pub use logger::Config as LoggerConfig; 27 | use logger::Logger; 28 | use structured_logger::StructuredLogger; 29 | 30 | pub fn init(config: &LoggerConfig, email_alarm: Option) -> Result<(), SetLoggerError> { 31 | let logger = Logger::new(config, email_alarm); 32 | log::set_max_level(logger.filter()); 33 | log::set_boxed_logger(Box::new(logger)) 34 | } 35 | 36 | lazy_static! { 37 | pub static ref SLOGGER: StructuredLogger = StructuredLogger::create(); 38 | } 39 | -------------------------------------------------------------------------------- /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 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 General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #[macro_use] 18 | extern crate log; 19 | #[macro_use] 20 | extern crate codechain_logger as clogger; 21 | 22 | mod timer; 23 | 24 | pub use crate::timer::{ 25 | ScheduleError as TimerScheduleError, TimeoutHandler, TimerApi, TimerLoop, TimerName, TimerToken, 26 | }; 27 | --------------------------------------------------------------------------------