├── .dockerignore ├── .gitattributes ├── .gitignore ├── .gitmodules ├── .mailmap ├── .travis.yml ├── AUTHORS ├── COPYING ├── COPYING.LESSER ├── Dockerfile ├── Dockerfile.alltools ├── Makefile ├── README.md ├── accounts ├── abi │ ├── abi.go │ ├── abi_test.go │ ├── argument.go │ ├── bind │ │ ├── auth.go │ │ ├── backend.go │ │ ├── backends │ │ │ └── simulated.go │ │ ├── base.go │ │ ├── base_test.go │ │ ├── bind.go │ │ ├── bind_test.go │ │ ├── template.go │ │ ├── topics.go │ │ ├── util.go │ │ └── util_test.go │ ├── doc.go │ ├── error.go │ ├── event.go │ ├── event_test.go │ ├── method.go │ ├── method_test.go │ ├── numbers.go │ ├── numbers_test.go │ ├── pack.go │ ├── pack_test.go │ ├── reflect.go │ ├── reflect_test.go │ ├── type.go │ ├── type_test.go │ ├── unpack.go │ └── unpack_test.go ├── accounts.go ├── errors.go ├── hd.go ├── hd_test.go ├── keystore │ ├── account_cache.go │ ├── account_cache_test.go │ ├── file_cache.go │ ├── key.go │ ├── keystore.go │ ├── keystore_test.go │ ├── passphrase.go │ ├── passphrase_test.go │ ├── plain.go │ ├── plain_test.go │ ├── presale.go │ ├── testdata │ │ ├── dupes │ │ │ ├── 1 │ │ │ ├── 2 │ │ │ └── foo │ │ ├── keystore │ │ │ ├── .hiddenfile │ │ │ ├── README │ │ │ ├── UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8 │ │ │ ├── aaa │ │ │ ├── empty │ │ │ ├── foo │ │ │ │ └── fd9bd350f08ee3c0c19b85a8e16114a11a60aa4e │ │ │ ├── garbage │ │ │ ├── no-address │ │ │ ├── zero │ │ │ └── zzz │ │ ├── v1 │ │ │ └── cb61d5a9c4896fb9658090b597ef0e7be6f7b67e │ │ │ │ └── cb61d5a9c4896fb9658090b597ef0e7be6f7b67e │ │ ├── v1_test_vector.json │ │ ├── v3_test_vector.json │ │ └── very-light-scrypt.json │ ├── wallet.go │ ├── watch.go │ └── watch_fallback.go ├── manager.go ├── url.go ├── url_test.go └── usbwallet │ ├── hub.go │ ├── internal │ └── trezor │ │ ├── messages.pb.go │ │ ├── messages.proto │ │ ├── trezor.go │ │ ├── types.pb.go │ │ └── types.proto │ ├── ledger.go │ ├── trezor.go │ └── wallet.go ├── appveyor.yml ├── build ├── ci-notes.md ├── ci.go ├── clean_go_build_cache.sh ├── deb │ ├── ethereum-swarm │ │ ├── deb.changelog │ │ ├── deb.control │ │ ├── deb.copyright │ │ ├── deb.docs │ │ ├── deb.install │ │ └── deb.rules │ └── ethereum │ │ ├── deb.changelog │ │ ├── deb.control │ │ ├── deb.copyright │ │ ├── deb.docs │ │ ├── deb.install │ │ └── deb.rules ├── env.sh ├── goimports.sh ├── mvn.pom ├── mvn.settings ├── nsis.envvarupdate.nsh ├── nsis.geth.nsi ├── nsis.install.nsh ├── nsis.pathupdate.nsh ├── nsis.simplefc.dll ├── nsis.simplefc.source.zip ├── nsis.uninstall.nsh ├── pod.podspec └── update-license.go ├── circle.yml ├── cmd ├── abigen │ └── main.go ├── bootnode │ └── main.go ├── clef │ ├── 4byte.json │ ├── README.md │ ├── docs │ │ ├── qubes │ │ │ ├── clef_qubes_http.png │ │ │ ├── clef_qubes_qrexec.png │ │ │ ├── qrexec-example.png │ │ │ ├── qubes-client.py │ │ │ ├── qubes.Clefsign │ │ │ ├── qubes_newaccount-1.png │ │ │ └── qubes_newaccount-2.png │ │ └── setup.md │ ├── extapi_changelog.md │ ├── intapi_changelog.md │ ├── main.go │ ├── pythonsigner.py │ ├── rules.md │ ├── sign_flow.png │ └── tutorial.md ├── ethkey │ ├── README.md │ ├── changepassphrase.go │ ├── generate.go │ ├── inspect.go │ ├── main.go │ ├── message.go │ ├── message_test.go │ ├── run_test.go │ └── utils.go ├── evm │ ├── compiler.go │ ├── disasm.go │ ├── internal │ │ └── compiler │ │ │ └── compiler.go │ ├── main.go │ ├── runner.go │ └── staterunner.go ├── faucet │ ├── faucet.go │ ├── faucet.html │ └── website.go ├── geth │ ├── accountcmd.go │ ├── accountcmd_test.go │ ├── bugcmd.go │ ├── chaincmd.go │ ├── config.go │ ├── consolecmd.go │ ├── consolecmd_test.go │ ├── dao_test.go │ ├── genesis_test.go │ ├── main.go │ ├── misccmd.go │ ├── monitorcmd.go │ ├── run_test.go │ ├── testdata │ │ ├── empty.js │ │ ├── guswallet.json │ │ ├── passwords.txt │ │ └── wrong-passwords.txt │ └── usage.go ├── internal │ └── browser │ │ └── browser.go ├── p2psim │ └── main.go ├── puppeth │ ├── genesis.go │ ├── genesis_test.go │ ├── module.go │ ├── module_dashboard.go │ ├── module_ethstats.go │ ├── module_explorer.go │ ├── module_faucet.go │ ├── module_nginx.go │ ├── module_node.go │ ├── module_wallet.go │ ├── puppeth.go │ ├── ssh.go │ ├── testdata │ │ ├── stureby_aleth.json │ │ ├── stureby_geth.json │ │ └── stureby_parity.json │ ├── wizard.go │ ├── wizard_dashboard.go │ ├── wizard_ethstats.go │ ├── wizard_explorer.go │ ├── wizard_faucet.go │ ├── wizard_genesis.go │ ├── wizard_intro.go │ ├── wizard_netstats.go │ ├── wizard_network.go │ ├── wizard_nginx.go │ ├── wizard_node.go │ └── wizard_wallet.go ├── rlpdump │ └── main.go ├── swarm │ ├── access.go │ ├── access_test.go │ ├── bootnodes.go │ ├── config.go │ ├── config_test.go │ ├── db.go │ ├── download.go │ ├── export_test.go │ ├── feeds.go │ ├── feeds_test.go │ ├── flags.go │ ├── fs.go │ ├── fs_test.go │ ├── hash.go │ ├── list.go │ ├── main.go │ ├── manifest.go │ ├── manifest_test.go │ ├── mimegen │ │ ├── generator.go │ │ └── mime.types │ ├── run_test.go │ ├── swarm-smoke │ │ ├── feed_upload_and_sync.go │ │ ├── main.go │ │ ├── upload_and_sync.go │ │ └── upload_speed.go │ ├── swarm-snapshot │ │ ├── create.go │ │ ├── create_test.go │ │ ├── main.go │ │ └── run_test.go │ ├── upload.go │ └── upload_test.go ├── utils │ ├── cmd.go │ ├── customflags.go │ ├── customflags_test.go │ └── flags.go └── wnode │ └── main.go ├── common ├── big.go ├── bitutil │ ├── bitutil.go │ ├── bitutil_test.go │ ├── compress.go │ ├── compress_fuzz.go │ └── compress_test.go ├── bytes.go ├── bytes_test.go ├── compiler │ ├── solidity.go │ └── solidity_test.go ├── debug.go ├── fdlimit │ ├── fdlimit_freebsd.go │ ├── fdlimit_test.go │ ├── fdlimit_unix.go │ └── fdlimit_windows.go ├── format.go ├── hexutil │ ├── hexutil.go │ ├── hexutil_test.go │ ├── json.go │ ├── json_example_test.go │ └── json_test.go ├── main_test.go ├── math │ ├── big.go │ ├── big_test.go │ ├── integer.go │ └── integer_test.go ├── mclock │ ├── mclock.go │ └── simclock.go ├── path.go ├── prque │ ├── prque.go │ └── sstack.go ├── size.go ├── size_test.go ├── test_utils.go ├── types.go └── types_test.go ├── consensus ├── clique │ ├── api.go │ ├── clique.go │ ├── snapshot.go │ └── snapshot_test.go ├── consensus.go ├── errors.go ├── ethash │ ├── algorithm.go │ ├── algorithm_test.go │ ├── api.go │ ├── consensus.go │ ├── consensus_test.go │ ├── ethash.go │ ├── ethash_test.go │ ├── sealer.go │ └── sealer_test.go └── misc │ ├── dao.go │ └── forks.go ├── console ├── bridge.go ├── console.go ├── console_test.go ├── prompter.go └── testdata │ ├── exec.js │ └── preload.js ├── containers └── docker │ ├── develop-alpine │ └── Dockerfile │ ├── develop-ubuntu │ └── Dockerfile │ ├── master-alpine │ └── Dockerfile │ └── master-ubuntu │ └── Dockerfile ├── contracts ├── chequebook │ ├── api.go │ ├── cheque.go │ ├── cheque_test.go │ ├── contract │ │ ├── chequebook.go │ │ ├── chequebook.sol │ │ ├── code.go │ │ ├── mortal.sol │ │ └── owned.sol │ └── gencode.go └── ens │ ├── README.md │ ├── contract │ ├── AbstractENS.sol │ ├── ENS.sol │ ├── FIFSRegistrar.sol │ ├── PublicResolver.sol │ ├── ens.go │ ├── fifsregistrar.go │ └── publicresolver.go │ ├── ens.go │ └── ens_test.go ├── core ├── .gitignore ├── asm │ ├── asm.go │ ├── asm_test.go │ ├── compiler.go │ ├── lex_test.go │ └── lexer.go ├── bench_test.go ├── block_validator.go ├── block_validator_test.go ├── blockchain.go ├── blockchain_insert.go ├── blockchain_test.go ├── blocks.go ├── bloombits │ ├── doc.go │ ├── generator.go │ ├── generator_test.go │ ├── matcher.go │ ├── matcher_test.go │ ├── scheduler.go │ └── scheduler_test.go ├── chain_indexer.go ├── chain_indexer_test.go ├── chain_makers.go ├── chain_makers_test.go ├── dao_test.go ├── error.go ├── events.go ├── evm.go ├── gaspool.go ├── gen_genesis.go ├── gen_genesis_account.go ├── genesis.go ├── genesis_alloc.go ├── genesis_test.go ├── headerchain.go ├── helper_test.go ├── mkalloc.go ├── rawdb │ ├── accessors_chain.go │ ├── accessors_chain_test.go │ ├── accessors_indexes.go │ ├── accessors_indexes_test.go │ ├── accessors_metadata.go │ ├── interfaces.go │ └── schema.go ├── state │ ├── database.go │ ├── dump.go │ ├── iterator.go │ ├── iterator_test.go │ ├── journal.go │ ├── main_test.go │ ├── managed_state.go │ ├── managed_state_test.go │ ├── state_object.go │ ├── state_test.go │ ├── statedb.go │ ├── statedb_test.go │ ├── sync.go │ └── sync_test.go ├── state_processor.go ├── state_transition.go ├── tx_cacher.go ├── tx_journal.go ├── tx_list.go ├── tx_list_test.go ├── tx_pool.go ├── tx_pool_test.go ├── types.go ├── types │ ├── block.go │ ├── block_test.go │ ├── bloom9.go │ ├── bloom9_test.go │ ├── derive_sha.go │ ├── gen_header_json.go │ ├── gen_log_json.go │ ├── gen_receipt_json.go │ ├── gen_tx_json.go │ ├── log.go │ ├── log_test.go │ ├── receipt.go │ ├── transaction.go │ ├── transaction_signing.go │ ├── transaction_signing_test.go │ └── transaction_test.go └── vm │ ├── analysis.go │ ├── analysis_test.go │ ├── common.go │ ├── contract.go │ ├── contracts.go │ ├── contracts_test.go │ ├── doc.go │ ├── errors.go │ ├── evm.go │ ├── gas.go │ ├── gas_table.go │ ├── gas_table_test.go │ ├── gen_structlog.go │ ├── instructions.go │ ├── instructions_test.go │ ├── int_pool_verifier.go │ ├── int_pool_verifier_empty.go │ ├── interface.go │ ├── interpreter.go │ ├── intpool.go │ ├── intpool_test.go │ ├── jump_table.go │ ├── logger.go │ ├── logger_json.go │ ├── logger_test.go │ ├── memory.go │ ├── memory_table.go │ ├── opcodes.go │ ├── runtime │ ├── doc.go │ ├── env.go │ ├── fuzz.go │ ├── runtime.go │ ├── runtime_example_test.go │ └── runtime_test.go │ ├── stack.go │ └── stack_table.go ├── crypto ├── bn256 │ ├── LICENSE │ ├── bn256_fast.go │ ├── bn256_fuzz.go │ ├── bn256_slow.go │ ├── cloudflare │ │ ├── LICENSE │ │ ├── bn256.go │ │ ├── bn256_test.go │ │ ├── constants.go │ │ ├── curve.go │ │ ├── example_test.go │ │ ├── gfp.go │ │ ├── gfp12.go │ │ ├── gfp2.go │ │ ├── gfp6.go │ │ ├── gfp_amd64.s │ │ ├── gfp_arm64.s │ │ ├── gfp_decl.go │ │ ├── gfp_generic.go │ │ ├── gfp_test.go │ │ ├── lattice.go │ │ ├── lattice_test.go │ │ ├── main_test.go │ │ ├── mul_amd64.h │ │ ├── mul_arm64.h │ │ ├── mul_bmi2_amd64.h │ │ ├── optate.go │ │ └── twist.go │ └── google │ │ ├── bn256.go │ │ ├── bn256_test.go │ │ ├── constants.go │ │ ├── curve.go │ │ ├── example_test.go │ │ ├── gfp12.go │ │ ├── gfp2.go │ │ ├── gfp6.go │ │ ├── main_test.go │ │ ├── optate.go │ │ └── twist.go ├── crypto.go ├── crypto_test.go ├── ecies │ ├── .gitignore │ ├── LICENSE │ ├── README │ ├── ecies.go │ ├── ecies_test.go │ └── params.go ├── secp256k1 │ ├── .gitignore │ ├── LICENSE │ ├── curve.go │ ├── ext.h │ ├── libsecp256k1 │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── COPYING │ │ ├── Makefile.am │ │ ├── README.md │ │ ├── TODO │ │ ├── autogen.sh │ │ ├── build-aux │ │ │ └── m4 │ │ │ │ ├── ax_jni_include_dir.m4 │ │ │ │ ├── ax_prog_cc_for_build.m4 │ │ │ │ └── bitcoin_secp.m4 │ │ ├── configure.ac │ │ ├── contrib │ │ │ ├── lax_der_parsing.c │ │ │ ├── lax_der_parsing.h │ │ │ ├── lax_der_privatekey_parsing.c │ │ │ └── lax_der_privatekey_parsing.h │ │ ├── include │ │ │ ├── secp256k1.h │ │ │ ├── secp256k1_ecdh.h │ │ │ └── secp256k1_recovery.h │ │ ├── libsecp256k1.pc.in │ │ ├── obj │ │ │ └── .gitignore │ │ ├── sage │ │ │ ├── group_prover.sage │ │ │ ├── secp256k1.sage │ │ │ └── weierstrass_prover.sage │ │ └── src │ │ │ ├── asm │ │ │ └── field_10x26_arm.s │ │ │ ├── basic-config.h │ │ │ ├── bench.h │ │ │ ├── bench_ecdh.c │ │ │ ├── bench_internal.c │ │ │ ├── bench_recover.c │ │ │ ├── bench_schnorr_verify.c │ │ │ ├── bench_sign.c │ │ │ ├── bench_verify.c │ │ │ ├── ecdsa.h │ │ │ ├── ecdsa_impl.h │ │ │ ├── eckey.h │ │ │ ├── eckey_impl.h │ │ │ ├── ecmult.h │ │ │ ├── ecmult_const.h │ │ │ ├── ecmult_const_impl.h │ │ │ ├── ecmult_gen.h │ │ │ ├── ecmult_gen_impl.h │ │ │ ├── ecmult_impl.h │ │ │ ├── field.h │ │ │ ├── field_10x26.h │ │ │ ├── field_10x26_impl.h │ │ │ ├── field_5x52.h │ │ │ ├── field_5x52_asm_impl.h │ │ │ ├── field_5x52_impl.h │ │ │ ├── field_5x52_int128_impl.h │ │ │ ├── field_impl.h │ │ │ ├── gen_context.c │ │ │ ├── group.h │ │ │ ├── group_impl.h │ │ │ ├── hash.h │ │ │ ├── hash_impl.h │ │ │ ├── java │ │ │ ├── org │ │ │ │ └── bitcoin │ │ │ │ │ ├── NativeSecp256k1.java │ │ │ │ │ ├── NativeSecp256k1Test.java │ │ │ │ │ ├── NativeSecp256k1Util.java │ │ │ │ │ └── Secp256k1Context.java │ │ │ ├── org_bitcoin_NativeSecp256k1.c │ │ │ ├── org_bitcoin_NativeSecp256k1.h │ │ │ ├── org_bitcoin_Secp256k1Context.c │ │ │ └── org_bitcoin_Secp256k1Context.h │ │ │ ├── modules │ │ │ ├── ecdh │ │ │ │ ├── Makefile.am.include │ │ │ │ ├── main_impl.h │ │ │ │ └── tests_impl.h │ │ │ └── recovery │ │ │ │ ├── Makefile.am.include │ │ │ │ ├── main_impl.h │ │ │ │ └── tests_impl.h │ │ │ ├── num.h │ │ │ ├── num_gmp.h │ │ │ ├── num_gmp_impl.h │ │ │ ├── num_impl.h │ │ │ ├── scalar.h │ │ │ ├── scalar_4x64.h │ │ │ ├── scalar_4x64_impl.h │ │ │ ├── scalar_8x32.h │ │ │ ├── scalar_8x32_impl.h │ │ │ ├── scalar_impl.h │ │ │ ├── scalar_low.h │ │ │ ├── scalar_low_impl.h │ │ │ ├── secp256k1.c │ │ │ ├── testrand.h │ │ │ ├── testrand_impl.h │ │ │ ├── tests.c │ │ │ ├── tests_exhaustive.c │ │ │ └── util.h │ ├── panic_cb.go │ ├── secp256.go │ └── secp256_test.go ├── signature_cgo.go ├── signature_nocgo.go └── signature_test.go ├── dashboard ├── README.md ├── assets.go ├── assets │ ├── .eslintrc │ ├── .flowconfig │ ├── common.jsx │ ├── components │ │ ├── Body.jsx │ │ ├── ChartRow.jsx │ │ ├── CustomTooltip.jsx │ │ ├── Dashboard.jsx │ │ ├── Footer.jsx │ │ ├── Header.jsx │ │ ├── Logs.jsx │ │ ├── Main.jsx │ │ └── SideBar.jsx │ ├── fa-only-woff-loader.js │ ├── index.html │ ├── index.jsx │ ├── package.json │ ├── types │ │ └── content.jsx │ └── webpack.config.js ├── config.go ├── cpu.go ├── cpu_windows.go ├── dashboard.go ├── log.go └── message.go ├── eth ├── api.go ├── api_backend.go ├── api_test.go ├── api_tracer.go ├── backend.go ├── bloombits.go ├── config.go ├── downloader │ ├── api.go │ ├── downloader.go │ ├── downloader_test.go │ ├── events.go │ ├── fakepeer.go │ ├── metrics.go │ ├── modes.go │ ├── peer.go │ ├── queue.go │ ├── statesync.go │ ├── testchain_test.go │ └── types.go ├── fetcher │ ├── fetcher.go │ ├── fetcher_test.go │ └── metrics.go ├── filters │ ├── api.go │ ├── api_test.go │ ├── bench_test.go │ ├── filter.go │ ├── filter_system.go │ ├── filter_system_test.go │ └── filter_test.go ├── gasprice │ └── gasprice.go ├── gen_config.go ├── handler.go ├── handler_test.go ├── helper_test.go ├── metrics.go ├── peer.go ├── protocol.go ├── protocol_test.go ├── sync.go ├── sync_test.go └── tracers │ ├── internal │ └── tracers │ │ ├── 4byte_tracer.js │ │ ├── assets.go │ │ ├── bigram_tracer.js │ │ ├── call_tracer.js │ │ ├── evmdis_tracer.js │ │ ├── noop_tracer.js │ │ ├── opcount_tracer.js │ │ ├── prestate_tracer.js │ │ ├── tracers.go │ │ ├── trigram_tracer.js │ │ └── unigram_tracer.js │ ├── testdata │ ├── call_tracer_create.json │ ├── call_tracer_deep_calls.json │ ├── call_tracer_delegatecall.json │ ├── call_tracer_inner_create_oog_outer_throw.json │ ├── call_tracer_inner_throw_outer_revert.json │ ├── call_tracer_oog.json │ ├── call_tracer_revert.json │ ├── call_tracer_simple.json │ └── call_tracer_throw.json │ ├── tracer.go │ ├── tracer_test.go │ ├── tracers.go │ └── tracers_test.go ├── ethclient ├── ethclient.go ├── ethclient_test.go └── signer.go ├── ethdb ├── .gitignore ├── database.go ├── database_js.go ├── database_js_test.go ├── database_test.go ├── interface.go ├── memory_database.go ├── table.go └── table_batch.go ├── ethstats └── ethstats.go ├── event ├── event.go ├── event_test.go ├── example_feed_test.go ├── example_scope_test.go ├── example_subscription_test.go ├── example_test.go ├── feed.go ├── feed_test.go ├── subscription.go └── subscription_test.go ├── interfaces.go ├── internal ├── build │ ├── archive.go │ ├── azure.go │ ├── env.go │ ├── pgp.go │ └── util.go ├── cmdtest │ └── test_cmd.go ├── debug │ ├── api.go │ ├── flags.go │ ├── loudpanic.go │ ├── loudpanic_fallback.go │ ├── trace.go │ └── trace_fallback.go ├── ethapi │ ├── addrlock.go │ ├── api.go │ └── backend.go ├── guide │ ├── guide.go │ └── guide_test.go ├── jsre │ ├── completion.go │ ├── completion_test.go │ ├── deps │ │ ├── bignumber.js │ │ ├── bindata.go │ │ ├── deps.go │ │ └── web3.js │ ├── jsre.go │ ├── jsre_test.go │ └── pretty.go └── web3ext │ └── web3ext.go ├── les ├── api_backend.go ├── backend.go ├── bloombits.go ├── commons.go ├── distributor.go ├── distributor_test.go ├── execqueue.go ├── execqueue_test.go ├── fetcher.go ├── flowcontrol │ ├── control.go │ └── manager.go ├── freeclient.go ├── freeclient_test.go ├── handler.go ├── handler_test.go ├── helper_test.go ├── metrics.go ├── odr.go ├── odr_requests.go ├── odr_test.go ├── peer.go ├── protocol.go ├── randselect.go ├── randselect_test.go ├── request_test.go ├── retrieve.go ├── server.go ├── serverpool.go ├── sync.go └── txrelay.go ├── light ├── lightchain.go ├── lightchain_test.go ├── nodeset.go ├── odr.go ├── odr_test.go ├── odr_util.go ├── postprocess.go ├── trie.go ├── trie_test.go ├── txpool.go └── txpool_test.go ├── log ├── CONTRIBUTORS ├── LICENSE ├── README.md ├── README_ETHEREUM.md ├── doc.go ├── format.go ├── handler.go ├── handler_glog.go ├── handler_go13.go ├── handler_go14.go ├── logger.go ├── root.go └── syslog.go ├── metrics ├── FORK.md ├── LICENSE ├── README.md ├── counter.go ├── counter_test.go ├── debug.go ├── debug_test.go ├── disk.go ├── disk_linux.go ├── disk_nop.go ├── ewma.go ├── ewma_test.go ├── exp │ └── exp.go ├── gauge.go ├── gauge_float64.go ├── gauge_float64_test.go ├── gauge_test.go ├── graphite.go ├── graphite_test.go ├── healthcheck.go ├── histogram.go ├── histogram_test.go ├── influxdb │ ├── LICENSE │ ├── README.md │ └── influxdb.go ├── init_test.go ├── json.go ├── json_test.go ├── librato │ ├── client.go │ └── librato.go ├── log.go ├── memory.md ├── meter.go ├── meter_test.go ├── metrics.go ├── metrics_test.go ├── opentsdb.go ├── opentsdb_test.go ├── registry.go ├── registry_test.go ├── resetting_timer.go ├── resetting_timer_test.go ├── runtime.go ├── runtime_cgo.go ├── runtime_gccpufraction.go ├── runtime_no_cgo.go ├── runtime_no_gccpufraction.go ├── runtime_test.go ├── sample.go ├── sample_test.go ├── syslog.go ├── timer.go ├── timer_test.go ├── validate.sh ├── writer.go └── writer_test.go ├── miner ├── miner.go ├── stress_clique.go ├── stress_ethash.go ├── unconfirmed.go ├── unconfirmed_test.go ├── worker.go └── worker_test.go ├── mobile ├── accounts.go ├── android_test.go ├── big.go ├── bind.go ├── common.go ├── context.go ├── discover.go ├── doc.go ├── ethclient.go ├── ethereum.go ├── geth.go ├── geth_android.go ├── geth_ios.go ├── geth_other.go ├── init.go ├── interface.go ├── logger.go ├── p2p.go ├── params.go ├── primitives.go ├── shhclient.go ├── types.go └── vm.go ├── node ├── api.go ├── config.go ├── config_test.go ├── defaults.go ├── doc.go ├── errors.go ├── node.go ├── node_example_test.go ├── node_test.go ├── service.go ├── service_test.go └── utils_test.go ├── p2p ├── dial.go ├── dial_test.go ├── discover │ ├── node.go │ ├── ntp.go │ ├── table.go │ ├── table_test.go │ ├── table_util_test.go │ ├── udp.go │ └── udp_test.go ├── discv5 │ ├── database.go │ ├── database_test.go │ ├── metrics.go │ ├── net.go │ ├── net_test.go │ ├── node.go │ ├── node_test.go │ ├── nodeevent_string.go │ ├── ntp.go │ ├── sim_run_test.go │ ├── sim_test.go │ ├── sim_testmain_test.go │ ├── table.go │ ├── table_test.go │ ├── ticket.go │ ├── topic.go │ ├── topic_test.go │ ├── udp.go │ └── udp_test.go ├── enode │ ├── idscheme.go │ ├── idscheme_test.go │ ├── localnode.go │ ├── localnode_test.go │ ├── node.go │ ├── node_test.go │ ├── nodedb.go │ ├── nodedb_test.go │ ├── urlv4.go │ └── urlv4_test.go ├── enr │ ├── enr.go │ ├── enr_test.go │ └── entries.go ├── message.go ├── message_test.go ├── metrics.go ├── nat │ ├── nat.go │ ├── nat_test.go │ ├── natpmp.go │ ├── natupnp.go │ └── natupnp_test.go ├── netutil │ ├── error.go │ ├── error_test.go │ ├── iptrack.go │ ├── iptrack_test.go │ ├── net.go │ ├── net_test.go │ ├── toobig_notwindows.go │ └── toobig_windows.go ├── peer.go ├── peer_error.go ├── peer_test.go ├── protocol.go ├── protocols │ ├── accounting.go │ ├── accounting_api.go │ ├── accounting_simulation_test.go │ ├── accounting_test.go │ ├── protocol.go │ ├── protocol_test.go │ ├── reporter.go │ └── reporter_test.go ├── rlpx.go ├── rlpx_test.go ├── server.go ├── server_test.go ├── simulations │ ├── README.md │ ├── adapters │ │ ├── exec.go │ │ ├── inproc.go │ │ ├── inproc_test.go │ │ └── types.go │ ├── connect.go │ ├── connect_test.go │ ├── events.go │ ├── examples │ │ ├── README.md │ │ ├── ping-pong.go │ │ └── ping-pong.sh │ ├── http.go │ ├── http_test.go │ ├── mocker.go │ ├── mocker_test.go │ ├── network.go │ ├── network_test.go │ ├── pipes │ │ └── pipes.go │ ├── simulation.go │ └── test.go └── testing │ ├── peerpool.go │ ├── protocolsession.go │ └── protocoltester.go ├── params ├── bootnodes.go ├── config.go ├── config_test.go ├── dao.go ├── denomination.go ├── gas_table.go ├── network_params.go ├── protocol_params.go └── version.go ├── rlp ├── decode.go ├── decode_tail_test.go ├── decode_test.go ├── doc.go ├── encode.go ├── encode_test.go ├── encoder_example_test.go ├── raw.go ├── raw_test.go └── typecache.go ├── rpc ├── client.go ├── client_example_test.go ├── client_test.go ├── doc.go ├── endpoints.go ├── errors.go ├── http.go ├── http_test.go ├── inproc.go ├── ipc.go ├── ipc_js.go ├── ipc_unix.go ├── ipc_windows.go ├── json.go ├── json_test.go ├── server.go ├── server_test.go ├── stdio.go ├── subscription.go ├── subscription_test.go ├── types.go ├── types_test.go ├── utils.go ├── utils_test.go ├── websocket.go └── websocket_test.go ├── signer ├── core │ ├── abihelper.go │ ├── abihelper_test.go │ ├── api.go │ ├── api_test.go │ ├── auditlog.go │ ├── cliui.go │ ├── stdioui.go │ ├── types.go │ ├── validation.go │ └── validation_test.go ├── rules │ ├── deps │ │ ├── bignumber.js │ │ ├── bindata.go │ │ └── deps.go │ ├── rules.go │ └── rules_test.go └── storage │ ├── aes_gcm_storage.go │ ├── aes_gcm_storage_test.go │ └── storage.go ├── swarm ├── AUTHORS ├── OWNERS ├── README.md ├── api │ ├── act.go │ ├── api.go │ ├── api_test.go │ ├── client │ │ ├── client.go │ │ └── client_test.go │ ├── config.go │ ├── config_test.go │ ├── encrypt.go │ ├── filesystem.go │ ├── filesystem_test.go │ ├── gen_mime.go │ ├── http │ │ ├── middleware.go │ │ ├── response.go │ │ ├── response_test.go │ │ ├── roundtripper.go │ │ ├── roundtripper_test.go │ │ ├── sctx.go │ │ ├── server.go │ │ ├── server_test.go │ │ ├── templates.go │ │ └── test_server.go │ ├── manifest.go │ ├── manifest_test.go │ ├── storage.go │ ├── storage_test.go │ ├── testapi.go │ ├── testdata │ │ └── test0 │ │ │ ├── img │ │ │ └── logo.png │ │ │ ├── index.css │ │ │ └── index.html │ ├── uri.go │ └── uri_test.go ├── bmt │ ├── bmt.go │ ├── bmt_r.go │ └── bmt_test.go ├── chunk │ └── chunk.go ├── dev │ ├── .dockerignore │ ├── .gitignore │ ├── Dockerfile │ ├── Makefile │ ├── README.md │ ├── bashrc │ ├── run.sh │ └── scripts │ │ ├── boot-cluster.sh │ │ ├── random-uploads.sh │ │ ├── stop-cluster.sh │ │ └── util.sh ├── docker │ ├── Dockerfile │ ├── run-smoke.sh │ └── run.sh ├── fuse │ ├── fuse_dir.go │ ├── fuse_file.go │ ├── fuse_root.go │ ├── swarmfs.go │ ├── swarmfs_fallback.go │ ├── swarmfs_test.go │ ├── swarmfs_unix.go │ └── swarmfs_util.go ├── log │ └── log.go ├── metrics │ └── flags.go ├── network │ ├── README.md │ ├── bitvector │ │ ├── bitvector.go │ │ └── bitvector_test.go │ ├── common.go │ ├── discovery.go │ ├── discovery_test.go │ ├── fetcher.go │ ├── fetcher_test.go │ ├── hive.go │ ├── hive_test.go │ ├── kademlia.go │ ├── kademlia_test.go │ ├── networkid_test.go │ ├── priorityqueue │ │ ├── priorityqueue.go │ │ └── priorityqueue_test.go │ ├── protocol.go │ ├── protocol_test.go │ ├── simulation │ │ ├── bucket.go │ │ ├── bucket_test.go │ │ ├── events.go │ │ ├── events_test.go │ │ ├── example_test.go │ │ ├── http.go │ │ ├── http_test.go │ │ ├── kademlia.go │ │ ├── kademlia_test.go │ │ ├── node.go │ │ ├── node_test.go │ │ ├── service.go │ │ ├── service_test.go │ │ ├── simulation.go │ │ └── simulation_test.go │ ├── simulations │ │ ├── discovery │ │ │ ├── discovery.go │ │ │ ├── discovery_test.go │ │ │ └── snapshot.json │ │ ├── overlay.go │ │ └── overlay_test.go │ └── stream │ │ ├── common_test.go │ │ ├── delivery.go │ │ ├── delivery_test.go │ │ ├── intervals │ │ ├── dbstore_test.go │ │ ├── intervals.go │ │ ├── intervals_test.go │ │ └── store_test.go │ │ ├── intervals_test.go │ │ ├── lightnode_test.go │ │ ├── messages.go │ │ ├── peer.go │ │ ├── snapshot_retrieval_test.go │ │ ├── snapshot_sync_test.go │ │ ├── stream.go │ │ ├── streamer_test.go │ │ ├── syncer.go │ │ ├── syncer_test.go │ │ ├── testing │ │ ├── snapshot_128.json │ │ ├── snapshot_16.json │ │ ├── snapshot_256.json │ │ ├── snapshot_32.json │ │ └── snapshot_64.json │ │ └── visualized_snapshot_sync_sim_test.go ├── network_test.go ├── pot │ ├── address.go │ ├── doc.go │ ├── pot.go │ └── pot_test.go ├── pss │ ├── ARCHITECTURE.md │ ├── README.md │ ├── api.go │ ├── client │ │ ├── client.go │ │ ├── client_test.go │ │ └── doc.go │ ├── doc.go │ ├── forwarding_test.go │ ├── handshake.go │ ├── handshake_none.go │ ├── handshake_test.go │ ├── notify │ │ ├── notify.go │ │ └── notify_test.go │ ├── ping.go │ ├── protocol.go │ ├── protocol_none.go │ ├── protocol_test.go │ ├── pss.go │ ├── pss_test.go │ ├── testdata │ │ ├── addpsstodiscoverytestsnapshot.pl │ │ ├── addpsstodiscoverytestsnapshot.sh │ │ ├── snapshot_128.json │ │ ├── snapshot_16.json │ │ ├── snapshot_2.json │ │ ├── snapshot_256.json │ │ ├── snapshot_3.json │ │ ├── snapshot_32.json │ │ ├── snapshot_4.json │ │ ├── snapshot_64.json │ │ └── snapshot_8.json │ ├── types.go │ └── writeup.md ├── sctx │ └── sctx.go ├── services │ └── swap │ │ ├── swap.go │ │ └── swap │ │ ├── swap.go │ │ └── swap_test.go ├── shed │ ├── db.go │ ├── db_test.go │ ├── example_store_test.go │ ├── field_string.go │ ├── field_string_test.go │ ├── field_struct.go │ ├── field_struct_test.go │ ├── field_uint64.go │ ├── field_uint64_test.go │ ├── index.go │ ├── index_test.go │ ├── schema.go │ └── schema_test.go ├── spancontext │ └── spancontext.go ├── state │ ├── dbstore.go │ └── dbstore_test.go ├── storage │ ├── chunker.go │ ├── chunker_test.go │ ├── common_test.go │ ├── database.go │ ├── encryption │ │ ├── encryption.go │ │ └── encryption_test.go │ ├── error.go │ ├── feed │ │ ├── binaryserializer.go │ │ ├── binaryserializer_test.go │ │ ├── cacheentry.go │ │ ├── doc.go │ │ ├── error.go │ │ ├── feed.go │ │ ├── feed_test.go │ │ ├── handler.go │ │ ├── handler_test.go │ │ ├── id.go │ │ ├── id_test.go │ │ ├── lookup │ │ │ ├── epoch.go │ │ │ ├── epoch_test.go │ │ │ ├── lookup.go │ │ │ └── lookup_test.go │ │ ├── query.go │ │ ├── query_test.go │ │ ├── request.go │ │ ├── request_test.go │ │ ├── sign.go │ │ ├── testutil.go │ │ ├── timestampprovider.go │ │ ├── topic.go │ │ ├── topic_test.go │ │ ├── update.go │ │ └── update_test.go │ ├── filestore.go │ ├── filestore_test.go │ ├── hasherstore.go │ ├── hasherstore_test.go │ ├── ldbstore.go │ ├── ldbstore_test.go │ ├── localstore.go │ ├── localstore_test.go │ ├── memstore.go │ ├── memstore_test.go │ ├── mock │ │ ├── db │ │ │ ├── db.go │ │ │ └── db_test.go │ │ ├── mem │ │ │ ├── mem.go │ │ │ └── mem_test.go │ │ ├── mock.go │ │ ├── rpc │ │ │ ├── rpc.go │ │ │ └── rpc_test.go │ │ └── test │ │ │ └── test.go │ ├── netstore.go │ ├── netstore_test.go │ ├── pyramid.go │ ├── schema.go │ ├── swarmhasher.go │ ├── types.go │ └── types_test.go ├── swap │ ├── swap.go │ └── swap_test.go ├── swarm.go ├── swarm_test.go ├── testutil │ └── file.go ├── tracing │ └── tracing.go └── version │ └── version.go ├── tests ├── block_test.go ├── block_test_util.go ├── difficulty_test.go ├── difficulty_test_util.go ├── gen_btheader.go ├── gen_difficultytest.go ├── gen_stenv.go ├── gen_sttransaction.go ├── gen_tttransaction.go ├── gen_vmexec.go ├── init.go ├── init_test.go ├── rlp_test.go ├── rlp_test_util.go ├── state_test.go ├── state_test_util.go ├── transaction_test.go ├── transaction_test_util.go ├── vm_test.go └── vm_test_util.go ├── trie ├── database.go ├── encoding.go ├── encoding_test.go ├── errors.go ├── hasher.go ├── iterator.go ├── iterator_test.go ├── node.go ├── node_test.go ├── proof.go ├── proof_test.go ├── secure_trie.go ├── secure_trie_test.go ├── sync.go ├── sync_test.go ├── trie.go └── trie_test.go └── whisper ├── mailserver ├── mailserver.go └── server_test.go ├── shhclient └── client.go ├── whisperv5 ├── api.go ├── benchmarks_test.go ├── config.go ├── doc.go ├── envelope.go ├── filter.go ├── filter_test.go ├── gen_criteria_json.go ├── gen_message_json.go ├── gen_newmessage_json.go ├── message.go ├── message_test.go ├── peer.go ├── peer_test.go ├── topic.go ├── topic_test.go ├── whisper.go └── whisper_test.go └── whisperv6 ├── api.go ├── api_test.go ├── benchmarks_test.go ├── config.go ├── doc.go ├── envelope.go ├── envelope_test.go ├── filter.go ├── filter_test.go ├── gen_criteria_json.go ├── gen_message_json.go ├── gen_newmessage_json.go ├── message.go ├── message_test.go ├── peer.go ├── peer_test.go ├── topic.go ├── topic_test.go ├── whisper.go └── whisper_test.go /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.git 2 | .git 3 | !.git/HEAD 4 | !.git/refs/heads 5 | **/*_test.go 6 | 7 | build/_workspace 8 | build/_bin 9 | tests/testdata 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | *.sol linguist-language=Solidity 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile ~/.gitignore_global 6 | 7 | /tmp 8 | */**/*un~ 9 | */**/*.test 10 | *un~ 11 | .DS_Store 12 | */**/.DS_Store 13 | .ethtest 14 | */**/*tx_database* 15 | */**/*dapps* 16 | build/_vendor/pkg 17 | 18 | #* 19 | .#* 20 | *# 21 | *~ 22 | .project 23 | .settings 24 | 25 | # used by the Makefile 26 | /build/_workspace/ 27 | /build/bin/ 28 | /geth*.zip 29 | 30 | # travis 31 | profile.tmp 32 | profile.cov 33 | 34 | # IdeaIDE 35 | .idea 36 | 37 | # VS Code 38 | .vscode 39 | 40 | # dashboard 41 | /dashboard/assets/flow-typed 42 | /dashboard/assets/node_modules 43 | /dashboard/assets/stats.json 44 | /dashboard/assets/bundle.js 45 | /dashboard/assets/package-lock.json 46 | 47 | **/yarn-error.log 48 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tests"] 2 | path = tests/testdata 3 | url = https://github.com/ethereum/tests 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Build Geth in a stock Go builder container 2 | FROM golang:1.11-alpine as builder 3 | 4 | RUN apk add --no-cache make gcc musl-dev linux-headers 5 | 6 | ADD . /go-ethereum 7 | RUN cd /go-ethereum && make geth 8 | 9 | # Pull Geth into a second stage deploy alpine container 10 | FROM alpine:latest 11 | 12 | RUN apk add --no-cache ca-certificates 13 | COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ 14 | 15 | EXPOSE 8545 8546 30303 30303/udp 16 | ENTRYPOINT ["geth"] 17 | -------------------------------------------------------------------------------- /Dockerfile.alltools: -------------------------------------------------------------------------------- 1 | # Build Geth in a stock Go builder container 2 | FROM golang:1.11-alpine as builder 3 | 4 | RUN apk add --no-cache make gcc musl-dev linux-headers 5 | 6 | ADD . /go-ethereum 7 | RUN cd /go-ethereum && make all 8 | 9 | # Pull all binaries into a second stage deploy alpine container 10 | FROM alpine:latest 11 | 12 | RUN apk add --no-cache ca-certificates 13 | COPY --from=builder /go-ethereum/build/bin/* /usr/local/bin/ 14 | 15 | EXPOSE 8545 8546 30303 30303/udp 16 | -------------------------------------------------------------------------------- /accounts/abi/doc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:31 10 | // 11 | 12 | 13 | //包ABI实现以太坊ABI(应用程序二进制 14 | //接口。 15 | // 16 | //以太坊ABI是强类型的,在编译时已知 17 | //静态。此ABI将处理基本类型转换;无符号 18 | //签署,反之亦然。它不处理切片铸造这样 19 | //作为无符号切片到有符号切片。钻头尺寸类型铸造 20 | //处理。位大小为32的整数将正确转换为Int256, 21 | //等。 22 | package abi 23 | 24 | -------------------------------------------------------------------------------- /accounts/abi/numbers.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:31 10 | // 11 | 12 | 13 | package abi 14 | 15 | import ( 16 | "math/big" 17 | "reflect" 18 | 19 | "github.com/ethereum/go-ethereum/common" 20 | "github.com/ethereum/go-ethereum/common/math" 21 | ) 22 | 23 | var ( 24 | bigT = reflect.TypeOf(&big.Int{}) 25 | derefbigT = reflect.TypeOf(big.Int{}) 26 | uint8T = reflect.TypeOf(uint8(0)) 27 | uint16T = reflect.TypeOf(uint16(0)) 28 | uint32T = reflect.TypeOf(uint32(0)) 29 | uint64T = reflect.TypeOf(uint64(0)) 30 | int8T = reflect.TypeOf(int8(0)) 31 | int16T = reflect.TypeOf(int16(0)) 32 | int32T = reflect.TypeOf(int32(0)) 33 | int64T = reflect.TypeOf(int64(0)) 34 | addressT = reflect.TypeOf(common.Address{}) 35 | ) 36 | 37 | //u256将一个大整数转换为256bit evm数。 38 | func U256(n *big.Int) []byte { 39 | return math.PaddedBigBytes(math.U256(n), 32) 40 | } 41 | 42 | -------------------------------------------------------------------------------- /accounts/abi/numbers_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:31 10 | // 11 | 12 | 13 | package abi 14 | 15 | import ( 16 | "bytes" 17 | "math/big" 18 | "testing" 19 | ) 20 | 21 | func TestNumberTypes(t *testing.T) { 22 | ubytes := make([]byte, 32) 23 | ubytes[31] = 1 24 | 25 | unsigned := U256(big.NewInt(1)) 26 | if !bytes.Equal(unsigned, ubytes) { 27 | t.Errorf("expected %x got %x", ubytes, unsigned) 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /accounts/keystore/testdata/dupes/1: -------------------------------------------------------------------------------- 1 | {"address":"f466859ead1932d743d622cb74fc058882e8648a","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/dupes/2: -------------------------------------------------------------------------------- 1 | {"address":"f466859ead1932d743d622cb74fc058882e8648a","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/dupes/foo: -------------------------------------------------------------------------------- 1 | {"address":"7ef5a6135f1fd6a02593eedc869c6d41d934aef8","crypto":{"cipher":"aes-128-ctr","ciphertext":"1d0839166e7a15b9c1333fc865d69858b22df26815ccf601b28219b6192974e1","cipherparams":{"iv":"8df6caa7ff1b00c4e871f002cb7921ed"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"e5e6ef3f4ea695f496b643ebd3f75c0aa58ef4070e90c80c5d3fb0241bf1595c"},"mac":"6d16dfde774845e4585357f24bce530528bc69f4f84e1e22880d34fa45c273e5"},"id":"950077c7-71e3-4c44-a4a1-143919141ed4","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/.hiddenfile: -------------------------------------------------------------------------------- 1 | {"address":"f466859ead1932d743d622cb74fc058882e8648a","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3} 2 | -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/README: -------------------------------------------------------------------------------- 1 | This directory contains accounts for testing. 2 | The passphrase that unlocks them is "foobar". 3 | 4 | The "good" key files which are supposed to be loadable are: 5 | 6 | - File: UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8 7 | Address: 0x7ef5a6135f1fd6a02593eedc869c6d41d934aef8 8 | - File: aaa 9 | Address: 0xf466859ead1932d743d622cb74fc058882e8648a 10 | - File: zzz 11 | Address: 0x289d485d9771714cce91d3393d764e1311907acc 12 | 13 | The other files (including this README) are broken in various ways 14 | and should not be picked up by package accounts: 15 | 16 | - File: no-address (missing address field, otherwise same as "aaa") 17 | - File: garbage (file with random data) 18 | - File: empty (file with no content) 19 | - File: swapfile~ (should be skipped) 20 | - File: .hiddenfile (should be skipped) 21 | - File: foo/... (should be skipped because it is a directory) 22 | -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8: -------------------------------------------------------------------------------- 1 | {"address":"7ef5a6135f1fd6a02593eedc869c6d41d934aef8","crypto":{"cipher":"aes-128-ctr","ciphertext":"1d0839166e7a15b9c1333fc865d69858b22df26815ccf601b28219b6192974e1","cipherparams":{"iv":"8df6caa7ff1b00c4e871f002cb7921ed"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"e5e6ef3f4ea695f496b643ebd3f75c0aa58ef4070e90c80c5d3fb0241bf1595c"},"mac":"6d16dfde774845e4585357f24bce530528bc69f4f84e1e22880d34fa45c273e5"},"id":"950077c7-71e3-4c44-a4a1-143919141ed4","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/aaa: -------------------------------------------------------------------------------- 1 | {"address":"f466859ead1932d743d622cb74fc058882e8648a","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/accounts/keystore/testdata/keystore/empty -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/foo/fd9bd350f08ee3c0c19b85a8e16114a11a60aa4e: -------------------------------------------------------------------------------- 1 | {"address":"fd9bd350f08ee3c0c19b85a8e16114a11a60aa4e","crypto":{"cipher":"aes-128-ctr","ciphertext":"8124d5134aa4a927c79fd852989e4b5419397566f04b0936a1eb1d168c7c68a5","cipherparams":{"iv":"e2febe17176414dd2cda28287947eb2f"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"44b415ede89f3bdd6830390a21b78965f571b347a589d1d943029f016c5e8bd5"},"mac":"5e149ff25bfd9dd45746a84bb2bcd2f015f2cbca2b6d25c5de8c29617f71fe5b"},"id":"d6ac5452-2b2c-4d3c-ad80-4bf0327d971c","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/garbage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/accounts/keystore/testdata/keystore/garbage -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/no-address: -------------------------------------------------------------------------------- 1 | {"crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/zero: -------------------------------------------------------------------------------- 1 | {"address":"0000000000000000000000000000000000000000","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/keystore/zzz: -------------------------------------------------------------------------------- 1 | {"address":"289d485d9771714cce91d3393d764e1311907acc","crypto":{"cipher":"aes-128-ctr","ciphertext":"faf32ca89d286b107f5e6d842802e05263c49b78d46eac74e6109e9a963378ab","cipherparams":{"iv":"558833eec4a665a8c55608d7d503407d"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"d571fff447ffb24314f9513f5160246f09997b857ac71348b73e785aab40dc04"},"mac":"21edb85ff7d0dab1767b9bf498f2c3cb7be7609490756bd32300bb213b59effe"},"id":"3279afcf-55ba-43ff-8997-02dcc46a6525","version":3} -------------------------------------------------------------------------------- /accounts/keystore/testdata/v1/cb61d5a9c4896fb9658090b597ef0e7be6f7b67e/cb61d5a9c4896fb9658090b597ef0e7be6f7b67e: -------------------------------------------------------------------------------- 1 | {"address":"cb61d5a9c4896fb9658090b597ef0e7be6f7b67e","Crypto":{"cipher":"aes-128-cbc","ciphertext":"6143d3192db8b66eabd693d9c4e414dcfaee52abda451af79ccf474dafb35f1bfc7ea013aa9d2ee35969a1a2e8d752d0","cipherparams":{"iv":"35337770fc2117994ecdcad026bccff4"},"kdf":"scrypt","kdfparams":{"n":262144,"r":8,"p":1,"dklen":32,"salt":"9afcddebca541253a2f4053391c673ff9fe23097cd8555d149d929e4ccf1257f"},"mac":"3f3d5af884b17a100b0b3232c0636c230a54dc2ac8d986227219b0dd89197644","version":"1"},"id":"e25f7c1f-d318-4f29-b62c-687190d4d299","version":"1"} -------------------------------------------------------------------------------- /accounts/keystore/testdata/v1_test_vector.json: -------------------------------------------------------------------------------- 1 | { 2 | "test1": { 3 | "json": { 4 | "Crypto": { 5 | "cipher": "aes-128-cbc", 6 | "cipherparams": { 7 | "iv": "35337770fc2117994ecdcad026bccff4" 8 | }, 9 | "ciphertext": "6143d3192db8b66eabd693d9c4e414dcfaee52abda451af79ccf474dafb35f1bfc7ea013aa9d2ee35969a1a2e8d752d0", 10 | "kdf": "scrypt", 11 | "kdfparams": { 12 | "dklen": 32, 13 | "n": 262144, 14 | "p": 1, 15 | "r": 8, 16 | "salt": "9afcddebca541253a2f4053391c673ff9fe23097cd8555d149d929e4ccf1257f" 17 | }, 18 | "mac": "3f3d5af884b17a100b0b3232c0636c230a54dc2ac8d986227219b0dd89197644", 19 | "version": "1" 20 | }, 21 | "address": "cb61d5a9c4896fb9658090b597ef0e7be6f7b67e", 22 | "id": "e25f7c1f-d318-4f29-b62c-687190d4d299", 23 | "version": "1" 24 | }, 25 | "password": "g", 26 | "priv": "d1b1178d3529626a1a93e073f65028370d14c7eb0936eb42abef05db6f37ad7d" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /accounts/keystore/testdata/very-light-scrypt.json: -------------------------------------------------------------------------------- 1 | {"address":"45dea0fb0bba44f4fcf290bba71fd57d7117cbb8","crypto":{"cipher":"aes-128-ctr","ciphertext":"b87781948a1befd247bff51ef4063f716cf6c2d3481163e9a8f42e1f9bb74145","cipherparams":{"iv":"dc4926b48a105133d2f16b96833abf1e"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"004244bbdc51cadda545b1cfa43cff9ed2ae88e08c61f1479dbb45410722f8f0"},"mac":"39990c1684557447940d4c69e06b1b82b2aceacb43f284df65c956daf3046b85"},"id":"ce541d8d-c79b-40f8-9f8c-20f59616faba","version":3} 2 | -------------------------------------------------------------------------------- /accounts/keystore/watch_fallback.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:32 10 | // 11 | 12 | 13 | //+构建iOS Linux,ARM64 Windows!达尔文!FreeBSD!Linux!NETBSD!索拉里斯 14 | 15 | //这是目录监视的后备实现。 16 | //它用于不受支持的平台。 17 | 18 | package keystore 19 | 20 | type watcher struct{ running bool } 21 | 22 | func newWatcher(*accountCache) *watcher { return new(watcher) } 23 | func (*watcher) start() {} 24 | func (*watcher) close() {} 25 | 26 | -------------------------------------------------------------------------------- /accounts/usbwallet/internal/trezor/trezor.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:32 10 | // 11 | 12 | 13 | //此文件包含用于与Trezor硬件交互的实现 14 | //钱包。有线协议规范可在Satoshilabs网站上找到: 15 | //https://doc.satoshilabs.com/trezor-tech/api-protobuf.html网站 16 | 17 | //go:generate protoc--go_out=import_path=trezor:。types.proto消息.proto 18 | 19 | //包trezor在go中包含有线协议包装器。 20 | package trezor 21 | 22 | import ( 23 | "reflect" 24 | 25 | "github.com/golang/protobuf/proto" 26 | ) 27 | 28 | //类型返回特定消息的协议缓冲区类型号。如果 29 | //消息为零,此方法会恐慌! 30 | func Type(msg proto.Message) uint16 { 31 | return uint16(MessageType_value["MessageType_"+reflect.TypeOf(msg).Elem().Name()]) 32 | } 33 | 34 | //name返回特定协议缓冲区的友好消息类型名称 35 | //类型号。 36 | func Name(kind uint16) string { 37 | name := MessageType_name[int32(kind)] 38 | if len(name) < 12 { 39 | return name 40 | } 41 | return name[12:] 42 | } 43 | 44 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | os: Visual Studio 2015 2 | 3 | # Clone directly into GOPATH. 4 | clone_folder: C:\gopath\src\github.com\ethereum\go-ethereum 5 | clone_depth: 5 6 | version: "{branch}.{build}" 7 | environment: 8 | global: 9 | GOPATH: C:\gopath 10 | CC: gcc.exe 11 | matrix: 12 | - GETH_ARCH: amd64 13 | MSYS2_ARCH: x86_64 14 | MSYS2_BITS: 64 15 | MSYSTEM: MINGW64 16 | PATH: C:\msys64\mingw64\bin\;C:\Program Files (x86)\NSIS\;%PATH% 17 | - GETH_ARCH: 386 18 | MSYS2_ARCH: i686 19 | MSYS2_BITS: 32 20 | MSYSTEM: MINGW32 21 | PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH% 22 | 23 | install: 24 | - git submodule update --init 25 | - rmdir C:\go /s /q 26 | - appveyor DownloadFile https://storage.googleapis.com/golang/go1.11.4.windows-%GETH_ARCH%.zip 27 | - 7z x go1.11.4.windows-%GETH_ARCH%.zip -y -oC:\ > NUL 28 | - go version 29 | - gcc --version 30 | 31 | build_script: 32 | - go run build\ci.go install 33 | 34 | after_build: 35 | - go run build\ci.go archive -type zip -signer WINDOWS_SIGNING_KEY -upload gethstore/builds 36 | - go run build\ci.go nsis -signer WINDOWS_SIGNING_KEY -upload gethstore/builds 37 | 38 | test_script: 39 | - set CGO_ENABLED=1 40 | - go run build\ci.go test -coverage 41 | -------------------------------------------------------------------------------- /build/clean_go_build_cache.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Cleaning the Go cache only makes sense if we actually have Go installed... or 4 | # if Go is actually callable. This does not hold true during deb packaging, so 5 | # we need an explicit check to avoid build failures. 6 | if ! command -v go > /dev/null; then 7 | exit 8 | fi 9 | 10 | version_gt() { 11 | test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" 12 | } 13 | 14 | golang_version=$(go version |cut -d' ' -f3 |sed 's/go//') 15 | 16 | # Clean go build cache when go version is greater than or equal to 1.10 17 | if !(version_gt 1.10 $golang_version); then 18 | go clean -cache 19 | fi 20 | -------------------------------------------------------------------------------- /build/deb/ethereum-swarm/deb.changelog: -------------------------------------------------------------------------------- 1 | {{.Name}} ({{.VersionString}}) {{.Distro}}; urgency=low 2 | 3 | * git build of {{.Env.Commit}} 4 | 5 | -- {{.Author}} {{.Time}} 6 | -------------------------------------------------------------------------------- /build/deb/ethereum-swarm/deb.control: -------------------------------------------------------------------------------- 1 | Source: {{.Name}} 2 | Section: science 3 | Priority: extra 4 | Maintainer: {{.Author}} 5 | Build-Depends: debhelper (>= 8.0.0), golang-1.10 6 | Standards-Version: 3.9.5 7 | Homepage: https://ethereum.org 8 | Vcs-Git: git://github.com/ethereum/go-ethereum.git 9 | Vcs-Browser: https://github.com/ethereum/go-ethereum 10 | 11 | {{range .Executables}} 12 | Package: {{$.ExeName .}} 13 | Conflicts: {{$.ExeConflicts .}} 14 | Architecture: any 15 | Depends: ${shlibs:Depends}, ${misc:Depends} 16 | Built-Using: ${misc:Built-Using} 17 | Description: {{.Description}} 18 | {{.Description}} 19 | {{end}} 20 | -------------------------------------------------------------------------------- /build/deb/ethereum-swarm/deb.copyright: -------------------------------------------------------------------------------- 1 | Copyright 2018 The go-ethereum Authors 2 | 3 | go-ethereum is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | go-ethereum is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with go-ethereum. If not, see . 15 | -------------------------------------------------------------------------------- /build/deb/ethereum-swarm/deb.docs: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | -------------------------------------------------------------------------------- /build/deb/ethereum-swarm/deb.install: -------------------------------------------------------------------------------- 1 | build/bin/{{.BinaryName}} usr/bin 2 | -------------------------------------------------------------------------------- /build/deb/ethereum-swarm/deb.rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | 4 | # Uncomment this to turn on verbose mode. 5 | #export DH_VERBOSE=1 6 | 7 | override_dh_auto_build: 8 | build/env.sh /usr/lib/go-1.10/bin/go run build/ci.go install -git-commit={{.Env.Commit}} -git-branch={{.Env.Branch}} -git-tag={{.Env.Tag}} -buildnum={{.Env.Buildnum}} -pull-request={{.Env.IsPullRequest}} 9 | 10 | override_dh_auto_test: 11 | 12 | %: 13 | dh $@ 14 | -------------------------------------------------------------------------------- /build/deb/ethereum/deb.changelog: -------------------------------------------------------------------------------- 1 | {{.Name}} ({{.VersionString}}) {{.Distro}}; urgency=low 2 | 3 | * git build of {{.Env.Commit}} 4 | 5 | -- {{.Author}} {{.Time}} 6 | -------------------------------------------------------------------------------- /build/deb/ethereum/deb.control: -------------------------------------------------------------------------------- 1 | Source: {{.Name}} 2 | Section: science 3 | Priority: extra 4 | Maintainer: {{.Author}} 5 | Build-Depends: debhelper (>= 8.0.0), golang-1.10 6 | Standards-Version: 3.9.5 7 | Homepage: https://ethereum.org 8 | Vcs-Git: git://github.com/ethereum/go-ethereum.git 9 | Vcs-Browser: https://github.com/ethereum/go-ethereum 10 | 11 | Package: {{.Name}} 12 | Architecture: any 13 | Depends: ${misc:Depends}, {{.ExeList}} 14 | Description: Meta-package to install geth, swarm, and other tools 15 | Meta-package to install geth, swarm and other tools 16 | 17 | {{range .Executables}} 18 | Package: {{$.ExeName .}} 19 | Conflicts: {{$.ExeConflicts .}} 20 | Architecture: any 21 | Depends: ${shlibs:Depends}, ${misc:Depends} 22 | Built-Using: ${misc:Built-Using} 23 | Description: {{.Description}} 24 | {{.Description}} 25 | {{end}} 26 | -------------------------------------------------------------------------------- /build/deb/ethereum/deb.copyright: -------------------------------------------------------------------------------- 1 | Copyright 2018 The go-ethereum Authors 2 | 3 | go-ethereum is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | go-ethereum is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with go-ethereum. If not, see . 15 | -------------------------------------------------------------------------------- /build/deb/ethereum/deb.docs: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | -------------------------------------------------------------------------------- /build/deb/ethereum/deb.install: -------------------------------------------------------------------------------- 1 | build/bin/{{.BinaryName}} usr/bin 2 | -------------------------------------------------------------------------------- /build/deb/ethereum/deb.rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | 4 | # Uncomment this to turn on verbose mode. 5 | #export DH_VERBOSE=1 6 | 7 | override_dh_auto_build: 8 | build/env.sh /usr/lib/go-1.10/bin/go run build/ci.go install -git-commit={{.Env.Commit}} -git-branch={{.Env.Branch}} -git-tag={{.Env.Tag}} -buildnum={{.Env.Buildnum}} -pull-request={{.Env.IsPullRequest}} 9 | 10 | override_dh_auto_test: 11 | 12 | %: 13 | dh $@ 14 | -------------------------------------------------------------------------------- /build/env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ ! -f "build/env.sh" ]; then 6 | echo "$0 must be run from the root of the repository." 7 | exit 2 8 | fi 9 | 10 | # Create fake Go workspace if it doesn't exist yet. 11 | workspace="$PWD/build/_workspace" 12 | root="$PWD" 13 | ethdir="$workspace/src/github.com/ethereum" 14 | if [ ! -L "$ethdir/go-ethereum" ]; then 15 | mkdir -p "$ethdir" 16 | cd "$ethdir" 17 | ln -s ../../../../../. go-ethereum 18 | cd "$root" 19 | fi 20 | 21 | # Set up the environment to use the workspace. 22 | GOPATH="$workspace" 23 | export GOPATH 24 | 25 | # Run the command inside the workspace. 26 | cd "$ethdir/go-ethereum" 27 | PWD="$ethdir/go-ethereum" 28 | 29 | # Launch the arguments with the configured environment. 30 | exec "$@" 31 | -------------------------------------------------------------------------------- /build/goimports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find_files() { 4 | find . ! \( \ 5 | \( \ 6 | -path '.github' \ 7 | -o -path './build/_workspace' \ 8 | -o -path './build/bin' \ 9 | -o -path './crypto/bn256' \ 10 | -o -path '*/vendor/*' \ 11 | \) -prune \ 12 | \) -name '*.go' 13 | } 14 | 15 | GOFMT="gofmt -s -w" 16 | GOIMPORTS="goimports -w" 17 | find_files | xargs $GOFMT 18 | find_files | xargs $GOIMPORTS 19 | -------------------------------------------------------------------------------- /build/mvn.settings: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | ossrh 8 | ${env.ANDROID_SONATYPE_USERNAME} 9 | ${env.ANDROID_SONATYPE_PASSWORD} 10 | 11 | 12 | 13 | 14 | ossrh 15 | 16 | true 17 | 18 | 19 | gpg 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /build/nsis.simplefc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/build/nsis.simplefc.dll -------------------------------------------------------------------------------- /build/nsis.simplefc.source.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/build/nsis.simplefc.source.zip -------------------------------------------------------------------------------- /build/nsis.uninstall.nsh: -------------------------------------------------------------------------------- 1 | Section "Uninstall" 2 | # uninstall for all users 3 | setShellVarContext all 4 | 5 | # Delete (optionally) installed files 6 | {{range $}}Delete $INSTDIR\{{.}} 7 | {{end}} 8 | Delete $INSTDIR\uninstall.exe 9 | 10 | # Delete install directory 11 | rmDir $INSTDIR 12 | 13 | # Delete start menu launcher 14 | Delete "$SMPROGRAMS\${APPNAME}\${APPNAME}.lnk" 15 | Delete "$SMPROGRAMS\${APPNAME}\Attach.lnk" 16 | Delete "$SMPROGRAMS\${APPNAME}\Uninstall.lnk" 17 | rmDir "$SMPROGRAMS\${APPNAME}" 18 | 19 | # Firewall - remove rules if exists 20 | SimpleFC::AdvRemoveRule "Geth incoming peers (TCP:30303)" 21 | SimpleFC::AdvRemoveRule "Geth outgoing peers (TCP:30303)" 22 | SimpleFC::AdvRemoveRule "Geth UDP discovery (UDP:30303)" 23 | 24 | # Remove IPC endpoint (https://github.com/ethereum/EIPs/issues/147) 25 | ${un.EnvVarUpdate} $0 "ETHEREUM_SOCKET" "R" "HKLM" "\\.\pipe\geth.ipc" 26 | 27 | # Remove install directory from PATH 28 | Push "$INSTDIR" 29 | Call un.RemoveFromPath 30 | 31 | # Cleanup registry (deletes all sub keys) 32 | DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" 33 | SectionEnd 34 | -------------------------------------------------------------------------------- /build/pod.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = 'Geth' 3 | spec.version = '{{.Version}}' 4 | spec.license = { :type => 'GNU Lesser General Public License, Version 3.0' } 5 | spec.homepage = 'https://github.com/ethereum/go-ethereum' 6 | spec.authors = { {{range .Contributors}} 7 | '{{.Name}}' => '{{.Email}}',{{end}} 8 | } 9 | spec.summary = 'iOS Ethereum Client' 10 | spec.source = { :git => 'https://github.com/ethereum/go-ethereum.git', :commit => '{{.Commit}}' } 11 | 12 | spec.platform = :ios 13 | spec.ios.deployment_target = '9.0' 14 | spec.ios.vendored_frameworks = 'Frameworks/Geth.framework' 15 | 16 | spec.prepare_command = <<-CMD 17 | curl https://gethstore.blob.core.windows.net/builds/{{.Archive}}.tar.gz | tar -xvz 18 | mkdir Frameworks 19 | mv {{.Archive}}/Geth.framework Frameworks 20 | rm -rf {{.Archive}} 21 | CMD 22 | end 23 | -------------------------------------------------------------------------------- /cmd/clef/docs/qubes/clef_qubes_http.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/cmd/clef/docs/qubes/clef_qubes_http.png -------------------------------------------------------------------------------- /cmd/clef/docs/qubes/clef_qubes_qrexec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/cmd/clef/docs/qubes/clef_qubes_qrexec.png -------------------------------------------------------------------------------- /cmd/clef/docs/qubes/qrexec-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/cmd/clef/docs/qubes/qrexec-example.png -------------------------------------------------------------------------------- /cmd/clef/docs/qubes/qubes-client.py: -------------------------------------------------------------------------------- 1 | """ 2 | This implements a dispatcher which listens to localhost:8550, and proxies 3 | requests via qrexec to the service qubes.EthSign on a target domain 4 | """ 5 | 6 | import http.server 7 | import socketserver,subprocess 8 | 9 | PORT=8550 10 | TARGET_DOMAIN= 'debian-work' 11 | 12 | class Dispatcher(http.server.BaseHTTPRequestHandler): 13 | def do_POST(self): 14 | post_data = self.rfile.read(int(self.headers['Content-Length'])) 15 | p = subprocess.Popen(['/usr/bin/qrexec-client-vm',TARGET_DOMAIN,'qubes.Clefsign'],stdin=subprocess.PIPE, stdout=subprocess.PIPE) 16 | output = p.communicate(post_data)[0] 17 | self.wfile.write(output) 18 | 19 | 20 | with socketserver.TCPServer(("",PORT), Dispatcher) as httpd: 21 | print("Serving at port", PORT) 22 | httpd.serve_forever() 23 | 24 | -------------------------------------------------------------------------------- /cmd/clef/docs/qubes/qubes.Clefsign: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SIGNER_BIN="/home/user/tools/clef/clef" 4 | SIGNER_CMD="/home/user/tools/gtksigner/gtkui.py -s $SIGNER_BIN" 5 | 6 | # Start clef if not already started 7 | if [ ! -S /home/user/.clef/clef.ipc ]; then 8 | $SIGNER_CMD & 9 | sleep 1 10 | fi 11 | 12 | # Should be started by now 13 | if [ -S /home/user/.clef/clef.ipc ]; then 14 | # Post incoming request to HTTP channel 15 | curl -H "Content-Type: application/json" -X POST -d @- http://localhost:8550 2>/dev/null 16 | fi 17 | -------------------------------------------------------------------------------- /cmd/clef/docs/qubes/qubes_newaccount-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/cmd/clef/docs/qubes/qubes_newaccount-1.png -------------------------------------------------------------------------------- /cmd/clef/docs/qubes/qubes_newaccount-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/cmd/clef/docs/qubes/qubes_newaccount-2.png -------------------------------------------------------------------------------- /cmd/clef/extapi_changelog.md: -------------------------------------------------------------------------------- 1 | ### Changelog for external API 2 | 3 | #### 4.0.0 4 | 5 | * The external `account_Ecrecover`-method was removed. 6 | * The external `account_Import`-method was removed. 7 | 8 | #### 3.0.0 9 | 10 | * The external `account_List`-method was changed to not expose `url`, which contained info about the local filesystem. It now returns only a list of addresses. 11 | 12 | #### 2.0.0 13 | 14 | * Commit `73abaf04b1372fa4c43201fb1b8019fe6b0a6f8d`, move `from` into `transaction` object in `signTransaction`. This 15 | makes the `accounts_signTransaction` identical to the old `eth_signTransaction`. 16 | 17 | 18 | #### 1.0.0 19 | 20 | Initial release. 21 | 22 | ### Versioning 23 | 24 | The API uses [semantic versioning](https://semver.org/). 25 | 26 | TLDR; Given a version number MAJOR.MINOR.PATCH, increment the: 27 | 28 | * MAJOR version when you make incompatible API changes, 29 | * MINOR version when you add functionality in a backwards-compatible manner, and 30 | * PATCH version when you make backwards-compatible bug fixes. 31 | 32 | Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. 33 | -------------------------------------------------------------------------------- /cmd/clef/sign_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/cmd/clef/sign_flow.png -------------------------------------------------------------------------------- /cmd/ethkey/main.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:32 10 | // 11 | 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "os" 18 | 19 | "github.com/ethereum/go-ethereum/cmd/utils" 20 | "gopkg.in/urfave/cli.v1" 21 | ) 22 | 23 | const ( 24 | defaultKeyfileName = "keyfile.json" 25 | ) 26 | 27 | //git sha1提交发布的哈希(通过链接器标志设置) 28 | var gitCommit = "" 29 | 30 | var app *cli.App 31 | 32 | func init() { 33 | app = utils.NewApp(gitCommit, "an Ethereum key manager") 34 | app.Commands = []cli.Command{ 35 | commandGenerate, 36 | commandInspect, 37 | commandChangePassphrase, 38 | commandSignMessage, 39 | commandVerifyMessage, 40 | } 41 | } 42 | 43 | //常用命令行标志。 44 | var ( 45 | passphraseFlag = cli.StringFlag{ 46 | Name: "passwordfile", 47 | Usage: "the file that contains the passphrase for the keyfile", 48 | } 49 | jsonFlag = cli.BoolFlag{ 50 | Name: "json", 51 | Usage: "output JSON instead of human-readable format", 52 | } 53 | ) 54 | 55 | func main() { 56 | if err := app.Run(os.Args); err != nil { 57 | fmt.Fprintln(os.Stderr, err) 58 | os.Exit(1) 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /cmd/ethkey/run_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:32 10 | // 11 | 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "os" 18 | "testing" 19 | 20 | "github.com/docker/docker/pkg/reexec" 21 | "github.com/ethereum/go-ethereum/internal/cmdtest" 22 | ) 23 | 24 | type testEthkey struct { 25 | *cmdtest.TestCmd 26 | } 27 | 28 | //使用给定的命令行参数生成ethkey。 29 | func runEthkey(t *testing.T, args ...string) *testEthkey { 30 | tt := new(testEthkey) 31 | tt.TestCmd = cmdtest.NewTestCmd(t, tt) 32 | tt.Run("ethkey-test", args...) 33 | return tt 34 | } 35 | 36 | func TestMain(m *testing.M) { 37 | //如果我们在run ethkey中被执行为“ethkey测试”,请运行该应用程序。 38 | reexec.Register("ethkey-test", func() { 39 | if err := app.Run(os.Args); err != nil { 40 | fmt.Fprintln(os.Stderr, err) 41 | os.Exit(1) 42 | } 43 | os.Exit(0) 44 | }) 45 | //检查我们是否被重新执行了 46 | if reexec.Init() { 47 | return 48 | } 49 | os.Exit(m.Run()) 50 | } 51 | 52 | -------------------------------------------------------------------------------- /cmd/evm/compiler.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:32 10 | // 11 | 12 | 13 | package main 14 | 15 | import ( 16 | "errors" 17 | "fmt" 18 | "io/ioutil" 19 | 20 | "github.com/ethereum/go-ethereum/cmd/evm/internal/compiler" 21 | 22 | cli "gopkg.in/urfave/cli.v1" 23 | ) 24 | 25 | var compileCommand = cli.Command{ 26 | Action: compileCmd, 27 | Name: "compile", 28 | Usage: "compiles easm source to evm binary", 29 | ArgsUsage: "", 30 | } 31 | 32 | func compileCmd(ctx *cli.Context) error { 33 | debug := ctx.GlobalBool(DebugFlag.Name) 34 | 35 | if len(ctx.Args().First()) == 0 { 36 | return errors.New("filename required") 37 | } 38 | 39 | fn := ctx.Args().First() 40 | src, err := ioutil.ReadFile(fn) 41 | if err != nil { 42 | return err 43 | } 44 | 45 | bin, err := compiler.Compile(fn, src, debug) 46 | if err != nil { 47 | return err 48 | } 49 | fmt.Println(bin) 50 | return nil 51 | } 52 | 53 | -------------------------------------------------------------------------------- /cmd/evm/disasm.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:32 10 | // 11 | 12 | 13 | package main 14 | 15 | import ( 16 | "errors" 17 | "fmt" 18 | "io/ioutil" 19 | "strings" 20 | 21 | "github.com/ethereum/go-ethereum/core/asm" 22 | cli "gopkg.in/urfave/cli.v1" 23 | ) 24 | 25 | var disasmCommand = cli.Command{ 26 | Action: disasmCmd, 27 | Name: "disasm", 28 | Usage: "disassembles evm binary", 29 | ArgsUsage: "", 30 | } 31 | 32 | func disasmCmd(ctx *cli.Context) error { 33 | if len(ctx.Args().First()) == 0 { 34 | return errors.New("filename required") 35 | } 36 | 37 | fn := ctx.Args().First() 38 | in, err := ioutil.ReadFile(fn) 39 | if err != nil { 40 | return err 41 | } 42 | 43 | code := strings.TrimSpace(string(in)) 44 | fmt.Printf("%v\n", code) 45 | return asm.PrintDisassembled(code) 46 | } 47 | 48 | -------------------------------------------------------------------------------- /cmd/evm/internal/compiler/compiler.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:32 10 | // 11 | 12 | 13 | package compiler 14 | 15 | import ( 16 | "errors" 17 | "fmt" 18 | 19 | "github.com/ethereum/go-ethereum/core/asm" 20 | ) 21 | 22 | func Compile(fn string, src []byte, debug bool) (string, error) { 23 | compiler := asm.NewCompiler(debug) 24 | compiler.Feed(asm.Lex(fn, src, debug)) 25 | 26 | bin, compileErrors := compiler.Compile() 27 | if len(compileErrors) > 0 { 28 | //报告错误 29 | for _, err := range compileErrors { 30 | fmt.Printf("%s:%v\n", fn, err) 31 | } 32 | return "", errors.New("compiling failed") 33 | } 34 | return bin, nil 35 | } 36 | 37 | -------------------------------------------------------------------------------- /cmd/geth/testdata/empty.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /cmd/geth/testdata/guswallet.json: -------------------------------------------------------------------------------- 1 | { 2 | "encseed": "26d87f5f2bf9835f9a47eefae571bc09f9107bb13d54ff12a4ec095d01f83897494cf34f7bed2ed34126ecba9db7b62de56c9d7cd136520a0427bfb11b8954ba7ac39b90d4650d3448e31185affcd74226a68f1e94b1108e6e0a4a91cdd83eba", 3 | "ethaddr": "d4584b5f6229b7be90727b0fc8c6b91bb427821f", 4 | "email": "gustav.simonsson@gmail.com", 5 | "btcaddr": "1EVknXyFC68kKNLkh6YnKzW41svSRoaAcx" 6 | } 7 | -------------------------------------------------------------------------------- /cmd/geth/testdata/passwords.txt: -------------------------------------------------------------------------------- 1 | foobar 2 | foobar 3 | foobar 4 | -------------------------------------------------------------------------------- /cmd/geth/testdata/wrong-passwords.txt: -------------------------------------------------------------------------------- 1 | wrong 2 | wrong 3 | wrong 4 | -------------------------------------------------------------------------------- /cmd/swarm/swarm-snapshot/run_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:33 10 | // 11 | 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "os" 18 | "testing" 19 | 20 | "github.com/docker/docker/pkg/reexec" 21 | "github.com/ethereum/go-ethereum/internal/cmdtest" 22 | ) 23 | 24 | func init() { 25 | reexec.Register("swarm-snapshot", func() { 26 | if err := newApp().Run(os.Args); err != nil { 27 | fmt.Fprintln(os.Stderr, err) 28 | os.Exit(1) 29 | } 30 | os.Exit(0) 31 | }) 32 | } 33 | 34 | func runSnapshot(t *testing.T, args ...string) *cmdtest.TestCmd { 35 | tt := cmdtest.NewTestCmd(t, nil) 36 | tt.Run("swarm-snapshot", args...) 37 | return tt 38 | } 39 | 40 | func TestMain(m *testing.M) { 41 | if reexec.Init() { 42 | return 43 | } 44 | os.Exit(m.Run()) 45 | } 46 | 47 | -------------------------------------------------------------------------------- /cmd/utils/customflags_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:33 10 | // 11 | 12 | 13 | package utils 14 | 15 | import ( 16 | "os" 17 | "os/user" 18 | "testing" 19 | ) 20 | 21 | func TestPathExpansion(t *testing.T) { 22 | user, _ := user.Current() 23 | tests := map[string]string{ 24 | "/home/someuser/tmp": "/home/someuser/tmp", 25 | "~/tmp": user.HomeDir + "/tmp", 26 | "~thisOtherUser/b/": "~thisOtherUser/b", 27 | "$DDDXXX/a/b": "/tmp/a/b", 28 | "/a/b/": "/a/b", 29 | } 30 | os.Setenv("DDDXXX", "/tmp") 31 | for test, expected := range tests { 32 | got := expandPath(test) 33 | if got != expected { 34 | t.Errorf("test %s, got %s, expected %s\n", test, got, expected) 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /common/big.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:33 10 | // 11 | 12 | 13 | package common 14 | 15 | import "math/big" 16 | 17 | //常用的普通大整数 18 | var ( 19 | Big1 = big.NewInt(1) 20 | Big2 = big.NewInt(2) 21 | Big3 = big.NewInt(3) 22 | Big0 = big.NewInt(0) 23 | Big32 = big.NewInt(32) 24 | Big256 = big.NewInt(256) 25 | Big257 = big.NewInt(257) 26 | ) 27 | 28 | -------------------------------------------------------------------------------- /common/bitutil/compress_fuzz.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:33 10 | // 11 | 12 | 13 | //+构建GouuZZ 14 | 15 | package bitutil 16 | 17 | import "bytes" 18 | 19 | //Fuzz实现了Go-Fuzz引信方法来测试各种编码方法 20 | //调用。 21 | func Fuzz(data []byte) int { 22 | if len(data) == 0 { 23 | return -1 24 | } 25 | if data[0]%2 == 0 { 26 | return fuzzEncode(data[1:]) 27 | } 28 | return fuzzDecode(data[1:]) 29 | } 30 | 31 | //Fuzzencode实现了一种go-fuzz引信方法来测试位集编码和 32 | //解码算法。 33 | func fuzzEncode(data []byte) int { 34 | proc, _ := bitsetDecodeBytes(bitsetEncodeBytes(data), len(data)) 35 | if !bytes.Equal(data, proc) { 36 | panic("content mismatch") 37 | } 38 | return 0 39 | } 40 | 41 | //fuzzdecode实现了一种go-fuzz引信方法来测试位解码和 42 | //重新编码算法。 43 | func fuzzDecode(data []byte) int { 44 | blob, err := bitsetDecodeBytes(data, 1024) 45 | if err != nil { 46 | return 0 47 | } 48 | if comp := bitsetEncodeBytes(blob); !bytes.Equal(comp, data) { 49 | panic("content mismatch") 50 | } 51 | return 0 52 | } 53 | 54 | -------------------------------------------------------------------------------- /common/debug.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:33 10 | // 11 | 12 | 13 | package common 14 | 15 | import ( 16 | "fmt" 17 | "os" 18 | "runtime" 19 | "runtime/debug" 20 | "strings" 21 | ) 22 | 23 | //报告发出警告,要求用户向Github跟踪器提交问题。 24 | func Report(extra ...interface{}) { 25 | fmt.Fprintln(os.Stderr, "You've encountered a sought after, hard to reproduce bug. Please report this to the developers <3 https://github.com/ethereum/go-ethereum/issues“) 26 | fmt.Fprintln(os.Stderr, extra...) 27 | 28 | _, file, line, _ := runtime.Caller(1) 29 | fmt.Fprintf(os.Stderr, "%v:%v\n", file, line) 30 | 31 | debug.PrintStack() 32 | 33 | fmt.Fprintln(os.Stderr, "#### BUG! PLEASE REPORT ####") 34 | } 35 | 36 | //使用fmt.println在框中打印出给定的字符串。 37 | func PrintDepricationWarning(str string) { 38 | line := strings.Repeat("#", len(str)+4) 39 | emptyLine := strings.Repeat(" ", len(str)) 40 | fmt.Printf(` 41 | %s 42 | # %s # 43 | # %s # 44 | # %s # 45 | %s 46 | 47 | `, line, emptyLine, str, emptyLine, line) 48 | } 49 | 50 | -------------------------------------------------------------------------------- /common/fdlimit/fdlimit_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:33 10 | // 11 | 12 | 13 | package fdlimit 14 | 15 | import ( 16 | "fmt" 17 | "testing" 18 | ) 19 | 20 | //testfiledescriptor限制只测试文件描述符是否允许 21 | //根据此过程可以检索。 22 | func TestFileDescriptorLimits(t *testing.T) { 23 | target := 4096 24 | hardlimit, err := Maximum() 25 | if err != nil { 26 | t.Fatal(err) 27 | } 28 | if hardlimit < target { 29 | t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target)) 30 | } 31 | 32 | if limit, err := Current(); err != nil || limit <= 0 { 33 | t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err) 34 | } 35 | if err := Raise(uint64(target)); err != nil { 36 | t.Fatalf("failed to raise file allowance") 37 | } 38 | if limit, err := Current(); err != nil || limit < target { 39 | t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err) 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /common/fdlimit/fdlimit_windows.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:33 10 | // 11 | 12 | 13 | package fdlimit 14 | 15 | import "errors" 16 | 17 | //raise尝试最大化此进程的文件描述符允许量 18 | //达到操作系统允许的最大硬限制。 19 | func Raise(max uint64) error { 20 | //该方法设计为NOP: 21 | //*Linux/Darwin对应程序需要手动增加每个进程的限制 22 | //*在Windows上,Go使用CreateFile API,该API仅限于16K个文件,非 23 | //可从正在运行的进程中更改 24 | //这样,我们就可以“请求”提高限额,这两种情况都有 25 | //或者基于我们运行的平台没有效果。 26 | if max > 16384 { 27 | return errors.New("file descriptor limit (16384) reached") 28 | } 29 | return nil 30 | } 31 | 32 | //当前检索允许由此打开的文件描述符数 33 | //过程。 34 | func Current() (int, error) { 35 | //请参阅“加薪”,了解我们为什么使用硬编码16K作为限制的原因。 36 | return 16384, nil 37 | } 38 | 39 | //最大检索此进程的最大文件描述符数 40 | //允许自己请求。 41 | func Maximum() (int, error) { 42 | return Current() 43 | } 44 | 45 | -------------------------------------------------------------------------------- /common/hexutil/json_example_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package hexutil_test 14 | 15 | import ( 16 | "encoding/json" 17 | "fmt" 18 | 19 | "github.com/ethereum/go-ethereum/common/hexutil" 20 | ) 21 | 22 | type MyType [5]byte 23 | 24 | func (v *MyType) UnmarshalText(input []byte) error { 25 | return hexutil.UnmarshalFixedText("MyType", input, v[:]) 26 | } 27 | 28 | func (v MyType) String() string { 29 | return hexutil.Bytes(v[:]).String() 30 | } 31 | 32 | func ExampleUnmarshalFixedText() { 33 | var v1, v2 MyType 34 | fmt.Println("v1 error:", json.Unmarshal([]byte(`"0x01"`), &v1)) 35 | fmt.Println("v2 error:", json.Unmarshal([]byte(`"0x0101010101"`), &v2)) 36 | fmt.Println("v2:", v2) 37 | //输出: 38 | //v1错误:十六进制字符串的长度为2,MyType需要10 39 | //V2错误: 40 | //版本2:0x0101010101 41 | } 42 | 43 | -------------------------------------------------------------------------------- /common/main_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package common 14 | 15 | import ( 16 | "testing" 17 | 18 | checker "gopkg.in/check.v1" 19 | ) 20 | 21 | func Test(t *testing.T) { checker.TestingT(t) } 22 | 23 | -------------------------------------------------------------------------------- /common/mclock/mclock.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | //包mclock是单调时钟源的包装器 14 | package mclock 15 | 16 | import ( 17 | "time" 18 | 19 | "github.com/aristanetworks/goarista/monotime" 20 | ) 21 | 22 | //Abstime代表绝对单调时间。 23 | type AbsTime time.Duration 24 | 25 | //现在返回当前绝对单调时间。 26 | func Now() AbsTime { 27 | return AbsTime(monotime.Now()) 28 | } 29 | 30 | //添加返回t+d。 31 | func (t AbsTime) Add(d time.Duration) AbsTime { 32 | return t + AbsTime(d) 33 | } 34 | 35 | //时钟接口使得用 36 | //模拟时钟。 37 | type Clock interface { 38 | Now() AbsTime 39 | Sleep(time.Duration) 40 | After(time.Duration) <-chan time.Time 41 | } 42 | 43 | //系统使用系统时钟实现时钟。 44 | type System struct{} 45 | 46 | //现在实现时钟。 47 | func (System) Now() AbsTime { 48 | return AbsTime(monotime.Now()) 49 | } 50 | 51 | //睡眠实现时钟。 52 | func (System) Sleep(d time.Duration) { 53 | time.Sleep(d) 54 | } 55 | 56 | //在执行时钟之后。 57 | func (System) After(d time.Duration) <-chan time.Time { 58 | return time.After(d) 59 | } 60 | 61 | -------------------------------------------------------------------------------- /common/path.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package common 14 | 15 | import ( 16 | "fmt" 17 | "os" 18 | "path/filepath" 19 | "runtime" 20 | ) 21 | 22 | //makename创建一个遵循以太坊约定的节点名 23 | //对于这样的名字。它添加了操作系统名称和go运行时版本 24 | //这个名字。 25 | func MakeName(name, version string) string { 26 | return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version()) 27 | } 28 | 29 | //fileexist检查文件路径中是否存在文件。 30 | func FileExist(filePath string) bool { 31 | _, err := os.Stat(filePath) 32 | if err != nil && os.IsNotExist(err) { 33 | return false 34 | } 35 | 36 | return true 37 | } 38 | 39 | //absolutePath返回datadir+filename,如果是绝对的,则返回filename。 40 | func AbsolutePath(datadir string, filename string) string { 41 | if filepath.IsAbs(filename) { 42 | return filename 43 | } 44 | return filepath.Join(datadir, filename) 45 | } 46 | 47 | -------------------------------------------------------------------------------- /common/size.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package common 14 | 15 | import ( 16 | "fmt" 17 | ) 18 | 19 | //StorageSize是一个围绕浮点值的包装器,它支持用户友好的 20 | //格式化。 21 | type StorageSize float64 22 | 23 | //字符串实现字符串接口。 24 | func (s StorageSize) String() string { 25 | if s > 1000000 { 26 | return fmt.Sprintf("%.2f mB", s/1000000) 27 | } else if s > 1000 { 28 | return fmt.Sprintf("%.2f kB", s/1000) 29 | } else { 30 | return fmt.Sprintf("%.2f B", s) 31 | } 32 | } 33 | 34 | //terminalString实现log.terminalStringer,为控制台格式化字符串 35 | //日志记录期间的输出。 36 | func (s StorageSize) TerminalString() string { 37 | if s > 1000000 { 38 | return fmt.Sprintf("%.2fmB", s/1000000) 39 | } else if s > 1000 { 40 | return fmt.Sprintf("%.2fkB", s/1000) 41 | } else { 42 | return fmt.Sprintf("%.2fB", s) 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /common/size_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package common 14 | 15 | import ( 16 | "testing" 17 | ) 18 | 19 | func TestStorageSizeString(t *testing.T) { 20 | tests := []struct { 21 | size StorageSize 22 | str string 23 | }{ 24 | {2381273, "2.38 mB"}, 25 | {2192, "2.19 kB"}, 26 | {12, "12.00 B"}, 27 | } 28 | 29 | for _, test := range tests { 30 | if test.size.String() != test.str { 31 | t.Errorf("%f: got %q, want %q", float64(test.size), test.size.String(), test.str) 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /common/test_utils.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package common 14 | 15 | import ( 16 | "encoding/json" 17 | "fmt" 18 | "io/ioutil" 19 | ) 20 | 21 | //loadjson读取给定的文件并取消其内容的标记。 22 | func LoadJSON(file string, val interface{}) error { 23 | content, err := ioutil.ReadFile(file) 24 | if err != nil { 25 | return err 26 | } 27 | if err := json.Unmarshal(content, val); err != nil { 28 | if syntaxerr, ok := err.(*json.SyntaxError); ok { 29 | line := findLine(content, syntaxerr.Offset) 30 | return fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err) 31 | } 32 | return fmt.Errorf("JSON unmarshal error in %v: %v", file, err) 33 | } 34 | return nil 35 | } 36 | 37 | //findline将给定偏移量的行号返回到数据中。 38 | func findLine(data []byte, offset int64) (line int) { 39 | line = 1 40 | for i, r := range string(data) { 41 | if int64(i) >= offset { 42 | return 43 | } 44 | if r == '\n' { 45 | line++ 46 | } 47 | } 48 | return 49 | } 50 | 51 | -------------------------------------------------------------------------------- /consensus/errors.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package consensus 14 | 15 | import "errors" 16 | 17 | var ( 18 | //当验证块需要祖先时返回errUnknownancestor 19 | //这是未知的。 20 | ErrUnknownAncestor = errors.New("unknown ancestor") 21 | 22 | //验证块需要祖先时返回errprunedancestor 23 | //这是已知的,但其状态不可用。 24 | ErrPrunedAncestor = errors.New("pruned ancestor") 25 | 26 | //当块的时间戳在将来时,根据 27 | //到当前节点。 28 | ErrFutureBlock = errors.New("block in the future") 29 | 30 | //如果块的编号不等于其父块的编号,则返回errInvalidNumber。 31 | //加一。 32 | ErrInvalidNumber = errors.New("invalid block number") 33 | ) 34 | 35 | -------------------------------------------------------------------------------- /consensus/misc/forks.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:34 10 | // 11 | 12 | 13 | package misc 14 | 15 | import ( 16 | "fmt" 17 | 18 | "github.com/ethereum/go-ethereum/common" 19 | "github.com/ethereum/go-ethereum/core/types" 20 | "github.com/ethereum/go-ethereum/params" 21 | ) 22 | 23 | //verifyforkhashes验证符合网络硬分叉的块是否具有 24 | //正确的散列,以避免客户在不同的链上离开。这是一个 25 | //可选功能。 26 | func VerifyForkHashes(config *params.ChainConfig, header *types.Header, uncle bool) error { 27 | //我们不关心叔叔 28 | if uncle { 29 | return nil 30 | } 31 | //如果设置了homestead重定价哈希,请验证它 32 | if config.EIP150Block != nil && config.EIP150Block.Cmp(header.Number) == 0 { 33 | if config.EIP150Hash != (common.Hash{}) && config.EIP150Hash != header.Hash() { 34 | return fmt.Errorf("homestead gas reprice fork: have 0x%x, want 0x%x", header.Hash(), config.EIP150Hash) 35 | } 36 | } 37 | //一切还好,归来 38 | return nil 39 | } 40 | 41 | -------------------------------------------------------------------------------- /console/testdata/exec.js: -------------------------------------------------------------------------------- 1 | var execed = "some-executed-string"; 2 | -------------------------------------------------------------------------------- /console/testdata/preload.js: -------------------------------------------------------------------------------- 1 | var preloaded = "some-preloaded-string"; 2 | -------------------------------------------------------------------------------- /containers/docker/develop-alpine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.7 2 | 3 | RUN \ 4 | apk add --update go git make gcc musl-dev linux-headers ca-certificates && \ 5 | git clone --depth 1 https://github.com/ethereum/go-ethereum && \ 6 | (cd go-ethereum && make geth) && \ 7 | cp go-ethereum/build/bin/geth /geth && \ 8 | apk del go git make gcc musl-dev linux-headers && \ 9 | rm -rf /go-ethereum && rm -rf /var/cache/apk/* 10 | 11 | EXPOSE 8545 12 | EXPOSE 30303 13 | 14 | ENTRYPOINT ["/geth"] 15 | -------------------------------------------------------------------------------- /containers/docker/develop-ubuntu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | ENV PATH=/usr/lib/go-1.9/bin:$PATH 4 | 5 | RUN \ 6 | apt-get update && apt-get upgrade -q -y && \ 7 | apt-get install -y --no-install-recommends golang-1.9 git make gcc libc-dev ca-certificates && \ 8 | git clone --depth 1 https://github.com/ethereum/go-ethereum && \ 9 | (cd go-ethereum && make geth) && \ 10 | cp go-ethereum/build/bin/geth /geth && \ 11 | apt-get remove -y golang-1.9 git make gcc libc-dev && apt autoremove -y && apt-get clean && \ 12 | rm -rf /go-ethereum 13 | 14 | EXPOSE 8545 15 | EXPOSE 30303 16 | 17 | ENTRYPOINT ["/geth"] 18 | -------------------------------------------------------------------------------- /containers/docker/master-alpine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.7 2 | 3 | RUN \ 4 | apk add --update go git make gcc musl-dev linux-headers ca-certificates && \ 5 | git clone --depth 1 --branch release/1.8 https://github.com/ethereum/go-ethereum && \ 6 | (cd go-ethereum && make geth) && \ 7 | cp go-ethereum/build/bin/geth /geth && \ 8 | apk del go git make gcc musl-dev linux-headers && \ 9 | rm -rf /go-ethereum && rm -rf /var/cache/apk/* 10 | 11 | EXPOSE 8545 12 | EXPOSE 30303 13 | 14 | ENTRYPOINT ["/geth"] 15 | -------------------------------------------------------------------------------- /containers/docker/master-ubuntu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | ENV PATH=/usr/lib/go-1.9/bin:$PATH 4 | 5 | RUN \ 6 | apt-get update && apt-get upgrade -q -y && \ 7 | apt-get install -y --no-install-recommends golang-1.9 git make gcc libc-dev ca-certificates && \ 8 | git clone --depth 1 --branch release/1.8 https://github.com/ethereum/go-ethereum && \ 9 | (cd go-ethereum && make geth) && \ 10 | cp go-ethereum/build/bin/geth /geth && \ 11 | apt-get remove -y golang-1.9 git make gcc libc-dev && apt autoremove -y && apt-get clean && \ 12 | rm -rf /go-ethereum 13 | 14 | EXPOSE 8545 15 | EXPOSE 30303 16 | 17 | ENTRYPOINT ["/geth"] 18 | -------------------------------------------------------------------------------- /contracts/chequebook/contract/mortal.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "./owned.sol"; 4 | 5 | contract mortal is owned { 6 | function kill() public { 7 | if (msg.sender == owner) 8 | selfdestruct(owner); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/chequebook/contract/owned.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract owned { 4 | address owner; 5 | 6 | modifier onlyowner() { 7 | if (msg.sender == owner) { 8 | _; 9 | } 10 | } 11 | 12 | function owned() public { 13 | owner = msg.sender; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /contracts/ens/README.md: -------------------------------------------------------------------------------- 1 | # Swarm ENS interface 2 | 3 | ## Usage 4 | 5 | Full documentation for the Ethereum Name Service [can be found as EIP 137](https://github.com/ethereum/EIPs/issues/137). 6 | This package offers a simple binding that streamlines the registration of arbitrary UTF8 domain names to swarm content hashes. 7 | 8 | ## Development 9 | 10 | The SOL file in contract subdirectory implements the ENS root registry, a simple 11 | first-in, first-served registrar for the root namespace, and a simple resolver contract; 12 | they're used in tests, and can be used to deploy these contracts for your own purposes. 13 | 14 | The solidity source code can be found at [github.com/arachnid/ens/](https://github.com/arachnid/ens/). 15 | 16 | The go bindings for ENS contracts are generated using `abigen` via the go generator: 17 | 18 | ```shell 19 | go generate ./contracts/ens 20 | ``` 21 | -------------------------------------------------------------------------------- /contracts/ens/contract/AbstractENS.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract AbstractENS { 4 | function owner(bytes32 node) constant returns(address); 5 | function resolver(bytes32 node) constant returns(address); 6 | function ttl(bytes32 node) constant returns(uint64); 7 | function setOwner(bytes32 node, address owner); 8 | function setSubnodeOwner(bytes32 node, bytes32 label, address owner); 9 | function setResolver(bytes32 node, address resolver); 10 | function setTTL(bytes32 node, uint64 ttl); 11 | 12 | // Logged when the owner of a node assigns a new owner to a subnode. 13 | event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner); 14 | 15 | // Logged when the owner of a node transfers ownership to a new account. 16 | event Transfer(bytes32 indexed node, address owner); 17 | 18 | // Logged when the resolver for a node changes. 19 | event NewResolver(bytes32 indexed node, address resolver); 20 | 21 | // Logged when the TTL of a node changes 22 | event NewTTL(bytes32 indexed node, uint64 ttl); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/ens/contract/FIFSRegistrar.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import './AbstractENS.sol'; 4 | 5 | /** 6 | * A registrar that allocates subdomains to the first person to claim them. 7 | */ 8 | contract FIFSRegistrar { 9 | AbstractENS ens; 10 | bytes32 rootNode; 11 | 12 | modifier only_owner(bytes32 subnode) { 13 | var node = sha3(rootNode, subnode); 14 | var currentOwner = ens.owner(node); 15 | 16 | if (currentOwner != 0 && currentOwner != msg.sender) throw; 17 | 18 | _; 19 | } 20 | 21 | /** 22 | * Constructor. 23 | * @param ensAddr The address of the ENS registry. 24 | * @param node The node that this registrar administers. 25 | */ 26 | function FIFSRegistrar(AbstractENS ensAddr, bytes32 node) { 27 | ens = ensAddr; 28 | rootNode = node; 29 | } 30 | 31 | /** 32 | * Register a name, or change the owner of an existing registration. 33 | * @param subnode The hash of the label to register. 34 | * @param owner The address of the new owner. 35 | */ 36 | function register(bytes32 subnode, address owner) only_owner(subnode) { 37 | ens.setSubnodeOwner(rootNode, subnode, owner); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /core/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile ~/.gitignore_global 6 | 7 | /tmp 8 | */**/*un~ 9 | *un~ 10 | .DS_Store 11 | */**/.DS_Store 12 | 13 | -------------------------------------------------------------------------------- /core/blocks.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package core 14 | 15 | import "github.com/ethereum/go-ethereum/common" 16 | 17 | //BadHash表示一组手动跟踪的错误哈希(通常是硬分叉) 18 | var BadHashes = map[common.Hash]bool{ 19 | common.HexToHash("05bef30ef572270f654746da22639a7a0c97dd97a7050b9e252391996aaeb689"): true, 20 | common.HexToHash("7d05d08cbc596a2e5e4f13b80a743e53e09221b5323c3a61946b20873e58583f"): true, 21 | } 22 | 23 | -------------------------------------------------------------------------------- /core/bloombits/doc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | //包BloomBits对成批数据执行Bloom过滤。 14 | package bloombits 15 | 16 | -------------------------------------------------------------------------------- /core/error.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package core 14 | 15 | import "errors" 16 | 17 | var ( 18 | //当要导入的块在本地已知时,返回errknownBlock。 19 | ErrKnownBlock = errors.New("block already known") 20 | 21 | //如果所需的气体量达到,则气体池将返回达到的ErrgasLimited。 22 | //一个事务比块中剩余的事务高。 23 | ErrGasLimitReached = errors.New("gas limit reached") 24 | 25 | //如果要导入的块在黑名单上,则返回errBlackListedHash。 26 | ErrBlacklistedHash = errors.New("blacklisted hash") 27 | 28 | //如果事务的nonce高于 29 | //下一个基于本地链的期望值。 30 | ErrNonceTooHigh = errors.New("nonce too high") 31 | ) 32 | 33 | -------------------------------------------------------------------------------- /core/events.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package core 14 | 15 | import ( 16 | "github.com/ethereum/go-ethereum/common" 17 | "github.com/ethereum/go-ethereum/core/types" 18 | ) 19 | 20 | //当一批交易进入交易池时,将过账newtxsevent。 21 | type NewTxsEvent struct{ Txs []*types.Transaction } 22 | 23 | //PendingLogSevent在挖掘前发布,并通知挂起的日志。 24 | type PendingLogsEvent struct { 25 | Logs []*types.Log 26 | } 27 | 28 | //当块被导入时,将发布NewMinedBlockEvent。 29 | type NewMinedBlockEvent struct{ Block *types.Block } 30 | 31 | //当发生REORG时,会发布REMOVEDLogsevent 32 | type RemovedLogsEvent struct{ Logs []*types.Log } 33 | 34 | type ChainEvent struct { 35 | Block *types.Block 36 | Hash common.Hash 37 | Logs []*types.Log 38 | } 39 | 40 | type ChainSideEvent struct { 41 | Block *types.Block 42 | } 43 | 44 | type ChainHeadEvent struct{ Block *types.Block } 45 | 46 | -------------------------------------------------------------------------------- /core/gaspool.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package core 14 | 15 | import ( 16 | "fmt" 17 | "math" 18 | ) 19 | 20 | //gaspool跟踪交易执行期间可用的气体量 21 | //在一个街区。零值是一个具有零气体的池。 22 | type GasPool uint64 23 | 24 | //addgas使气体可用于执行。 25 | func (gp *GasPool) AddGas(amount uint64) *GasPool { 26 | if uint64(*gp) > math.MaxUint64-amount { 27 | panic("gas pool pushed above uint64") 28 | } 29 | *(*uint64)(gp) += amount 30 | return gp 31 | } 32 | 33 | //如果有足够的气体,子气体从池中扣除给定的量。 34 | //可用,否则返回错误。 35 | func (gp *GasPool) SubGas(amount uint64) error { 36 | if uint64(*gp) < amount { 37 | return ErrGasLimitReached 38 | } 39 | *(*uint64)(gp) -= amount 40 | return nil 41 | } 42 | 43 | //气体返回池中剩余的气体量。 44 | func (gp *GasPool) Gas() uint64 { 45 | return uint64(*gp) 46 | } 47 | 48 | func (gp *GasPool) String() string { 49 | return fmt.Sprintf("%d", *gp) 50 | } 51 | 52 | -------------------------------------------------------------------------------- /core/rawdb/interfaces.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package rawdb 14 | 15 | //DatabaseReader包装支持数据存储的has和get方法。 16 | type DatabaseReader interface { 17 | Has(key []byte) (bool, error) 18 | Get(key []byte) ([]byte, error) 19 | } 20 | 21 | //databasewriter包装支持数据存储的Put方法。 22 | type DatabaseWriter interface { 23 | Put(key []byte, value []byte) error 24 | } 25 | 26 | //databaseDeleter包装备份数据存储的删除方法。 27 | type DatabaseDeleter interface { 28 | Delete(key []byte) error 29 | } 30 | 31 | -------------------------------------------------------------------------------- /core/state/main_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package state 14 | 15 | import ( 16 | "testing" 17 | 18 | checker "gopkg.in/check.v1" 19 | ) 20 | 21 | func Test(t *testing.T) { checker.TestingT(t) } 22 | 23 | -------------------------------------------------------------------------------- /core/state/sync.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package state 14 | 15 | import ( 16 | "bytes" 17 | 18 | "github.com/ethereum/go-ethereum/common" 19 | "github.com/ethereum/go-ethereum/rlp" 20 | "github.com/ethereum/go-ethereum/trie" 21 | ) 22 | 23 | //newstatesync创建新的状态trie下载计划程序。 24 | func NewStateSync(root common.Hash, database trie.DatabaseReader) *trie.Sync { 25 | var syncer *trie.Sync 26 | callback := func(leaf []byte, parent common.Hash) error { 27 | var obj Account 28 | if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil { 29 | return err 30 | } 31 | syncer.AddSubTrie(obj.Root, 64, parent, nil) 32 | syncer.AddRawEntry(common.BytesToHash(obj.CodeHash), 64, parent) 33 | return nil 34 | } 35 | syncer = trie.NewSync(root, database, callback) 36 | return syncer 37 | } 38 | 39 | -------------------------------------------------------------------------------- /core/tx_list_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package core 14 | 15 | import ( 16 | "math/rand" 17 | "testing" 18 | 19 | "github.com/ethereum/go-ethereum/core/types" 20 | "github.com/ethereum/go-ethereum/crypto" 21 | ) 22 | 23 | //测试可以将事务添加到严格的列表和列表内容以及 24 | //正确维护当前边界。 25 | func TestStrictTxListAdd(t *testing.T) { 26 | //生成要插入的事务列表 27 | key, _ := crypto.GenerateKey() 28 | 29 | txs := make(types.Transactions, 1024) 30 | for i := 0; i < len(txs); i++ { 31 | txs[i] = transaction(uint64(i), 0, key) 32 | } 33 | //按随机顺序插入交易记录 34 | list := newTxList(true) 35 | for _, v := range rand.Perm(len(txs)) { 36 | list.Add(txs[v], DefaultTxPoolConfig.PriceBump) 37 | } 38 | //验证内部状态 39 | if len(list.txs.items) != len(txs) { 40 | t.Errorf("transaction count mismatch: have %d, want %d", len(list.txs.items), len(txs)) 41 | } 42 | for i, tx := range txs { 43 | if list.txs.items[tx.Nonce()] != tx { 44 | t.Errorf("item %d: transaction mismatch: have %v, want %v", i, list.txs.items[tx.Nonce()], tx) 45 | } 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /core/types.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package core 14 | 15 | import ( 16 | "github.com/ethereum/go-ethereum/core/state" 17 | "github.com/ethereum/go-ethereum/core/types" 18 | "github.com/ethereum/go-ethereum/core/vm" 19 | ) 20 | 21 | //validator是定义块验证标准的接口。它 22 | //只负责验证块内容,因为头验证是 23 | //由特定的共识引擎完成。 24 | // 25 | type Validator interface { 26 | //validateBody验证给定块的内容。 27 | ValidateBody(block *types.Block) error 28 | 29 | //validateState验证给定的statedb,以及可选的收据和 30 | //使用的气体。 31 | ValidateState(block, parent *types.Block, state *state.StateDB, receipts types.Receipts, usedGas uint64) error 32 | } 33 | 34 | //处理器是使用给定初始状态处理块的接口。 35 | // 36 | //process接受要处理的块和statedb,在该块上 37 | //初始状态是基于的。它应该返回生成的收据,金额 38 | //过程中使用的气体,如果有任何内部规则,则返回错误 39 | //失败。 40 | type Processor interface { 41 | Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) 42 | } 43 | 44 | -------------------------------------------------------------------------------- /core/types/derive_sha.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:35 10 | // 11 | 12 | 13 | package types 14 | 15 | import ( 16 | "bytes" 17 | 18 | "github.com/ethereum/go-ethereum/common" 19 | "github.com/ethereum/go-ethereum/rlp" 20 | "github.com/ethereum/go-ethereum/trie" 21 | ) 22 | 23 | type DerivableList interface { 24 | Len() int 25 | GetRlp(i int) []byte 26 | } 27 | 28 | func DeriveSha(list DerivableList) common.Hash { 29 | keybuf := new(bytes.Buffer) 30 | trie := new(trie.Trie) 31 | for i := 0; i < list.Len(); i++ { 32 | keybuf.Reset() 33 | rlp.Encode(keybuf, uint(i)) 34 | trie.Update(keybuf.Bytes(), list.GetRlp(i)) 35 | } 36 | return trie.Hash() 37 | } 38 | 39 | -------------------------------------------------------------------------------- /core/vm/doc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | /* 14 | 包VM实现了以太坊虚拟机。 15 | 16 | vm包实现一个evm,一个字节代码vm。BC(字节码)VM循环 17 | 超过一组字节,并根据定义的规则集执行它们 18 | 在以太黄纸上。 19 | **/ 20 | 21 | package vm 22 | 23 | -------------------------------------------------------------------------------- /core/vm/errors.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | package vm 14 | 15 | import "errors" 16 | 17 | //列表执行错误 18 | var ( 19 | ErrOutOfGas = errors.New("out of gas") 20 | ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas") 21 | ErrDepth = errors.New("max call depth exceeded") 22 | ErrTraceLimitReached = errors.New("the number of logs reached the specified limit") 23 | ErrInsufficientBalance = errors.New("insufficient balance for transfer") 24 | ErrContractAddressCollision = errors.New("contract address collision") 25 | ErrNoCompatibleInterpreter = errors.New("no compatible interpreter") 26 | ) 27 | 28 | -------------------------------------------------------------------------------- /core/vm/gas_table_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | package vm 14 | 15 | import "testing" 16 | 17 | func TestMemoryGasCost(t *testing.T) { 18 | //大小:=uint64(math.maxuint64-64) 19 | size := uint64(0xffffffffe0) 20 | v, err := memoryGasCost(&Memory{}, size) 21 | if err != nil { 22 | t.Error("didn't expect error:", err) 23 | } 24 | if v != 36028899963961341 { 25 | t.Errorf("Expected: 36028899963961341, got %d", v) 26 | } 27 | 28 | _, err = memoryGasCost(&Memory{}, size+1) 29 | if err == nil { 30 | t.Error("expected error") 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /core/vm/int_pool_verifier.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | //+生成验证\ evm \整数\池 14 | 15 | package vm 16 | 17 | import "fmt" 18 | 19 | const verifyPool = true 20 | 21 | func verifyIntegerPool(ip *intPool) { 22 | for i, item := range ip.pool.data { 23 | if item.Cmp(checkVal) != 0 { 24 | panic(fmt.Sprintf("%d'th item failed aggressive pool check. Value was modified", i)) 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /core/vm/int_pool_verifier_empty.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | //+建设!验证_evm_integer_池 14 | 15 | package vm 16 | 17 | const verifyPool = false 18 | 19 | func verifyIntegerPool(ip *intPool) {} 20 | 21 | -------------------------------------------------------------------------------- /core/vm/runtime/doc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | //包运行时提供执行EVM代码的基本执行模型。 14 | package runtime 15 | 16 | -------------------------------------------------------------------------------- /core/vm/runtime/env.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | package runtime 14 | 15 | import ( 16 | "github.com/ethereum/go-ethereum/common" 17 | "github.com/ethereum/go-ethereum/core" 18 | "github.com/ethereum/go-ethereum/core/vm" 19 | ) 20 | 21 | func NewEnv(cfg *Config) *vm.EVM { 22 | context := vm.Context{ 23 | CanTransfer: core.CanTransfer, 24 | Transfer: core.Transfer, 25 | GetHash: func(uint64) common.Hash { return common.Hash{} }, 26 | 27 | Origin: cfg.Origin, 28 | Coinbase: cfg.Coinbase, 29 | BlockNumber: cfg.BlockNumber, 30 | Time: cfg.Time, 31 | Difficulty: cfg.Difficulty, 32 | GasLimit: cfg.GasLimit, 33 | GasPrice: cfg.GasPrice, 34 | } 35 | 36 | return vm.NewEVM(context, cfg.State, cfg.ChainConfig, cfg.EVMConfig) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /core/vm/runtime/fuzz.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | //+构建GouuZZ 14 | 15 | package runtime 16 | 17 | //引信是Go-Fuzz工具的基本切入点 18 | // 19 | //对于有效的可分析/不可运行代码,返回1,0 20 | //对于无效的操作码。 21 | func Fuzz(input []byte) int { 22 | _, _, err := Execute(input, input, &Config{ 23 | GasLimit: 3000000, 24 | }) 25 | 26 | //无效操作码 27 | if err != nil && len(err.Error()) > 6 && string(err.Error()[:7]) == "invalid" { 28 | return 0 29 | } 30 | 31 | return 1 32 | } 33 | 34 | -------------------------------------------------------------------------------- /core/vm/runtime/runtime_example_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | package runtime_test 14 | 15 | import ( 16 | "fmt" 17 | 18 | "github.com/ethereum/go-ethereum/common" 19 | "github.com/ethereum/go-ethereum/core/vm/runtime" 20 | ) 21 | 22 | func ExampleExecute() { 23 | ret, _, err := runtime.Execute(common.Hex2Bytes("6060604052600a8060106000396000f360606040526008565b00"), nil, nil) 24 | if err != nil { 25 | fmt.Println(err) 26 | } 27 | fmt.Println(ret) 28 | //输出: 29 | //[96 96 96 64 82 96 8 86 91 0] 30 | } 31 | 32 | -------------------------------------------------------------------------------- /core/vm/stack_table.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | 13 | package vm 14 | 15 | import ( 16 | "fmt" 17 | 18 | "github.com/ethereum/go-ethereum/params" 19 | ) 20 | 21 | func makeStackFunc(pop, push int) stackValidationFunc { 22 | return func(stack *Stack) error { 23 | if err := stack.require(pop); err != nil { 24 | return err 25 | } 26 | 27 | if stack.len()+push-pop > int(params.StackLimit) { 28 | return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit) 29 | } 30 | return nil 31 | } 32 | } 33 | 34 | func makeDupStackFunc(n int) stackValidationFunc { 35 | return makeStackFunc(n, n+1) 36 | } 37 | 38 | func makeSwapStackFunc(n int) stackValidationFunc { 39 | return makeStackFunc(n, n) 40 | } 41 | 42 | -------------------------------------------------------------------------------- /crypto/bn256/bn256_fast.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | //版权所有2018 P_ter Szil_gyi。版权所有。 13 | //此源代码的使用受可以找到的BSD样式许可证的控制 14 | //在许可证文件中。 15 | 16 | //+构建AMD64 ARM64 17 | 18 | //包bn256在256位的barreto-naehrig曲线上实现了最佳的ate对。 19 | package bn256 20 | 21 | import "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" 22 | 23 | //g1是一个抽象的循环群。零值适合用作 24 | //操作的输出,但不能用作输入。 25 | type G1 = bn256.G1 26 | 27 | //g2是一个抽象的循环群。零值适合用作 28 | //操作的输出,但不能用作输入。 29 | type G2 = bn256.G2 30 | 31 | //pairingcheck计算一组点的最佳ate对。 32 | func PairingCheck(a []*G1, b []*G2) bool { 33 | return bn256.PairingCheck(a, b) 34 | } 35 | 36 | -------------------------------------------------------------------------------- /crypto/bn256/bn256_slow.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | //版权所有2018 P_ter Szil_gyi。版权所有。 13 | //此源代码的使用受可以找到的BSD样式许可证的控制 14 | //在许可证文件中。 15 | 16 | //+建设!AMD64!ARM64 17 | 18 | //包bn256在256位的barreto-naehrig曲线上实现了最佳的ate对。 19 | package bn256 20 | 21 | import "github.com/ethereum/go-ethereum/crypto/bn256/google" 22 | 23 | //g1是一个抽象的循环群。零值适合用作 24 | //操作的输出,但不能用作输入。 25 | type G1 = bn256.G1 26 | 27 | //g2是一个抽象的循环群。零值适合用作 28 | //操作的输出,但不能用作输入。 29 | type G2 = bn256.G2 30 | 31 | //pairingcheck计算一组点的最佳ate对。 32 | func PairingCheck(a []*G1, b []*G2) bool { 33 | return bn256.PairingCheck(a, b) 34 | } 35 | 36 | -------------------------------------------------------------------------------- /crypto/bn256/cloudflare/gfp_decl.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | //+建立AMD64,!通用ARM64,!通用的 13 | 14 | package bn256 15 | 16 | //此文件包含特定于体系结构的转发声明 17 | //这些函数的程序集实现,前提是它们存在。 18 | 19 | import ( 20 | "golang.org/x/sys/cpu" 21 | ) 22 | 23 | //诺林特 24 | var hasBMI2 = cpu.X86.HasBMI2 25 | 26 | //逃走 27 | func gfpNeg(c, a *gfP) 28 | 29 | //逃走 30 | func gfpAdd(c, a, b *gfP) 31 | 32 | //逃走 33 | func gfpSub(c, a, b *gfP) 34 | 35 | //逃走 36 | func gfpMul(c, a, b *gfP) 37 | 38 | -------------------------------------------------------------------------------- /crypto/bn256/cloudflare/lattice_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | package bn256 13 | 14 | import ( 15 | "crypto/rand" 16 | 17 | "testing" 18 | ) 19 | 20 | func TestLatticeReduceCurve(t *testing.T) { 21 | k, _ := rand.Int(rand.Reader, Order) 22 | ks := curveLattice.decompose(k) 23 | 24 | if ks[0].BitLen() > 130 || ks[1].BitLen() > 130 { 25 | t.Fatal("reduction too large") 26 | } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 { 27 | t.Fatal("reduction must be positive") 28 | } 29 | } 30 | 31 | func TestLatticeReduceTarget(t *testing.T) { 32 | k, _ := rand.Int(rand.Reader, Order) 33 | ks := targetLattice.decompose(k) 34 | 35 | if ks[0].BitLen() > 66 || ks[1].BitLen() > 66 || ks[2].BitLen() > 66 || ks[3].BitLen() > 66 { 36 | t.Fatal("reduction too large") 37 | } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 || ks[2].Sign() < 0 || ks[3].Sign() < 0 { 38 | t.Fatal("reduction must be positive") 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /crypto/bn256/google/example_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | //版权所有2012 Go作者。版权所有。 13 | //此源代码的使用受BSD样式的控制 14 | //可以在许可文件中找到的许可证。 15 | 16 | package bn256 17 | 18 | import ( 19 | "crypto/rand" 20 | ) 21 | 22 | func ExamplePair() { 23 | //这实现了从“a”到“a”的三方diffie-hellman算法 24 | //三方diffie-hellman的圆形协议”,A.joux。 25 | //http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf 26 | 27 | //三方(A、B和C)中的每一方都会产生一个私人价值。 28 | a, _ := rand.Int(rand.Reader, Order) 29 | b, _ := rand.Int(rand.Reader, Order) 30 | c, _ := rand.Int(rand.Reader, Order) 31 | 32 | //然后,每一方计算g_和g₂乘以其私有价值。 33 | pa := new(G1).ScalarBaseMult(a) 34 | qa := new(G2).ScalarBaseMult(a) 35 | 36 | pb := new(G1).ScalarBaseMult(b) 37 | qb := new(G2).ScalarBaseMult(b) 38 | 39 | pc := new(G1).ScalarBaseMult(c) 40 | qc := new(G2).ScalarBaseMult(c) 41 | 42 | //现在,每一方都与另外两方交换其公共价值观,以及 43 | //所有参与方都可以计算共享密钥。 44 | k1 := Pair(pb, qc) 45 | k1.ScalarMult(k1, a) 46 | 47 | k2 := Pair(pc, qa) 48 | k2.ScalarMult(k2, b) 49 | 50 | k3 := Pair(pa, qb) 51 | k3.ScalarMult(k3, c) 52 | 53 | //k1、k2和k3都相等。 54 | } 55 | 56 | -------------------------------------------------------------------------------- /crypto/ecies/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | *~ 25 | -------------------------------------------------------------------------------- /crypto/secp256k1/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | *~ 25 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/.gitignore: -------------------------------------------------------------------------------- 1 | bench_inv 2 | bench_ecdh 3 | bench_sign 4 | bench_verify 5 | bench_schnorr_verify 6 | bench_recover 7 | bench_internal 8 | tests 9 | exhaustive_tests 10 | gen_context 11 | *.exe 12 | *.so 13 | *.a 14 | !.gitignore 15 | 16 | Makefile 17 | configure 18 | .libs/ 19 | Makefile.in 20 | aclocal.m4 21 | autom4te.cache/ 22 | config.log 23 | config.status 24 | *.tar.gz 25 | *.la 26 | libtool 27 | .deps/ 28 | .dirstamp 29 | *.lo 30 | *.o 31 | *~ 32 | src/libsecp256k1-config.h 33 | src/libsecp256k1-config.h.in 34 | src/ecmult_static_context.h 35 | build-aux/config.guess 36 | build-aux/config.sub 37 | build-aux/depcomp 38 | build-aux/install-sh 39 | build-aux/ltmain.sh 40 | build-aux/m4/libtool.m4 41 | build-aux/m4/lt~obsolete.m4 42 | build-aux/m4/ltoptions.m4 43 | build-aux/m4/ltsugar.m4 44 | build-aux/m4/ltversion.m4 45 | build-aux/missing 46 | build-aux/compile 47 | build-aux/test-driver 48 | src/stamp-h1 49 | libsecp256k1.pc 50 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Pieter Wuille 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/TODO: -------------------------------------------------------------------------------- 1 | * Unit tests for fieldelem/groupelem, including ones intended to 2 | trigger fieldelem's boundary cases. 3 | * Complete constant-time operations for signing/keygen 4 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | autoreconf -if --warnings=all 4 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef _SECP256K1_ECDH_ 2 | # define _SECP256K1_ECDH_ 3 | 4 | # include "secp256k1.h" 5 | 6 | # ifdef __cplusplus 7 | extern "C" { 8 | # endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | # ifdef __cplusplus 28 | } 29 | # endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/libsecp256k1.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libsecp256k1 7 | Description: Optimized C library for EC operations on curve secp256k1 8 | URL: https://github.com/bitcoin-core/secp256k1 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs.private: @SECP_LIBS@ 12 | Libs: -L${libdir} -lsecp256k1 13 | 14 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/obj/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/crypto/secp256k1/libsecp256k1/obj/.gitignore -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/basic-config.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_BASIC_CONFIG_ 8 | #define _SECP256K1_BASIC_CONFIG_ 9 | 10 | #ifdef USE_BASIC_CONFIG 11 | 12 | #undef USE_ASM_X86_64 13 | #undef USE_ENDOMORPHISM 14 | #undef USE_FIELD_10X26 15 | #undef USE_FIELD_5X52 16 | #undef USE_FIELD_INV_BUILTIN 17 | #undef USE_FIELD_INV_NUM 18 | #undef USE_NUM_GMP 19 | #undef USE_NUM_NONE 20 | #undef USE_SCALAR_4X64 21 | #undef USE_SCALAR_8X32 22 | #undef USE_SCALAR_INV_BUILTIN 23 | #undef USE_SCALAR_INV_NUM 24 | 25 | #define USE_NUM_NONE 1 26 | #define USE_FIELD_INV_BUILTIN 1 27 | #define USE_SCALAR_INV_BUILTIN 1 28 | #define USE_FIELD_10X26 1 29 | #define USE_SCALAR_8X32 1 30 | 31 | #endif // USE_BASIC_CONFIG 32 | #endif // _SECP256K1_BASIC_CONFIG_ 33 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/ecdsa.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECDSA_ 8 | #define _SECP256K1_ECDSA_ 9 | 10 | #include 11 | 12 | #include "scalar.h" 13 | #include "group.h" 14 | #include "ecmult.h" 15 | 16 | static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size); 17 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s); 18 | static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message); 19 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/eckey.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECKEY_ 8 | #define _SECP256K1_ECKEY_ 9 | 10 | #include 11 | 12 | #include "group.h" 13 | #include "scalar.h" 14 | #include "ecmult.h" 15 | #include "ecmult_gen.h" 16 | 17 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size); 18 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed); 19 | 20 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak); 21 | static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 22 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak); 23 | static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/ecmult_const.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_CONST_ 8 | #define _SECP256K1_ECMULT_CONST_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "org_bitcoin_Secp256k1Context.h" 4 | #include "include/secp256k1.h" 5 | 6 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 7 | (JNIEnv* env, jclass classObject) 8 | { 9 | secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 10 | 11 | (void)classObject;(void)env; 12 | 13 | return (uintptr_t)ctx; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | #include "include/secp256k1.h" 4 | /* Header for class org_bitcoin_Secp256k1Context */ 5 | 6 | #ifndef _Included_org_bitcoin_Secp256k1Context 7 | #define _Included_org_bitcoin_Secp256k1Context 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | /* 12 | * Class: org_bitcoin_Secp256k1Context 13 | * Method: secp256k1_init_context 14 | * Signature: ()J 15 | */ 16 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 17 | (JNIEnv *, jclass); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/modules/ecdh/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_ecdh.h 2 | noinst_HEADERS += src/modules/ecdh/main_impl.h 3 | noinst_HEADERS += src/modules/ecdh/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_ecdh 6 | bench_ecdh_SOURCES = src/bench_ecdh.c 7 | bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/modules/recovery/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_recovery.h 2 | noinst_HEADERS += src/modules/recovery/main_impl.h 3 | noinst_HEADERS += src/modules/recovery/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_recover 6 | bench_recover_SOURCES = src/bench_recover.c 7 | bench_recover_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/num_gmp.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_REPR_ 8 | #define _SECP256K1_NUM_REPR_ 9 | 10 | #include 11 | 12 | #define NUM_LIMBS ((256+GMP_NUMB_BITS-1)/GMP_NUMB_BITS) 13 | 14 | typedef struct { 15 | mp_limb_t data[2*NUM_LIMBS]; 16 | int neg; 17 | int limbs; 18 | } secp256k1_num; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/num_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_IMPL_H_ 8 | #define _SECP256K1_NUM_IMPL_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include "num.h" 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp_impl.h" 18 | #elif defined(USE_NUM_NONE) 19 | /* Nothing. */ 20 | #else 21 | #error "Please select num implementation" 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/scalar_8x32.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint32_t d[8]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /crypto/secp256k1/libsecp256k1/src/scalar_low.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef uint32_t secp256k1_scalar; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /crypto/secp256k1/panic_cb.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:36 10 | // 11 | 12 | //版权所有2015 Jeffrey Wilcke、Felix Lange、Gustav Simonsson。版权所有。 13 | //此源代码的使用受BSD样式许可证的控制,该许可证可在 14 | //许可证文件。 15 | 16 | package secp256k1 17 | 18 | import "C" 19 | import "unsafe" 20 | 21 | //将libsecp256k1内部故障转换为 22 | //恢复性恐慌。 23 | 24 | //出口secp256k1gopanicilegal 25 | func secp256k1GoPanicIllegal(msg *C.char, data unsafe.Pointer) { 26 | panic("illegal argument: " + C.GoString(msg)) 27 | } 28 | 29 | //导出secp256k1gopanicerror 30 | func secp256k1GoPanicError(msg *C.char, data unsafe.Pointer) { 31 | panic("internal error: " + C.GoString(msg)) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /dashboard/assets/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | /node_modules/material-ui/.*\.js\.flow 3 | 4 | [libs] 5 | /flow-typed/ 6 | node_modules/jss/flow-typed 7 | 8 | [options] 9 | include_warnings=true 10 | -------------------------------------------------------------------------------- /dashboard/assets/fa-only-woff-loader.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The go-ethereum Authors 2 | // This file is part of the go-ethereum library. 3 | // 4 | // The go-ethereum library is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Lesser 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 | // The go-ethereum library 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 Lesser General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public License 15 | // along with the go-ethereum library. If not, see . 16 | 17 | // fa-only-woff-loader removes the .eot, .ttf, .svg dependencies of the FontAwesome library, 18 | // because they produce unused extra blobs. 19 | module.exports = function(content) { 20 | return content 21 | .replace(/src.*url(?!.*url.*(\.eot)).*(\.eot)[^;]*;/,'') 22 | .replace(/url(?!.*url.*(\.eot)).*(\.eot)[^,]*,/,'') 23 | .replace(/url(?!.*url.*(\.ttf)).*(\.ttf)[^,]*,/,'') 24 | .replace(/,[^,]*url(?!.*url.*(\.svg)).*(\.svg)[^;]*;/,';'); 25 | }; 26 | -------------------------------------------------------------------------------- /dashboard/assets/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Go Ethereum Dashboard 9 | 10 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dashboard/config.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:37 10 | // 11 | 12 | 13 | package dashboard 14 | 15 | import "time" 16 | 17 | //DefaultConfig contains default settings for the dashboard. 18 | var DefaultConfig = Config{ 19 | Host: "localhost", 20 | Port: 8080, 21 | Refresh: 5 * time.Second, 22 | } 23 | 24 | //配置包含仪表板的配置参数。 25 | type Config struct { 26 | //主机是启动仪表板服务器的主机接口。如果这样 27 | //field is empty, no dashboard will be started. 28 | Host string `toml:",omitempty"` 29 | 30 | //端口是启动仪表板服务器的TCP端口号。这个 31 | //默认的零值是/有效的,将随机选择端口号(有用 32 | //for ephemeral nodes). 33 | Port int `toml:",omitempty"` 34 | 35 | //refresh是数据更新的刷新率,通常会收集图表条目。 36 | Refresh time.Duration `toml:",omitempty"` 37 | } 38 | 39 | -------------------------------------------------------------------------------- /dashboard/cpu.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:37 10 | // 11 | 12 | 13 | //+建设!窗户 14 | 15 | package dashboard 16 | 17 | import ( 18 | "syscall" 19 | 20 | "github.com/ethereum/go-ethereum/log" 21 | ) 22 | 23 | //GetProcessCPutime检索自程序启动后的进程的CPU时间。 24 | func getProcessCPUTime() float64 { 25 | var usage syscall.Rusage 26 | if err := syscall.Getrusage(syscall.RUSAGE_SELF, &usage); err != nil { 27 | log.Warn("Failed to retrieve CPU time", "err", err) 28 | return 0 29 | } 30 | return float64(usage.Utime.Sec+usage.Stime.Sec) + float64(usage.Utime.Usec+usage.Stime.Usec)/1000000 31 | } 32 | 33 | -------------------------------------------------------------------------------- /dashboard/cpu_windows.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:37 10 | // 11 | 12 | 13 | package dashboard 14 | 15 | //GetProcessCPutime在Windows上返回0,因为没有要解析的系统调用 16 | //实际进程的CPU时间。 17 | func getProcessCPUTime() float64 { 18 | return 0 19 | } 20 | 21 | -------------------------------------------------------------------------------- /eth/downloader/events.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:37 10 | // 11 | 12 | 13 | package downloader 14 | 15 | type DoneEvent struct{} 16 | type StartEvent struct{} 17 | type FailedEvent struct{ Err error } 18 | 19 | -------------------------------------------------------------------------------- /eth/tracers/internal/tracers/tracers.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:37 10 | // 11 | 12 | 13 | //go:生成go bindata-nometadata-o assets.go-pkg tracers-ignore tracers.go-ignore assets.go./… 14 | //go:生成gofmt-s-w assets.go 15 | 16 | //包跟踪程序包含实际的javascript跟踪程序资产。 17 | package tracers 18 | 19 | -------------------------------------------------------------------------------- /eth/tracers/tracers.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:37 10 | // 11 | 12 | 13 | //包跟踪程序是JavaScript事务跟踪程序的集合。 14 | package tracers 15 | 16 | import ( 17 | "strings" 18 | "unicode" 19 | 20 | "github.com/ethereum/go-ethereum/eth/tracers/internal/tracers" 21 | ) 22 | 23 | //全部按名称包含所有内置的javascript跟踪程序。 24 | var all = make(map[string]string) 25 | 26 | //camel将snake-cased输入字符串转换为camel-cased输出。 27 | func camel(str string) string { 28 | pieces := strings.Split(str, "_") 29 | for i := 1; i < len(pieces); i++ { 30 | pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:] 31 | } 32 | return strings.Join(pieces, "") 33 | } 34 | 35 | //init检索go-ethereum中包含的javascript事务跟踪程序。 36 | func init() { 37 | for _, file := range tracers.AssetNames() { 38 | name := camel(strings.TrimSuffix(file, ".js")) 39 | all[name] = string(tracers.MustAsset(file)) 40 | } 41 | } 42 | 43 | //跟踪程序按名称检索特定的javascript跟踪程序。 44 | func tracer(name string) (string, bool) { 45 | if tracer, ok := all[name]; ok { 46 | return tracer, true 47 | } 48 | return "", false 49 | } 50 | 51 | -------------------------------------------------------------------------------- /ethdb/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile ~/.gitignore_global 6 | 7 | /tmp 8 | */**/*un~ 9 | *un~ 10 | .DS_Store 11 | */**/.DS_Store 12 | 13 | -------------------------------------------------------------------------------- /ethdb/database_js_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | //+构建JS 14 | 15 | package ethdb_test 16 | 17 | import ( 18 | "github.com/ethereum/go-ethereum/ethdb" 19 | ) 20 | 21 | var _ ethdb.Database = ðdb.LDBDatabase{} 22 | 23 | -------------------------------------------------------------------------------- /ethdb/interface.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | package ethdb 14 | 15 | //使用批处理的代码应该尝试向批处理中添加这么多的数据。 16 | //该值是根据经验确定的。 17 | const IdealBatchSize = 100 * 1024 18 | 19 | //推杆包装批处理和常规数据库都支持的数据库写入操作。 20 | type Putter interface { 21 | Put(key []byte, value []byte) error 22 | } 23 | 24 | //删除程序包装批处理数据库和常规数据库都支持的数据库删除操作。 25 | type Deleter interface { 26 | Delete(key []byte) error 27 | } 28 | 29 | //数据库包装所有数据库操作。所有方法对于并发使用都是安全的。 30 | type Database interface { 31 | Putter 32 | Deleter 33 | Get(key []byte) ([]byte, error) 34 | Has(key []byte) (bool, error) 35 | Close() 36 | NewBatch() Batch 37 | } 38 | 39 | //批处理是一个只写的数据库,它将更改提交到其主机数据库。 40 | //当调用写入时。批处理不能同时使用。 41 | type Batch interface { 42 | Putter 43 | Deleter 44 | ValueSize() int //批中的数据量 45 | Write() error 46 | //重置将批重置为可重用 47 | Reset() 48 | } 49 | 50 | -------------------------------------------------------------------------------- /ethdb/table.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | package ethdb 14 | 15 | type table struct { 16 | db Database 17 | prefix string 18 | } 19 | 20 | //NewTable返回一个数据库对象,该对象在所有键前面加上给定的 21 | //字符串。 22 | func NewTable(db Database, prefix string) Database { 23 | return &table{ 24 | db: db, 25 | prefix: prefix, 26 | } 27 | } 28 | 29 | func (dt *table) Put(key []byte, value []byte) error { 30 | return dt.db.Put(append([]byte(dt.prefix), key...), value) 31 | } 32 | 33 | func (dt *table) Has(key []byte) (bool, error) { 34 | return dt.db.Has(append([]byte(dt.prefix), key...)) 35 | } 36 | 37 | func (dt *table) Get(key []byte) ([]byte, error) { 38 | return dt.db.Get(append([]byte(dt.prefix), key...)) 39 | } 40 | 41 | func (dt *table) Delete(key []byte) error { 42 | return dt.db.Delete(append([]byte(dt.prefix), key...)) 43 | } 44 | 45 | func (dt *table) Close() { 46 | //什么都不做;不要关闭底层数据库。 47 | } 48 | 49 | -------------------------------------------------------------------------------- /ethdb/table_batch.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | package ethdb 14 | 15 | type tableBatch struct { 16 | batch Batch 17 | prefix string 18 | } 19 | 20 | //NewTableBatch返回一个批处理对象,该对象在所有键前面加上一个给定的字符串。 21 | func NewTableBatch(db Database, prefix string) Batch { 22 | return &tableBatch{db.NewBatch(), prefix} 23 | } 24 | 25 | func (dt *table) NewBatch() Batch { 26 | return &tableBatch{dt.db.NewBatch(), dt.prefix} 27 | } 28 | 29 | func (tb *tableBatch) Put(key, value []byte) error { 30 | return tb.batch.Put(append([]byte(tb.prefix), key...), value) 31 | } 32 | 33 | func (tb *tableBatch) Delete(key []byte) error { 34 | return tb.batch.Delete(append([]byte(tb.prefix), key...)) 35 | } 36 | 37 | func (tb *tableBatch) Write() error { 38 | return tb.batch.Write() 39 | } 40 | 41 | func (tb *tableBatch) ValueSize() int { 42 | return tb.batch.ValueSize() 43 | } 44 | 45 | func (tb *tableBatch) Reset() { 46 | tb.batch.Reset() 47 | } 48 | 49 | -------------------------------------------------------------------------------- /event/example_subscription_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | package event_test 14 | 15 | import ( 16 | "fmt" 17 | 18 | "github.com/ethereum/go-ethereum/event" 19 | ) 20 | 21 | func ExampleNewSubscription() { 22 | //创建在ch上发送10个整数的订阅。 23 | ch := make(chan int) 24 | sub := event.NewSubscription(func(quit <-chan struct{}) error { 25 | for i := 0; i < 10; i++ { 26 | select { 27 | case ch <- i: 28 | case <-quit: 29 | fmt.Println("unsubscribed") 30 | return nil 31 | } 32 | } 33 | return nil 34 | }) 35 | 36 | //这是消费者。它读取5个整数,然后中止订阅。 37 | //请注意,取消订阅会一直等到生产者关闭。 38 | for i := range ch { 39 | fmt.Println(i) 40 | if i == 4 { 41 | sub.Unsubscribe() 42 | break 43 | } 44 | } 45 | //输出: 46 | //零 47 | //一 48 | //二 49 | //三 50 | //四 51 | //退订 52 | } 53 | 54 | -------------------------------------------------------------------------------- /event/example_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | package event 14 | 15 | import "fmt" 16 | 17 | func ExampleTypeMux() { 18 | type someEvent struct{ I int } 19 | type otherEvent struct{ S string } 20 | type yetAnotherEvent struct{ X, Y int } 21 | 22 | var mux TypeMux 23 | 24 | //Start a subscriber. 25 | done := make(chan struct{}) 26 | sub := mux.Subscribe(someEvent{}, otherEvent{}) 27 | go func() { 28 | for event := range sub.Chan() { 29 | fmt.Printf("Received: %#v\n", event.Data) 30 | } 31 | fmt.Println("done") 32 | close(done) 33 | }() 34 | 35 | //发布一些事件。 36 | mux.Post(someEvent{5}) 37 | mux.Post(yetAnotherEvent{X: 3, Y: 4}) 38 | mux.Post(someEvent{6}) 39 | mux.Post(otherEvent{"whoa"}) 40 | 41 | //stop关闭所有订阅通道。 42 | //订户GOUDOTIN将打印“完成” 43 | //然后退出。 44 | mux.Stop() 45 | 46 | //等待订阅服务器返回。 47 | <-done 48 | 49 | //输出: 50 | //接收:事件。某些事件i:5 51 | //接收:事件。某些事件i:6 52 | //事件:其他事件{s:“哇”} 53 | //完成 54 | } 55 | 56 | -------------------------------------------------------------------------------- /internal/debug/loudpanic.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | //+构建GO1.6 14 | 15 | package debug 16 | 17 | import "runtime/debug" 18 | 19 | //响亮的恐慌以一种方式让所有的血腥堆栈打印在stderr上。 20 | func LoudPanic(x interface{}) { 21 | debug.SetTraceback("all") 22 | panic(x) 23 | } 24 | 25 | -------------------------------------------------------------------------------- /internal/debug/loudpanic_fallback.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | //+建设!GO1.6 14 | 15 | package debug 16 | 17 | //响亮的恐慌以一种方式让所有的血腥堆栈打印在stderr上。 18 | func LoudPanic(x interface{}) { 19 | panic(x) 20 | } 21 | 22 | -------------------------------------------------------------------------------- /internal/debug/trace_fallback.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | //+建设!GO1.5 14 | 15 | //go<1.5的跟踪方法没有OP实现。 16 | 17 | package debug 18 | 19 | import "errors" 20 | 21 | func (*HandlerT) StartGoTrace(string) error { 22 | return errors.New("tracing is not supported on Go < 1.5") 23 | } 24 | 25 | func (*HandlerT) StopGoTrace() error { 26 | return errors.New("tracing is not supported on Go < 1.5") 27 | } 28 | 29 | -------------------------------------------------------------------------------- /internal/ethapi/addrlock.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | package ethapi 14 | 15 | import ( 16 | "sync" 17 | 18 | "github.com/ethereum/go-ethereum/common" 19 | ) 20 | 21 | type AddrLocker struct { 22 | mu sync.Mutex 23 | locks map[common.Address]*sync.Mutex 24 | } 25 | 26 | //lock returns the lock of the given address. 27 | func (l *AddrLocker) lock(address common.Address) *sync.Mutex { 28 | l.mu.Lock() 29 | defer l.mu.Unlock() 30 | if l.locks == nil { 31 | l.locks = make(map[common.Address]*sync.Mutex) 32 | } 33 | if _, ok := l.locks[address]; !ok { 34 | l.locks[address] = new(sync.Mutex) 35 | } 36 | return l.locks[address] 37 | } 38 | 39 | //lockaddr锁定帐户的mutex。这用于阻止另一个Tx获取 40 | //直到释放锁。互斥体阻止(相同的nonce) 41 | //在签署第一个事务期间被再次读取。 42 | func (l *AddrLocker) LockAddr(address common.Address) { 43 | l.lock(address).Lock() 44 | } 45 | 46 | //unlockaddr解锁给定帐户的互斥体。 47 | func (l *AddrLocker) UnlockAddr(address common.Address) { 48 | l.lock(address).Unlock() 49 | } 50 | 51 | -------------------------------------------------------------------------------- /internal/guide/guide.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | //包指南是一个小型测试套件,用于确保开发指南中的代码段正常工作。 14 | package guide 15 | 16 | -------------------------------------------------------------------------------- /internal/jsre/deps/deps.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | //包deps包含控制台javascript依赖项go embedded。 14 | package deps 15 | 16 | //go:生成go bindata-nometadata-pkg deps-o bindata.go bignumber.js web3.js 17 | //go:生成gofmt-w-s bindata.go 18 | 19 | -------------------------------------------------------------------------------- /les/execqueue_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:38 10 | // 11 | 12 | 13 | package les 14 | 15 | import ( 16 | "testing" 17 | ) 18 | 19 | func TestExecQueue(t *testing.T) { 20 | var ( 21 | N = 10000 22 | q = newExecQueue(N) 23 | counter int 24 | execd = make(chan int) 25 | testexit = make(chan struct{}) 26 | ) 27 | defer q.quit() 28 | defer close(testexit) 29 | 30 | check := func(state string, wantOK bool) { 31 | c := counter 32 | counter++ 33 | qf := func() { 34 | select { 35 | case execd <- c: 36 | case <-testexit: 37 | } 38 | } 39 | if q.canQueue() != wantOK { 40 | t.Fatalf("canQueue() == %t for %s", !wantOK, state) 41 | } 42 | if q.queue(qf) != wantOK { 43 | t.Fatalf("canQueue() == %t for %s", !wantOK, state) 44 | } 45 | } 46 | 47 | for i := 0; i < N; i++ { 48 | check("queue below cap", true) 49 | } 50 | check("full queue", false) 51 | for i := 0; i < N; i++ { 52 | if c := <-execd; c != i { 53 | t.Fatal("execution out of order") 54 | } 55 | } 56 | q.quit() 57 | check("closed queue", false) 58 | } 59 | 60 | -------------------------------------------------------------------------------- /log/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Contributors to log15: 2 | 3 | - Aaron L 4 | - Alan Shreve 5 | - Chris Hines 6 | - Ciaran Downey 7 | - Dmitry Chestnykh 8 | - Evan Shaw 9 | - Péter Szilágyi 10 | - Trevor Gattis 11 | - Vincent Vanackere 12 | -------------------------------------------------------------------------------- /log/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /log/README_ETHEREUM.md: -------------------------------------------------------------------------------- 1 | This package is a fork of https://github.com/inconshreveable/log15, with some 2 | minor modifications required by the go-ethereum codebase: 3 | 4 | * Support for log level `trace` 5 | * Modified behavior to exit on `critical` failure 6 | -------------------------------------------------------------------------------- /log/handler_go13.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:39 10 | // 11 | 12 | //+建设!GO1.4 13 | 14 | package log 15 | 16 | import ( 17 | "sync/atomic" 18 | "unsafe" 19 | ) 20 | 21 | //swaphandler包装了另一个可以换出的处理程序 22 | //在运行时以线程安全的方式动态运行。 23 | type swapHandler struct { 24 | handler unsafe.Pointer 25 | } 26 | 27 | func (h *swapHandler) Log(r *Record) error { 28 | return h.Get().Log(r) 29 | } 30 | 31 | func (h *swapHandler) Get() Handler { 32 | return *(*Handler)(atomic.LoadPointer(&h.handler)) 33 | } 34 | 35 | func (h *swapHandler) Swap(newHandler Handler) { 36 | atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler)) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /log/handler_go14.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:39 10 | // 11 | 12 | //+构建GO1.4 13 | 14 | package log 15 | 16 | import "sync/atomic" 17 | 18 | //swaphandler包装了另一个可以换出的处理程序 19 | //在运行时以线程安全的方式动态运行。 20 | type swapHandler struct { 21 | handler atomic.Value 22 | } 23 | 24 | func (h *swapHandler) Log(r *Record) error { 25 | return (*h.handler.Load().(*Handler)).Log(r) 26 | } 27 | 28 | func (h *swapHandler) Swap(newHandler Handler) { 29 | h.handler.Store(&newHandler) 30 | } 31 | 32 | func (h *swapHandler) Get() Handler { 33 | return *h.handler.Load().(*Handler) 34 | } 35 | 36 | -------------------------------------------------------------------------------- /metrics/FORK.md: -------------------------------------------------------------------------------- 1 | This repo has been forked from https://github.com/rcrowley/go-metrics at commit e181e09 2 | -------------------------------------------------------------------------------- /metrics/disk.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:39 10 | // 11 | 12 | 13 | package metrics 14 | 15 | //disk stats是每个进程的磁盘IO状态。 16 | type DiskStats struct { 17 | ReadCount int64 //执行的读取操作数 18 | ReadBytes int64 //读取的字节总数 19 | WriteCount int64 //执行的写入操作数 20 | WriteBytes int64 //写入的字节总数 21 | } 22 | 23 | -------------------------------------------------------------------------------- /metrics/disk_nop.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:39 10 | // 11 | 12 | 13 | //+建设!Linux 14 | 15 | package metrics 16 | 17 | import "errors" 18 | 19 | //readdiskstats检索属于当前进程的磁盘IO状态。 20 | func ReadDiskStats(stats *DiskStats) error { 21 | return errors.New("Not implemented") 22 | } 23 | 24 | -------------------------------------------------------------------------------- /metrics/graphite_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | package metrics 13 | 14 | import ( 15 | "net" 16 | "time" 17 | ) 18 | 19 | func ExampleGraphite() { 20 | addr, _ := net.ResolveTCPAddr("net", ":2003") 21 | go Graphite(DefaultRegistry, 1*time.Second, "some.prefix", addr) 22 | } 23 | 24 | func ExampleGraphiteWithConfig() { 25 | addr, _ := net.ResolveTCPAddr("net", ":2003") 26 | go GraphiteWithConfig(GraphiteConfig{ 27 | Addr: addr, 28 | Registry: DefaultRegistry, 29 | FlushInterval: 1 * time.Second, 30 | DurationUnit: time.Millisecond, 31 | Percentiles: []float64{0.5, 0.75, 0.99, 0.999}, 32 | }) 33 | } 34 | 35 | -------------------------------------------------------------------------------- /metrics/influxdb/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Vincent Rischmann 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /metrics/influxdb/README.md: -------------------------------------------------------------------------------- 1 | go-metrics-influxdb 2 | =================== 3 | 4 | This is a reporter for the [go-metrics](https://github.com/rcrowley/go-metrics) library which will post the metrics to [InfluxDB](https://influxdb.com/). 5 | 6 | Note 7 | ---- 8 | 9 | This is only compatible with InfluxDB 0.9+. 10 | 11 | Usage 12 | ----- 13 | 14 | ```go 15 | import "github.com/vrischmann/go-metrics-influxdb" 16 | 17 | go influxdb.InfluxDB( 18 | metrics.DefaultRegistry, // metrics registry 19 | time.Second * 10, // interval 20 | "http://localhost:8086", // the InfluxDB url 21 | "mydb", // your InfluxDB database 22 | "myuser", // your InfluxDB user 23 | "mypassword", // your InfluxDB password 24 | ) 25 | ``` 26 | 27 | License 28 | ------- 29 | 30 | go-metrics-influxdb is licensed under the MIT license. See the LICENSE file for details. 31 | -------------------------------------------------------------------------------- /metrics/init_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | package metrics 13 | 14 | func init() { 15 | Enabled = true 16 | } 17 | 18 | -------------------------------------------------------------------------------- /metrics/json.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | package metrics 13 | 14 | import ( 15 | "encoding/json" 16 | "io" 17 | "time" 18 | ) 19 | 20 | //marshaljson返回一个字节片,其中包含所有 21 | //注册表中的指标。 22 | func (r *StandardRegistry) MarshalJSON() ([]byte, error) { 23 | return json.Marshal(r.GetAll()) 24 | } 25 | 26 | //WRITEJSON定期将给定注册表中的度量值写入 27 | //指定IO.Writer为JSON。 28 | func WriteJSON(r Registry, d time.Duration, w io.Writer) { 29 | for range time.Tick(d) { 30 | WriteJSONOnce(r, w) 31 | } 32 | } 33 | 34 | //writejsonce将给定注册表中的度量值写入指定的 35 | //写JSON。 36 | func WriteJSONOnce(r Registry, w io.Writer) { 37 | json.NewEncoder(w).Encode(r) 38 | } 39 | 40 | func (p *PrefixedRegistry) MarshalJSON() ([]byte, error) { 41 | return json.Marshal(p.GetAll()) 42 | } 43 | 44 | -------------------------------------------------------------------------------- /metrics/json_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | package metrics 13 | 14 | import ( 15 | "bytes" 16 | "encoding/json" 17 | "testing" 18 | ) 19 | 20 | func TestRegistryMarshallJSON(t *testing.T) { 21 | b := &bytes.Buffer{} 22 | enc := json.NewEncoder(b) 23 | r := NewRegistry() 24 | r.Register("counter", NewCounter()) 25 | enc.Encode(r) 26 | if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s { 27 | t.Fatalf(s) 28 | } 29 | } 30 | 31 | func TestRegistryWriteJSONOnce(t *testing.T) { 32 | r := NewRegistry() 33 | r.Register("counter", NewCounter()) 34 | b := &bytes.Buffer{} 35 | WriteJSONOnce(r, b) 36 | if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" { 37 | t.Fail() 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /metrics/opentsdb_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | package metrics 13 | 14 | import ( 15 | "net" 16 | "time" 17 | ) 18 | 19 | func ExampleOpenTSDB() { 20 | addr, _ := net.ResolveTCPAddr("net", ":2003") 21 | go OpenTSDB(DefaultRegistry, 1*time.Second, "some.prefix", addr) 22 | } 23 | 24 | func ExampleOpenTSDBWithConfig() { 25 | addr, _ := net.ResolveTCPAddr("net", ":2003") 26 | go OpenTSDBWithConfig(OpenTSDBConfig{ 27 | Addr: addr, 28 | Registry: DefaultRegistry, 29 | FlushInterval: 1 * time.Second, 30 | DurationUnit: time.Millisecond, 31 | }) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /metrics/runtime_cgo.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | //+构建CGO 13 | //+建设!应用程序引擎 14 | 15 | package metrics 16 | 17 | import "runtime" 18 | 19 | func numCgoCall() int64 { 20 | return runtime.NumCgoCall() 21 | } 22 | 23 | -------------------------------------------------------------------------------- /metrics/runtime_gccpufraction.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | //+建立GO1.5 13 | 14 | package metrics 15 | 16 | import "runtime" 17 | 18 | func gcCPUFraction(memStats *runtime.MemStats) float64 { 19 | return memStats.GCCPUFraction 20 | } 21 | 22 | -------------------------------------------------------------------------------- /metrics/runtime_no_cgo.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | //+建设!CGO AppEngine 13 | 14 | package metrics 15 | 16 | func numCgoCall() int64 { 17 | return 0 18 | } 19 | 20 | -------------------------------------------------------------------------------- /metrics/runtime_no_gccpufraction.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | //+建设!GO1.5 13 | 14 | package metrics 15 | 16 | import "runtime" 17 | 18 | func gcCPUFraction(memStats *runtime.MemStats) float64 { 19 | return 0 20 | } 21 | 22 | -------------------------------------------------------------------------------- /metrics/validate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # check there are no formatting issues 6 | GOFMT_LINES=`gofmt -l . | wc -l | xargs` 7 | test $GOFMT_LINES -eq 0 || echo "gofmt needs to be run, ${GOFMT_LINES} files have issues" 8 | 9 | # run the tests for the root package 10 | go test -race . 11 | -------------------------------------------------------------------------------- /metrics/writer_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | package metrics 13 | 14 | import ( 15 | "sort" 16 | "testing" 17 | ) 18 | 19 | func TestMetricsSorting(t *testing.T) { 20 | var namedMetrics = namedMetricSlice{ 21 | {name: "zzz"}, 22 | {name: "bbb"}, 23 | {name: "fff"}, 24 | {name: "ggg"}, 25 | } 26 | 27 | sort.Sort(namedMetrics) 28 | for i, name := range []string{"bbb", "fff", "ggg", "zzz"} { 29 | if namedMetrics[i].name != name { 30 | t.Fail() 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /mobile/geth_android.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | 13 | //+构建Android 14 | 15 | package geth 16 | 17 | //clientIdentifier是一个硬编码的标识符,用于向网络报告。 18 | var clientIdentifier = "GethDroid" 19 | 20 | -------------------------------------------------------------------------------- /mobile/geth_ios.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | 13 | //+构建iOS 14 | 15 | package geth 16 | 17 | //clientIdentifier是一个硬编码的标识符,用于向网络报告。 18 | var clientIdentifier = "iGeth" 19 | 20 | -------------------------------------------------------------------------------- /mobile/geth_other.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | 13 | //+建设!安卓,!网间网操作系统 14 | 15 | package geth 16 | 17 | //clientIdentifier是一个硬编码的标识符,用于向网络报告。 18 | var clientIdentifier = "GethMobile" 19 | 20 | -------------------------------------------------------------------------------- /mobile/init.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | 13 | //包含mbile库的初始化代码。 14 | 15 | package geth 16 | 17 | import ( 18 | "os" 19 | "runtime" 20 | 21 | "github.com/ethereum/go-ethereum/log" 22 | ) 23 | 24 | func init() { 25 | //初始化记录器 26 | log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stderr, log.TerminalFormat(false)))) 27 | 28 | //初始化goroutine计数 29 | runtime.GOMAXPROCS(runtime.NumCPU()) 30 | } 31 | 32 | -------------------------------------------------------------------------------- /mobile/logger.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | 13 | package geth 14 | 15 | import ( 16 | "os" 17 | 18 | "github.com/ethereum/go-ethereum/log" 19 | ) 20 | 21 | //setverbosity设置全局详细级别(介于0和6之间-请参阅logger/verbosity.go)。 22 | func SetVerbosity(level int) { 23 | log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(level), log.StreamHandler(os.Stderr, log.TerminalFormat(false)))) 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mobile/primitives.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:40 10 | // 11 | 12 | 13 | //包含用于基元类型的各种包装器。 14 | 15 | package geth 16 | 17 | import ( 18 | "errors" 19 | "fmt" 20 | ) 21 | 22 | //字符串表示str的s切片。 23 | type Strings struct{ strs []string } 24 | 25 | //SIZE返回切片中str的数目。 26 | func (s *Strings) Size() int { 27 | return len(s.strs) 28 | } 29 | 30 | //get从切片返回给定索引处的字符串。 31 | func (s *Strings) Get(index int) (str string, _ error) { 32 | if index < 0 || index >= len(s.strs) { 33 | return "", errors.New("index out of bounds") 34 | } 35 | return s.strs[index], nil 36 | } 37 | 38 | //set在切片中的给定索引处设置字符串。 39 | func (s *Strings) Set(index int, str string) error { 40 | if index < 0 || index >= len(s.strs) { 41 | return errors.New("index out of bounds") 42 | } 43 | s.strs[index] = str 44 | return nil 45 | } 46 | 47 | //字符串实现字符串接口。 48 | func (s *Strings) String() string { 49 | return fmt.Sprintf("%v", s.strs) 50 | } 51 | 52 | -------------------------------------------------------------------------------- /p2p/discv5/metrics.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:41 10 | // 11 | 12 | package discv5 13 | 14 | import "github.com/ethereum/go-ethereum/metrics" 15 | 16 | var ( 17 | ingressTrafficMeter = metrics.NewRegisteredMeter("discv5/InboundTraffic", nil) 18 | egressTrafficMeter = metrics.NewRegisteredMeter("discv5/OutboundTraffic", nil) 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /p2p/discv5/nodeevent_string.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:41 10 | // 11 | 12 | //由“stringer-type=nodeEvent”生成的代码;不要编辑。 13 | 14 | package discv5 15 | 16 | import "strconv" 17 | 18 | const _nodeEvent_name = "pongTimeoutpingTimeoutneighboursTimeout" 19 | 20 | var _nodeEvent_index = [...]uint8{0, 11, 22, 39} 21 | 22 | func (i nodeEvent) String() string { 23 | i -= 264 24 | if i >= nodeEvent(len(_nodeEvent_index)-1) { 25 | return "nodeEvent(" + strconv.FormatInt(int64(i+264), 10) + ")" 26 | } 27 | return _nodeEvent_name[_nodeEvent_index[i]:_nodeEvent_index[i+1]] 28 | } 29 | 30 | -------------------------------------------------------------------------------- /p2p/discv5/sim_testmain_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:41 10 | // 11 | 12 | 13 | //+构建Go1.4、Nacl、Faketime_模拟 14 | 15 | package discv5 16 | 17 | import ( 18 | "os" 19 | "runtime" 20 | "testing" 21 | "unsafe" 22 | ) 23 | 24 | //在运行时启用假时间模式,如在游乐场上。 25 | //这有一点可能不起作用,因为有些go代码 26 | //可能在设置变量之前执行。 27 | 28 | //转到:linkname faketime runtime.faketime 29 | var faketime = 1 30 | 31 | func TestMain(m *testing.M) { 32 | //为了获得go:linkname的访问权限,我们需要以某种方式使用unsafe。 33 | _ = unsafe.Sizeof(0) 34 | 35 | //运行实际测试。runwithplaygroundtime确保 36 | //这就是所谓的跑步。 37 | runtime.GOMAXPROCS(8) 38 | os.Exit(m.Run()) 39 | } 40 | 41 | -------------------------------------------------------------------------------- /p2p/netutil/error.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:41 10 | // 11 | 12 | 13 | package netutil 14 | 15 | //IsTemporaryError检查给定的错误是否应被视为临时错误。 16 | func IsTemporaryError(err error) bool { 17 | tempErr, ok := err.(interface { 18 | Temporary() bool 19 | }) 20 | return ok && tempErr.Temporary() || isPacketTooBig(err) 21 | } 22 | 23 | -------------------------------------------------------------------------------- /p2p/netutil/toobig_notwindows.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:41 10 | // 11 | 12 | 13 | //+建设!窗户 14 | 15 | package netutil 16 | 17 | //ispackettoobig报告err是否指示UDP数据包没有 18 | //安装接收缓冲区。在上没有这样的错误 19 | //非Windows平台。 20 | func isPacketTooBig(err error) bool { 21 | return false 22 | } 23 | 24 | -------------------------------------------------------------------------------- /p2p/netutil/toobig_windows.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:41 10 | // 11 | 12 | 13 | //+构建窗口 14 | 15 | package netutil 16 | 17 | import ( 18 | "net" 19 | "os" 20 | "syscall" 21 | ) 22 | 23 | const _WSAEMSGSIZE = syscall.Errno(10040) 24 | 25 | //ispackettoobig报告err是否指示UDP数据包没有 26 | //安装接收缓冲区。在Windows上,wsarecvfrom返回 27 | //对wsaemsgsize进行编码,如果发生这种情况,则没有数据。 28 | func isPacketTooBig(err error) bool { 29 | if opErr, ok := err.(*net.OpError); ok { 30 | if scErr, ok := opErr.Err.(*os.SyscallError); ok { 31 | return scErr.Err == _WSAEMSGSIZE 32 | } 33 | return opErr.Err == _WSAEMSGSIZE 34 | } 35 | return false 36 | } 37 | 38 | -------------------------------------------------------------------------------- /p2p/simulations/examples/README.md: -------------------------------------------------------------------------------- 1 | # devp2p simulation examples 2 | 3 | ## ping-pong 4 | 5 | `ping-pong.go` implements a simulation network which contains nodes running a 6 | simple "ping-pong" protocol where nodes send a ping message to all their 7 | connected peers every 10s and receive pong messages in return. 8 | 9 | To run the simulation, run `go run ping-pong.go` in one terminal to start the 10 | simulation API and `./ping-pong.sh` in another to start and connect the nodes: 11 | 12 | ``` 13 | $ go run ping-pong.go 14 | INFO [08-15|13:53:49] using sim adapter 15 | INFO [08-15|13:53:49] starting simulation server on 0.0.0.0:8888... 16 | ``` 17 | 18 | ``` 19 | $ ./ping-pong.sh 20 | ---> 13:58:12 creating 10 nodes 21 | Created node01 22 | Started node01 23 | ... 24 | Created node10 25 | Started node10 26 | ---> 13:58:13 connecting node01 to all other nodes 27 | Connected node01 to node02 28 | ... 29 | Connected node01 to node10 30 | ---> 13:58:14 done 31 | ``` 32 | 33 | Use the `--adapter` flag to choose the adapter type: 34 | 35 | ``` 36 | $ go run ping-pong.go --adapter exec 37 | INFO [08-15|14:01:14] using exec adapter tmpdir=/var/folders/k6/wpsgfg4n23ddbc6f5cnw5qg00000gn/T/p2p-example992833779 38 | INFO [08-15|14:01:14] starting simulation server on 0.0.0.0:8888... 39 | ``` 40 | -------------------------------------------------------------------------------- /p2p/simulations/examples/ping-pong.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Boot a ping-pong network simulation using the HTTP API started by ping-pong.go 4 | 5 | set -e 6 | 7 | main() { 8 | if ! which p2psim &>/dev/null; then 9 | fail "missing p2psim binary (you need to build cmd/p2psim and put it in \$PATH)" 10 | fi 11 | 12 | info "creating 10 nodes" 13 | for i in $(seq 1 10); do 14 | p2psim node create --name "$(node_name $i)" 15 | p2psim node start "$(node_name $i)" 16 | done 17 | 18 | info "connecting node01 to all other nodes" 19 | for i in $(seq 2 10); do 20 | p2psim node connect "node01" "$(node_name $i)" 21 | done 22 | 23 | info "done" 24 | } 25 | 26 | node_name() { 27 | local num=$1 28 | echo "node$(printf '%02d' $num)" 29 | } 30 | 31 | info() { 32 | echo -e "\033[1;32m---> $(date +%H:%M:%S) ${@}\033[0m" 33 | } 34 | 35 | fail() { 36 | echo -e "\033[1;31mERROR: ${@}\033[0m" >&2 37 | exit 1 38 | } 39 | 40 | main "$@" 41 | -------------------------------------------------------------------------------- /p2p/simulations/pipes/pipes.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package pipes 14 | 15 | import ( 16 | "net" 17 | ) 18 | 19 | //net pipe在返回错误的签名中包装net.pipe 20 | func NetPipe() (net.Conn, net.Conn, error) { 21 | p1, p2 := net.Pipe() 22 | return p1, p2, nil 23 | } 24 | 25 | //tcp pipe基于本地主机tcp套接字创建进程内全双工管道 26 | func TCPPipe() (net.Conn, net.Conn, error) { 27 | l, err := net.Listen("tcp", "127.0.0.1:0") 28 | if err != nil { 29 | return nil, nil, err 30 | } 31 | defer l.Close() 32 | 33 | var aconn net.Conn 34 | aerr := make(chan error, 1) 35 | go func() { 36 | var err error 37 | aconn, err = l.Accept() 38 | aerr <- err 39 | }() 40 | 41 | dconn, err := net.Dial("tcp", l.Addr().String()) 42 | if err != nil { 43 | <-aerr 44 | return nil, nil, err 45 | } 46 | if err := <-aerr; err != nil { 47 | dconn.Close() 48 | return nil, nil, err 49 | } 50 | return aconn, dconn, nil 51 | } 52 | 53 | -------------------------------------------------------------------------------- /params/denomination.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package params 14 | 15 | //这些是乙醚名称的乘数。 16 | //示例:要获取“gwei”中金额的wei值,请使用 17 | // 18 | //new(big.int).mul(值,big.new int(params.gwei)) 19 | // 20 | const ( 21 | Wei = 1 22 | GWei = 1e9 23 | Ether = 1e18 24 | ) 25 | 26 | -------------------------------------------------------------------------------- /params/network_params.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package params 14 | 15 | //这些是需要在客户端之间保持不变的网络参数,但是 16 | //不一定与共识有关。 17 | 18 | const ( 19 | //BloomBitsBlocks是单个BloomBit部分向量的块数。 20 | //包含在服务器端。 21 | BloomBitsBlocks uint64 = 4096 22 | 23 | //BloomBitsBlocksClient是单个BloomBit部分向量的块数。 24 | //在轻型客户端包含 25 | BloomBitsBlocksClient uint64 = 32768 26 | 27 | //BloomConfirms是在Bloom部分 28 | //考虑可能是最终的,并计算其旋转位。 29 | BloomConfirms = 256 30 | 31 | //chtfrequenceclient是在客户端创建cht的块频率。 32 | CHTFrequencyClient = 32768 33 | 34 | //chtfrequencyserver是在服务器端创建cht的块频率。 35 | //最终,这可以与客户端版本合并,但这需要 36 | //完整的数据库升级,所以应该留一段合适的时间。 37 | CHTFrequencyServer = 4096 38 | 39 | //BloomTrieFrequency是在两个对象上创建BloomTrie的块频率。 40 | //服务器/客户端。 41 | BloomTrieFrequency = 32768 42 | 43 | //HelperTrieConfirmations是预期客户端之前的确认数 44 | //提供所给的帮助者。 45 | HelperTrieConfirmations = 2048 46 | 47 | //HelperTrieProcessConfirmations是HelperTrie之前的确认数 48 | //生成 49 | HelperTrieProcessConfirmations = 256 50 | ) 51 | 52 | -------------------------------------------------------------------------------- /rlp/decode_tail_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package rlp 14 | 15 | import ( 16 | "bytes" 17 | "fmt" 18 | ) 19 | 20 | type structWithTail struct { 21 | A, B uint 22 | C []uint `rlp:"tail"` 23 | } 24 | 25 | func ExampleDecode_structTagTail() { 26 | //在本例中,“tail”结构标记用于解码 27 | //结构中的不同长度。 28 | var val structWithTail 29 | 30 | err := Decode(bytes.NewReader([]byte{0xC4, 0x01, 0x02, 0x03, 0x04}), &val) 31 | fmt.Printf("with 4 elements: err=%v val=%v\n", err, val) 32 | 33 | err = Decode(bytes.NewReader([]byte{0xC6, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}), &val) 34 | fmt.Printf("with 6 elements: err=%v val=%v\n", err, val) 35 | 36 | //请注意,必须至少有两个list元素存在于 37 | //填充字段A和B: 38 | err = Decode(bytes.NewReader([]byte{0xC1, 0x01}), &val) 39 | fmt.Printf("with 1 element: err=%q\n", err) 40 | 41 | //输出: 42 | //有4个元素:err=val=1 2[3 4] 43 | //有6个元素:err=val=1 2[3 4 5 6] 44 | //with 1 element:err=“rlp:rlp.structWithTail的元素太少” 45 | } 46 | 47 | -------------------------------------------------------------------------------- /rlp/doc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | /* 14 | 包rlp实现rlp序列化格式。 15 | 16 | RLP(递归线性前缀)的目的是任意编码 17 | 嵌套的二进制数据数组,rlp是使用的主要编码方法 18 | 在以太坊中序列化对象。RLP的唯一目的是编码 19 | 结构;编码特定的原子数据类型(例如字符串、整数、 20 | 浮点数)保留到高阶协议;在以太坊整数中 21 | 必须用不带前导零的大尾数二进制形式表示 22 | (因此使整数值为零等于空字节 23 | 数组)。 24 | 25 | RLP值由类型标记区分。类型标记位于 26 | 输入流中的值,并定义字节的大小和类型 27 | 接下来就是这样。 28 | **/ 29 | 30 | package rlp 31 | 32 | -------------------------------------------------------------------------------- /rlp/encoder_example_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package rlp 14 | 15 | import ( 16 | "fmt" 17 | "io" 18 | ) 19 | 20 | type MyCoolType struct { 21 | Name string 22 | a, b uint 23 | } 24 | 25 | //encoderlp将x写为rlp list[a,b],省略name字段。 26 | func (x *MyCoolType) EncodeRLP(w io.Writer) (err error) { 27 | //注意:接收器可以是零指针。这允许你 28 | //控制nil的编码,但这也意味着必须 29 | //检查零接收器。 30 | if x == nil { 31 | err = Encode(w, []uint{0, 0}) 32 | } else { 33 | err = Encode(w, []uint{x.a, x.b}) 34 | } 35 | return err 36 | } 37 | 38 | func ExampleEncoder() { 39 | var t *MyCoolType //T为零,指向mycoltype的指针 40 | bytes, _ := EncodeToBytes(t) 41 | fmt.Printf("%v → %X\n", t, bytes) 42 | 43 | t = &MyCoolType{Name: "foobar", a: 5, b: 6} 44 | bytes, _ = EncodeToBytes(t) 45 | fmt.Printf("%v → %X\n", t, bytes) 46 | 47 | //输出: 48 | //→C28080 49 | //&foobar 5 6→C20506 50 | } 51 | 52 | -------------------------------------------------------------------------------- /rpc/inproc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package rpc 14 | 15 | import ( 16 | "context" 17 | "net" 18 | ) 19 | 20 | //dialinproc将进程内连接附加到给定的RPC服务器。 21 | func DialInProc(handler *Server) *Client { 22 | initctx := context.Background() 23 | c, _ := newClient(initctx, func(context.Context) (net.Conn, error) { 24 | p1, p2 := net.Pipe() 25 | go handler.ServeCodec(NewJSONCodec(p1), OptionMethodInvocation|OptionSubscriptions) 26 | return p2, nil 27 | }) 28 | return c 29 | } 30 | 31 | -------------------------------------------------------------------------------- /rpc/ipc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package rpc 14 | 15 | import ( 16 | "context" 17 | "net" 18 | 19 | "github.com/ethereum/go-ethereum/log" 20 | "github.com/ethereum/go-ethereum/p2p/netutil" 21 | ) 22 | 23 | //servelistener接受L上的连接,并为它们提供JSON-RPC。 24 | func (srv *Server) ServeListener(l net.Listener) error { 25 | for { 26 | conn, err := l.Accept() 27 | if netutil.IsTemporaryError(err) { 28 | log.Warn("IPC accept error", "err", err) 29 | continue 30 | } else if err != nil { 31 | return err 32 | } 33 | log.Trace("IPC accepted connection") 34 | go srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions) 35 | } 36 | } 37 | 38 | //DialIPC创建一个新的连接到给定端点的IPC客户端。在Unix上,它假定 39 | //端点是指向Unix套接字的完整路径,而Windows端点是 40 | //命名管道的标识符。 41 | // 42 | //上下文用于建立初始连接。它不 43 | //影响与客户的后续交互。 44 | func DialIPC(ctx context.Context, endpoint string) (*Client, error) { 45 | return newClient(ctx, func(ctx context.Context) (net.Conn, error) { 46 | return newIPCConnection(ctx, endpoint) 47 | }) 48 | } 49 | 50 | -------------------------------------------------------------------------------- /rpc/ipc_js.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | //+构建JS 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | "errors" 20 | "net" 21 | ) 22 | 23 | var errNotSupported = errors.New("rpc: not supported") 24 | 25 | //ipclisten将在给定的端点上创建命名管道。 26 | func ipcListen(endpoint string) (net.Listener, error) { 27 | return nil, errNotSupported 28 | } 29 | 30 | //NewIPCConnection将连接到具有给定端点作为名称的命名管道。 31 | func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) { 32 | return nil, errNotSupported 33 | } 34 | 35 | -------------------------------------------------------------------------------- /rpc/ipc_windows.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | //+构建窗口 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | "net" 20 | "time" 21 | 22 | "gopkg.in/natefinch/npipe.v2" 23 | ) 24 | 25 | //如果拨号上下文没有截止时间,则使用此选项。它比 26 | //默认拨号超时,因为命名管道是本地的,不需要等待太长时间。 27 | const defaultPipeDialTimeout = 2 * time.Second 28 | 29 | //ipclisten将在给定的端点上创建命名管道。 30 | func ipcListen(endpoint string) (net.Listener, error) { 31 | return npipe.Listen(endpoint) 32 | } 33 | 34 | //NewIPCConnection将连接到具有给定端点作为名称的命名管道。 35 | func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) { 36 | timeout := defaultPipeDialTimeout 37 | if deadline, ok := ctx.Deadline(); ok { 38 | timeout = deadline.Sub(time.Now()) 39 | if timeout < 0 { 40 | timeout = 0 41 | } 42 | } 43 | return npipe.DialTimeout(endpoint, timeout) 44 | } 45 | 46 | -------------------------------------------------------------------------------- /rpc/utils_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | package rpc 14 | 15 | import ( 16 | "strings" 17 | "testing" 18 | ) 19 | 20 | func TestNewID(t *testing.T) { 21 | hexchars := "0123456789ABCDEFabcdef" 22 | for i := 0; i < 100; i++ { 23 | id := string(NewID()) 24 | if !strings.HasPrefix(id, "0x") { 25 | t.Fatalf("invalid ID prefix, want '0x...', got %s", id) 26 | } 27 | 28 | id = id[2:] 29 | if len(id) == 0 || len(id) > 32 { 30 | t.Fatalf("invalid ID length, want len(id) > 0 && len(id) <= 32), got %d", len(id)) 31 | } 32 | 33 | for i := 0; i < len(id); i++ { 34 | if strings.IndexByte(hexchars, id[i]) == -1 { 35 | t.Fatalf("unexpected byte, want any valid hex char, got %c", id[i]) 36 | } 37 | } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /signer/rules/deps/deps.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | 13 | //包deps包含控制台javascript依赖项go embedded。 14 | package deps 15 | 16 | //go:生成go bindata-nometadata-pkg deps-o bindata.go bignumber.js 17 | //go:生成gofmt-w-s bindata.go 18 | 19 | -------------------------------------------------------------------------------- /signer/storage/storage.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:42 10 | // 11 | 12 | // 13 | 14 | package storage 15 | 16 | import ( 17 | "fmt" 18 | ) 19 | 20 | type Storage interface { 21 | //按键存储值。0长度键导致无操作 22 | Put(key, value string) 23 | //get返回以前存储的值,如果该值不存在或键的长度为0,则返回空字符串 24 | Get(key string) string 25 | } 26 | 27 | //短暂存储是一种内存存储,它可以 28 | //不将值持久化到磁盘。主要用于测试 29 | type EphemeralStorage struct { 30 | data map[string]string 31 | namespace string 32 | } 33 | 34 | func (s *EphemeralStorage) Put(key, value string) { 35 | if len(key) == 0 { 36 | return 37 | } 38 | fmt.Printf("storage: put %v -> %v\n", key, value) 39 | s.data[key] = value 40 | } 41 | 42 | func (s *EphemeralStorage) Get(key string) string { 43 | if len(key) == 0 { 44 | return "" 45 | } 46 | fmt.Printf("storage: get %v\n", key) 47 | if v, exist := s.data[key]; exist { 48 | return v 49 | } 50 | return "" 51 | } 52 | 53 | func NewEphemeralStorage() Storage { 54 | s := &EphemeralStorage{ 55 | data: make(map[string]string), 56 | } 57 | return s 58 | } 59 | 60 | -------------------------------------------------------------------------------- /swarm/AUTHORS: -------------------------------------------------------------------------------- 1 | # Core team members 2 | 3 | Viktor Trón - @zelig 4 | Louis Holbrook - @nolash 5 | Lewis Marshall - @lmars 6 | Anton Evangelatov - @nonsense 7 | Janoš Guljaš - @janos 8 | Balint Gabor - @gbalint 9 | Elad Nachmias - @justelad 10 | Daniel A. Nagy - @nagydani 11 | Aron Fischer - @homotopycolimit 12 | Fabio Barone - @holisticode 13 | Zahoor Mohamed - @jmozah 14 | Zsolt Felföldi - @zsfelfoldi 15 | 16 | # External contributors 17 | 18 | Kiel Barry 19 | Gary Rong 20 | Jared Wasinger 21 | Leon Stanko 22 | Javier Peletier [epiclabs.io] 23 | Bartek Borkowski [tungsten-labs.com] 24 | Shane Howley [mainframe.com] 25 | Doug Leonard [mainframe.com] 26 | Ivan Daniluk [status.im] 27 | Felix Lange [EF] 28 | Martin Holst Swende [EF] 29 | Guillaume Ballet [EF] 30 | ligi [EF] 31 | Christopher Dro [blick-labs.com] 32 | Sergii Bomko [ledgerleopard.com] 33 | Domino Valdano 34 | Rafael Matias 35 | Coogan Brennan -------------------------------------------------------------------------------- /swarm/OWNERS: -------------------------------------------------------------------------------- 1 | # Ownership by go packages 2 | 3 | swarm 4 | ├── api ─────────────────── ethersphere 5 | ├── bmt ─────────────────── @zelig 6 | ├── dev ─────────────────── @lmars 7 | ├── fuse ────────────────── @jmozah, @holisticode 8 | ├── grafana_dashboards ──── @nonsense 9 | ├── metrics ─────────────── @nonsense, @holisticode 10 | ├── network ─────────────── ethersphere 11 | │ ├── bitvector ───────── @zelig, @janos, @gbalint 12 | │ ├── priorityqueue ───── @zelig, @janos, @gbalint 13 | │ ├── simulations ─────── @zelig 14 | │ └── stream ──────────── @janos, @zelig, @gbalint, @holisticode, @justelad 15 | │ ├── intervals ───── @janos 16 | │ └── testing ─────── @zelig 17 | ├── pot ─────────────────── @zelig 18 | ├── pss ─────────────────── @nolash, @zelig, @nonsense 19 | ├── services ────────────── @zelig 20 | ├── state ───────────────── @justelad 21 | ├── storage ─────────────── ethersphere 22 | │ ├── encryption ──────── @gbalint, @zelig, @nagydani 23 | │ ├── mock ────────────── @janos 24 | │ └── feed ────────────── @nolash, @jpeletier 25 | └── testutil ────────────── @lmars -------------------------------------------------------------------------------- /swarm/api/http/sctx.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | package http 13 | 14 | import ( 15 | "context" 16 | 17 | "github.com/ethereum/go-ethereum/swarm/api" 18 | "github.com/ethereum/go-ethereum/swarm/sctx" 19 | ) 20 | 21 | type uriKey struct{} 22 | 23 | func GetRUID(ctx context.Context) string { 24 | v, ok := ctx.Value(sctx.HTTPRequestIDKey{}).(string) 25 | if ok { 26 | return v 27 | } 28 | return "xxxxxxxx" 29 | } 30 | 31 | func SetRUID(ctx context.Context, ruid string) context.Context { 32 | return context.WithValue(ctx, sctx.HTTPRequestIDKey{}, ruid) 33 | } 34 | 35 | func GetURI(ctx context.Context) *api.URI { 36 | v, ok := ctx.Value(uriKey{}).(*api.URI) 37 | if ok { 38 | return v 39 | } 40 | return nil 41 | } 42 | 43 | func SetURI(ctx context.Context, uri *api.URI) context.Context { 44 | return context.WithValue(ctx, uriKey{}, uri) 45 | } 46 | 47 | -------------------------------------------------------------------------------- /swarm/api/testapi.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package api 14 | 15 | import ( 16 | "github.com/ethereum/go-ethereum/swarm/network" 17 | ) 18 | 19 | type Control struct { 20 | api *API 21 | hive *network.Hive 22 | } 23 | 24 | func NewControl(api *API, hive *network.Hive) *Control { 25 | return &Control{api, hive} 26 | } 27 | 28 | func (c *Control) Hive() string { 29 | return c.hive.String() 30 | } 31 | 32 | -------------------------------------------------------------------------------- /swarm/api/testdata/test0/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linapex/ethereum-go-chinese/f8b7a73c3fa104d792b0829e47388b2d4e130467/swarm/api/testdata/test0/img/logo.png -------------------------------------------------------------------------------- /swarm/api/testdata/test0/index.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: black; 3 | font-size: 12px; 4 | background-color: orange; 5 | border: 4px solid black; 6 | } 7 | body { 8 | background-color: orange 9 | } 10 | -------------------------------------------------------------------------------- /swarm/api/testdata/test0/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Swarm Test

8 | Ethereum logo 9 | 10 | -------------------------------------------------------------------------------- /swarm/chunk/chunk.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | package chunk 13 | 14 | const ( 15 | DefaultSize = 4096 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /swarm/dev/.dockerignore: -------------------------------------------------------------------------------- 1 | bin/* 2 | cluster/* 3 | -------------------------------------------------------------------------------- /swarm/dev/.gitignore: -------------------------------------------------------------------------------- 1 | bin/* 2 | cluster/* 3 | -------------------------------------------------------------------------------- /swarm/dev/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | # install build + test dependencies 4 | RUN apt-get update && \ 5 | apt-get install --yes --no-install-recommends \ 6 | ca-certificates \ 7 | curl \ 8 | fuse \ 9 | g++ \ 10 | gcc \ 11 | git \ 12 | iproute2 \ 13 | iputils-ping \ 14 | less \ 15 | libc6-dev \ 16 | make \ 17 | pkg-config \ 18 | && \ 19 | apt-get clean 20 | 21 | # install Go 22 | ENV GO_VERSION 1.8.1 23 | RUN curl -fSLo golang.tar.gz "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" && \ 24 | tar -xzf golang.tar.gz -C /usr/local && \ 25 | rm golang.tar.gz 26 | ENV GOPATH /go 27 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 28 | 29 | # install docker CLI 30 | RUN curl -fSLo docker.tar.gz https://get.docker.com/builds/Linux/x86_64/docker-17.04.0-ce.tgz && \ 31 | tar -xzf docker.tar.gz -C /usr/local/bin --strip-components=1 docker/docker && \ 32 | rm docker.tar.gz 33 | 34 | # install jq 35 | RUN curl -fSLo /usr/local/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 && \ 36 | chmod +x /usr/local/bin/jq 37 | 38 | # install govendor 39 | RUN go get -u github.com/kardianos/govendor 40 | 41 | # add custom bashrc 42 | ADD bashrc /root/.bashrc 43 | -------------------------------------------------------------------------------- /swarm/dev/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build cluster test 2 | 3 | default: build 4 | 5 | build: 6 | go build -o bin/swarm github.com/ethereum/go-ethereum/cmd/swarm 7 | go build -o bin/geth github.com/ethereum/go-ethereum/cmd/geth 8 | go build -o bin/bootnode github.com/ethereum/go-ethereum/cmd/bootnode 9 | 10 | cluster: build 11 | scripts/boot-cluster.sh 12 | 13 | test: 14 | go test -v github.com/ethereum/go-ethereum/swarm/... 15 | -------------------------------------------------------------------------------- /swarm/dev/README.md: -------------------------------------------------------------------------------- 1 | Swarm development environment 2 | ============================= 3 | 4 | The Swarm development environment is a Linux bash shell which can be run in a 5 | Docker container and provides a predictable build and test environment. 6 | 7 | ### Start the Docker container 8 | 9 | Run the `run.sh` script to build the Docker image and run it, you will then be 10 | at a bash prompt inside the `swarm/dev` directory. 11 | 12 | ### Build binaries 13 | 14 | Run `make` to build the `swarm`, `geth` and `bootnode` binaries into the 15 | `swarm/dev/bin` directory. 16 | 17 | ### Boot a cluster 18 | 19 | Run `make cluster` to start a 3 node Swarm cluster, or run 20 | `scripts/boot-cluster.sh --size N` to boot a cluster of size N. 21 | -------------------------------------------------------------------------------- /swarm/dev/bashrc: -------------------------------------------------------------------------------- 1 | export ROOT="${GOPATH}/src/github.com/ethereum/go-ethereum" 2 | export PATH="${ROOT}/swarm/dev/bin:${PATH}" 3 | 4 | cd "${ROOT}/swarm/dev" 5 | 6 | cat < ${timestamp} ${msg}" "green" 7 | } 8 | 9 | warn() { 10 | local msg="$@" 11 | local timestamp=$(date +%H:%M:%S) 12 | say "===> ${timestamp} WARN: ${msg}" "yellow" >&2 13 | } 14 | 15 | fail() { 16 | local msg="$@" 17 | say "ERROR: ${msg}" "red" >&2 18 | exit 1 19 | } 20 | 21 | # say prints the given message to STDOUT, using the optional color if 22 | # STDOUT is a terminal. 23 | # 24 | # usage: 25 | # 26 | # say "foo" - prints "foo" 27 | # say "bar" "red" - prints "bar" in red 28 | # say "baz" "green" - prints "baz" in green 29 | # say "qux" "red" | tee - prints "qux" with no colour 30 | # 31 | say() { 32 | local msg=$1 33 | local color=$2 34 | 35 | if [[ -n "${color}" ]] && [[ -t 1 ]]; then 36 | case "${color}" in 37 | red) 38 | echo -e "\033[1;31m${msg}\033[0m" 39 | ;; 40 | green) 41 | echo -e "\033[1;32m${msg}\033[0m" 42 | ;; 43 | yellow) 44 | echo -e "\033[1;33m${msg}\033[0m" 45 | ;; 46 | *) 47 | echo "${msg}" 48 | ;; 49 | esac 50 | else 51 | echo "${msg}" 52 | fi 53 | } 54 | -------------------------------------------------------------------------------- /swarm/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.11-alpine as builder 2 | 3 | ARG VERSION 4 | 5 | RUN apk add --update git gcc g++ linux-headers 6 | RUN mkdir -p $GOPATH/src/github.com/ethereum && \ 7 | cd $GOPATH/src/github.com/ethereum && \ 8 | git clone https://github.com/ethersphere/go-ethereum && \ 9 | cd $GOPATH/src/github.com/ethereum/go-ethereum && \ 10 | git checkout ${VERSION} && \ 11 | go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm && \ 12 | go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/swarm-smoke && \ 13 | go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/geth && \ 14 | cp $GOPATH/bin/swarm /swarm && cp $GOPATH/bin/geth /geth && cp $GOPATH/bin/swarm-smoke /swarm-smoke 15 | 16 | 17 | # Release image with the required binaries and scripts 18 | FROM alpine:3.8 19 | WORKDIR / 20 | COPY --from=builder /swarm /geth /swarm-smoke / 21 | ADD run.sh /run.sh 22 | ADD run-smoke.sh /run-smoke.sh 23 | ENTRYPOINT ["/run.sh"] 24 | -------------------------------------------------------------------------------- /swarm/docker/run-smoke.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -o errexit 4 | set -o pipefail 5 | set -o nounset 6 | 7 | /swarm-smoke $@ 2>&1 || true 8 | -------------------------------------------------------------------------------- /swarm/docker/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -o errexit 4 | set -o pipefail 5 | set -o nounset 6 | 7 | PASSWORD=${PASSWORD:-} 8 | DATADIR=${DATADIR:-/root/.ethereum/} 9 | 10 | if [ "$PASSWORD" == "" ]; then echo "Password must be set, in order to use swarm non-interactively." && exit 1; fi 11 | 12 | echo $PASSWORD > /password 13 | 14 | KEYFILE=`find $DATADIR | grep UTC | head -n 1` || true 15 | if [ ! -f "$KEYFILE" ]; then echo "No keyfile found. Generating..." && /geth --datadir $DATADIR --password /password account new; fi 16 | KEYFILE=`find $DATADIR | grep UTC | head -n 1` || true 17 | if [ ! -f "$KEYFILE" ]; then echo "Could not find nor generate a BZZ keyfile." && exit 1; else echo "Found keyfile $KEYFILE"; fi 18 | 19 | VERSION=`/swarm version` 20 | echo "Running Swarm:" 21 | echo $VERSION 22 | 23 | export BZZACCOUNT="`echo -n $KEYFILE | tail -c 40`" || true 24 | if [ "$BZZACCOUNT" == "" ]; then echo "Could not parse BZZACCOUNT from keyfile." && exit 1; fi 25 | 26 | exec /swarm --bzzaccount=$BZZACCOUNT --password /password --datadir $DATADIR $@ 2>&1 27 | -------------------------------------------------------------------------------- /swarm/fuse/fuse_root.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | //+构建Linux Darwin Freebsd 14 | 15 | package fuse 16 | 17 | import ( 18 | "bazil.org/fuse/fs" 19 | ) 20 | 21 | var ( 22 | _ fs.Node = (*SwarmDir)(nil) 23 | ) 24 | 25 | type SwarmRoot struct { 26 | root *SwarmDir 27 | } 28 | 29 | func (filesystem *SwarmRoot) Root() (fs.Node, error) { 30 | return filesystem.root, nil 31 | } 32 | 33 | -------------------------------------------------------------------------------- /swarm/fuse/swarmfs.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package fuse 14 | 15 | import ( 16 | "sync" 17 | "time" 18 | 19 | "github.com/ethereum/go-ethereum/swarm/api" 20 | ) 21 | 22 | const ( 23 | Swarmfs_Version = "0.1" 24 | mountTimeout = time.Second * 5 25 | unmountTimeout = time.Second * 10 26 | maxFuseMounts = 5 27 | ) 28 | 29 | var ( 30 | swarmfs *SwarmFS //swarm文件系统singleton 31 | swarmfsLock sync.Once 32 | 33 | inode uint64 = 1 //全局索引 34 | inodeLock sync.RWMutex 35 | ) 36 | 37 | type SwarmFS struct { 38 | swarmApi *api.API 39 | activeMounts map[string]*MountInfo 40 | swarmFsLock *sync.RWMutex 41 | } 42 | 43 | func NewSwarmFS(api *api.API) *SwarmFS { 44 | swarmfsLock.Do(func() { 45 | swarmfs = &SwarmFS{ 46 | swarmApi: api, 47 | swarmFsLock: &sync.RWMutex{}, 48 | activeMounts: map[string]*MountInfo{}, 49 | } 50 | }) 51 | return swarmfs 52 | 53 | } 54 | 55 | //inode编号必须是唯一的,它们用于在fuse中缓存 56 | func NewInode() uint64 { 57 | inodeLock.Lock() 58 | defer inodeLock.Unlock() 59 | inode += 1 60 | return inode 61 | } 62 | 63 | -------------------------------------------------------------------------------- /swarm/fuse/swarmfs_fallback.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | //+建设!Linux!达尔文!FreeBSD 14 | 15 | package fuse 16 | 17 | import ( 18 | "errors" 19 | ) 20 | 21 | var errNoFUSE = errors.New("FUSE is not supported on this platform") 22 | 23 | func isFUSEUnsupportedError(err error) bool { 24 | return err == errNoFUSE 25 | } 26 | 27 | type MountInfo struct { 28 | MountPoint string 29 | StartManifest string 30 | LatestManifest string 31 | } 32 | 33 | func (self *SwarmFS) Mount(mhash, mountpoint string) (*MountInfo, error) { 34 | return nil, errNoFUSE 35 | } 36 | 37 | func (self *SwarmFS) Unmount(mountpoint string) (bool, error) { 38 | return false, errNoFUSE 39 | } 40 | 41 | func (self *SwarmFS) Listmounts() ([]*MountInfo, error) { 42 | return nil, errNoFUSE 43 | } 44 | 45 | func (self *SwarmFS) Stop() error { 46 | return nil 47 | } 48 | 49 | -------------------------------------------------------------------------------- /swarm/network/bitvector/bitvector.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package bitvector 14 | 15 | import ( 16 | "errors" 17 | ) 18 | 19 | var errInvalidLength = errors.New("invalid length") 20 | 21 | type BitVector struct { 22 | len int 23 | b []byte 24 | } 25 | 26 | func New(l int) (bv *BitVector, err error) { 27 | return NewFromBytes(make([]byte, l/8+1), l) 28 | } 29 | 30 | func NewFromBytes(b []byte, l int) (bv *BitVector, err error) { 31 | if l <= 0 { 32 | return nil, errInvalidLength 33 | } 34 | if len(b)*8 < l { 35 | return nil, errInvalidLength 36 | } 37 | return &BitVector{ 38 | len: l, 39 | b: b, 40 | }, nil 41 | } 42 | 43 | func (bv *BitVector) Get(i int) bool { 44 | bi := i / 8 45 | return bv.b[bi]&(0x1< 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package network 14 | 15 | import ( 16 | "fmt" 17 | "strings" 18 | ) 19 | 20 | func LogAddrs(nns [][]byte) string { 21 | var nnsa []string 22 | for _, nn := range nns { 23 | nnsa = append(nnsa, fmt.Sprintf("%08x", nn[:4])) 24 | } 25 | return strings.Join(nnsa, ", ") 26 | } 27 | 28 | -------------------------------------------------------------------------------- /swarm/network/discovery_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package network 14 | 15 | import ( 16 | "testing" 17 | 18 | p2ptest "github.com/ethereum/go-ethereum/p2p/testing" 19 | ) 20 | 21 | /** 22 | * 23 | *-连接后,发送出站子进程msg 24 | * 25 | **/ 26 | 27 | func TestDiscovery(t *testing.T) { 28 | params := NewHiveParams() 29 | s, pp := newHiveTester(t, params, 1, nil) 30 | 31 | node := s.Nodes[0] 32 | raddr := NewAddr(node) 33 | pp.Register(raddr) 34 | 35 | //启动配置单元并等待连接 36 | pp.Start(s.Server) 37 | defer pp.Stop() 38 | 39 | //向对等端发送子进程msg 40 | err := s.TestExchanges(p2ptest.Exchange{ 41 | Label: "outgoing subPeersMsg", 42 | Expects: []p2ptest.Expect{ 43 | { 44 | Code: 1, 45 | Msg: &subPeersMsg{Depth: 0}, 46 | Peer: node.ID(), 47 | }, 48 | }, 49 | }) 50 | 51 | if err != nil { 52 | t.Fatal(err) 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /swarm/network/simulation/service_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package simulation 14 | 15 | import ( 16 | "testing" 17 | ) 18 | 19 | func TestService(t *testing.T) { 20 | sim := New(noopServiceFuncMap) 21 | defer sim.Close() 22 | 23 | id, err := sim.AddNode() 24 | if err != nil { 25 | t.Fatal(err) 26 | } 27 | 28 | _, ok := sim.Service("noop", id).(*noopService) 29 | if !ok { 30 | t.Fatalf("service is not of %T type", &noopService{}) 31 | } 32 | 33 | _, ok = sim.RandomService("noop").(*noopService) 34 | if !ok { 35 | t.Fatalf("service is not of %T type", &noopService{}) 36 | } 37 | 38 | _, ok = sim.Services("noop")[id].(*noopService) 39 | if !ok { 40 | t.Fatalf("service is not of %T type", &noopService{}) 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /swarm/network/simulations/discovery/discovery.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package discovery 14 | 15 | -------------------------------------------------------------------------------- /swarm/network/stream/intervals/dbstore_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:43 10 | // 11 | 12 | 13 | package intervals 14 | 15 | import ( 16 | "io/ioutil" 17 | "os" 18 | "testing" 19 | 20 | "github.com/ethereum/go-ethereum/swarm/state" 21 | ) 22 | 23 | //testdbstore测试dbstore的基本功能。 24 | func TestDBStore(t *testing.T) { 25 | dir, err := ioutil.TempDir("", "intervals_test_db_store") 26 | if err != nil { 27 | panic(err) 28 | } 29 | defer os.RemoveAll(dir) 30 | 31 | store, err := state.NewDBStore(dir) 32 | if err != nil { 33 | t.Fatal(err) 34 | } 35 | defer store.Close() 36 | 37 | testStore(t, store) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /swarm/pss/handshake_none.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | 13 | //+构建nopshandshake 14 | 15 | package pss 16 | 17 | const ( 18 | IsActiveHandshake = false 19 | ) 20 | 21 | func NewHandshakeParams() interface{} { 22 | return nil 23 | } 24 | 25 | -------------------------------------------------------------------------------- /swarm/pss/protocol_none.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | 13 | //+构建nopssProtocol 14 | 15 | package pss 16 | 17 | const ( 18 | IsActiveProtocol = false 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /swarm/pss/testdata/addpsstodiscoverytestsnapshot.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use JSON; 4 | 5 | my $f; 6 | my $jsontext; 7 | my $nodelist; 8 | my $network; 9 | 10 | open($f, "<", $ARGV[0]) || die "cant open " . $ARGV[0]; 11 | while (<$f>) { 12 | $jsontext .= $_; 13 | } 14 | close($f); 15 | 16 | $network = decode_json($jsontext); 17 | $nodelist = $network->{'nodes'}; 18 | 19 | for ($i = 0; $i < 0+@$nodelist; $i++) { 20 | #my $protocollist = $$nodelist[$i]{'node'}{'info'}{'protocols'}; 21 | #$$protocollist{'pss'} = "pss"; 22 | my $svc = $$nodelist[$i]{'node'}{'config'}{'services'}; 23 | pop(@$svc); 24 | push(@$svc, "pss"); 25 | push(@$svc, "bzz"); 26 | } 27 | 28 | print encode_json($network); 29 | -------------------------------------------------------------------------------- /swarm/pss/testdata/addpsstodiscoverytestsnapshot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sed -e 's/\(\"services\"\):\["discovery\"]/\1:["pss","bzz"]/' 4 | -------------------------------------------------------------------------------- /swarm/pss/testdata/snapshot_2.json: -------------------------------------------------------------------------------- 1 | {"nodes":[{"node":{"config":{"id":"73d6ad4a75069dced660fa4cb98143ee5573df7cb15d9a295acf1655e9683384","private_key":"e567b7d9c554e5102cdc99b6523bace02dbb8951415c8816d82ba2d2e97fa23b","name":"node01","services":["pss","bzz"],"enable_msg_events":false,"port":0},"up":true}},{"node":{"config":{"id":"6e8da86abb894ab35044c8c455147225df96cab498da067a118f1fb9a417f9e3","private_key":"c7526db70acd02f36d3b201ef3e1d85e38c52bee6931453213dbc5edec4d0976","name":"node02","services":["pss","bzz"],"enable_msg_events":false,"port":0},"up":true}}],"conns":[{"one":"73d6ad4a75069dced660fa4cb98143ee5573df7cb15d9a295acf1655e9683384","other":"6e8da86abb894ab35044c8c455147225df96cab498da067a118f1fb9a417f9e3","up":true}]} -------------------------------------------------------------------------------- /swarm/pss/testdata/snapshot_3.json: -------------------------------------------------------------------------------- 1 | {"nodes":[{"node":{"config":{"id":"73d6ad4a75069dced660fa4cb98143ee5573df7cb15d9a295acf1655e9683384","private_key":"e567b7d9c554e5102cdc99b6523bace02dbb8951415c8816d82ba2d2e97fa23b","name":"node01","services":["bzz","pss"],"enable_msg_events":false,"port":0},"up":true}},{"node":{"config":{"id":"6e8da86abb894ab35044c8c455147225df96cab498da067a118f1fb9a417f9e3","private_key":"c7526db70acd02f36d3b201ef3e1d85e38c52bee6931453213dbc5edec4d0976","name":"node02","services":["bzz","pss"],"enable_msg_events":false,"port":0},"up":true}},{"node":{"config":{"id":"8a1eb78ff13df318e7f8116dffee98cd7d9905650fa53f16766b754a63f387ac","private_key":"61b5728f59bc43080c3b8eb0458fb30d7723e2747355b6dc980f35f3ed431199","name":"node03","services":["bzz","pss"],"enable_msg_events":false,"port":0},"up":true}}],"conns":[{"one":"6e8da86abb894ab35044c8c455147225df96cab498da067a118f1fb9a417f9e3","other":"8a1eb78ff13df318e7f8116dffee98cd7d9905650fa53f16766b754a63f387ac","up":true},{"one":"73d6ad4a75069dced660fa4cb98143ee5573df7cb15d9a295acf1655e9683384","other":"6e8da86abb894ab35044c8c455147225df96cab498da067a118f1fb9a417f9e3","up":true}]} -------------------------------------------------------------------------------- /swarm/sctx/sctx.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | package sctx 13 | 14 | import "context" 15 | 16 | type ( 17 | HTTPRequestIDKey struct{} 18 | requestHostKey struct{} 19 | ) 20 | 21 | func SetHost(ctx context.Context, domain string) context.Context { 22 | return context.WithValue(ctx, requestHostKey{}, domain) 23 | } 24 | 25 | func GetHost(ctx context.Context) string { 26 | v, ok := ctx.Value(requestHostKey{}).(string) 27 | if ok { 28 | return v 29 | } 30 | return "" 31 | } 32 | 33 | -------------------------------------------------------------------------------- /swarm/storage/error.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | 13 | package storage 14 | 15 | import ( 16 | "errors" 17 | ) 18 | 19 | const ( 20 | ErrInit = iota 21 | ErrNotFound 22 | ErrUnauthorized 23 | ErrInvalidValue 24 | ErrDataOverflow 25 | ErrNothingToReturn 26 | ErrInvalidSignature 27 | ErrNotSynced 28 | ) 29 | 30 | var ( 31 | ErrChunkNotFound = errors.New("chunk not found") 32 | ErrChunkInvalid = errors.New("invalid chunk") 33 | ) 34 | 35 | -------------------------------------------------------------------------------- /swarm/storage/feed/binaryserializer.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | 13 | package feed 14 | 15 | import "github.com/ethereum/go-ethereum/common/hexutil" 16 | 17 | type binarySerializer interface { 18 | binaryPut(serializedData []byte) error 19 | binaryLength() int 20 | binaryGet(serializedData []byte) error 21 | } 22 | 23 | //值接口表示字符串键值存储 24 | //用于生成查询字符串 25 | type Values interface { 26 | Get(key string) string 27 | Set(key, value string) 28 | } 29 | 30 | type valueSerializer interface { 31 | FromValues(values Values) error 32 | AppendValues(values Values) 33 | } 34 | 35 | //十六进制序列化结构并将其转换为十六进制字符串 36 | func Hex(bin binarySerializer) string { 37 | b := make([]byte, bin.binaryLength()) 38 | bin.binaryPut(b) 39 | return hexutil.Encode(b) 40 | } 41 | 42 | -------------------------------------------------------------------------------- /swarm/storage/feed/cacheentry.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | 13 | package feed 14 | 15 | import ( 16 | "bytes" 17 | "context" 18 | "time" 19 | 20 | "github.com/ethereum/go-ethereum/swarm/storage" 21 | ) 22 | 23 | const ( 24 | hasherCount = 8 25 | feedsHashAlgorithm = storage.SHA3Hash 26 | defaultRetrieveTimeout = 100 * time.Millisecond 27 | ) 28 | 29 | //cacheEntry缓存特定群源的最后一次已知更新。 30 | type cacheEntry struct { 31 | Update 32 | *bytes.Reader 33 | lastKey storage.Address 34 | } 35 | 36 | //实现Storage.LazySectionReader 37 | func (r *cacheEntry) Size(ctx context.Context, _ chan bool) (int64, error) { 38 | return int64(len(r.Update.data)), nil 39 | } 40 | 41 | //返回源的主题 42 | func (r *cacheEntry) Topic() Topic { 43 | return r.Feed.Topic 44 | } 45 | 46 | -------------------------------------------------------------------------------- /swarm/storage/feed/doc.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | /* 13 | 包饲料定义了群体饲料。 14 | 15 | Swarm feeds允许用户构建有关特定主题的更新feed 16 | 每次更新都不使用ENS。 17 | 更新方案建立在群块上,块键如下 18 | 可预测的、可版本控制的模式。 19 | 20 | 提要绑定到唯一标识符,该标识符由 21 | 所选主题。 22 | 23 | 提要定义为特定用户对特定主题的一系列更新。 24 | 25 | 实际数据更新也以群块的形式进行。钥匙 26 | 其中的更新是属性串联的散列,如下所示: 27 | 28 | updateaddr=h(提要,epoch id) 29 | 其中h是sha3散列函数 30 | feed是主题和用户地址的组合 31 | epoch id是一个时隙。有关详细信息,请参阅查找包。 32 | 33 | 在订阅源中查找最新更新的用户只需知道主题 34 | 以及另一个用户的地址。 35 | 36 | 源更新数据为: 37 | updatedata=feed epoch数据 38 | 39 | 进入区块负载的完整更新数据是: 40 | updatedata符号(updatedata) 41 | 42 | 结构总结: 43 | 44 | 请求:带签名的订阅源更新 45 | 更新:标题+数据 46 | 标题:协议版本,保留供将来使用的占位符 47 | ID:有关如何定位特定更新的信息 48 | 提要:表示用户关于特定主题的一系列出版物 49 | 主题:更新所涉及的项目 50 | 用户:更新源的用户 51 | epoch:存储更新的时隙 52 | 53 | **/ 54 | 55 | package feed 56 | 57 | -------------------------------------------------------------------------------- /swarm/storage/feed/feed_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | package feed 13 | 14 | import ( 15 | "testing" 16 | ) 17 | 18 | func getTestFeed() *Feed { 19 | topic, _ := NewTopic("world news report, every hour", nil) 20 | return &Feed{ 21 | Topic: topic, 22 | User: newCharlieSigner().Address(), 23 | } 24 | } 25 | 26 | func TestFeedSerializerDeserializer(t *testing.T) { 27 | testBinarySerializerRecovery(t, getTestFeed(), "0x776f726c64206e657773207265706f72742c20657665727920686f7572000000876a8936a7cd0b79ef0735ad0896c1afe278781c") 28 | } 29 | 30 | func TestFeedSerializerLengthCheck(t *testing.T) { 31 | testBinarySerializerLengthCheck(t, getTestFeed()) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /swarm/storage/feed/id_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | package feed 13 | 14 | import ( 15 | "testing" 16 | 17 | "github.com/ethereum/go-ethereum/swarm/storage/feed/lookup" 18 | ) 19 | 20 | func getTestID() *ID { 21 | return &ID{ 22 | Feed: *getTestFeed(), 23 | Epoch: lookup.GetFirstEpoch(1000), 24 | } 25 | } 26 | 27 | func TestIDAddr(t *testing.T) { 28 | id := getTestID() 29 | updateAddr := id.Addr() 30 | compareByteSliceToExpectedHex(t, "updateAddr", updateAddr, "0x8b24583ec293e085f4c78aaee66d1bc5abfb8b4233304d14a349afa57af2a783") 31 | } 32 | 33 | func TestIDSerializer(t *testing.T) { 34 | testBinarySerializerRecovery(t, getTestID(), "0x776f726c64206e657773207265706f72742c20657665727920686f7572000000876a8936a7cd0b79ef0735ad0896c1afe278781ce803000000000019") 35 | } 36 | 37 | func TestIDLengthCheck(t *testing.T) { 38 | testBinarySerializerLengthCheck(t, getTestID()) 39 | } 40 | 41 | -------------------------------------------------------------------------------- /swarm/storage/feed/query_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:44 10 | // 11 | 12 | 13 | package feed 14 | 15 | import ( 16 | "testing" 17 | ) 18 | 19 | func getTestQuery() *Query { 20 | id := getTestID() 21 | return &Query{ 22 | TimeLimit: 5000, 23 | Feed: id.Feed, 24 | Hint: id.Epoch, 25 | } 26 | } 27 | 28 | func TestQueryValues(t *testing.T) { 29 | var expected = KV{"hint.level": "25", "hint.time": "1000", "time": "5000", "topic": "0x776f726c64206e657773207265706f72742c20657665727920686f7572000000", "user": "0x876A8936A7Cd0b79Ef0735AD0896c1AFe278781c"} 30 | 31 | query := getTestQuery() 32 | testValueSerializer(t, query, expected) 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /swarm/storage/mock/mem/mem_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | 13 | package mem 14 | 15 | import ( 16 | "testing" 17 | 18 | "github.com/ethereum/go-ethereum/swarm/storage/mock/test" 19 | ) 20 | 21 | //TestGlobalStore正在为GlobalStore运行测试 22 | //使用test.mockstore函数。 23 | func TestGlobalStore(t *testing.T) { 24 | test.MockStore(t, NewGlobalStore(), 100) 25 | } 26 | 27 | //testmortexport正在运行用于导入和 28 | //在两个GlobalStores之间导出数据 29 | //使用test.importexport函数。 30 | func TestImportExport(t *testing.T) { 31 | test.ImportExport(t, NewGlobalStore(), NewGlobalStore(), 100) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /swarm/storage/mock/rpc/rpc_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | 13 | package rpc 14 | 15 | import ( 16 | "testing" 17 | 18 | "github.com/ethereum/go-ethereum/rpc" 19 | "github.com/ethereum/go-ethereum/swarm/storage/mock/mem" 20 | "github.com/ethereum/go-ethereum/swarm/storage/mock/test" 21 | ) 22 | 23 | //testdbstore正在为GlobalStore运行测试 24 | //使用test.mockstore函数。 25 | func TestRPCStore(t *testing.T) { 26 | serverStore := mem.NewGlobalStore() 27 | 28 | server := rpc.NewServer() 29 | if err := server.RegisterName("mockStore", serverStore); err != nil { 30 | t.Fatal(err) 31 | } 32 | 33 | store := NewGlobalStore(rpc.DialInProc(server)) 34 | defer store.Close() 35 | 36 | test.MockStore(t, store, 30) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /swarm/storage/schema.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | package storage 13 | 14 | //我们要使用的DB模式。实际/当前数据库架构可能不同 15 | //直到运行迁移。 16 | const CurrentDbSchema = DbSchemaHalloween 17 | 18 | //曾经有一段时间我们根本没有模式。 19 | const DbSchemaNone = "" 20 | 21 | //“纯度”是我们与Swarm 0.3.5一起发布的第一个级别数据库的正式模式。 22 | const DbSchemaPurity = "purity" 23 | 24 | //“万圣节”在这里是因为我们有一个螺丝钉在垃圾回收索引。 25 | //因此,我们必须重建gc索引以消除错误的 26 | //这需要很长的时间。此模式用于记账, 27 | //所以重建索引只运行一次。 28 | const DbSchemaHalloween = "halloween" 29 | 30 | -------------------------------------------------------------------------------- /swarm/storage/swarmhasher.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | 13 | package storage 14 | 15 | import ( 16 | "hash" 17 | ) 18 | 19 | const ( 20 | BMTHash = "BMT" 21 | SHA3Hash = "SHA3" //http://golang.org/pkg/hash/hash 22 | DefaultHash = BMTHash 23 | ) 24 | 25 | type SwarmHash interface { 26 | hash.Hash 27 | ResetWithLength([]byte) 28 | } 29 | 30 | type HashWithLength struct { 31 | hash.Hash 32 | } 33 | 34 | func (h *HashWithLength) ResetWithLength(length []byte) { 35 | h.Reset() 36 | h.Write(length) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tests/rlp_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | 13 | package tests 14 | 15 | import ( 16 | "testing" 17 | ) 18 | 19 | func TestRLP(t *testing.T) { 20 | t.Parallel() 21 | tm := new(testMatcher) 22 | tm.walk(t, rlpTestDir, func(t *testing.T, name string, test *RLPTest) { 23 | if err := tm.checkFailure(t, name, test.Run()); err != nil { 24 | t.Error(err) 25 | } 26 | }) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /tests/vm_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | 13 | package tests 14 | 15 | import ( 16 | "testing" 17 | 18 | "github.com/ethereum/go-ethereum/core/vm" 19 | ) 20 | 21 | func TestVM(t *testing.T) { 22 | t.Parallel() 23 | vmt := new(testMatcher) 24 | vmt.slow("^vmPerformance") 25 | vmt.fails("^vmSystemOperationsTest.json/createNameRegistrator$", "fails without parallel execution") 26 | 27 | vmt.walk(t, vmTestDir, func(t *testing.T, name string, test *VMTest) { 28 | withTrace(t, test.json.Exec.GasLimit, func(vmconfig vm.Config) error { 29 | return vmt.checkFailure(t, name, test.Run(vmconfig)) 30 | }) 31 | }) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /trie/errors.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | 13 | package trie 14 | 15 | import ( 16 | "fmt" 17 | 18 | "github.com/ethereum/go-ethereum/common" 19 | ) 20 | 21 | //trie函数(tryget、tryupdate、trydelete)返回MissingNodeError 22 | //如果本地数据库中没有trie节点。它包含 23 | //检索丢失节点所需的信息。 24 | type MissingNodeError struct { 25 | NodeHash common.Hash //缺少节点的哈希 26 | Path []byte //丢失节点的十六进制编码路径 27 | } 28 | 29 | func (err *MissingNodeError) Error() string { 30 | return fmt.Sprintf("missing trie node %x (path %x)", err.NodeHash, err.Path) 31 | } 32 | 33 | -------------------------------------------------------------------------------- /trie/node_test.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:45 10 | // 11 | 12 | 13 | package trie 14 | 15 | import "testing" 16 | 17 | func TestCanUnload(t *testing.T) { 18 | tests := []struct { 19 | flag nodeFlag 20 | cachegen, cachelimit uint16 21 | want bool 22 | }{ 23 | { 24 | flag: nodeFlag{dirty: true, gen: 0}, 25 | want: false, 26 | }, 27 | { 28 | flag: nodeFlag{dirty: false, gen: 0}, 29 | cachegen: 0, cachelimit: 0, 30 | want: true, 31 | }, 32 | { 33 | flag: nodeFlag{dirty: false, gen: 65534}, 34 | cachegen: 65535, cachelimit: 1, 35 | want: true, 36 | }, 37 | { 38 | flag: nodeFlag{dirty: false, gen: 65534}, 39 | cachegen: 0, cachelimit: 1, 40 | want: true, 41 | }, 42 | { 43 | flag: nodeFlag{dirty: false, gen: 1}, 44 | cachegen: 65535, cachelimit: 1, 45 | want: true, 46 | }, 47 | } 48 | 49 | for _, test := range tests { 50 | if got := test.flag.canUnload(test.cachegen, test.cachelimit); got != test.want { 51 | t.Errorf("%+v\n got %t, want %t", test, got, test.want) 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /whisper/whisperv5/config.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:46 10 | // 11 | 12 | 13 | package whisperv5 14 | 15 | type Config struct { 16 | MaxMessageSize uint32 `toml:",omitempty"` 17 | MinimumAcceptedPOW float64 `toml:",omitempty"` 18 | } 19 | 20 | var DefaultConfig = Config{ 21 | MaxMessageSize: DefaultMaxMessageSize, 22 | MinimumAcceptedPOW: DefaultMinimumPoW, 23 | } 24 | 25 | -------------------------------------------------------------------------------- /whisper/whisperv5/topic.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:46 10 | // 11 | 12 | 13 | //包含耳语协议主题元素。 14 | 15 | package whisperv5 16 | 17 | import ( 18 | "github.com/ethereum/go-ethereum/common" 19 | "github.com/ethereum/go-ethereum/common/hexutil" 20 | ) 21 | 22 | //TopicType表示密码安全的概率部分 23 | //消息的分类,确定为 24 | //sha3消息原始作者给出的某些任意数据的散列。 25 | type TopicType [TopicLength]byte 26 | 27 | func BytesToTopic(b []byte) (t TopicType) { 28 | sz := TopicLength 29 | if x := len(b); x < TopicLength { 30 | sz = x 31 | } 32 | for i := 0; i < sz; i++ { 33 | t[i] = b[i] 34 | } 35 | return t 36 | } 37 | 38 | //字符串将主题字节数组转换为字符串表示形式。 39 | func (t *TopicType) String() string { 40 | return common.ToHex(t[:]) 41 | } 42 | 43 | //marshalText返回t的十六进制表示形式。 44 | func (t TopicType) MarshalText() ([]byte, error) { 45 | return hexutil.Bytes(t[:]).MarshalText() 46 | } 47 | 48 | //UnmarshalText解析主题的十六进制表示。 49 | func (t *TopicType) UnmarshalText(input []byte) error { 50 | return hexutil.UnmarshalFixedText("Topic", input, t[:]) 51 | } 52 | 53 | -------------------------------------------------------------------------------- /whisper/whisperv6/config.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:46 10 | // 11 | 12 | 13 | package whisperv6 14 | 15 | //config表示耳语节点的配置状态。 16 | type Config struct { 17 | MaxMessageSize uint32 `toml:",omitempty"` 18 | MinimumAcceptedPOW float64 `toml:",omitempty"` 19 | RestrictConnectionBetweenLightClients bool `toml:",omitempty"` 20 | } 21 | 22 | //defaultconfig表示(shocker!)默认配置。 23 | var DefaultConfig = Config{ 24 | MaxMessageSize: DefaultMaxMessageSize, 25 | MinimumAcceptedPOW: DefaultMinimumPoW, 26 | RestrictConnectionBetweenLightClients: true, 27 | } 28 | 29 | -------------------------------------------------------------------------------- /whisper/whisperv6/topic.go: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // linapex 曹一峰 4 | // linapex@163.com 5 | // superexc 6 | // 128148617 7 | // https://jsq.ink 8 | // pku engineer 9 | // 2019-03-16 19:16:46 10 | // 11 | 12 | 13 | //包含耳语协议主题元素。 14 | 15 | package whisperv6 16 | 17 | import ( 18 | "github.com/ethereum/go-ethereum/common" 19 | "github.com/ethereum/go-ethereum/common/hexutil" 20 | ) 21 | 22 | //TopicType表示密码安全的概率部分 23 | //消息的分类,确定为 24 | //sha3消息原始作者给出的某些任意数据的散列。 25 | type TopicType [TopicLength]byte 26 | 27 | //BytesToTopic从主题的字节数组表示形式转换 28 | //进入TopicType类型。 29 | func BytesToTopic(b []byte) (t TopicType) { 30 | sz := TopicLength 31 | if x := len(b); x < TopicLength { 32 | sz = x 33 | } 34 | for i := 0; i < sz; i++ { 35 | t[i] = b[i] 36 | } 37 | return t 38 | } 39 | 40 | //字符串将主题字节数组转换为字符串表示形式。 41 | func (t *TopicType) String() string { 42 | return common.ToHex(t[:]) 43 | } 44 | 45 | //marshalText返回t的十六进制表示形式。 46 | func (t TopicType) MarshalText() ([]byte, error) { 47 | return hexutil.Bytes(t[:]).MarshalText() 48 | } 49 | 50 | //UnmarshalText解析主题的十六进制表示。 51 | func (t *TopicType) UnmarshalText(input []byte) error { 52 | return hexutil.UnmarshalFixedText("Topic", input, t[:]) 53 | } 54 | 55 | --------------------------------------------------------------------------------