├── .gitignore ├── .travis.yml ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── README_CN.md ├── build.sh ├── chain ├── app │ ├── app.go │ └── evm │ │ ├── evm.go │ │ ├── kv.go │ │ ├── kv_test.go │ │ ├── tx_pool.go │ │ ├── tx_sort.go │ │ ├── verify_test.go │ │ ├── verifycpuparallel.go │ │ └── verifycpuserial.go ├── commands │ ├── global │ │ └── global.go │ ├── init.go │ ├── others.go │ ├── rendez.go │ └── run.go ├── core │ ├── node.go │ └── routes.go └── types │ ├── transaction.go │ ├── types.go │ └── version.go ├── cmd ├── client │ ├── cmd │ │ ├── abidef.json │ │ ├── bytecode.txt │ │ ├── callparams.json │ │ ├── keystore │ │ │ ├── UTC--2016-12-20T08-25-39.222984108Z--58acd19b532526eacc628ed0e59df1ae0d056728 │ │ │ ├── UTC--2017-01-02T12-31-21.575303200Z--30f122da89194369bbaf4daea0bf194e3b0bb56b │ │ │ ├── UTC--2017-01-02T12-40-49.619717400Z--3a4fe69a2ffaa793fb02d24b3a0c772b33551585 │ │ │ └── UTC--2017-01-25T03-17-27.681660600Z--ed18ca8e8b33d02495841179a24b7d09a90ad8f8 │ │ └── readparams.json │ ├── commands │ │ ├── accounts.go │ │ ├── admin_op.go │ │ ├── basecheck.go │ │ ├── evm.go │ │ ├── exam.go │ │ ├── flags.go │ │ ├── info.go │ │ ├── kv.go │ │ ├── log.go │ │ ├── signbyca.go │ │ ├── state_query.go │ │ ├── transfer_bench.go │ │ ├── tx.go │ │ └── version.go │ ├── commons │ │ ├── abi_helpers.go │ │ ├── constants.go │ │ └── global.go │ ├── main.go │ └── utils │ │ ├── directory2go │ │ └── main.go │ │ ├── io │ │ └── io.go │ │ └── value_parser.go └── genesis │ └── main.go ├── codecov.yml ├── docker-compose.yaml ├── docs ├── cmd.md ├── cmd_CN.md └── img │ └── ann.png ├── eth ├── accounts │ └── abi │ │ ├── abi.go │ │ ├── abi_test.go │ │ ├── argument.go │ │ ├── bind │ │ ├── auth.go │ │ ├── backend.go │ │ ├── base.go │ │ ├── bind.go │ │ ├── template.go │ │ ├── topics.go │ │ └── util.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 ├── common │ ├── big.go │ ├── bytes.go │ ├── bytes_test.go │ ├── debug.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 ├── core │ ├── error.go │ ├── events.go │ ├── evm.go │ ├── evm_config.go │ ├── gaspool.go │ ├── genesis.go │ ├── genesis_alloc.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 │ │ ├── asm.go │ │ ├── base_gas_table.go │ │ ├── common.go │ │ ├── contract.go │ │ ├── contracts.go │ │ ├── contracts_test.go │ │ ├── disasm.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 │ │ ├── LICENSE │ │ ├── README │ │ ├── ecies.go │ │ ├── ecies_test.go │ │ └── params.go │ ├── secp256k1 │ │ ├── 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 ├── ethdb │ ├── database.go │ ├── database_test.go │ ├── interface.go │ ├── memory_database.go │ ├── table.go │ └── table_batch.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 ├── 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 │ ├── init_test.go │ ├── json.go │ ├── json_test.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 ├── 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 └── 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 ├── gemmill ├── LICENSE ├── angine.go ├── archive │ └── archive.go ├── blockchain │ ├── pool.go │ ├── pool_test.go │ ├── reactor.go │ ├── store.go │ └── storetool.go ├── config │ ├── config.go │ ├── mapconfig.go │ ├── mapconfig_test.go │ └── templates.go ├── consensus │ ├── engine.go │ ├── pbft │ │ ├── README.md │ │ ├── common.go │ │ ├── height_vote_set.go │ │ ├── reactor.go │ │ ├── replay.go │ │ ├── state.go │ │ ├── test_data │ │ │ ├── README.md │ │ │ ├── build.sh │ │ │ ├── empty_block.cswal │ │ │ ├── small_block1.cswal │ │ │ └── small_block2.cswal │ │ ├── ticker.go │ │ ├── version.go │ │ └── wal.go │ └── raft │ │ ├── api.go │ │ ├── fsm.go │ │ ├── peer.go │ │ ├── secret_tcp_transport.go │ │ ├── snapshot.go │ │ └── state.go ├── ed25519 │ ├── LICENSE │ ├── ed25519.go │ ├── ed25519_test.go │ ├── edwards25519 │ │ ├── const.go │ │ └── edwards25519.go │ ├── extra25519 │ │ ├── extra25519.go │ │ └── extra25519_test.go │ └── testdata │ │ └── sign.input.gz ├── go-crypto │ ├── LICENSE │ ├── armor.go │ ├── armor_test.go │ ├── bcrypt │ │ ├── base64.go │ │ └── bcrypt.go │ ├── hash.go │ ├── node.go │ ├── node_test.go │ ├── priv_key.go │ ├── pub_key.go │ ├── random.go │ ├── signature.go │ ├── signature_test.go │ ├── symmetric.go │ └── symmetric_test.go ├── go-hash │ └── hash.go ├── go-utils │ ├── regexp.go │ ├── regexp_test.go │ ├── statistic.go │ └── tools.go ├── go-wire │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── byteslice.go │ ├── byteslice_test.go │ ├── cmd │ │ └── wire │ │ │ └── wire.go │ ├── codec.go │ ├── expr │ │ ├── expr.go │ │ ├── expr.peg │ │ ├── expr_test.go │ │ ├── types.go │ │ └── util.go │ ├── float.go │ ├── int.go │ ├── int_test.go │ ├── reflect.go │ ├── reflect_test.go │ ├── string.go │ ├── time.go │ ├── util.go │ ├── version.go │ └── wire.go ├── log.go ├── mempool │ ├── mempool.go │ └── reactor.go ├── modules │ ├── go-autofile │ │ ├── README.md │ │ ├── autofile.go │ │ ├── autofile_test.go │ │ ├── group.go │ │ ├── group_test.go │ │ └── sighup_watcher.go │ ├── go-clist │ │ ├── clist.go │ │ └── clist_test.go │ ├── go-common │ │ ├── LICENSE │ │ ├── array.go │ │ ├── async.go │ │ ├── bit_array.go │ │ ├── bit_array_test.go │ │ ├── byteslice.go │ │ ├── cmap.go │ │ ├── colors.go │ │ ├── errors.go │ │ ├── heap.go │ │ ├── int.go │ │ ├── io.go │ │ ├── math.go │ │ ├── mutate.go │ │ ├── net.go │ │ ├── os.go │ │ ├── random.go │ │ ├── repeat_timer.go │ │ ├── service.go │ │ ├── service_test.go │ │ ├── string.go │ │ ├── throttle_timer.go │ │ └── word.go │ ├── go-db │ │ ├── LICENSE.md │ │ ├── README.md │ │ ├── c_level_db.go │ │ ├── c_level_db_test.go │ │ ├── db.go │ │ ├── go_level_db.go │ │ ├── go_level_db_test.go │ │ └── mem_db.go │ ├── go-events │ │ ├── LICENSE │ │ ├── README.md │ │ ├── event_cache.go │ │ ├── events.go │ │ └── events_test.go │ ├── go-flowrate │ │ ├── LICENSE │ │ ├── README │ │ └── flowrate │ │ │ ├── flowrate.go │ │ │ ├── io.go │ │ │ ├── io_test.go │ │ │ └── util.go │ ├── go-log │ │ ├── dump.go │ │ ├── log_test.go │ │ ├── logger.go │ │ └── zap.go │ └── go-merkle │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── benchmarks │ │ └── EthansMacBook.txt │ │ ├── circle.yml │ │ ├── glide.lock │ │ ├── glide.yaml │ │ ├── iavl_node.go │ │ ├── iavl_proof.go │ │ ├── iavl_test.go │ │ ├── iavl_tree.go │ │ ├── scripts │ │ └── looper.go │ │ ├── simple_tree.go │ │ ├── simple_tree_test.go │ │ ├── types.go │ │ ├── util.go │ │ └── version.go ├── p2p │ ├── LICENSE │ ├── README.md │ ├── addrbook.go │ ├── addrbook_test.go │ ├── config.go │ ├── connection.go │ ├── fuzz.go │ ├── ip_range_counter.go │ ├── listener.go │ ├── listener_test.go │ ├── netaddress.go │ ├── peer.go │ ├── peer_set.go │ ├── peer_set_test.go │ ├── pex_reactor.go │ ├── secret_connection.go │ ├── secret_connection_test.go │ ├── switch.go │ ├── types.go │ ├── upnp │ │ ├── README.md │ │ ├── probe.go │ │ └── upnp.go │ ├── util.go │ └── version.go ├── plugin │ ├── admin_op.go │ ├── init.go │ └── queryCache.go ├── refuse_list │ ├── refuse_list.go │ └── refuse_list_test.go ├── rpc │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── circle.yml │ ├── client │ │ ├── http_client.go │ │ └── ws_client.go │ ├── server │ │ ├── handlers.go │ │ ├── http_params.go │ │ ├── http_server.go │ │ └── server_test.go │ ├── types │ │ └── types.go │ └── version.go ├── state │ ├── errors.go │ ├── execution.go │ ├── state.go │ ├── statetool.go │ ├── tps.go │ └── tps_test.go ├── trace │ ├── reactor.go │ └── router.go ├── types │ ├── admin_op.go │ ├── application.go │ ├── block.go │ ├── block_meta.go │ ├── blockcache_other.go │ ├── canonical_json.go │ ├── common.go │ ├── events.go │ ├── genesis.go │ ├── hooks.go │ ├── keys.go │ ├── kv.go │ ├── mempool.go │ ├── part_set.go │ ├── part_set_test.go │ ├── priv_validator.go │ ├── priv_validator_tool.go │ ├── proposal.go │ ├── proposal_test.go │ ├── query.go │ ├── result.go │ ├── resultcode.go │ ├── rpc.go │ ├── signable.go │ ├── tools.go │ ├── tx.go │ ├── tx_pool.go │ ├── validator.go │ ├── validator_set.go │ ├── validator_set_test.go │ ├── vote.go │ ├── vote_set.go │ ├── vote_set_test.go │ └── vote_test.go ├── utils │ ├── crypto.go │ ├── crypto_test.go │ ├── statistic.go │ ├── tools.go │ ├── tools_test.go │ └── zip │ │ ├── zip.go │ │ └── zip_test.go ├── vendor │ └── gopkg.in │ │ └── natefinch │ │ └── lumberjack.v2 │ │ ├── LICENSE │ │ ├── README.md │ │ ├── chown.go │ │ ├── chown_linux.go │ │ ├── example_test.go │ │ ├── linux_test.go │ │ ├── lumberjack.go │ │ ├── lumberjack_test.go │ │ ├── rotate_test.go │ │ └── testing_test.go └── version.go ├── get_pkgs.sh ├── go.mod ├── go.sum ├── scripts ├── archive │ └── commands.sh ├── bench │ ├── Makefile │ ├── bench.sh │ ├── contracts │ │ ├── complex │ │ │ ├── policy.abi │ │ │ ├── policy.bin │ │ │ └── policy.sol │ │ ├── sample │ │ │ ├── commands.sh │ │ │ ├── policy.md │ │ │ ├── sample.abi │ │ │ ├── sample.json │ │ │ ├── sample.sol │ │ │ ├── sample_execute.json │ │ │ ├── sample_exist.json │ │ │ └── sample_read.json │ │ └── simple │ │ │ ├── all │ │ │ ├── greeter.sol │ │ │ ├── math.sol │ │ │ ├── storage.sol │ │ │ └── token.sol │ ├── defaults.go │ └── main.go └── examples │ └── evm │ ├── commands.sh │ ├── sample.abi │ ├── sample.json │ ├── sample_execute.json │ ├── sample_exist.json │ └── sample_read.json ├── utils ├── file.go ├── request_id.go └── request_id_test.go └── version └── gemmill.go /.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 | *# 8 | *~ 9 | .project 10 | .settings 11 | 12 | # used by the Makefile 13 | /build/_workspace/ 14 | /build/bin/ 15 | *.zip 16 | /gemmill/modules/go-log/testdir 17 | 18 | # travis 19 | profile.tmp 20 | profile.cov 21 | 22 | # IdeaIDE 23 | .idea 24 | 25 | # VS Code 26 | .vscode 27 | 28 | *.log 29 | build 30 | .DS_Store 31 | 32 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/dappledger/AnnChain 3 | os : linux 4 | jobs: 5 | include: 6 | - stage: build 7 | os: linux 8 | go: 1.12.5 9 | env: GO111MODULE=on TEST_PLATFORM=binary TEST_GENESIS_IMAGE=$GOPATH/src/github.com/dappledger/AnnChain/build/genesis TEST_CONSENSUS_TYPE=pbft 10 | before_script: 11 | - make 12 | - make image 13 | script: 14 | - make test 15 | - go test ./gemmill/... -coverprofile=coverage.txt -covermode=atomic 16 | - cd .. 17 | - git clone -b $TRAVIS_BRANCH --depth=10 https://github.com/dappledger/ann-tests.git 18 | - git clone -b $TRAVIS_BRANCH --depth=10 https://github.com/dappledger/ann-go-sdk.git 19 | - cd ann-tests 20 | - make test-bdd 21 | after_success: 22 | - bash <(curl -s https://codecov.io/bash) 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # compile environment; 2 | FROM annchain/builder:go1.12 as builder 3 | #copy files; 4 | ADD . /AnnChain 5 | WORKDIR /AnnChain 6 | RUN GO111MODULE="on" GOPROXY="https://goproxy.io" make genesis 7 | 8 | # package environment; 9 | FROM annchain/runner:alpine3.11 10 | WORKDIR /genesis 11 | COPY --from=builder /AnnChain/build/genesis /bin/ 12 | ENTRYPOINT ["genesis"] 13 | 14 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | base=`pwd` 4 | bindir=$base/bin 5 | prev=github.com/dappledger/AnnChain 6 | 7 | begin() 8 | { 9 | mkdir -p bin 10 | cd $base/../../../../ 11 | export GOPATH=`pwd` 12 | } 13 | 14 | end() 15 | { 16 | cd $base 17 | } 18 | 19 | build() 20 | { 21 | echo $GOPATH 22 | echo "go build -o $bindir/$2 $1" 23 | go build -o $bindir/$2 $1 24 | } 25 | 26 | run() 27 | { 28 | begin 29 | case $1 in 30 | genesis ) 31 | build $prev"/cmd/genesis" "genesis" 32 | ;; 33 | gtool ) 34 | build $prev"/cmd/client" "gtool" 35 | ;; 36 | * ) 37 | build $prev"/cmd/genesis" "genesis" 38 | build $prev"/cmd/client" "gtool" 39 | ;; 40 | esac 41 | end 42 | } 43 | 44 | run $1 45 | -------------------------------------------------------------------------------- /chain/app/app.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 ZhongAn Technology 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package app 15 | 16 | import ( 17 | "github.com/spf13/viper" 18 | 19 | "github.com/dappledger/AnnChain/chain/app/evm" 20 | "github.com/dappledger/AnnChain/gemmill/types" 21 | ) 22 | 23 | type AppMaker func(*viper.Viper) (types.Application, error) 24 | 25 | var AppMap = map[string]AppMaker{ 26 | "evm": func(c *viper.Viper) (types.Application, error) { 27 | return evm.NewEVMApp(c) 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /chain/app/evm/verifycpuserial.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 ZhongAn Technology 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package evm 15 | 16 | import ( 17 | etypes "github.com/dappledger/AnnChain/eth/core/types" 18 | "github.com/dappledger/AnnChain/eth/rlp" 19 | gtypes "github.com/dappledger/AnnChain/gemmill/types" 20 | ) 21 | 22 | func exeWithCPUSerialVeirfy(txs gtypes.Txs, beginExec BeginExecFunc) { 23 | for i, raw := range txs { 24 | txbs := gtypes.Tx(txs[i]) 25 | exec, end := beginExec() 26 | err := execTx(txbs, exec, i, raw) 27 | end(raw, err) 28 | } 29 | } 30 | 31 | func execTx(atx gtypes.Tx, exec ExecFunc, index int, raw gtypes.Tx) error { 32 | var tx *etypes.Transaction 33 | if len(atx) > 0 { 34 | tx = new(etypes.Transaction) 35 | if err := rlp.DecodeBytes(atx, tx); err != nil { 36 | return err 37 | } 38 | if err := exec(index, raw, tx); err != nil { 39 | return err 40 | } 41 | } 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /chain/types/version.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 ZhongAn Technology 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package types 15 | 16 | import ( 17 | "fmt" 18 | "strings" 19 | 20 | "github.com/dappledger/AnnChain/gemmill/go-crypto" 21 | ) 22 | 23 | const CommitPrefixLength = 8 24 | 25 | var ( 26 | Version = "0.1.6" 27 | commitVer string 28 | ) 29 | 30 | func GetVersion() string { 31 | if len(commitVer) < CommitPrefixLength { 32 | commitVer = "unknown" 33 | } 34 | 35 | return fmt.Sprintf("%s-%s", Version, commitVer) 36 | } 37 | 38 | func GetCommitVersion() string { 39 | if len(commitVer) < CommitPrefixLength { 40 | commitVer = "unknown" 41 | } 42 | 43 | ctype := fmt.Sprintf("(crypto: %s)", crypto.CryptoType) 44 | 45 | return fmt.Sprintf("%s-%s-%s", Version, commitVer, ctype) 46 | } 47 | 48 | /*=======================unholy separator===========================*/ 49 | 50 | var ( 51 | app_name string 52 | ) 53 | 54 | func InitNodeInfo(app string) { 55 | if len(app_name) > 0 { 56 | return 57 | } 58 | if slc := strings.Split(app, "-"); len(slc) > 1 { 59 | app_name = slc[1] 60 | } else { 61 | app_name = app 62 | } 63 | } 64 | 65 | func AppName() string { 66 | return app_name 67 | } 68 | -------------------------------------------------------------------------------- /cmd/client/cmd/abidef.json: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"k","type":"string"},{"name":"v","type":"string"}],"name":"putString","outputs":[],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"k","type":"string"},{"name":"v","type":"int256"}],"name":"putInt","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"k","type":"string"}],"name":"getString","outputs":[{"name":"","type":"string"}],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"k","type":"string"}],"name":"getInt","outputs":[{"name":"","type":"int256"}],"type":"function","payable":true},{"inputs":[],"type":"constructor","payable":true},{"type":"fallback","payable":true}] 2 | -------------------------------------------------------------------------------- /cmd/client/cmd/callparams.json: -------------------------------------------------------------------------------- 1 | { 2 | "privkey": "a8971729fbc199fb3459529cebcd8704791fc699d88ac89284f23ff8e7fca7d6", 3 | "contract": "341efb295051fa28c5fc31a4aea21a53128cd496", 4 | "function":"putString", 5 | "params":[ 6 | "name", "dabing" 7 | ] 8 | } -------------------------------------------------------------------------------- /cmd/client/cmd/keystore/UTC--2016-12-20T08-25-39.222984108Z--58acd19b532526eacc628ed0e59df1ae0d056728: -------------------------------------------------------------------------------- 1 | {"address":"58acd19b532526eacc628ed0e59df1ae0d056728","crypto":{"cipher":"aes-128-ctr","ciphertext":"09c62a9ca81bac85bf9e07e905768b664bb0d7e5326feba843f2ded8ff221f3e","cipherparams":{"iv":"a70aa8e986a55091a05fce6c97e7bfdf"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"c96efe9b491191a847610533c8f05b48be939bc22815d3d9d8d32f49d099fc6c"},"mac":"53434e093bcfe3a3861e8c4b483d4ecf597aa9891cdf5b6f5e883f31a5e223ef"},"id":"6537dca8-3518-4e0b-b30a-f996c07625f2","version":3} -------------------------------------------------------------------------------- /cmd/client/cmd/keystore/UTC--2017-01-02T12-31-21.575303200Z--30f122da89194369bbaf4daea0bf194e3b0bb56b: -------------------------------------------------------------------------------- 1 | {"address":"30f122da89194369bbaf4daea0bf194e3b0bb56b","crypto":{"cipher":"aes-128-ctr","ciphertext":"ea354764d2f800574134a1e400ba6d0f25041f9fff01d37ea480087ff497c6b8","cipherparams":{"iv":"ef8893b76715318fa41662ff88a66fca"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"080fbeab0341dbb57904a88ad793362bc3ea5e9d85cb0a229855b9035756c7ac"},"mac":"37dc2aa1e20f0bb43438fad7c8ac3675973219c86805497e5f61750e3b765671"},"id":"ffdc1b90-f812-4ca7-bc6a-7aaa34df6f6f","version":3} -------------------------------------------------------------------------------- /cmd/client/cmd/keystore/UTC--2017-01-02T12-40-49.619717400Z--3a4fe69a2ffaa793fb02d24b3a0c772b33551585: -------------------------------------------------------------------------------- 1 | {"address":"3a4fe69a2ffaa793fb02d24b3a0c772b33551585","crypto":{"cipher":"aes-128-ctr","ciphertext":"e4ccfc33445f9750069de0c07b70aaeada53ec0c1419dfbcbc3156fd2909875b","cipherparams":{"iv":"4670a8e87e4464e187ae5c69f44cdc0e"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"349d9740999725786020dbfd7a69e47fda9cea0a8bac5f5057038cac763030c5"},"mac":"8f591fe8185c748c10aaff25dc63b9e1232f28b18fc0ee90dae92bd4b6d29159"},"id":"853ee265-ff9f-43d6-8f2c-6679e57b1777","version":3} -------------------------------------------------------------------------------- /cmd/client/cmd/keystore/UTC--2017-01-25T03-17-27.681660600Z--ed18ca8e8b33d02495841179a24b7d09a90ad8f8: -------------------------------------------------------------------------------- 1 | {"address":"ed18ca8e8b33d02495841179a24b7d09a90ad8f8","crypto":{"cipher":"aes-128-ctr","ciphertext":"aa5214d087ec32abd1507e75649b59a168d5da8cb1b25db983d9dc46d973655c","cipherparams":{"iv":"899d7e856291eab5d0c46601d257e255"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"280a66d602f2a1bdeb77b0e88b0549665ad94ccfafb2d7373589347f740dffc5"},"mac":"91b74173a6f779421b81d45761bfe23cd0add7a252c01c7c7197abccddc4b38c"},"id":"9f1722b1-31ed-42d0-bc2b-5375867c79c6","version":3} -------------------------------------------------------------------------------- /cmd/client/cmd/readparams.json: -------------------------------------------------------------------------------- 1 | { 2 | "privkey": "a8971729fbc199fb3459529cebcd8704791fc699d88ac89284f23ff8e7fca7d6", 3 | "contract": "341efb295051fa28c5fc31a4aea21a53128cd496", 4 | "function":"getString", 5 | "params":[ 6 | "name" 7 | ] 8 | } -------------------------------------------------------------------------------- /cmd/client/commands/log.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 ZhongAn Technology 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package commands 15 | 16 | import ( 17 | "os" 18 | "path" 19 | 20 | "go.uber.org/zap" 21 | ) 22 | 23 | var logger *zap.Logger 24 | 25 | func InitLog() { 26 | var err error 27 | pwd, err := os.Getwd() 28 | if err != nil { 29 | panic(err) 30 | } 31 | 32 | zapConf := zap.NewDevelopmentConfig() 33 | zapConf.OutputPaths = []string{path.Join(pwd, "client.out.log")} 34 | zapConf.ErrorOutputPaths = []string{} 35 | logger, err = zapConf.Build() 36 | if err != nil { 37 | panic(err.Error()) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cmd/client/commands/version.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 ZhongAn Technology 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package commands 15 | 16 | import ( 17 | "fmt" 18 | 19 | "gopkg.in/urfave/cli.v1" 20 | 21 | "github.com/dappledger/AnnChain/chain/types" 22 | ) 23 | 24 | var ( 25 | VersionCommands = cli.Command{ 26 | Name: "version", 27 | Action: ShowVersion, 28 | Usage: "show version of gtool", 29 | Flags: []cli.Flag{ 30 | cli.StringFlag{ 31 | Name: "version", 32 | Usage: "show version of gtool", 33 | Value: "0", 34 | }, 35 | }, 36 | } 37 | ) 38 | 39 | func ShowVersion(ctx *cli.Context) { 40 | fmt.Println("version:", types.GetVersion()) 41 | } 42 | -------------------------------------------------------------------------------- /cmd/client/commons/global.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 ZhongAn Technology 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package commons 15 | 16 | var ( 17 | QueryServer = "tcp://localhost:46657" 18 | CallMode = "sync" 19 | ) 20 | -------------------------------------------------------------------------------- /cmd/genesis/main.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 ZhongAn Technology 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | genesis "github.com/dappledger/AnnChain/chain/commands" 18 | "github.com/dappledger/AnnChain/gemmill/modules/go-log" 19 | ) 20 | 21 | func main() { 22 | defer log.DumpStack() 23 | genesis.Start() 24 | } 25 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 2 3 | round: down 4 | range: "70...100" 5 | 6 | status: 7 | project: 8 | default: 9 | threshold: 1% 10 | patch: on 11 | changes: off 12 | 13 | comment: 14 | layout: "diff, files" 15 | behavior: default 16 | require_changes: no 17 | require_base: no 18 | require_head: yes 19 | 20 | ignore: 21 | - "docs" 22 | - "DOCKER" 23 | - "scripts" 24 | - "**/*.pb.go" 25 | -------------------------------------------------------------------------------- /docs/img/ann.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dappledger/AnnChain/916cc142c344937c01c5459270a64cb133f95c08/docs/img/ann.png -------------------------------------------------------------------------------- /eth/accounts/abi/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | // Package abi implements the Ethereum ABI (Application Binary 18 | // Interface). 19 | // 20 | // The Ethereum ABI is strongly typed, known at compile time 21 | // and static. This ABI will handle basic type casting; unsigned 22 | // to signed and visa versa. It does not handle slice casting such 23 | // as unsigned slice to signed slice. Bit size type casting is also 24 | // handled. ints with a bit size of 32 will be properly cast to int256, 25 | // etc. 26 | package abi 27 | -------------------------------------------------------------------------------- /eth/accounts/abi/numbers.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package abi 18 | 19 | import ( 20 | "math/big" 21 | "reflect" 22 | 23 | "github.com/dappledger/AnnChain/eth/common" 24 | "github.com/dappledger/AnnChain/eth/common/math" 25 | ) 26 | 27 | var ( 28 | bigT = reflect.TypeOf(&big.Int{}) 29 | derefbigT = reflect.TypeOf(big.Int{}) 30 | uint8T = reflect.TypeOf(uint8(0)) 31 | uint16T = reflect.TypeOf(uint16(0)) 32 | uint32T = reflect.TypeOf(uint32(0)) 33 | uint64T = reflect.TypeOf(uint64(0)) 34 | int8T = reflect.TypeOf(int8(0)) 35 | int16T = reflect.TypeOf(int16(0)) 36 | int32T = reflect.TypeOf(int32(0)) 37 | int64T = reflect.TypeOf(int64(0)) 38 | addressT = reflect.TypeOf(common.Address{}) 39 | ) 40 | 41 | // U256 converts a big Int into a 256bit EVM number. 42 | func U256(n *big.Int) []byte { 43 | return math.PaddedBigBytes(math.U256(n), 32) 44 | } 45 | -------------------------------------------------------------------------------- /eth/accounts/abi/numbers_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package abi 18 | 19 | import ( 20 | "bytes" 21 | "math/big" 22 | "testing" 23 | ) 24 | 25 | func TestNumberTypes(t *testing.T) { 26 | ubytes := make([]byte, 32) 27 | ubytes[31] = 1 28 | 29 | unsigned := U256(big.NewInt(1)) 30 | if !bytes.Equal(unsigned, ubytes) { 31 | t.Errorf("expected %x got %x", ubytes, unsigned) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /eth/common/big.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package common 18 | 19 | import "math/big" 20 | 21 | // Common big integers often used 22 | var ( 23 | Big1 = big.NewInt(1) 24 | Big2 = big.NewInt(2) 25 | Big3 = big.NewInt(3) 26 | Big0 = big.NewInt(0) 27 | Big32 = big.NewInt(32) 28 | Big256 = big.NewInt(256) 29 | Big257 = big.NewInt(257) 30 | ) 31 | -------------------------------------------------------------------------------- /eth/common/hexutil/json_example_test.go: -------------------------------------------------------------------------------- 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 | package hexutil_test 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | 23 | "github.com/dappledger/AnnChain/eth/common/hexutil" 24 | ) 25 | 26 | type MyType [5]byte 27 | 28 | func (v *MyType) UnmarshalText(input []byte) error { 29 | return hexutil.UnmarshalFixedText("MyType", input, v[:]) 30 | } 31 | 32 | func (v MyType) String() string { 33 | return hexutil.Bytes(v[:]).String() 34 | } 35 | 36 | func ExampleUnmarshalFixedText() { 37 | var v1, v2 MyType 38 | fmt.Println("v1 error:", json.Unmarshal([]byte(`"0x01"`), &v1)) 39 | fmt.Println("v2 error:", json.Unmarshal([]byte(`"0x0101010101"`), &v2)) 40 | fmt.Println("v2:", v2) 41 | // Output: 42 | // v1 error: hex string has length 2, want 10 for MyType 43 | // v2 error: 44 | // v2: 0x0101010101 45 | } 46 | -------------------------------------------------------------------------------- /eth/common/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package common 18 | 19 | import ( 20 | "testing" 21 | 22 | checker "gopkg.in/check.v1" 23 | ) 24 | 25 | func Test(t *testing.T) { checker.TestingT(t) } 26 | -------------------------------------------------------------------------------- /eth/common/path.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package common 18 | 19 | import ( 20 | "fmt" 21 | "os" 22 | "path/filepath" 23 | "runtime" 24 | ) 25 | 26 | // MakeName creates a node name that follows the ethereum convention 27 | // for such names. It adds the operation system name and Go runtime version 28 | // the name. 29 | func MakeName(name, version string) string { 30 | return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version()) 31 | } 32 | 33 | // FileExist checks if a file exists at filePath. 34 | func FileExist(filePath string) bool { 35 | _, err := os.Stat(filePath) 36 | if err != nil && os.IsNotExist(err) { 37 | return false 38 | } 39 | 40 | return true 41 | } 42 | 43 | // AbsolutePath returns datadir + filename, or filename if it is absolute. 44 | func AbsolutePath(datadir string, filename string) string { 45 | if filepath.IsAbs(filename) { 46 | return filename 47 | } 48 | return filepath.Join(datadir, filename) 49 | } 50 | -------------------------------------------------------------------------------- /eth/common/prque/prque.go: -------------------------------------------------------------------------------- 1 | // This is a duplicated and slightly modified version of "gopkg.in/karalabe/cookiejar.v2/collections/prque". 2 | 3 | package prque 4 | 5 | import ( 6 | "container/heap" 7 | ) 8 | 9 | // Priority queue data structure. 10 | type Prque struct { 11 | cont *sstack 12 | } 13 | 14 | // Creates a new priority queue. 15 | func New(setIndex setIndexCallback) *Prque { 16 | return &Prque{newSstack(setIndex)} 17 | } 18 | 19 | // Pushes a value with a given priority into the queue, expanding if necessary. 20 | func (p *Prque) Push(data interface{}, priority int64) { 21 | heap.Push(p.cont, &item{data, priority}) 22 | } 23 | 24 | // Pops the value with the greates priority off the stack and returns it. 25 | // Currently no shrinking is done. 26 | func (p *Prque) Pop() (interface{}, int64) { 27 | item := heap.Pop(p.cont).(*item) 28 | return item.value, item.priority 29 | } 30 | 31 | // Pops only the item from the queue, dropping the associated priority value. 32 | func (p *Prque) PopItem() interface{} { 33 | return heap.Pop(p.cont).(*item).value 34 | } 35 | 36 | // Remove removes the element with the given index. 37 | func (p *Prque) Remove(i int) interface{} { 38 | if i < 0 { 39 | return nil 40 | } 41 | return heap.Remove(p.cont, i) 42 | } 43 | 44 | // Checks whether the priority queue is empty. 45 | func (p *Prque) Empty() bool { 46 | return p.cont.Len() == 0 47 | } 48 | 49 | // Returns the number of element in the priority queue. 50 | func (p *Prque) Size() int { 51 | return p.cont.Len() 52 | } 53 | 54 | // Clears the contents of the priority queue. 55 | func (p *Prque) Reset() { 56 | *p = *New(p.cont.setIndex) 57 | } 58 | -------------------------------------------------------------------------------- /eth/common/size.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package common 18 | 19 | import ( 20 | "fmt" 21 | ) 22 | 23 | // StorageSize is a wrapper around a float value that supports user friendly 24 | // formatting. 25 | type StorageSize float64 26 | 27 | // String implements the stringer interface. 28 | func (s StorageSize) String() string { 29 | if s > 1000000 { 30 | return fmt.Sprintf("%.2f mB", s/1000000) 31 | } else if s > 1000 { 32 | return fmt.Sprintf("%.2f kB", s/1000) 33 | } else { 34 | return fmt.Sprintf("%.2f B", s) 35 | } 36 | } 37 | 38 | // TerminalString implements log.TerminalStringer, formatting a string for console 39 | // output during logging. 40 | func (s StorageSize) TerminalString() string { 41 | if s > 1000000 { 42 | return fmt.Sprintf("%.2fmB", s/1000000) 43 | } else if s > 1000 { 44 | return fmt.Sprintf("%.2fkB", s/1000) 45 | } else { 46 | return fmt.Sprintf("%.2fB", s) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /eth/common/size_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package common 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | func TestStorageSizeString(t *testing.T) { 24 | tests := []struct { 25 | size StorageSize 26 | str string 27 | }{ 28 | {2381273, "2.38 mB"}, 29 | {2192, "2.19 kB"}, 30 | {12, "12.00 B"}, 31 | } 32 | 33 | for _, test := range tests { 34 | if test.size.String() != test.str { 35 | t.Errorf("%f: got %q, want %q", float64(test.size), test.size.String(), test.str) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /eth/core/error.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package core 18 | 19 | import "errors" 20 | 21 | var ( 22 | // ErrKnownBlock is returned when a block to import is already known locally. 23 | ErrKnownBlock = errors.New("block already known") 24 | 25 | // ErrGasLimitReached is returned by the gas pool if the amount of gas required 26 | // by a transaction is higher than what's left in the block. 27 | ErrGasLimitReached = errors.New("gas limit reached") 28 | 29 | // ErrBlacklistedHash is returned if a block to import is on the blacklist. 30 | ErrBlacklistedHash = errors.New("blacklisted hash") 31 | 32 | // ErrNonceTooHigh is returned if the nonce of a transaction is higher than the 33 | // next one expected based on the local chain. 34 | ErrNonceTooHigh = errors.New("nonce too high") 35 | ) 36 | -------------------------------------------------------------------------------- /eth/core/events.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package core 18 | 19 | import ( 20 | "github.com/dappledger/AnnChain/eth/common" 21 | "github.com/dappledger/AnnChain/eth/core/types" 22 | ) 23 | 24 | // NewTxsEvent is posted when a batch of transactions enter the transaction pool. 25 | type NewTxsEvent struct{ Txs []*types.Transaction } 26 | 27 | // PendingLogsEvent is posted pre mining and notifies of pending logs. 28 | type PendingLogsEvent struct { 29 | Logs []*types.Log 30 | } 31 | 32 | // NewMinedBlockEvent is posted when a block has been imported. 33 | type NewMinedBlockEvent struct{ Block *types.Block } 34 | 35 | // RemovedLogsEvent is posted when a reorg happens 36 | type RemovedLogsEvent struct{ Logs []*types.Log } 37 | 38 | type ChainEvent struct { 39 | Block *types.Block 40 | Hash common.Hash 41 | Logs []*types.Log 42 | } 43 | 44 | type ChainSideEvent struct { 45 | Block *types.Block 46 | } 47 | 48 | type ChainHeadEvent struct{ Block *types.Block } 49 | -------------------------------------------------------------------------------- /eth/core/rawdb/interfaces.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 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 | package rawdb 18 | 19 | // DatabaseReader wraps the Has and Get method of a backing data store. 20 | type DatabaseReader interface { 21 | Has(key []byte) (bool, error) 22 | Get(key []byte) ([]byte, error) 23 | } 24 | 25 | // DatabaseWriter wraps the Put method of a backing data store. 26 | type DatabaseWriter interface { 27 | Put(key []byte, value []byte) error 28 | } 29 | 30 | // DatabaseDeleter wraps the Delete method of a backing data store. 31 | type DatabaseDeleter interface { 32 | Delete(key []byte) error 33 | } 34 | -------------------------------------------------------------------------------- /eth/core/state/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package state 18 | 19 | import ( 20 | "testing" 21 | 22 | checker "gopkg.in/check.v1" 23 | ) 24 | 25 | func Test(t *testing.T) { checker.TestingT(t) } 26 | -------------------------------------------------------------------------------- /eth/core/state/sync.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package state 18 | 19 | import ( 20 | "bytes" 21 | 22 | "github.com/dappledger/AnnChain/eth/common" 23 | "github.com/dappledger/AnnChain/eth/rlp" 24 | "github.com/dappledger/AnnChain/eth/trie" 25 | ) 26 | 27 | // NewStateSync create a new state trie download scheduler. 28 | func NewStateSync(root common.Hash, database trie.DatabaseReader) *trie.Sync { 29 | var syncer *trie.Sync 30 | callback := func(leaf []byte, parent common.Hash) error { 31 | var obj Account 32 | if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil { 33 | return err 34 | } 35 | syncer.AddSubTrie(obj.Root, 64, parent, nil) 36 | syncer.AddRawEntry(common.BytesToHash(obj.CodeHash), 64, parent) 37 | return nil 38 | } 39 | syncer = trie.NewSync(root, database, callback) 40 | return syncer 41 | } 42 | -------------------------------------------------------------------------------- /eth/core/types/derive_sha.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package types 18 | 19 | import ( 20 | "bytes" 21 | 22 | "github.com/dappledger/AnnChain/eth/common" 23 | "github.com/dappledger/AnnChain/eth/rlp" 24 | "github.com/dappledger/AnnChain/eth/trie" 25 | ) 26 | 27 | type DerivableList interface { 28 | Len() int 29 | GetRlp(i int) []byte 30 | } 31 | 32 | func DeriveSha(list DerivableList) common.Hash { 33 | keybuf := new(bytes.Buffer) 34 | trie := new(trie.Trie) 35 | for i := 0; i < list.Len(); i++ { 36 | keybuf.Reset() 37 | rlp.Encode(keybuf, uint(i)) 38 | trie.Update(keybuf.Bytes(), list.GetRlp(i)) 39 | } 40 | return trie.Hash() 41 | } 42 | -------------------------------------------------------------------------------- /eth/core/vm/disasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package vm 18 | 19 | import "fmt" 20 | 21 | func Disasm(code []byte) []string { 22 | var out []string 23 | for pc := uint64(0); pc < uint64(len(code)); pc++ { 24 | op := OpCode(code[pc]) 25 | out = append(out, op.String()) 26 | 27 | switch op { 28 | case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32: 29 | a := uint64(op) - uint64(PUSH1) + 1 30 | out = append(out, fmt.Sprintf("0x%x", code[pc+1:pc+1+a])) 31 | 32 | pc += a 33 | } 34 | } 35 | 36 | return out 37 | } 38 | -------------------------------------------------------------------------------- /eth/core/vm/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | /* 18 | Package vm implements the Ethereum Virtual Machine. 19 | 20 | The vm package implements one EVM, a byte code VM. The BC (Byte Code) VM loops 21 | over a set of bytes and executes them according to the set of rules defined 22 | in the Ethereum yellow paper. 23 | */ 24 | package vm 25 | -------------------------------------------------------------------------------- /eth/core/vm/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package vm 18 | 19 | import "errors" 20 | 21 | // List execution errors 22 | var ( 23 | ErrOutOfGas = errors.New("out of gas") 24 | ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas") 25 | ErrDepth = errors.New("max call depth exceeded") 26 | ErrTraceLimitReached = errors.New("the number of logs reached the specified limit") 27 | ErrInsufficientBalance = errors.New("insufficient balance for transfer") 28 | ErrContractAddressCollision = errors.New("contract address collision") 29 | ErrNoCompatibleInterpreter = errors.New("no compatible interpreter") 30 | ) 31 | -------------------------------------------------------------------------------- /eth/core/vm/gas_table_test.go: -------------------------------------------------------------------------------- 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 | package vm 18 | 19 | import "testing" 20 | 21 | func TestMemoryGasCost(t *testing.T) { 22 | //size := uint64(math.MaxUint64 - 64) 23 | size := uint64(0xffffffffe0) 24 | v, err := memoryGasCost(&Memory{}, size) 25 | if err != nil { 26 | t.Error("didn't expect error:", err) 27 | } 28 | if v != 36028899963961341 { 29 | t.Errorf("Expected: 36028899963961341, got %d", v) 30 | } 31 | 32 | _, err = memoryGasCost(&Memory{}, size+1) 33 | if err == nil { 34 | t.Error("expected error") 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /eth/core/vm/int_pool_verifier.go: -------------------------------------------------------------------------------- 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 | // +build VERIFY_EVM_INTEGER_POOL 18 | 19 | package vm 20 | 21 | import "fmt" 22 | 23 | const verifyPool = true 24 | 25 | func verifyIntegerPool(ip *intPool) { 26 | for i, item := range ip.pool.data { 27 | if item.Cmp(checkVal) != 0 { 28 | panic(fmt.Sprintf("%d'th item failed aggressive pool check. Value was modified", i)) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /eth/core/vm/int_pool_verifier_empty.go: -------------------------------------------------------------------------------- 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 | // +build !VERIFY_EVM_INTEGER_POOL 18 | 19 | package vm 20 | 21 | const verifyPool = false 22 | 23 | func verifyIntegerPool(ip *intPool) {} 24 | -------------------------------------------------------------------------------- /eth/core/vm/runtime/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | // Package runtime provides a basic execution model for executing EVM code. 18 | package runtime 19 | -------------------------------------------------------------------------------- /eth/core/vm/runtime/env.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package runtime 18 | 19 | import ( 20 | "github.com/dappledger/AnnChain/eth/common" 21 | "github.com/dappledger/AnnChain/eth/core" 22 | "github.com/dappledger/AnnChain/eth/core/vm" 23 | ) 24 | 25 | func NewEnv(cfg *Config) *vm.EVM { 26 | context := vm.Context{ 27 | CanTransfer: core.CanTransfer, 28 | Transfer: core.Transfer, 29 | GetHash: func(uint64) common.Hash { return common.Hash{} }, 30 | 31 | Origin: cfg.Origin, 32 | Coinbase: cfg.Coinbase, 33 | BlockNumber: cfg.BlockNumber, 34 | Time: cfg.Time, 35 | Difficulty: cfg.Difficulty, 36 | GasLimit: cfg.GasLimit, 37 | GasPrice: cfg.GasPrice, 38 | } 39 | 40 | return vm.NewEVM(context, cfg.State, cfg.ChainConfig, cfg.EVMConfig) 41 | } 42 | -------------------------------------------------------------------------------- /eth/core/vm/runtime/fuzz.go: -------------------------------------------------------------------------------- 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 | // +build gofuzz 18 | 19 | package runtime 20 | 21 | // Fuzz is the basic entry point for the go-fuzz tool 22 | // 23 | // This returns 1 for valid parsable/runable code, 0 24 | // for invalid opcode. 25 | func Fuzz(input []byte) int { 26 | _, _, err := Execute(input, input, &Config{ 27 | GasLimit: 3000000, 28 | }) 29 | 30 | // invalid opcode 31 | if err != nil && len(err.Error()) > 6 && string(err.Error()[:7]) == "invalid" { 32 | return 0 33 | } 34 | 35 | return 1 36 | } 37 | -------------------------------------------------------------------------------- /eth/core/vm/runtime/runtime_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package runtime_test 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/dappledger/AnnChain/eth/common" 23 | "github.com/dappledger/AnnChain/eth/core/vm" 24 | "github.com/dappledger/AnnChain/eth/core/vm/runtime" 25 | ) 26 | 27 | func ExampleExecute() { 28 | ret, _, err := runtime.Execute(common.Hex2Bytes("6060604052600a8060106000396000f360606040526008565b00"), nil, &runtime.Config{EVMConfig: vm.Config{EVMGasLimit: 100000000}}) 29 | if err != nil { 30 | fmt.Println(err) 31 | } 32 | fmt.Println(ret) 33 | // Output: 34 | // [96 96 96 64 82 96 8 86 91 0] 35 | } 36 | -------------------------------------------------------------------------------- /eth/core/vm/stack_table.go: -------------------------------------------------------------------------------- 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 | package vm 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/dappledger/AnnChain/eth/params" 23 | ) 24 | 25 | func makeStackFunc(pop, push int) stackValidationFunc { 26 | return func(stack *Stack) error { 27 | if err := stack.require(pop); err != nil { 28 | return err 29 | } 30 | 31 | if stack.len()+push-pop > int(params.StackLimit) { 32 | return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit) 33 | } 34 | return nil 35 | } 36 | } 37 | 38 | func makeDupStackFunc(n int) stackValidationFunc { 39 | return makeStackFunc(n, n+1) 40 | } 41 | 42 | func makeSwapStackFunc(n int) stackValidationFunc { 43 | return makeStackFunc(n, n) 44 | } 45 | -------------------------------------------------------------------------------- /eth/crypto/bn256/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 The Go Authors. All rights reserved. 2 | Copyright (c) 2018 Péter Szilágyi. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /eth/crypto/bn256/bn256_fast.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Péter Szilágyi. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be found 3 | // in the LICENSE file. 4 | 5 | // +build amd64 arm64 6 | 7 | // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. 8 | package bn256 9 | 10 | import "github.com/dappledger/AnnChain/eth/crypto/bn256/cloudflare" 11 | 12 | // G1 is an abstract cyclic group. The zero value is suitable for use as the 13 | // output of an operation, but cannot be used as an input. 14 | type G1 = bn256.G1 15 | 16 | // G2 is an abstract cyclic group. The zero value is suitable for use as the 17 | // output of an operation, but cannot be used as an input. 18 | type G2 = bn256.G2 19 | 20 | // PairingCheck calculates the Optimal Ate pairing for a set of points. 21 | func PairingCheck(a []*G1, b []*G2) bool { 22 | return bn256.PairingCheck(a, b) 23 | } 24 | -------------------------------------------------------------------------------- /eth/crypto/bn256/bn256_slow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Péter Szilágyi. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be found 3 | // in the LICENSE file. 4 | 5 | // +build !amd64,!arm64 6 | 7 | // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. 8 | package bn256 9 | 10 | import "github.com/dappledger/AnnChain/eth/crypto/bn256/google" 11 | 12 | // G1 is an abstract cyclic group. The zero value is suitable for use as the 13 | // output of an operation, but cannot be used as an input. 14 | type G1 = bn256.G1 15 | 16 | // G2 is an abstract cyclic group. The zero value is suitable for use as the 17 | // output of an operation, but cannot be used as an input. 18 | type G2 = bn256.G2 19 | 20 | // PairingCheck calculates the Optimal Ate pairing for a set of points. 21 | func PairingCheck(a []*G1, b []*G2) bool { 22 | return bn256.PairingCheck(a, b) 23 | } 24 | -------------------------------------------------------------------------------- /eth/crypto/bn256/cloudflare/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /eth/crypto/bn256/cloudflare/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bn256 6 | 7 | import ( 8 | "crypto/rand" 9 | "testing" 10 | 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | func TestExamplePair(t *testing.T) { 15 | // This implements the tripartite Diffie-Hellman algorithm from "A One 16 | // Round Protocol for Tripartite Diffie-Hellman", A. Joux. 17 | // http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf 18 | 19 | // Each of three parties, a, b and c, generate a private value. 20 | a, _ := rand.Int(rand.Reader, Order) 21 | b, _ := rand.Int(rand.Reader, Order) 22 | c, _ := rand.Int(rand.Reader, Order) 23 | 24 | // Then each party calculates g₁ and g₂ times their private value. 25 | pa := new(G1).ScalarBaseMult(a) 26 | qa := new(G2).ScalarBaseMult(a) 27 | 28 | pb := new(G1).ScalarBaseMult(b) 29 | qb := new(G2).ScalarBaseMult(b) 30 | 31 | pc := new(G1).ScalarBaseMult(c) 32 | qc := new(G2).ScalarBaseMult(c) 33 | 34 | // Now each party exchanges its public values with the other two and 35 | // all parties can calculate the shared key. 36 | k1 := Pair(pb, qc) 37 | k1.ScalarMult(k1, a) 38 | 39 | k2 := Pair(pc, qa) 40 | k2.ScalarMult(k2, b) 41 | 42 | k3 := Pair(pa, qb) 43 | k3.ScalarMult(k3, c) 44 | 45 | // k1, k2 and k3 will all be equal. 46 | 47 | require.Equal(t, k1, k2) 48 | require.Equal(t, k1, k3) 49 | 50 | require.Equal(t, len(np), 4) //Avoid gometalinter varcheck err on np 51 | } 52 | -------------------------------------------------------------------------------- /eth/crypto/bn256/cloudflare/gfp_decl.go: -------------------------------------------------------------------------------- 1 | // +build amd64,!generic arm64,!generic 2 | 3 | package bn256 4 | 5 | // This file contains forward declarations for the architecture-specific 6 | // assembly implementations of these functions, provided that they exist. 7 | 8 | import ( 9 | "golang.org/x/sys/cpu" 10 | ) 11 | 12 | //nolint:varcheck 13 | var hasBMI2 = cpu.X86.HasBMI2 14 | 15 | // go:noescape 16 | func gfpNeg(c, a *gfP) 17 | 18 | //go:noescape 19 | func gfpAdd(c, a, b *gfP) 20 | 21 | //go:noescape 22 | func gfpSub(c, a, b *gfP) 23 | 24 | //go:noescape 25 | func gfpMul(c, a, b *gfP) 26 | -------------------------------------------------------------------------------- /eth/crypto/bn256/cloudflare/lattice_test.go: -------------------------------------------------------------------------------- 1 | package bn256 2 | 3 | import ( 4 | "crypto/rand" 5 | 6 | "testing" 7 | ) 8 | 9 | func TestLatticeReduceCurve(t *testing.T) { 10 | k, _ := rand.Int(rand.Reader, Order) 11 | ks := curveLattice.decompose(k) 12 | 13 | if ks[0].BitLen() > 130 || ks[1].BitLen() > 130 { 14 | t.Fatal("reduction too large") 15 | } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 { 16 | t.Fatal("reduction must be positive") 17 | } 18 | } 19 | 20 | func TestLatticeReduceTarget(t *testing.T) { 21 | k, _ := rand.Int(rand.Reader, Order) 22 | ks := targetLattice.decompose(k) 23 | 24 | if ks[0].BitLen() > 66 || ks[1].BitLen() > 66 || ks[2].BitLen() > 66 || ks[3].BitLen() > 66 { 25 | t.Fatal("reduction too large") 26 | } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 || ks[2].Sign() < 0 || ks[3].Sign() < 0 { 27 | t.Fatal("reduction must be positive") 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /eth/crypto/bn256/google/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bn256 6 | 7 | import ( 8 | "crypto/rand" 9 | ) 10 | 11 | func ExamplePair() { 12 | // This implements the tripartite Diffie-Hellman algorithm from "A One 13 | // Round Protocol for Tripartite Diffie-Hellman", A. Joux. 14 | // http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf 15 | 16 | // Each of three parties, a, b and c, generate a private value. 17 | a, _ := rand.Int(rand.Reader, Order) 18 | b, _ := rand.Int(rand.Reader, Order) 19 | c, _ := rand.Int(rand.Reader, Order) 20 | 21 | // Then each party calculates g₁ and g₂ times their private value. 22 | pa := new(G1).ScalarBaseMult(a) 23 | qa := new(G2).ScalarBaseMult(a) 24 | 25 | pb := new(G1).ScalarBaseMult(b) 26 | qb := new(G2).ScalarBaseMult(b) 27 | 28 | pc := new(G1).ScalarBaseMult(c) 29 | qc := new(G2).ScalarBaseMult(c) 30 | 31 | // Now each party exchanges its public values with the other two and 32 | // all parties can calculate the shared key. 33 | k1 := Pair(pb, qc) 34 | k1.ScalarMult(k1, a) 35 | 36 | k2 := Pair(pc, qa) 37 | k2.ScalarMult(k2, b) 38 | 39 | k3 := Pair(pa, qb) 40 | k3.ScalarMult(k3, c) 41 | 42 | // k1, k2 and k3 will all be equal. 43 | } 44 | -------------------------------------------------------------------------------- /eth/crypto/ecies/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Kyle Isom 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/crypto/secp256k1/libsecp256k1/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | autoreconf -if --warnings=all 4 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/crypto/secp256k1/libsecp256k1/obj/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dappledger/AnnChain/916cc142c344937c01c5459270a64cb133f95c08/eth/crypto/secp256k1/libsecp256k1/obj/.gitignore -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/crypto/secp256k1/libsecp256k1/src/ecmult.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_ECMULT_ 8 | #define _SECP256K1_ECMULT_ 9 | 10 | #include "num.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*P + b*G: */ 15 | secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */ 16 | #ifdef USE_ENDOMORPHISM 17 | secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */ 18 | #endif 19 | } secp256k1_ecmult_context; 20 | 21 | static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx); 22 | static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb); 23 | static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst, 24 | const secp256k1_ecmult_context *src, const secp256k1_callback *cb); 25 | static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx); 26 | static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx); 27 | 28 | /** Double multiply: R = na*A + ng*G */ 29 | static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/crypto/secp256k1/libsecp256k1/src/testrand.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_TESTRAND_H_ 8 | #define _SECP256K1_TESTRAND_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | /* A non-cryptographic RNG used only for test infrastructure. */ 15 | 16 | /** Seed the pseudorandom number generator for testing. */ 17 | SECP256K1_INLINE static void secp256k1_rand_seed(const unsigned char *seed16); 18 | 19 | /** Generate a pseudorandom number in the range [0..2**32-1]. */ 20 | static uint32_t secp256k1_rand32(void); 21 | 22 | /** Generate a pseudorandom number in the range [0..2**bits-1]. Bits must be 1 or 23 | * more. */ 24 | static uint32_t secp256k1_rand_bits(int bits); 25 | 26 | /** Generate a pseudorandom number in the range [0..range-1]. */ 27 | static uint32_t secp256k1_rand_int(uint32_t range); 28 | 29 | /** Generate a pseudorandom 32-byte array. */ 30 | static void secp256k1_rand256(unsigned char *b32); 31 | 32 | /** Generate a pseudorandom 32-byte array with long sequences of zero and one bits. */ 33 | static void secp256k1_rand256_test(unsigned char *b32); 34 | 35 | /** Generate pseudorandom bytes with long sequences of zero and one bits. */ 36 | static void secp256k1_rand_bytes_test(unsigned char *bytes, size_t len); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /eth/crypto/secp256k1/panic_cb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Jeffrey Wilcke, Felix Lange, Gustav Simonsson. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be found in 3 | // the LICENSE file. 4 | 5 | package secp256k1 6 | 7 | import "C" 8 | import "unsafe" 9 | 10 | // Callbacks for converting libsecp256k1 internal faults into 11 | // recoverable Go panics. 12 | 13 | //export secp256k1GoPanicIllegal 14 | func secp256k1GoPanicIllegal(msg *C.char, data unsafe.Pointer) { 15 | panic("illegal argument: " + C.GoString(msg)) 16 | } 17 | 18 | //export secp256k1GoPanicError 19 | func secp256k1GoPanicError(msg *C.char, data unsafe.Pointer) { 20 | panic("internal error: " + C.GoString(msg)) 21 | } 22 | -------------------------------------------------------------------------------- /eth/ethdb/table_batch.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | package ethdb 18 | 19 | type tableBatch struct { 20 | batch Batch 21 | prefix string 22 | } 23 | 24 | // NewTableBatch returns a Batch object which prefixes all keys with a given string. 25 | func NewTableBatch(db Database, prefix string) Batch { 26 | return &tableBatch{db.NewBatch(), prefix} 27 | } 28 | 29 | func (dt *table) NewBatch() Batch { 30 | return &tableBatch{dt.db.NewBatch(), dt.prefix} 31 | } 32 | 33 | func (tb *tableBatch) Put(key, value []byte) error { 34 | return tb.batch.Put(append([]byte(tb.prefix), key...), value) 35 | } 36 | 37 | func (tb *tableBatch) Delete(key []byte) error { 38 | return tb.batch.Delete(append([]byte(tb.prefix), key...)) 39 | } 40 | 41 | func (tb *tableBatch) Write() error { 42 | return tb.batch.Write() 43 | } 44 | 45 | func (tb *tableBatch) ValueSize() int { 46 | return tb.batch.ValueSize() 47 | } 48 | 49 | func (tb *tableBatch) Reset() { 50 | tb.batch.Reset() 51 | } 52 | -------------------------------------------------------------------------------- /eth/event/example_subscription_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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 | package event_test 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/dappledger/AnnChain/eth/event" 23 | ) 24 | 25 | func ExampleNewSubscription() { 26 | // Create a subscription that sends 10 integers on ch. 27 | ch := make(chan int) 28 | sub := event.NewSubscription(func(quit <-chan struct{}) error { 29 | for i := 0; i < 10; i++ { 30 | select { 31 | case ch <- i: 32 | case <-quit: 33 | fmt.Println("unsubscribed") 34 | return nil 35 | } 36 | } 37 | return nil 38 | }) 39 | 40 | // This is the consumer. It reads 5 integers, then aborts the subscription. 41 | // Note that Unsubscribe waits until the producer has shut down. 42 | for i := range ch { 43 | fmt.Println(i) 44 | if i == 4 { 45 | sub.Unsubscribe() 46 | break 47 | } 48 | } 49 | // Output: 50 | // 0 51 | // 1 52 | // 2 53 | // 3 54 | // 4 55 | // unsubscribed 56 | } 57 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/log/handler_go13.go: -------------------------------------------------------------------------------- 1 | // +build !go1.4 2 | 3 | package log 4 | 5 | import ( 6 | "sync/atomic" 7 | "unsafe" 8 | ) 9 | 10 | // swapHandler wraps another handler that may be swapped out 11 | // dynamically at runtime in a thread-safe fashion. 12 | type swapHandler struct { 13 | handler unsafe.Pointer 14 | } 15 | 16 | func (h *swapHandler) Log(r *Record) error { 17 | return h.Get().Log(r) 18 | } 19 | 20 | func (h *swapHandler) Get() Handler { 21 | return *(*Handler)(atomic.LoadPointer(&h.handler)) 22 | } 23 | 24 | func (h *swapHandler) Swap(newHandler Handler) { 25 | atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler)) 26 | } 27 | -------------------------------------------------------------------------------- /eth/log/handler_go14.go: -------------------------------------------------------------------------------- 1 | // +build go1.4 2 | 3 | package log 4 | 5 | import "sync/atomic" 6 | 7 | // swapHandler wraps another handler that may be swapped out 8 | // dynamically at runtime in a thread-safe fashion. 9 | type swapHandler struct { 10 | handler atomic.Value 11 | } 12 | 13 | func (h *swapHandler) Log(r *Record) error { 14 | return (*h.handler.Load().(*Handler)).Log(r) 15 | } 16 | 17 | func (h *swapHandler) Swap(newHandler Handler) { 18 | h.handler.Store(&newHandler) 19 | } 20 | 21 | func (h *swapHandler) Get() Handler { 22 | return *h.handler.Load().(*Handler) 23 | } 24 | -------------------------------------------------------------------------------- /eth/metrics/FORK.md: -------------------------------------------------------------------------------- 1 | This repo has been forked from https://github.com/rcrowley/go-metrics at commit e181e09 2 | -------------------------------------------------------------------------------- /eth/metrics/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2012 Richard Crowley. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following 12 | disclaimer in the documentation and/or other materials provided 13 | with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY RICHARD CROWLEY ``AS IS'' AND ANY EXPRESS 16 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL RICHARD CROWLEY OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 25 | THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | The views and conclusions contained in the software and documentation 28 | are those of the authors and should not be interpreted as representing 29 | official policies, either expressed or implied, of Richard Crowley. 30 | -------------------------------------------------------------------------------- /eth/metrics/debug_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "runtime" 5 | "runtime/debug" 6 | "testing" 7 | "time" 8 | ) 9 | 10 | func BenchmarkDebugGCStats(b *testing.B) { 11 | r := NewRegistry() 12 | RegisterDebugGCStats(r) 13 | b.ResetTimer() 14 | for i := 0; i < b.N; i++ { 15 | CaptureDebugGCStatsOnce(r) 16 | } 17 | } 18 | 19 | func TestDebugGCStatsBlocking(t *testing.T) { 20 | if g := runtime.GOMAXPROCS(0); g < 2 { 21 | t.Skipf("skipping TestDebugGCMemStatsBlocking with GOMAXPROCS=%d\n", g) 22 | return 23 | } 24 | ch := make(chan int) 25 | go testDebugGCStatsBlocking(ch) 26 | var gcStats debug.GCStats 27 | t0 := time.Now() 28 | debug.ReadGCStats(&gcStats) 29 | t1 := time.Now() 30 | t.Log("i++ during debug.ReadGCStats:", <-ch) 31 | go testDebugGCStatsBlocking(ch) 32 | d := t1.Sub(t0) 33 | t.Log(d) 34 | time.Sleep(d) 35 | t.Log("i++ during time.Sleep:", <-ch) 36 | } 37 | 38 | func testDebugGCStatsBlocking(ch chan int) { 39 | i := 0 40 | for { 41 | select { 42 | case ch <- i: 43 | return 44 | default: 45 | i++ 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /eth/metrics/disk.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package metrics 18 | 19 | // DiskStats is the per process disk io stats. 20 | type DiskStats struct { 21 | ReadCount int64 // Number of read operations executed 22 | ReadBytes int64 // Total number of bytes read 23 | WriteCount int64 // Number of write operations executed 24 | WriteBytes int64 // Total number of byte written 25 | } 26 | -------------------------------------------------------------------------------- /eth/metrics/disk_nop.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | // +build !linux 18 | 19 | package metrics 20 | 21 | import "errors" 22 | 23 | // ReadDiskStats retrieves the disk IO stats belonging to the current process. 24 | func ReadDiskStats(stats *DiskStats) error { 25 | return errors.New("Not implemented") 26 | } 27 | -------------------------------------------------------------------------------- /eth/metrics/gauge_float64_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import "testing" 4 | 5 | func BenchmarkGuageFloat64(b *testing.B) { 6 | g := NewGaugeFloat64() 7 | b.ResetTimer() 8 | for i := 0; i < b.N; i++ { 9 | g.Update(float64(i)) 10 | } 11 | } 12 | 13 | func TestGaugeFloat64(t *testing.T) { 14 | g := NewGaugeFloat64() 15 | g.Update(float64(47.0)) 16 | if v := g.Value(); float64(47.0) != v { 17 | t.Errorf("g.Value(): 47.0 != %v\n", v) 18 | } 19 | } 20 | 21 | func TestGaugeFloat64Snapshot(t *testing.T) { 22 | g := NewGaugeFloat64() 23 | g.Update(float64(47.0)) 24 | snapshot := g.Snapshot() 25 | g.Update(float64(0)) 26 | if v := snapshot.Value(); float64(47.0) != v { 27 | t.Errorf("g.Value(): 47.0 != %v\n", v) 28 | } 29 | } 30 | 31 | func TestGetOrRegisterGaugeFloat64(t *testing.T) { 32 | r := NewRegistry() 33 | NewRegisteredGaugeFloat64("foo", r).Update(float64(47.0)) 34 | t.Logf("registry: %v", r) 35 | if g := GetOrRegisterGaugeFloat64("foo", r); float64(47.0) != g.Value() { 36 | t.Fatal(g) 37 | } 38 | } 39 | 40 | func TestFunctionalGaugeFloat64(t *testing.T) { 41 | var counter float64 42 | fg := NewFunctionalGaugeFloat64(func() float64 { 43 | counter++ 44 | return counter 45 | }) 46 | fg.Value() 47 | fg.Value() 48 | if counter != 2 { 49 | t.Error("counter != 2") 50 | } 51 | } 52 | 53 | func TestGetOrRegisterFunctionalGaugeFloat64(t *testing.T) { 54 | r := NewRegistry() 55 | NewRegisteredFunctionalGaugeFloat64("foo", r, func() float64 { return 47 }) 56 | if g := GetOrRegisterGaugeFloat64("foo", r); 47 != g.Value() { 57 | t.Fatal(g) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /eth/metrics/gauge_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func BenchmarkGuage(b *testing.B) { 9 | g := NewGauge() 10 | b.ResetTimer() 11 | for i := 0; i < b.N; i++ { 12 | g.Update(int64(i)) 13 | } 14 | } 15 | 16 | func TestGauge(t *testing.T) { 17 | g := NewGauge() 18 | g.Update(int64(47)) 19 | if v := g.Value(); 47 != v { 20 | t.Errorf("g.Value(): 47 != %v\n", v) 21 | } 22 | } 23 | 24 | func TestGaugeSnapshot(t *testing.T) { 25 | g := NewGauge() 26 | g.Update(int64(47)) 27 | snapshot := g.Snapshot() 28 | g.Update(int64(0)) 29 | if v := snapshot.Value(); 47 != v { 30 | t.Errorf("g.Value(): 47 != %v\n", v) 31 | } 32 | } 33 | 34 | func TestGetOrRegisterGauge(t *testing.T) { 35 | r := NewRegistry() 36 | NewRegisteredGauge("foo", r).Update(47) 37 | if g := GetOrRegisterGauge("foo", r); 47 != g.Value() { 38 | t.Fatal(g) 39 | } 40 | } 41 | 42 | func TestFunctionalGauge(t *testing.T) { 43 | var counter int64 44 | fg := NewFunctionalGauge(func() int64 { 45 | counter++ 46 | return counter 47 | }) 48 | fg.Value() 49 | fg.Value() 50 | if counter != 2 { 51 | t.Error("counter != 2") 52 | } 53 | } 54 | 55 | func TestGetOrRegisterFunctionalGauge(t *testing.T) { 56 | r := NewRegistry() 57 | NewRegisteredFunctionalGauge("foo", r, func() int64 { return 47 }) 58 | if g := GetOrRegisterGauge("foo", r); 47 != g.Value() { 59 | t.Fatal(g) 60 | } 61 | } 62 | 63 | func ExampleGetOrRegisterGauge() { 64 | m := "server.bytes_sent" 65 | g := GetOrRegisterGauge(m, nil) 66 | g.Update(47) 67 | fmt.Println(g.Value()) // Output: 47 68 | } 69 | -------------------------------------------------------------------------------- /eth/metrics/graphite_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | func ExampleGraphite() { 9 | addr, _ := net.ResolveTCPAddr("net", ":2003") 10 | go Graphite(DefaultRegistry, 1*time.Second, "some.prefix", addr) 11 | } 12 | 13 | func ExampleGraphiteWithConfig() { 14 | addr, _ := net.ResolveTCPAddr("net", ":2003") 15 | go GraphiteWithConfig(GraphiteConfig{ 16 | Addr: addr, 17 | Registry: DefaultRegistry, 18 | FlushInterval: 1 * time.Second, 19 | DurationUnit: time.Millisecond, 20 | Percentiles: []float64{0.5, 0.75, 0.99, 0.999}, 21 | }) 22 | } 23 | -------------------------------------------------------------------------------- /eth/metrics/healthcheck.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | // Healthchecks hold an error value describing an arbitrary up/down status. 4 | type Healthcheck interface { 5 | Check() 6 | Error() error 7 | Healthy() 8 | Unhealthy(error) 9 | } 10 | 11 | // NewHealthcheck constructs a new Healthcheck which will use the given 12 | // function to update its status. 13 | func NewHealthcheck(f func(Healthcheck)) Healthcheck { 14 | if !Enabled { 15 | return NilHealthcheck{} 16 | } 17 | return &StandardHealthcheck{nil, f} 18 | } 19 | 20 | // NilHealthcheck is a no-op. 21 | type NilHealthcheck struct{} 22 | 23 | // Check is a no-op. 24 | func (NilHealthcheck) Check() {} 25 | 26 | // Error is a no-op. 27 | func (NilHealthcheck) Error() error { return nil } 28 | 29 | // Healthy is a no-op. 30 | func (NilHealthcheck) Healthy() {} 31 | 32 | // Unhealthy is a no-op. 33 | func (NilHealthcheck) Unhealthy(error) {} 34 | 35 | // StandardHealthcheck is the standard implementation of a Healthcheck and 36 | // stores the status and a function to call to update the status. 37 | type StandardHealthcheck struct { 38 | err error 39 | f func(Healthcheck) 40 | } 41 | 42 | // Check runs the healthcheck function to update the healthcheck's status. 43 | func (h *StandardHealthcheck) Check() { 44 | h.f(h) 45 | } 46 | 47 | // Error returns the healthcheck's status, which will be nil if it is healthy. 48 | func (h *StandardHealthcheck) Error() error { 49 | return h.err 50 | } 51 | 52 | // Healthy marks the healthcheck as healthy. 53 | func (h *StandardHealthcheck) Healthy() { 54 | h.err = nil 55 | } 56 | 57 | // Unhealthy marks the healthcheck as unhealthy. The error is stored and 58 | // may be retrieved by the Error method. 59 | func (h *StandardHealthcheck) Unhealthy(err error) { 60 | h.err = err 61 | } 62 | -------------------------------------------------------------------------------- /eth/metrics/init_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | func init() { 4 | Enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /eth/metrics/json.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | "time" 7 | ) 8 | 9 | // MarshalJSON returns a byte slice containing a JSON representation of all 10 | // the metrics in the Registry. 11 | func (r *StandardRegistry) MarshalJSON() ([]byte, error) { 12 | return json.Marshal(r.GetAll()) 13 | } 14 | 15 | // WriteJSON writes metrics from the given registry periodically to the 16 | // specified io.Writer as JSON. 17 | func WriteJSON(r Registry, d time.Duration, w io.Writer) { 18 | for range time.Tick(d) { 19 | WriteJSONOnce(r, w) 20 | } 21 | } 22 | 23 | // WriteJSONOnce writes metrics from the given registry to the specified 24 | // io.Writer as JSON. 25 | func WriteJSONOnce(r Registry, w io.Writer) { 26 | json.NewEncoder(w).Encode(r) 27 | } 28 | 29 | func (p *PrefixedRegistry) MarshalJSON() ([]byte, error) { 30 | return json.Marshal(p.GetAll()) 31 | } 32 | -------------------------------------------------------------------------------- /eth/metrics/json_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "testing" 7 | ) 8 | 9 | func TestRegistryMarshallJSON(t *testing.T) { 10 | b := &bytes.Buffer{} 11 | enc := json.NewEncoder(b) 12 | r := NewRegistry() 13 | r.Register("counter", NewCounter()) 14 | enc.Encode(r) 15 | if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s { 16 | t.Fatalf(s) 17 | } 18 | } 19 | 20 | func TestRegistryWriteJSONOnce(t *testing.T) { 21 | r := NewRegistry() 22 | r.Register("counter", NewCounter()) 23 | b := &bytes.Buffer{} 24 | WriteJSONOnce(r, b) 25 | if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" { 26 | t.Fail() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /eth/metrics/opentsdb_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | func ExampleOpenTSDB() { 9 | addr, _ := net.ResolveTCPAddr("net", ":2003") 10 | go OpenTSDB(DefaultRegistry, 1*time.Second, "some.prefix", addr) 11 | } 12 | 13 | func ExampleOpenTSDBWithConfig() { 14 | addr, _ := net.ResolveTCPAddr("net", ":2003") 15 | go OpenTSDBWithConfig(OpenTSDBConfig{ 16 | Addr: addr, 17 | Registry: DefaultRegistry, 18 | FlushInterval: 1 * time.Second, 19 | DurationUnit: time.Millisecond, 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /eth/metrics/runtime_cgo.go: -------------------------------------------------------------------------------- 1 | // +build cgo 2 | // +build !appengine 3 | 4 | package metrics 5 | 6 | import "runtime" 7 | 8 | func numCgoCall() int64 { 9 | return runtime.NumCgoCall() 10 | } 11 | -------------------------------------------------------------------------------- /eth/metrics/runtime_gccpufraction.go: -------------------------------------------------------------------------------- 1 | // +build go1.5 2 | 3 | package metrics 4 | 5 | import "runtime" 6 | 7 | func gcCPUFraction(memStats *runtime.MemStats) float64 { 8 | return memStats.GCCPUFraction 9 | } 10 | -------------------------------------------------------------------------------- /eth/metrics/runtime_no_cgo.go: -------------------------------------------------------------------------------- 1 | // +build !cgo appengine 2 | 3 | package metrics 4 | 5 | func numCgoCall() int64 { 6 | return 0 7 | } 8 | -------------------------------------------------------------------------------- /eth/metrics/runtime_no_gccpufraction.go: -------------------------------------------------------------------------------- 1 | // +build !go1.5 2 | 3 | package metrics 4 | 5 | import "runtime" 6 | 7 | func gcCPUFraction(memStats *runtime.MemStats) float64 { 8 | return 0 9 | } 10 | -------------------------------------------------------------------------------- /eth/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 | -------------------------------------------------------------------------------- /eth/metrics/writer_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "sort" 5 | "testing" 6 | ) 7 | 8 | func TestMetricsSorting(t *testing.T) { 9 | var namedMetrics = namedMetricSlice{ 10 | {name: "zzz"}, 11 | {name: "bbb"}, 12 | {name: "fff"}, 13 | {name: "ggg"}, 14 | } 15 | 16 | sort.Sort(namedMetrics) 17 | for i, name := range []string{"bbb", "fff", "ggg", "zzz"} { 18 | if namedMetrics[i].name != name { 19 | t.Fail() 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /eth/params/denomination.go: -------------------------------------------------------------------------------- 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 | package params 18 | 19 | // These are the multipliers for ether denominations. 20 | // Example: To get the wei value of an amount in 'gwei', use 21 | // 22 | // new(big.Int).Mul(value, big.NewInt(params.GWei)) 23 | // 24 | const ( 25 | Wei = 1 26 | GWei = 1e9 27 | Ether = 1e18 28 | ) 29 | -------------------------------------------------------------------------------- /eth/rlp/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 | /* 18 | Package rlp implements the RLP serialization format. 19 | 20 | The purpose of RLP (Recursive Linear Prefix) is to encode arbitrarily 21 | nested arrays of binary data, and RLP is the main encoding method used 22 | to serialize objects in Ethereum. The only purpose of RLP is to encode 23 | structure; encoding specific atomic data types (eg. strings, ints, 24 | floats) is left up to higher-order protocols; in Ethereum integers 25 | must be represented in big endian binary form with no leading zeroes 26 | (thus making the integer value zero equivalent to the empty byte 27 | array). 28 | 29 | RLP values are distinguished by a type tag. The type tag precedes the 30 | value in the input stream and defines the size and kind of the bytes 31 | that follow. 32 | */ 33 | package rlp 34 | -------------------------------------------------------------------------------- /eth/trie/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | package trie 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/dappledger/AnnChain/eth/common" 23 | ) 24 | 25 | // MissingNodeError is returned by the trie functions (TryGet, TryUpdate, TryDelete) 26 | // in the case where a trie node is not present in the local database. It contains 27 | // information necessary for retrieving the missing node. 28 | type MissingNodeError struct { 29 | NodeHash common.Hash // hash of the missing node 30 | Path []byte // hex-encoded path to the missing node 31 | } 32 | 33 | func (err *MissingNodeError) Error() string { 34 | return fmt.Sprintf("missing trie node %x (path %x)", err.NodeHash, err.Path) 35 | } 36 | -------------------------------------------------------------------------------- /gemmill/config/templates.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package config 16 | 17 | const CONFIGTPL = `# This is a TOML config file. 18 | # For more information, see https://github.com/toml-lang/toml 19 | 20 | environment = "production" 21 | node_laddr = "tcp://0.0.0.0:46656" 22 | rpc_laddr = "tcp://0.0.0.0:46657" 23 | api_laddr = ":8889" 24 | moniker = "__MONIKER__" 25 | fast_sync = true 26 | db_backend = "leveldb" 27 | seeds = "" 28 | signbyCA = "" 29 | 30 | ` 31 | -------------------------------------------------------------------------------- /gemmill/consensus/engine.go: -------------------------------------------------------------------------------- 1 | package consensus 2 | 3 | import ( 4 | "github.com/dappledger/AnnChain/gemmill/state" 5 | "github.com/dappledger/AnnChain/gemmill/types" 6 | ) 7 | 8 | type Engine interface { 9 | GetValidators() (int64, []*types.Validator) 10 | SetEventSwitch(types.EventSwitch) 11 | ValidateBlock(*types.Block) error 12 | SetOnUpdateStatus(onUpdateState func (s*state.State)) 13 | } 14 | -------------------------------------------------------------------------------- /gemmill/consensus/pbft/README.md: -------------------------------------------------------------------------------- 1 | # The core consensus algorithm. 2 | 3 | * state.go - The state machine as detailed in the whitepaper 4 | * reactor.go - A reactor that connects the state machine to the gossip network 5 | 6 | # Go-routine summary 7 | 8 | The reactor runs 2 go-routines for each added peer: gossipDataRoutine and gossipVotesRoutine. 9 | 10 | The consensus state runs two persistent go-routines: timeoutRoutine and receiveRoutine. 11 | Go-routines are also started to trigger timeouts and to avoid blocking when the internalMsgQueue is really backed up. 12 | 13 | # Replay/WAL 14 | 15 | A write-ahead log is used to record all messages processed by the receiveRoutine, 16 | which amounts to all inputs to the consensus state machine: 17 | messages from peers, messages from ourselves, and timeouts. 18 | They can be played back deterministically at startup or using the replay console. 19 | -------------------------------------------------------------------------------- /gemmill/consensus/pbft/common.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package pbft 16 | 17 | import ( 18 | "github.com/dappledger/AnnChain/gemmill/types" 19 | ) 20 | 21 | // XXX: WARNING: these functions can halt the consensus as firing events is synchronous. 22 | // Make sure to read off the channels, and in the case of subscribeToEventRespond, to write back on it 23 | 24 | // NOTE: if chanCap=0, this blocks on the event being consumed 25 | func subscribeToEvent(evsw types.EventSwitch, receiver, eventID string, chanCap int) chan interface{} { 26 | // listen for event 27 | ch := make(chan interface{}, chanCap) 28 | types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) { 29 | ch <- data 30 | }) 31 | return ch 32 | } 33 | 34 | // NOTE: this blocks on receiving a response after the event is consumed 35 | func subscribeToEventRespond(evsw types.EventSwitch, receiver, eventID string) chan interface{} { 36 | // listen for event 37 | ch := make(chan interface{}) 38 | types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) { 39 | ch <- data 40 | <-ch 41 | }) 42 | return ch 43 | } 44 | -------------------------------------------------------------------------------- /gemmill/consensus/pbft/test_data/README.md: -------------------------------------------------------------------------------- 1 | # Generating test data 2 | 3 | To generate the data, run `build.sh`. See that script for more details. 4 | 5 | Make sure to adjust the stepChanges in the testCases if the number of messages changes. 6 | This sometimes happens for the `small_block2.cswal`, where the number of block parts changes between 4 and 5. 7 | 8 | If you need to change the signatures, you can use a script as follows: 9 | The privBytes comes from `config/tendermint_test/...`: 10 | 11 | ``` 12 | package main 13 | 14 | import ( 15 | "encoding/hex" 16 | "fmt" 17 | 18 | "github.com/tendermint/go-crypto" 19 | ) 20 | 21 | func main() { 22 | signBytes, err := hex.DecodeString("7B22636861696E5F6964223A2274656E6465726D696E745F74657374222C22766F7465223A7B22626C6F636B5F68617368223A2242453544373939433846353044354645383533364334333932464443384537423342313830373638222C22626C6F636B5F70617274735F686561646572223A506172745365747B543A31204236323237323535464632307D2C22686569676874223A312C22726F756E64223A302C2274797065223A327D7D") 23 | if err != nil { 24 | panic(err) 25 | } 26 | privBytes, err := hex.DecodeString("27F82582AEFAE7AB151CFB01C48BB6C1A0DA78F9BDDA979A9F70A84D074EB07D3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8") 27 | if err != nil { 28 | panic(err) 29 | } 30 | privKey := crypto.PrivKeyEd25519{} 31 | copy(privKey[:], privBytes) 32 | signature := privKey.Sign(signBytes) 33 | fmt.Printf("Signature Bytes: %X\n", signature.Bytes()) 34 | } 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /gemmill/consensus/pbft/test_data/build.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | cd $GOPATH/src/github.com/tendermint/tendermint 4 | 5 | # specify a dir to copy 6 | # NOTE: eventually we should replace with `tendermint init --test` 7 | DIR=$HOME/.tendermint_test/consensus_state_test 8 | 9 | # XXX: remove tendermint dir 10 | rm -rf $HOME/.tendermint 11 | cp -r $DIR $HOME/.tendermint 12 | 13 | function reset(){ 14 | rm -rf $HOME/.tendermint/data 15 | tendermint unsafe_reset_priv_validator 16 | } 17 | 18 | reset 19 | 20 | # empty block 21 | tendermint node --proxy_app=dummy &> /dev/null & 22 | sleep 5 23 | killall tendermint 24 | 25 | # /q would print up to and including the match, then quit. 26 | # /Q doesn't include the match. 27 | # http://unix.stackexchange.com/questions/11305/grep-show-all-the-file-up-to-the-match 28 | sed '/HEIGHT: 2/Q' ~/.tendermint/data/cs.wal/wal > consensus/test_data/empty_block.cswal 29 | 30 | reset 31 | 32 | # small block 1 33 | bash scripts/txs/random.sh 1000 36657 &> /dev/null & 34 | PID=$! 35 | tendermint node --proxy_app=dummy &> /dev/null & 36 | sleep 5 37 | killall tendermint 38 | kill -9 $PID 39 | 40 | sed '/HEIGHT: 2/Q' ~/.tendermint/data/cs.wal/wal > consensus/test_data/small_block1.cswal 41 | 42 | reset 43 | 44 | 45 | # small block 2 (part size = 512) 46 | echo "" >> ~/.tendermint/config.toml 47 | echo "block_part_size = 512" >> ~/.tendermint/config.toml 48 | bash scripts/txs/random.sh 1000 36657 &> /dev/null & 49 | PID=$! 50 | tendermint node --proxy_app=dummy &> /dev/null & 51 | sleep 5 52 | killall tendermint 53 | kill -9 $PID 54 | 55 | sed '/HEIGHT: 2/Q' ~/.tendermint/data/cs.wal/wal > consensus/test_data/small_block2.cswal 56 | 57 | reset 58 | 59 | -------------------------------------------------------------------------------- /gemmill/consensus/pbft/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package pbft 16 | 17 | import ( 18 | gcmn "github.com/dappledger/AnnChain/gemmill/modules/go-common" 19 | ) 20 | 21 | // kind of arbitrary 22 | var Spec = "1" // async 23 | var Major = "0" // 24 | var Minor = "2" // replay refactor 25 | var Revision = "2" // validation -> commit 26 | 27 | var Version = gcmn.Fmt("v%s/%s.%s.%s", Spec, Major, Minor, Revision) 28 | -------------------------------------------------------------------------------- /gemmill/consensus/raft/snapshot.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "fmt" 5 | "github.com/hashicorp/raft" 6 | ) 7 | 8 | type BlockChainSnapshot struct { 9 | Height int64 10 | Hash []byte 11 | } 12 | 13 | func (s *BlockChainSnapshot) Persist(sink raft.SnapshotSink) error { 14 | _, err := sink.Write([]byte(fmt.Sprintf("%d-%x", s.Height, s.Hash))) 15 | return err 16 | } 17 | 18 | func (s *BlockChainSnapshot) Release() { 19 | // nothing to do 20 | } 21 | -------------------------------------------------------------------------------- /gemmill/ed25519/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /gemmill/ed25519/testdata/sign.input.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dappledger/AnnChain/916cc142c344937c01c5459270a64cb133f95c08/gemmill/ed25519/testdata/sign.input.gz -------------------------------------------------------------------------------- /gemmill/go-crypto/armor_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package crypto 16 | 17 | import ( 18 | "bytes" 19 | "testing" 20 | ) 21 | 22 | func TestSimpleArmor(t *testing.T) { 23 | blockType := "MINT TEST" 24 | data := []byte("somedata") 25 | armorStr := EncodeArmor(blockType, nil, data) 26 | t.Log("Got armor: ", armorStr) 27 | 28 | // Decode armorStr and test for equivalence. 29 | blockType2, _, data2, err := DecodeArmor(armorStr) 30 | if err != nil { 31 | t.Error(err) 32 | } 33 | if blockType != blockType2 { 34 | t.Errorf("Expected block type %v but got %v", blockType, blockType2) 35 | } 36 | if !bytes.Equal(data, data2) { 37 | t.Errorf("Expected data %X but got %X", data2, data) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /gemmill/go-crypto/bcrypt/base64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | // Copyright 2011 The Go Authors. All rights reserved. 16 | // Use of this source code is governed by a BSD-style 17 | // license that can be found in the LICENSE file. 18 | 19 | package bcrypt 20 | 21 | import "encoding/base64" 22 | 23 | const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 24 | 25 | var bcEncoding = base64.NewEncoding(alphabet) 26 | 27 | func base64Encode(src []byte) []byte { 28 | n := bcEncoding.EncodedLen(len(src)) 29 | dst := make([]byte, n) 30 | bcEncoding.Encode(dst, src) 31 | for dst[n-1] == '=' { 32 | n-- 33 | } 34 | return dst[:n] 35 | } 36 | 37 | func base64Decode(src []byte) ([]byte, error) { 38 | numOfEquals := 4 - (len(src) % 4) 39 | for i := 0; i < numOfEquals; i++ { 40 | src = append(src, '=') 41 | } 42 | 43 | dst := make([]byte, bcEncoding.DecodedLen(len(src))) 44 | n, err := bcEncoding.Decode(dst, src) 45 | if err != nil { 46 | return nil, err 47 | } 48 | return dst[:n], nil 49 | } 50 | -------------------------------------------------------------------------------- /gemmill/go-crypto/hash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package crypto 16 | 17 | import ( 18 | "crypto/sha256" 19 | "golang.org/x/crypto/ripemd160" 20 | ) 21 | 22 | func Sha256(bytes []byte) []byte { 23 | hasher := sha256.New() 24 | hasher.Write(bytes) 25 | return hasher.Sum(nil) 26 | } 27 | 28 | func Ripemd160(bytes []byte) []byte { 29 | hasher := ripemd160.New() 30 | hasher.Write(bytes) 31 | return hasher.Sum(nil) 32 | } 33 | -------------------------------------------------------------------------------- /gemmill/go-hash/hash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package hash 16 | 17 | import ( 18 | "golang.org/x/crypto/ripemd160" 19 | "golang.org/x/crypto/sha3" 20 | ) 21 | 22 | type HashType string 23 | 24 | const ( 25 | HashTypeSha256 HashType = "sha256" 26 | HashTypeRipemd160 = "ripemd160" 27 | ) 28 | 29 | var DoHash = ripemd160Func 30 | var DoHashName string 31 | 32 | func ConfigHasher(typ HashType) { 33 | switch typ { 34 | case HashTypeSha256: 35 | DoHash = sha256Func 36 | default: 37 | DoHash = ripemd160Func 38 | } 39 | } 40 | 41 | func sha256Func(bytes []byte) []byte { 42 | hasher := sha3.NewLegacyKeccak256() 43 | hasher.Write(bytes) 44 | return hasher.Sum(nil) 45 | 46 | } 47 | 48 | func ripemd160Func(bytes []byte) []byte { 49 | hasher := ripemd160.New() 50 | hasher.Write(bytes) 51 | return hasher.Sum(nil) 52 | } 53 | 54 | //Workrand 55 | func Keccak256Func(bytes []byte) []byte { 56 | return sha256Func(bytes) 57 | } 58 | -------------------------------------------------------------------------------- /gemmill/go-utils/regexp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package utils 16 | 17 | import ( 18 | "net" 19 | "regexp" 20 | "strconv" 21 | "strings" 22 | ) 23 | 24 | var ( 25 | regexp_NotNumLetterUnderline *regexp.Regexp 26 | ) 27 | 28 | func init() { 29 | //regexp_NotNumLetterUnderline = regexp.MustCompile(`^[0-9a-zA-Z_]+`) 30 | regexp_NotNumLetterUnderline = regexp.MustCompile(`[\W]+`) 31 | } 32 | 33 | func OnlyNumLetterUnderline(str string) bool { 34 | return regexp_NotNumLetterUnderline.FindStringIndex(str) == nil 35 | } 36 | 37 | func CheckNumber(str string) bool { 38 | _, err := strconv.Atoi(str) 39 | return err == nil 40 | } 41 | 42 | func CheckIPAddrSlc(str string) bool { 43 | addrSlc := strings.Split(str, ",") 44 | if len(addrSlc) == 0 { 45 | return false 46 | } 47 | for i := range addrSlc { 48 | if _, err := net.ResolveTCPAddr("tcp", addrSlc[i]); err != nil { 49 | return false 50 | } 51 | } 52 | return true 53 | } 54 | -------------------------------------------------------------------------------- /gemmill/go-utils/regexp_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package utils 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestOnlyNumLetterUnderline(t *testing.T) { 22 | str1 := "abc1abc2_" 23 | if !OnlyNumLetterUnderline(str1) { 24 | t.Error(str1, OnlyNumLetterUnderline(str1)) 25 | return 26 | } 27 | str2 := "_12bc1_aAAAAVBBbc2" 28 | if !OnlyNumLetterUnderline(str2) { 29 | t.Error(str2, OnlyNumLetterUnderline(str2)) 30 | return 31 | } 32 | str3 := "$" + str1 33 | if OnlyNumLetterUnderline(str3) { 34 | t.Error(str3, OnlyNumLetterUnderline(str3)) 35 | return 36 | } 37 | str4 := str1 + "_/\"" + str1 38 | if OnlyNumLetterUnderline(str4) { 39 | t.Error(str4, OnlyNumLetterUnderline(str4)) 40 | return 41 | } 42 | str5 := str1 + "_/\"" 43 | if OnlyNumLetterUnderline(str5) { 44 | t.Error(str5, OnlyNumLetterUnderline(str5)) 45 | return 46 | } 47 | str6 := "%" 48 | if OnlyNumLetterUnderline(str6) { 49 | t.Error(str6, OnlyNumLetterUnderline(str6)) 50 | return 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gemmill/go-wire/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all test get_deps 2 | 3 | all: test install 4 | 5 | install: get_deps 6 | go install github.com/tendermint/go-wire/cmd/... 7 | 8 | test: 9 | go test --race github.com/tendermint/go-wire/... 10 | 11 | get_deps: 12 | go get -d github.com/tendermint/go-wire/... 13 | 14 | pigeon: 15 | pigeon -o expr/expr.go expr/expr.peg 16 | -------------------------------------------------------------------------------- /gemmill/go-wire/cmd/wire/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "os" 20 | "strings" 21 | 22 | "github.com/dappledger/AnnChain/gemmill/go-wire/expr" 23 | gcmn "github.com/dappledger/AnnChain/gemmill/modules/go-common" 24 | ) 25 | 26 | func main() { 27 | input := "" 28 | if len(os.Args) > 2 { 29 | input = strings.Join(os.Args[1:], " ") 30 | } else if len(os.Args) == 2 { 31 | input = os.Args[1] 32 | } else { 33 | fmt.Println("Usage: wire 'u64:1 u64:2 '") 34 | return 35 | } 36 | 37 | // fmt.Println(input) 38 | got, err := expr.ParseReader(input, strings.NewReader(input)) 39 | if err != nil { 40 | gcmn.Exit("Error parsing input: " + err.Error()) 41 | } 42 | gotBytes, err := got.(expr.Byteful).Bytes() 43 | if err != nil { 44 | gcmn.Exit("Error serializing parsed input: " + err.Error()) 45 | } 46 | 47 | fmt.Println(gcmn.Fmt("%X", gotBytes)) 48 | } 49 | -------------------------------------------------------------------------------- /gemmill/go-wire/expr/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package expr 16 | 17 | import ( 18 | "strings" 19 | ) 20 | 21 | func Compile(exprStr string) ([]byte, error) { 22 | exprObj, err := ParseReader("", strings.NewReader(exprStr)) 23 | if err != nil { 24 | return nil, err 25 | } 26 | bz, err := exprObj.(Byteful).Bytes() 27 | if err != nil { 28 | return nil, err 29 | } 30 | return bz, err 31 | } 32 | -------------------------------------------------------------------------------- /gemmill/go-wire/float.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package wire 16 | 17 | import ( 18 | "io" 19 | "math" 20 | ) 21 | 22 | // Float32 23 | 24 | func WriteFloat32(f float32, w io.Writer, n *int, err *error) { 25 | WriteUint32(math.Float32bits(f), w, n, err) 26 | } 27 | 28 | func ReadFloat32(r io.Reader, n *int, err *error) float32 { 29 | x := ReadUint32(r, n, err) 30 | return math.Float32frombits(x) 31 | } 32 | 33 | // Float64 34 | 35 | func WriteFloat64(f float64, w io.Writer, n *int, err *error) { 36 | WriteUint64(math.Float64bits(f), w, n, err) 37 | } 38 | 39 | func ReadFloat64(r io.Reader, n *int, err *error) float64 { 40 | x := ReadUint64(r, n, err) 41 | return math.Float64frombits(x) 42 | } 43 | -------------------------------------------------------------------------------- /gemmill/go-wire/string.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package wire 16 | 17 | import ( 18 | "io" 19 | ) 20 | 21 | func WriteString(s string, w io.Writer, n *int, err *error) { 22 | WriteByteSlice([]byte(s), w, n, err) 23 | } 24 | 25 | func ReadString(r io.Reader, lmt int, n *int, err *error) string { 26 | return string(ReadByteSlice(r, lmt, n, err)) 27 | } 28 | 29 | func PutString(buf []byte, s string) (n int, err error) { 30 | return PutByteSlice(buf, []byte(s)) 31 | } 32 | 33 | func GetString(buf []byte) (s string, n int, err error) { 34 | bz, n, err := GetString(buf) 35 | return string(bz), n, err 36 | } 37 | -------------------------------------------------------------------------------- /gemmill/go-wire/time.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package wire 16 | 17 | import ( 18 | "io" 19 | "time" 20 | 21 | gcmn "github.com/dappledger/AnnChain/gemmill/modules/go-common" 22 | ) 23 | 24 | /* 25 | Writes nanoseconds since epoch but with millisecond precision. 26 | This is to ease compatibility with Javascript etc. 27 | */ 28 | 29 | func WriteTime(t time.Time, w io.Writer, n *int, err *error) { 30 | nanosecs := t.UnixNano() 31 | millisecs := nanosecs / 1000000 32 | WriteInt64(millisecs*1000000, w, n, err) 33 | } 34 | 35 | func ReadTime(r io.Reader, n *int, err *error) time.Time { 36 | t := ReadInt64(r, n, err) 37 | if t%1000000 != 0 { 38 | gcmn.PanicSanity("Time cannot have sub-millisecond precision") 39 | } 40 | return time.Unix(0, t) 41 | } 42 | -------------------------------------------------------------------------------- /gemmill/go-wire/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package wire 16 | 17 | const Version = "0.6.0" 18 | -------------------------------------------------------------------------------- /gemmill/log.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package gemmill 16 | 17 | import ( 18 | "go.uber.org/zap/zapcore" 19 | ) 20 | 21 | type ( 22 | infoOnly struct{} 23 | infoWithDebug struct{} 24 | aboveWarn struct{} 25 | ) 26 | 27 | func (l infoOnly) Enabled(lv zapcore.Level) bool { 28 | return lv == zapcore.InfoLevel 29 | } 30 | func (l infoWithDebug) Enabled(lv zapcore.Level) bool { 31 | return lv == zapcore.InfoLevel || lv == zapcore.DebugLevel 32 | } 33 | func (l aboveWarn) Enabled(lv zapcore.Level) bool { 34 | return lv >= zapcore.WarnLevel 35 | } 36 | 37 | func makeInfoFilter(env string) zapcore.LevelEnabler { 38 | switch env { 39 | case "production": 40 | return infoOnly{} 41 | default: 42 | return infoWithDebug{} 43 | } 44 | } 45 | 46 | func makeErrorFilter() zapcore.LevelEnabler { 47 | return aboveWarn{} 48 | } 49 | -------------------------------------------------------------------------------- /gemmill/modules/go-autofile/README.md: -------------------------------------------------------------------------------- 1 | # go-autofile 2 | -------------------------------------------------------------------------------- /gemmill/modules/go-common/array.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package common 16 | 17 | func Arr(items ...interface{}) []interface{} { 18 | return items 19 | } 20 | -------------------------------------------------------------------------------- /gemmill/modules/go-common/async.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package common 16 | 17 | import "sync" 18 | 19 | func Parallel(tasks ...func()) { 20 | var wg sync.WaitGroup 21 | wg.Add(len(tasks)) 22 | for _, task := range tasks { 23 | go func(task func()) { 24 | task() 25 | wg.Done() 26 | }(task) 27 | } 28 | wg.Wait() 29 | } 30 | -------------------------------------------------------------------------------- /gemmill/modules/go-common/byteslice.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package common 16 | 17 | import ( 18 | "bytes" 19 | ) 20 | 21 | func Fingerprint(slice []byte) []byte { 22 | fingerprint := make([]byte, 6) 23 | copy(fingerprint, slice) 24 | return fingerprint 25 | } 26 | 27 | func IsZeros(slice []byte) bool { 28 | for _, byt := range slice { 29 | if byt != byte(0) { 30 | return false 31 | } 32 | } 33 | return true 34 | } 35 | 36 | func RightPadBytes(slice []byte, l int) []byte { 37 | if l < len(slice) { 38 | return slice 39 | } 40 | padded := make([]byte, l) 41 | copy(padded[0:len(slice)], slice) 42 | return padded 43 | } 44 | 45 | func LeftPadBytes(slice []byte, l int) []byte { 46 | if l < len(slice) { 47 | return slice 48 | } 49 | padded := make([]byte, l) 50 | copy(padded[l-len(slice):], slice) 51 | return padded 52 | } 53 | 54 | func TrimmedString(b []byte) string { 55 | trimSet := string([]byte{0}) 56 | return string(bytes.TrimLeft(b, trimSet)) 57 | 58 | } 59 | -------------------------------------------------------------------------------- /gemmill/modules/go-common/mutate.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package common 16 | 17 | // Contract: !bytes.Equal(input, output) && len(input) >= len(output) 18 | func MutateByteSlice(bytez []byte) []byte { 19 | // If bytez is empty, panic 20 | if len(bytez) == 0 { 21 | panic("Cannot mutate an empty bytez") 22 | } 23 | 24 | // Copy bytez 25 | mBytez := make([]byte, len(bytez)) 26 | copy(mBytez, bytez) 27 | bytez = mBytez 28 | 29 | // Try a random mutation 30 | switch RandInt() % 2 { 31 | case 0: // Mutate a single byte 32 | bytez[RandInt()%len(bytez)] += byte(RandInt()%255 + 1) 33 | case 1: // Remove an arbitrary byte 34 | pos := RandInt() % len(bytez) 35 | bytez = append(bytez[:pos], bytez[pos+1:]...) 36 | } 37 | return bytez 38 | } -------------------------------------------------------------------------------- /gemmill/modules/go-common/net.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package common 16 | 17 | import ( 18 | "net" 19 | "strings" 20 | ) 21 | 22 | // protoAddr: e.g. "tcp://127.0.0.1:8080" or "unix:///tmp/test.sock" 23 | func Connect(protoAddr string) (net.Conn, error) { 24 | parts := strings.SplitN(protoAddr, "://", 2) 25 | proto, address := parts[0], parts[1] 26 | conn, err := net.Dial(proto, address) 27 | return conn, err 28 | } 29 | -------------------------------------------------------------------------------- /gemmill/modules/go-common/service_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package common 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestBaseServiceWait(t *testing.T) { 22 | 23 | type TestService struct { 24 | BaseService 25 | } 26 | ts := &TestService{} 27 | ts.BaseService = *NewBaseService("TestService", ts) 28 | ts.Start() 29 | 30 | go func() { 31 | ts.Stop() 32 | }() 33 | 34 | for i := 0; i < 10; i++ { 35 | ts.Wait() 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /gemmill/modules/go-common/string.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package common 16 | 17 | import ( 18 | "fmt" 19 | "strings" 20 | ) 21 | 22 | var Fmt = fmt.Sprintf 23 | 24 | func RightPadString(s string, totalLength int) string { 25 | remaining := totalLength - len(s) 26 | if remaining > 0 { 27 | s = s + strings.Repeat(" ", remaining) 28 | } 29 | return s 30 | } 31 | 32 | func LeftPadString(s string, totalLength int) string { 33 | remaining := totalLength - len(s) 34 | if remaining > 0 { 35 | s = strings.Repeat(" ", remaining) + s 36 | } 37 | return s 38 | } 39 | 40 | //SanitizeHex trim the prefix '0x'|'0X' if present 41 | func SanitizeHex(hex string) string { 42 | return strings.TrimPrefix(strings.ToLower(hex), "0x") 43 | } 44 | -------------------------------------------------------------------------------- /gemmill/modules/go-db/README.md: -------------------------------------------------------------------------------- 1 | TODO: syndtr/goleveldb should be replaced with actual LevelDB instance 2 | -------------------------------------------------------------------------------- /gemmill/modules/go-events/README.md: -------------------------------------------------------------------------------- 1 | # go-events 2 | PubSub in Go with event caching. 3 | -------------------------------------------------------------------------------- /gemmill/modules/go-flowrate/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 The Go-FlowRate Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the 13 | distribution. 14 | 15 | * Neither the name of the go-flowrate project nor the names of its 16 | contributors may be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /gemmill/modules/go-flowrate/README: -------------------------------------------------------------------------------- 1 | Data Flow Rate Control 2 | ====================== 3 | 4 | To download and install this package run: 5 | 6 | go get github.com/mxk/go-flowrate/flowrate 7 | 8 | The documentation is available at: 9 | 10 | http://godoc.org/github.com/mxk/go-flowrate/flowrate 11 | -------------------------------------------------------------------------------- /gemmill/modules/go-log/dump.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package log 16 | 17 | import ( 18 | "bytes" 19 | "fmt" 20 | "io/ioutil" 21 | "runtime" 22 | "time" 23 | ) 24 | 25 | // If non-empty, overrides the choice of directory in which to write logs. 26 | // See createLogDirs for the full list of possible destinations. 27 | //var logDir = flag.String("log_dir", "", "./") 28 | var logDir = "./" 29 | 30 | func DumpStack() { 31 | if err := recover(); err != nil { 32 | var buf bytes.Buffer 33 | bs := make([]byte, 1<<12) 34 | num := runtime.Stack(bs, false) 35 | buf.WriteString(fmt.Sprintf("Panic: %s\n", err)) 36 | buf.Write(bs[:num]) 37 | dumpName := logDir + "/dump_" + time.Now().Format("20060102-150405") 38 | nerr := ioutil.WriteFile(dumpName, buf.Bytes(), 0644) 39 | if nerr != nil { 40 | fmt.Println("write dump file error", nerr) 41 | fmt.Println(buf.Bytes()) 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /gemmill/modules/go-log/log_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package log 16 | 17 | import "testing" 18 | 19 | func TestLog(t *testing.T) { 20 | logger, err := Initialize("dev", "testdir") 21 | if err != nil { 22 | t.Error("initialize err ", err) 23 | return 24 | } 25 | SetLog(logger) 26 | Error("error log") 27 | Warn("warn log") 28 | Info("info log") 29 | } 30 | -------------------------------------------------------------------------------- /gemmill/modules/go-log/logger.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package log 16 | 17 | // Logger is a common logger used univeral 18 | type Logger interface { 19 | Debug(msg string, keyvals ...interface{}) error 20 | Info(msg string, keyvals ...interface{}) error 21 | Error(msg string, keyvals ...interface{}) error 22 | 23 | With(keyvals ...interface{}) Logger 24 | } 25 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: get_deps all bench test 2 | 3 | all: test 4 | 5 | test: 6 | go test -v -race `glide novendor` 7 | 8 | bench: 9 | go test `glide novendor` -tags gcc -bench=. 10 | 11 | get_deps: 12 | go get github.com/Masterminds/glide 13 | rm -rf ./vendor 14 | glide install 15 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/benchmarks/EthansMacBook.txt: -------------------------------------------------------------------------------- 1 | go test -bench . 2 | ok, starting 3 | BenchmarkImmutableAvlTreeLevelDB2-4 ok, starting 4 | ok, starting 5 | 2000 813477 ns/op 6 | ok, starting 7 | BenchmarkImmutableAvlTreeMemDB-4 ok, starting 8 | ok, starting 9 | 10000 104649 ns/op 10 | PASS 11 | ok github.com/tendermint/go-merkle 229.565s 12 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | environment: 3 | GO15VENDOREXPERIMENT: 1 4 | 5 | dependencies: 6 | pre: 7 | - make get_deps 8 | 9 | test: 10 | override: 11 | - make test 12 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/tendermint/go-merkle 2 | import: 3 | - package: github.com/tendermint/go-common 4 | - package: github.com/tendermint/go-db 5 | - package: github.com/tendermint/go-wire 6 | - package: golang.org/x/crypto 7 | subpackages: 8 | - ripemd160 9 | - package: github.com/stretchr/testify 10 | version: ^1.1.4 11 | subpackages: 12 | - assert 13 | - require 14 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/scripts/looper.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | gcmn "github.com/dappledger/AnnChain/gemmill/modules/go-common" 21 | "github.com/dappledger/AnnChain/gemmill/modules/go-db" 22 | "github.com/dappledger/AnnChain/gemmill/modules/go-merkle" 23 | ) 24 | 25 | func main() { 26 | db := db.NewMemDB() 27 | t := merkle.NewIAVLTree(0, db) 28 | // 23000ns/op, 43000ops/s 29 | // for i := 0; i < 10000000; i++ { 30 | // for i := 0; i < 1000000; i++ { 31 | for i := 0; i < 1000; i++ { 32 | t.Set(gcmn.RandBytes(12), nil) 33 | } 34 | t.Save() 35 | 36 | fmt.Println("ok, starting") 37 | 38 | for i := 0; ; i++ { 39 | key := gcmn.RandBytes(12) 40 | t.Set(key, nil) 41 | t.Remove(key) 42 | if i%1000 == 0 { 43 | t.Save() 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/types.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package merkle 16 | 17 | type Tree interface { 18 | Size() (size int) 19 | Height() (height int8) 20 | Has(key []byte) (has bool) 21 | Proof(key []byte) (proof []byte, exists bool) 22 | Get(key []byte) (index int, value []byte, exists bool) 23 | GetByIndex(index int) (key []byte, value []byte) 24 | Set(key []byte, value []byte) (updated bool) 25 | Remove(key []byte) (value []byte, removed bool) 26 | HashWithCount() (hash []byte, count int) 27 | Hash() (hash []byte) 28 | Save() (hash []byte) 29 | Load(hash []byte) 30 | Copy() Tree 31 | Iterate(func(key []byte, value []byte) (stop bool)) (stopped bool) 32 | IterateRange(start []byte, end []byte, ascending bool, fx func(key []byte, value []byte) (stop bool)) (stopped bool) 33 | } 34 | 35 | type Hashable interface { 36 | Hash() []byte 37 | } 38 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package merkle 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | // Prints the in-memory children recursively. 22 | func PrintIAVLNode(node *IAVLNode) { 23 | fmt.Println("==== NODE") 24 | if node != nil { 25 | printIAVLNode(node, 0) 26 | } 27 | fmt.Println("==== END") 28 | } 29 | 30 | func printIAVLNode(node *IAVLNode, indent int) { 31 | indentPrefix := "" 32 | for i := 0; i < indent; i++ { 33 | indentPrefix += " " 34 | } 35 | 36 | if node.rightNode != nil { 37 | printIAVLNode(node.rightNode, indent+1) 38 | } else if node.rightHash != nil { 39 | fmt.Printf("%s %X\n", indentPrefix, node.rightHash) 40 | } 41 | 42 | fmt.Printf("%s%v:%v\n", indentPrefix, node.key, node.height) 43 | 44 | if node.leftNode != nil { 45 | printIAVLNode(node.leftNode, indent+1) 46 | } else if node.leftHash != nil { 47 | fmt.Printf("%s %X\n", indentPrefix, node.leftHash) 48 | } 49 | 50 | } 51 | 52 | func maxInt8(a, b int8) int8 { 53 | if a > b { 54 | return a 55 | } 56 | return b 57 | } 58 | -------------------------------------------------------------------------------- /gemmill/modules/go-merkle/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package merkle 16 | 17 | const Version = "0.3.0" // pruning, proof, iterate-range 18 | -------------------------------------------------------------------------------- /gemmill/p2p/ip_range_counter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package p2p 16 | 17 | import ( 18 | "strings" 19 | ) 20 | 21 | // TODO Test 22 | func AddToIPRangeCounts(counts map[string]int, ip string) map[string]int { 23 | changes := make(map[string]int) 24 | ipParts := strings.Split(ip, ":") 25 | for i := 1; i < len(ipParts); i++ { 26 | prefix := strings.Join(ipParts[:i], ":") 27 | counts[prefix] += 1 28 | changes[prefix] = counts[prefix] 29 | } 30 | return changes 31 | } 32 | 33 | // TODO Test 34 | func CheckIPRangeCounts(counts map[string]int, limits []int) bool { 35 | for prefix, count := range counts { 36 | ipParts := strings.Split(prefix, ":") 37 | numParts := len(ipParts) 38 | if limits[numParts] < count { 39 | return false 40 | } 41 | } 42 | return true 43 | } 44 | -------------------------------------------------------------------------------- /gemmill/p2p/listener_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package p2p 16 | 17 | import ( 18 | "bytes" 19 | "testing" 20 | ) 21 | 22 | func TestListener(t *testing.T) { 23 | // Create a listener 24 | l, err := NewDefaultListener("tcp", ":8001", true) 25 | if err != nil { 26 | t.Fatalf("Error creating a listener: %v", err) 27 | } 28 | 29 | // Dial the listener 30 | lAddr := l.ExternalAddress() 31 | connOut, err := lAddr.Dial() 32 | if err != nil { 33 | t.Fatalf("Could not connect to listener address %v", lAddr) 34 | } else { 35 | t.Logf("Created a connection to listener address %v", lAddr) 36 | } 37 | connIn, ok := <-l.Connections() 38 | if !ok { 39 | t.Fatalf("Could not get inbound connection from listener") 40 | } 41 | 42 | msg := []byte("hi!") 43 | go connIn.Write(msg) 44 | b := make([]byte, 32) 45 | n, err := connOut.Read(b) 46 | if err != nil { 47 | t.Fatalf("Error reading off connection: %v", err) 48 | } 49 | 50 | b = b[:n] 51 | if !bytes.Equal(msg, b) { 52 | t.Fatalf("Got %s, expected %s", b, msg) 53 | } 54 | 55 | // Close the server, no longer needed. 56 | l.Stop() 57 | } 58 | -------------------------------------------------------------------------------- /gemmill/p2p/upnp/README.md: -------------------------------------------------------------------------------- 1 | # `tendermint/p2p/upnp` 2 | 3 | ## Resources 4 | 5 | * http://www.upnp-hacks.org/upnp.html 6 | -------------------------------------------------------------------------------- /gemmill/p2p/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package p2p 16 | 17 | import ( 18 | "crypto/sha256" 19 | ) 20 | 21 | // doubleSha256 calculates sha256(sha256(b)) and returns the resulting bytes. 22 | func doubleSha256(b []byte) []byte { 23 | hasher := sha256.New() 24 | hasher.Write(b) 25 | sum := hasher.Sum(nil) 26 | hasher.Reset() 27 | hasher.Write(sum) 28 | return hasher.Sum(nil) 29 | } 30 | -------------------------------------------------------------------------------- /gemmill/p2p/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package p2p 16 | 17 | const Version = "0.3.5" // minor fixes 18 | -------------------------------------------------------------------------------- /gemmill/refuse_list/refuse_list_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package refuse_list 16 | 17 | import ( 18 | "os" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | 23 | "github.com/dappledger/AnnChain/gemmill/modules/go-db" 24 | "github.com/dappledger/AnnChain/gemmill/types" 25 | ) 26 | 27 | func TestRefuseList(t *testing.T) { 28 | refuseList := NewRefuseList(db.LevelDBBackendStr, "./") 29 | defer func() { 30 | os.RemoveAll("refuse_list.db") 31 | refuseList.db.Close() 32 | }() 33 | var keyStr = "6FEBD39916627AA0CD7CFDA4A94586F3BA958078621E6E466488A423272B9700" 34 | 35 | pubKey, err := types.StringTo32byte(keyStr) 36 | assert.Nil(t, err) 37 | refuseList.AddRefuseKey(pubKey[:]) 38 | assert.Equal(t, true, refuseList.QueryRefuseKey(pubKey[:])) 39 | assert.Equal(t, []string{keyStr}, refuseList.ListAllKey()) 40 | refuseList.DeleteRefuseKey(pubKey[:]) 41 | assert.Equal(t, 0, len(refuseList.ListAllKey())) 42 | } 43 | -------------------------------------------------------------------------------- /gemmill/rpc/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all test get_deps 2 | 3 | all: test 4 | 5 | test: 6 | bash ./test/test.sh 7 | 8 | get_deps: 9 | go get -t -u github.com/tendermint/go-rpc/... 10 | -------------------------------------------------------------------------------- /gemmill/rpc/circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | environment: 3 | GOPATH: /home/ubuntu/.go_workspace 4 | REPO: $GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME 5 | hosts: 6 | circlehost: 127.0.0.1 7 | localhost: 127.0.0.1 8 | 9 | checkout: 10 | post: 11 | - rm -rf $REPO 12 | - mkdir -p $HOME/.go_workspace/src/github.com/$CIRCLE_PROJECT_USERNAME 13 | - mv $HOME/$CIRCLE_PROJECT_REPONAME $REPO 14 | # - git submodule sync 15 | # - git submodule update --init # use submodules 16 | 17 | dependencies: 18 | override: 19 | - "cd $REPO" 20 | 21 | test: 22 | override: 23 | - "cd $REPO && make test" 24 | -------------------------------------------------------------------------------- /gemmill/rpc/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package rpc 16 | 17 | const Maj = "0" 18 | const Min = "6" // 0x-prefixed string args handled as hex 19 | const Fix = "0" // 20 | 21 | const Version = Maj + "." + Min + "." + Fix 22 | -------------------------------------------------------------------------------- /gemmill/state/tps_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package state 16 | 17 | import ( 18 | "fmt" 19 | "math/rand" 20 | "testing" 21 | "time" 22 | ) 23 | 24 | func TestTPS(t *testing.T) { 25 | tps := NewTPSCalculator(5) 26 | for i := 0; i < 20; i++ { 27 | time.Sleep(time.Millisecond * time.Duration(rand.Int()%1000)) 28 | tps.AddRecord(uint32(rand.Int()%1000 + 1000)) 29 | fmt.Println("tps now:", tps.TPS()) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gemmill/types/block_meta.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package types 16 | 17 | type BlockMeta struct { 18 | Hash []byte `json:"hash"` // The block hash 19 | Header *Header `json:"header"` // The block's Header 20 | PartsHeader PartSetHeader `json:"parts_header"` // The PartSetHeader, for transfer 21 | } 22 | 23 | func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta { 24 | return &BlockMeta{ 25 | Hash: block.Hash(), 26 | Header: block.Header, 27 | PartsHeader: blockParts.Header(), 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /gemmill/types/keys.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package types 16 | 17 | var ( 18 | PeerStateKey = "ConsensusReactor.peerState" 19 | PeerMempoolChKey = "MempoolReactor.peerMempoolCh" 20 | ) 21 | -------------------------------------------------------------------------------- /gemmill/types/kv.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "encoding/hex" 5 | "fmt" 6 | ) 7 | 8 | type ValueUpdateHistory struct { 9 | TxHash []byte `json:"tx_hash"` 10 | BlockHeight uint64 `json:"block_height"` 11 | TimeStamp uint64 `json:"time_stamp"` 12 | Value []byte `json:"value"` 13 | TxIndex uint32 `json:"tx_index"` 14 | } 15 | 16 | type ValueHistoryResult struct { 17 | Key []byte `json:"key"` 18 | ValueUpdateHistories []*ValueUpdateHistory `json:"value_update_histories"` 19 | Total uint32 `json:"total"` 20 | } 21 | 22 | func (v *ValueUpdateHistory) String() string { 23 | if v == nil { 24 | return "" 25 | } 26 | return fmt.Sprintf("hight : %d , hash :%s ,time: %d , value %s , txIndx %d", 27 | v.BlockHeight, hex.EncodeToString(v.TxHash), v.TimeStamp, string(v.Value),v.TxIndex) 28 | } 29 | 30 | type KeyValueHistory struct { 31 | Key []byte 32 | ValueUpdateHistory *ValueUpdateHistory 33 | } 34 | 35 | func (k *KeyValueHistory)String()string { 36 | if k == nil { 37 | return "" 38 | } 39 | return fmt.Sprintf("key : %s ,history: %s",string(k.Key),k.ValueUpdateHistory.String()) 40 | } 41 | 42 | type KeyValueHistories []*KeyValueHistory 43 | 44 | func (k KeyValueHistories)String()string { 45 | if len(k) ==0 { 46 | return "" 47 | } 48 | result := "[" 49 | for _, v := range k { 50 | result += v.String()+" " 51 | } 52 | result+="]" 53 | return result 54 | } -------------------------------------------------------------------------------- /gemmill/types/mempool.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package types 16 | 17 | type IMempool interface { 18 | Lock() 19 | Unlock() 20 | Update(height int64, txs []Tx) 21 | } 22 | -------------------------------------------------------------------------------- /gemmill/types/query.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package types 16 | 17 | import ( 18 | "github.com/dappledger/AnnChain/eth/rlp" 19 | ) 20 | 21 | const ( 22 | // angine takes query id from 0x01 to 0x2F 23 | QueryTxExecution = 0x01 24 | QueryTx = 0x02 25 | ) 26 | 27 | type TxExecutionResult struct { 28 | Height uint64 `json:"height"` 29 | BlockHash []byte `json:"blockhash"` 30 | Index uint64 `json:"index"` 31 | } 32 | 33 | func (i *TxExecutionResult) ToBytes() ([]byte, error) { 34 | return rlp.EncodeToBytes(i) 35 | } 36 | 37 | func (i *TxExecutionResult) FromBytes(data []byte) error { 38 | return rlp.DecodeBytes(data, i) 39 | } 40 | -------------------------------------------------------------------------------- /gemmill/types/signable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package types 16 | 17 | import ( 18 | "bytes" 19 | "io" 20 | 21 | gcmn "github.com/dappledger/AnnChain/gemmill/modules/go-common" 22 | "github.com/dappledger/AnnChain/gemmill/modules/go-merkle" 23 | ) 24 | 25 | // Signable is an interface for all signable things. 26 | // It typically removes signatures before serializing. 27 | type Signable interface { 28 | WriteSignBytes(chainID string, w io.Writer, n *int, err *error) 29 | } 30 | 31 | // SignBytes is a convenience method for getting the bytes to sign of a Signable. 32 | func SignBytes(chainID string, o Signable) []byte { 33 | buf, n, err := new(bytes.Buffer), new(int), new(error) 34 | o.WriteSignBytes(chainID, buf, n, err) 35 | if *err != nil { 36 | gcmn.PanicCrisis(err) 37 | } 38 | return buf.Bytes() 39 | } 40 | 41 | // HashSignBytes is a convenience method for getting the hash of the bytes of a signable 42 | func HashSignBytes(chainID string, o Signable) []byte { 43 | return merkle.SimpleHashFromBinary(SignBytes(chainID, o)) 44 | } 45 | -------------------------------------------------------------------------------- /gemmill/types/tools.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package types 16 | 17 | import ( 18 | crypto "github.com/dappledger/AnnChain/gemmill/go-crypto" 19 | ) 20 | 21 | func SignCA(priv crypto.PrivKey, pubbytes []byte) string { 22 | return priv.Sign(pubbytes).KeyString() 23 | } 24 | -------------------------------------------------------------------------------- /gemmill/types/vote_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package types 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestVoteSignable(t *testing.T) { 22 | vote := &Vote{ 23 | ValidatorAddress: []byte("addr"), 24 | ValidatorIndex: 56789, 25 | Height: 12345, 26 | Round: 23456, 27 | Type: byte(2), 28 | BlockID: BlockID{ 29 | Hash: []byte("hash"), 30 | PartsHeader: PartSetHeader{ 31 | Total: 1000000, 32 | Hash: []byte("parts_hash"), 33 | }, 34 | }, 35 | } 36 | signBytes := SignBytes("test_chain_id", vote) 37 | signStr := string(signBytes) 38 | 39 | expected := `{"chain_id":"test_chain_id","vote":{"block_id":{"hash":"68617368","parts":{"hash":"70617274735F68617368","total":1000000}},"height":12345,"round":23456,"type":2}}` 40 | if signStr != expected { 41 | // NOTE: when this fails, you probably want to fix up consensus/replay_test too 42 | t.Errorf("Got unexpected sign string for Vote. Expected:\n%v\nGot:\n%v", expected, signStr) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /gemmill/utils/crypto_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package utils 16 | 17 | import ( 18 | "encoding/hex" 19 | "fmt" 20 | "testing" 21 | ) 22 | 23 | func Test_Crypto(t *testing.T) { 24 | text := "aa" 25 | pwd := "aa" 26 | ret, err := Encrypt([]byte(text), []byte(pwd)) 27 | fmt.Println("Encrypt:", ret, ",err:", err, ",hex:", hex.EncodeToString(ret)) 28 | deret, err := Decrypt(ret, []byte(pwd)) 29 | fmt.Println("Decrypt:", string(deret), ",err:", err) 30 | } 31 | -------------------------------------------------------------------------------- /gemmill/utils/tools_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package utils 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestSortInt64Slc(t *testing.T) { 22 | var slc = []int64{1, 129, 20, 4, 45, 66} 23 | Int64Slice(slc).Sort() 24 | pre := slc[0] 25 | for i := range slc { 26 | if pre > slc[i] { 27 | t.Error("sort err") 28 | return 29 | } 30 | pre = slc[i] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /gemmill/utils/zip/zip_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package zip 16 | 17 | import ( 18 | "bytes" 19 | "io" 20 | "io/ioutil" 21 | "os" 22 | "path/filepath" 23 | "testing" 24 | 25 | "github.com/stretchr/testify/assert" 26 | ) 27 | 28 | func TestZip(t *testing.T) { 29 | dir := "./testZip" 30 | err := os.Mkdir(dir, 0777) 31 | assert.Nil(t, err) 32 | defer os.RemoveAll(dir) 33 | file, err := os.Create(filepath.Join(dir, "text")) 34 | assert.Nil(t, err) 35 | defer file.Close() 36 | fileContent := "just for test" 37 | reader := bytes.NewReader([]byte(fileContent)) 38 | _, err = io.Copy(file, reader) 39 | assert.Nil(t, err) 40 | 41 | err = CompressDir(dir) 42 | assert.Nil(t, err) 43 | _, err = os.Stat(dir + ".zip") 44 | assert.Nil(t, err) 45 | defer os.Remove(dir + ".zip") 46 | newDir := "./testDecompress" 47 | err = Decompress(dir+".zip", newDir) 48 | assert.Nil(t, err) 49 | defer os.RemoveAll(newDir) 50 | bytez, err := ioutil.ReadFile(filepath.Join(newDir, "text")) 51 | assert.Nil(t, err) 52 | assert.Equal(t, fileContent, string(bytez)) 53 | } 54 | -------------------------------------------------------------------------------- /gemmill/vendor/gopkg.in/natefinch/lumberjack.v2/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Nate Finch 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /gemmill/vendor/gopkg.in/natefinch/lumberjack.v2/chown.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package lumberjack 4 | 5 | import ( 6 | "os" 7 | ) 8 | 9 | func chown(_ string, _ os.FileInfo) error { 10 | return nil 11 | } 12 | -------------------------------------------------------------------------------- /gemmill/vendor/gopkg.in/natefinch/lumberjack.v2/chown_linux.go: -------------------------------------------------------------------------------- 1 | package lumberjack 2 | 3 | import ( 4 | "os" 5 | "syscall" 6 | ) 7 | 8 | // os_Chown is a var so we can mock it out during tests. 9 | var os_Chown = os.Chown 10 | 11 | func chown(name string, info os.FileInfo) error { 12 | f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode()) 13 | if err != nil { 14 | return err 15 | } 16 | f.Close() 17 | stat := info.Sys().(*syscall.Stat_t) 18 | return os_Chown(name, int(stat.Uid), int(stat.Gid)) 19 | } 20 | -------------------------------------------------------------------------------- /gemmill/vendor/gopkg.in/natefinch/lumberjack.v2/example_test.go: -------------------------------------------------------------------------------- 1 | package lumberjack_test 2 | 3 | import ( 4 | "log" 5 | 6 | "gopkg.in/natefinch/lumberjack.v2" 7 | ) 8 | 9 | // To use lumberjack with the standard library's log package, just pass it into 10 | // the SetOutput function when your application starts. 11 | func Example() { 12 | log.SetOutput(&lumberjack.Logger{ 13 | Filename: "/var/log/myapp/foo.log", 14 | MaxSize: 500, // megabytes 15 | MaxBackups: 3, 16 | MaxAge: 28, // days 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /gemmill/vendor/gopkg.in/natefinch/lumberjack.v2/rotate_test.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package lumberjack_test 4 | 5 | import ( 6 | "log" 7 | "os" 8 | "os/signal" 9 | "syscall" 10 | 11 | "gopkg.in/natefinch/lumberjack.v2" 12 | ) 13 | 14 | // Example of how to rotate in response to SIGHUP. 15 | func ExampleLogger_Rotate() { 16 | l := &lumberjack.Logger{} 17 | log.SetOutput(l) 18 | c := make(chan os.Signal, 1) 19 | signal.Notify(c, syscall.SIGHUP) 20 | 21 | go func() { 22 | for { 23 | <-c 24 | l.Rotate() 25 | } 26 | }() 27 | } 28 | -------------------------------------------------------------------------------- /gemmill/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package gemmill 16 | 17 | const Gversion = "0.1.5" 18 | -------------------------------------------------------------------------------- /get_pkgs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | tryGetInternalPkgs() 4 | { 5 | unset GOPROXY 6 | # 解决jenkins与gitlab不通 7 | if [ ! -z "$HTTPS_PRXOY" ] 8 | then 9 | export https_proxy=$HTTPS_PRXOY 10 | fi 11 | go mod download 12 | } 13 | 14 | tryGetBlockedPkgs() 15 | { 16 | export GOPROXY=https://goproxy.io 17 | if [ ! -z "$HTTPS_PRXOY" ] 18 | then 19 | unset https_proxy 20 | fi 21 | go mod download 22 | } 23 | 24 | # trick make 25 | tryMake() 26 | { 27 | t=`expr $1 - 1`; 28 | if [ $t == 0 ] ;then 29 | exit 1 30 | fi 31 | 32 | tryGetBlockedPkgs 33 | if [ $? -ne 0 ]; then 34 | tryGetInternalPkgs 35 | if [ $? -ne 0 ]; then 36 | tryMake $t 37 | fi 38 | fi 39 | } 40 | 41 | tryMake 10 42 | -------------------------------------------------------------------------------- /scripts/archive/commands.sh: -------------------------------------------------------------------------------- 1 | ./build/rtool info num_archived_blocks 2 | -------------------------------------------------------------------------------- /scripts/bench/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: rz-bench 2 | all: rz-bench 3 | 4 | rz-bench: 5 | go build -o ./rzb . 6 | 7 | clean: 8 | rm ./rzb 9 | -------------------------------------------------------------------------------- /scripts/bench/bench.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | inputDir=./cases 4 | outputDir=./out 5 | loader=./mapred 6 | bencher=rzb 7 | 8 | send() { 9 | action=$1 10 | outFile=$2 11 | procNum=$3 12 | requestNum=$4 13 | ip=$5 14 | 15 | test -z $ip && ip=localhost:46657 16 | 17 | # 1. create 18 | ./mapred --mapper="./rzb -action=${action} -num=${requestNum} ${ip}" --count=$procNum > $outFile 19 | start=`grep "START" $outFile | awk '{print $2}' | sort -n | head -1` 20 | end=`grep "END" $outFile | awk '{print $2}' | sort -n | tail -1` 21 | interval=`expr $end - $start` 22 | # num=`cat ${inputDir}/${caseName} | wc -l` 23 | ftps=`echo "${requestNum}*${procNum}/$interval" | bc -l` 24 | tps=`echo "$ftps*1000" | bc -l` 25 | echo "[ProcNum ]: $procNum" 26 | echo "[Requests]: $requestNum" 27 | echo "[Interval]: ${interval}ms" 28 | echo "[TPS ]: $tps" 29 | 30 | # 2. read 31 | # ${binDir}/${loader} --mapper='${bencher} -action=read localhost:46657' --count=$procNum > $outFile_read 32 | 33 | # 3. call 34 | # ${binDir}/${loader} --mapper='${bencher} -action=call localhost:46657' --count=$procNum > $outFile_call 35 | } 36 | 37 | function main() { 38 | send $1 $2 $3 $4 $5 39 | #for req in `ls ${inputDir}` 40 | #do 41 | # send ${req} ${procNum} 42 | #done 43 | 44 | } 45 | 46 | main $* -------------------------------------------------------------------------------- /scripts/bench/contracts/complex/policy.abi: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": false, 4 | "inputs": [ 5 | { 6 | "name": "x", 7 | "type": "uint256" 8 | } 9 | ], 10 | "name": "set", 11 | "outputs": [], 12 | "payable": false, 13 | "stateMutability": "nonpayable", 14 | "type": "function" 15 | }, 16 | { 17 | "constant": true, 18 | "inputs": [], 19 | "name": "get", 20 | "outputs": [ 21 | { 22 | "name": "", 23 | "type": "uint256" 24 | } 25 | ], 26 | "payable": false, 27 | "stateMutability": "view", 28 | "type": "function" 29 | } 30 | ] -------------------------------------------------------------------------------- /scripts/bench/contracts/complex/policy.bin: -------------------------------------------------------------------------------- 1 | 6060604052341561000f57600080fd5b60d38061001d6000396000f3006060604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c14606e575b600080fd5b3415605857600080fd5b606c60048080359060200190919050506094565b005b3415607857600080fd5b607e609e565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a723058202f196d73b019bfadd056125155d3a0728f0f73dad0eb44ac6dfc4eb3c6a0a3ec0029 -------------------------------------------------------------------------------- /scripts/bench/contracts/sample/commands.sh: -------------------------------------------------------------------------------- 1 | ./rtool --backend="tcp://localhost:46657" evm create --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.json --abif /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.abi --nonce 0 2 | 3 | ./rtool --backend="tcp://localhost:46657" evm exist --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample_exist.json 4 | 5 | ./rtool --backend="tcp://localhost:46657" query nonce --address aaf40b3b7d103b01e89c7aa489ed186c5467dabf 6 | 7 | ./rtool --backend="tcp://localhost:46657" evm call --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample_execute.json --abif /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.abi --nonce 1 8 | 9 | ./rtool --backend="tcp://localhost:46657" evm read --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample_read.json --abif /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.abi --nonce 2 10 | -------------------------------------------------------------------------------- /scripts/bench/contracts/sample/sample.abi: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": false, 4 | "inputs": [ 5 | { 6 | "name": "Id", 7 | "type": "uint256" 8 | }, 9 | { 10 | "name": "Amount", 11 | "type": "uint256" 12 | } 13 | ], 14 | "name": "createCheckInfos", 15 | "outputs": [], 16 | "payable": false, 17 | "stateMutability": "nonpayable", 18 | "type": "function" 19 | }, 20 | { 21 | "constant": true, 22 | "inputs": [ 23 | { 24 | "name": "Id", 25 | "type": "uint256" 26 | } 27 | ], 28 | "name": "getPremiumInfos", 29 | "outputs": [ 30 | { 31 | "name": "", 32 | "type": "uint256" 33 | } 34 | ], 35 | "payable": false, 36 | "stateMutability": "view", 37 | "type": "function" 38 | }, 39 | { 40 | "anonymous": false, 41 | "inputs": [ 42 | { 43 | "indexed": false, 44 | "name": "Id", 45 | "type": "uint256" 46 | }, 47 | { 48 | "indexed": false, 49 | "name": "Amount", 50 | "type": "uint256" 51 | } 52 | ], 53 | "name": "InputLog", 54 | "type": "event" 55 | } 56 | ] -------------------------------------------------------------------------------- /scripts/bench/contracts/sample/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "privkey" : "9f24af64906c916fae5a07f33005149a89a22d5ca97bdfbfbbdddbba39c49796", 3 | "bytecode" : "6060604052341561000f57600080fd5b6101818061001e6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063a6226f2114610051578063b051c1e01461007d575b600080fd5b341561005c57600080fd5b61007b60048080359060200190919080359060200190919050506100b4565b005b341561008857600080fd5b61009e6004808035906020019091905050610136565b6040518082815260200191505060405180910390f35b60007fb45ab3e8c50935ce2fa51d37817fd16e7358a3087fd93a9ac7fbddb22a926c358383604051808381526020018281526020019250505060405180910390a1828160000181905550818160010181905550806000808581526020019081526020016000206000820154816000015560018201548160010155905050505050565b60008060008381526020019081526020016000206001015490509190505600a165627a7a723058207eaf119132cfc4008c97339b874c4c16d20d27a72875e55a6a22a29fee30876d0029", 4 | "params" :[] 5 | } -------------------------------------------------------------------------------- /scripts/bench/contracts/sample/sample.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Check { 4 | 5 | struct check { 6 | uint Id; 7 | uint Amount; 8 | } 9 | 10 | event InputLog ( 11 | uint Id, 12 | uint Amount 13 | ); 14 | 15 | mapping (uint => check) checkInfos; 16 | 17 | function createCheckInfos( uint Id, uint Amount) { 18 | InputLog(Id,Amount); 19 | check c; 20 | c.Id = Id; 21 | c.Amount = Amount; 22 | 23 | checkInfos[Id] = c; 24 | } 25 | 26 | function getPremiumInfos(uint Id) public constant returns(string,uint) { 27 | return ( 28 | checkInfos[Id].Amount 29 | ); 30 | } 31 | } -------------------------------------------------------------------------------- /scripts/bench/contracts/sample/sample_execute.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract" : "0xe12025dd2f2373e30c2ecf920c992da40311cd48", 3 | "privkey" : "9f24af64906c916fae5a07f33005149a89a22d5ca97bdfbfbbdddbba39c49796", 4 | "function" : "createCheckInfos", 5 | "params":[ 6 | 1, 100 7 | ] 8 | } -------------------------------------------------------------------------------- /scripts/bench/contracts/sample/sample_exist.json: -------------------------------------------------------------------------------- 1 | { 2 | "privkey": "9f24af64906c916fae5a07f33005149a89a22d5ca97bdfbfbbdddbba39c49796", 3 | "contract": "0xe12025dd2f2373e30c2ecf920c992da40311cd48", 4 | "bytecode": "6060604052341561000f57600080fd5b6101818061001e6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063a6226f2114610051578063b051c1e01461007d575b600080fd5b341561005c57600080fd5b61007b60048080359060200190919080359060200190919050506100b4565b005b341561008857600080fd5b61009e6004808035906020019091905050610136565b6040518082815260200191505060405180910390f35b60007fb45ab3e8c50935ce2fa51d37817fd16e7358a3087fd93a9ac7fbddb22a926c358383604051808381526020018281526020019250505060405180910390a1828160000181905550818160010181905550806000808581526020019081526020016000206000820154816000015560018201548160010155905050505050565b60008060008381526020019081526020016000206001015490509190505600a165627a7a723058207eaf119132cfc4008c97339b874c4c16d20d27a72875e55a6a22a29fee30876d0029" 5 | } 6 | -------------------------------------------------------------------------------- /scripts/bench/contracts/sample/sample_read.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract" : "0xe12025dd2f2373e30c2ecf920c992da40311cd48", 3 | "privkey" : "9f24af64906c916fae5a07f33005149a89a22d5ca97bdfbfbbdddbba39c49796", 4 | "function" : "getPremiumInfos", 5 | "params":[ 6 | 1 7 | ] 8 | } -------------------------------------------------------------------------------- /scripts/bench/contracts/simple/greeter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | The following is an extremely basic example of a solidity contract. 3 | It takes a string upon creation and then repeats it when greet() is called. 4 | */ 5 | 6 | contract Greeter { // The contract definition. A constructor of the same name will be automatically called on contract creation. 7 | address creator; // At first, an empty "address"-type variable of the name "creator". Will be set in the constructor. 8 | string greeting; // At first, an empty "string"-type variable of the name "greeting". Will be set in constructor and can be changed. 9 | 10 | function Greeter(string _greeting) public { // The constructor. It accepts a string input and saves it to the contract's "greeting" variable. 11 | creator = msg.sender; 12 | greeting = _greeting; 13 | } 14 | 15 | function greet() constant returns (string) { 16 | return greeting; 17 | } 18 | 19 | function getBlockNumber() constant returns (uint) { // this doesn't have anything to do with the act of greeting 20 | // just demonstrating return of some global variable 21 | return block.number; 22 | } 23 | 24 | function setGreeting(string _newgreeting) { 25 | greeting = _newgreeting; 26 | } 27 | 28 | // Standard kill() function to recover funds 29 | function kill() { 30 | if (msg.sender == creator) // only allow this action if the account sending the signal is the creator 31 | suicide(creator); // kills this contract and sends remaining funds back to creator 32 | } 33 | } -------------------------------------------------------------------------------- /scripts/bench/contracts/simple/math.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Math { 4 | function multiply(uint a) pure public returns(uint d) { 5 | return a * 7; 6 | } 7 | } -------------------------------------------------------------------------------- /scripts/bench/contracts/simple/storage.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract SimpleStorage { 4 | uint storedData; 5 | 6 | function set(uint x) public{ 7 | storedData = x; 8 | } 9 | 10 | function get() public constant returns (uint) { 11 | return storedData; 12 | } 13 | } -------------------------------------------------------------------------------- /scripts/bench/contracts/simple/token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.21; 2 | 3 | contract Token { 4 | mapping (address => uint) public balances; 5 | 6 | function Token() public{ 7 | balances[msg.sender] = 1000000; 8 | } 9 | 10 | function transfer(address _to, uint _amount) public{ 11 | if (balances[msg.sender] < _amount) { 12 | return; 13 | } 14 | 15 | balances[msg.sender] -= _amount; 16 | balances[_to] += _amount; 17 | } 18 | } -------------------------------------------------------------------------------- /scripts/bench/defaults.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const ( 4 | defaultRpcAddress = "tcp://localhost:46657" 5 | defaultAbis = "[{\"constant\":false,\"inputs\":[],\"name\":\"add\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"int32\"}],\"payable\":false,\"type\":\"function\"}]" 6 | defaultBytecode = "6060604052341561000f57600080fd5b5b6101058061001f6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680634f2be91f1460475780636d4ce63c146059575b600080fd5b3415605157600080fd5b60576085565b005b3415606357600080fd5b606960c2565b604051808260030b60030b815260200191505060405180910390f35b60008081819054906101000a900460030b8092919060010191906101000a81548163ffffffff021916908360030b63ffffffff160217905550505b565b60008060009054906101000a900460030b90505b905600a165627a7a72305820259a0a3f2a8a112df2232529a36c75cc314d05060713c663a0786913fee723160029" 7 | defaultContractAddr = "0x0f3200148775219ead5ba8d2f2bf9f0ae1f76ea9" 8 | defaultToAccountAddr = "0x7752b42608a0f1943c19fc5802cb027e60b4c911" 9 | defaultPrivKey = "7d73c3dafd3c0215b8526b26f8dbdb93242fc7dcfbdfa1000d93436d577c3b94" 10 | defaultChainID = "annchain-genesis" 11 | ) 12 | -------------------------------------------------------------------------------- /scripts/examples/evm/commands.sh: -------------------------------------------------------------------------------- 1 | ./rtool --backend="tcp://localhost:46657" evm create --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.json --abif /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.abi --nonce 0 2 | 3 | ./rtool --backend="tcp://localhost:46657" evm exist --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample_exist.json 4 | 5 | ./rtool --backend="tcp://localhost:46657" query nonce --address aaf40b3b7d103b01e89c7aa489ed186c5467dabf 6 | 7 | ./rtool --backend="tcp://localhost:46657" evm call --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample_execute.json --abif /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.abi --nonce 1 8 | 9 | ./rtool --backend="tcp://localhost:46657" evm read --callf /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample_read.json --abif /Users/za/workspace/src/gitlab.zhonganonline.com/ann/rendezvous/scripts/examples/evm/sample.abi --nonce 2 10 | -------------------------------------------------------------------------------- /scripts/examples/evm/sample.abi: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": false, 4 | "inputs": [ 5 | { 6 | "name": "Id", 7 | "type": "uint256" 8 | }, 9 | { 10 | "name": "Amount", 11 | "type": "uint256" 12 | } 13 | ], 14 | "name": "createCheckInfos", 15 | "outputs": [], 16 | "payable": false, 17 | "stateMutability": "nonpayable", 18 | "type": "function" 19 | }, 20 | { 21 | "constant": true, 22 | "inputs": [ 23 | { 24 | "name": "Id", 25 | "type": "uint256" 26 | } 27 | ], 28 | "name": "getPremiumInfos", 29 | "outputs": [ 30 | { 31 | "name": "", 32 | "type": "uint256" 33 | } 34 | ], 35 | "payable": false, 36 | "stateMutability": "view", 37 | "type": "function" 38 | }, 39 | { 40 | "anonymous": false, 41 | "inputs": [ 42 | { 43 | "indexed": false, 44 | "name": "Id", 45 | "type": "uint256" 46 | }, 47 | { 48 | "indexed": false, 49 | "name": "Amount", 50 | "type": "uint256" 51 | } 52 | ], 53 | "name": "InputLog", 54 | "type": "event" 55 | } 56 | ] -------------------------------------------------------------------------------- /scripts/examples/evm/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "bytecode" : "6060604052341561000f57600080fd5b6101818061001e6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063a6226f2114610051578063b051c1e01461007d575b600080fd5b341561005c57600080fd5b61007b60048080359060200190919080359060200190919050506100b4565b005b341561008857600080fd5b61009e6004808035906020019091905050610136565b6040518082815260200191505060405180910390f35b60007fb45ab3e8c50935ce2fa51d37817fd16e7358a3087fd93a9ac7fbddb22a926c358383604051808381526020018281526020019250505060405180910390a1828160000181905550818160010181905550806000808581526020019081526020016000206000820154816000015560018201548160010155905050505050565b60008060008381526020019081526020016000206001015490509190505600a165627a7a723058207eaf119132cfc4008c97339b874c4c16d20d27a72875e55a6a22a29fee30876d0029", 3 | "params" :[] 4 | } -------------------------------------------------------------------------------- /scripts/examples/evm/sample_execute.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract" : "0xb001c1da1e0491a7abe8b0e1d55c4874df62dd28", 3 | "function" : "createCheckInfos", 4 | "params":[ 5 | 1, 100 6 | ] 7 | } -------------------------------------------------------------------------------- /scripts/examples/evm/sample_exist.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract": "0xb001c1da1e0491a7abe8b0e1d55c4874df62dd28", 3 | "bytecode": "6060604052341561000f57600080fd5b6101818061001e6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063a6226f2114610051578063b051c1e01461007d575b600080fd5b341561005c57600080fd5b61007b60048080359060200190919080359060200190919050506100b4565b005b341561008857600080fd5b61009e6004808035906020019091905050610136565b6040518082815260200191505060405180910390f35b60007fb45ab3e8c50935ce2fa51d37817fd16e7358a3087fd93a9ac7fbddb22a926c358383604051808381526020018281526020019250505060405180910390a1828160000181905550818160010181905550806000808581526020019081526020016000206000820154816000015560018201548160010155905050505050565b60008060008381526020019081526020016000206001015490509190505600a165627a7a723058207eaf119132cfc4008c97339b874c4c16d20d27a72875e55a6a22a29fee30876d0029" 4 | } 5 | -------------------------------------------------------------------------------- /scripts/examples/evm/sample_read.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract" : "0xb001c1da1e0491a7abe8b0e1d55c4874df62dd28", 3 | "function" : "getPremiumInfos", 4 | "params":[ 5 | 1 6 | ] 7 | } -------------------------------------------------------------------------------- /utils/file.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "os/user" 8 | "path" 9 | "strings" 10 | ) 11 | 12 | func PathExists(path string) (bool, error) { 13 | _, err := os.Stat(path) 14 | if err == nil { 15 | return true, nil 16 | } 17 | if os.IsNotExist(err) { 18 | return false, nil 19 | } 20 | return false, err 21 | } 22 | 23 | func FileExists(filename string) bool { 24 | fi, err := os.Lstat(filename) 25 | if fi != nil || (err != nil && !os.IsNotExist(err)) { 26 | return true 27 | } 28 | return false 29 | } 30 | 31 | func ExpandPath(p string) string { 32 | if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") { 33 | if home := HomeDir(); home != "" { 34 | p = home + p[1:] 35 | } 36 | } 37 | return path.Clean(os.ExpandEnv(p)) 38 | } 39 | 40 | func HomeDir() string { 41 | if home := os.Getenv("HOME"); home != "" { 42 | return home 43 | } 44 | if usr, err := user.Current(); err == nil { 45 | return usr.HomeDir 46 | } 47 | return "" 48 | } 49 | 50 | func EnsureDir(dir string, mode os.FileMode) error { 51 | if _, err := os.Stat(dir); os.IsNotExist(err) { 52 | err := os.MkdirAll(dir, mode) 53 | if err != nil { 54 | return fmt.Errorf("could not create directory %v. %v", dir, err) 55 | } 56 | } 57 | return nil 58 | } 59 | 60 | func ReadFileData(str string) ([]byte, error) { 61 | path, err := PathExists(str) 62 | if err != nil || !path { 63 | fstr := strings.Replace(str, "\\\r\n", "\r\n", -1) 64 | fstr = strings.Replace(fstr, "\\\"", "\"", -1) 65 | return []byte(fstr), nil 66 | } 67 | return ioutil.ReadFile(str) 68 | } 69 | -------------------------------------------------------------------------------- /utils/request_id_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestTraceId (t *testing.T) { 11 | begin := time.Now() 12 | traceIdStr := NewTraceId(begin).String() 13 | traceId,err := TraceIDFromString(traceIdStr) 14 | assert.NoError(t,err) 15 | assert.Equal(t,traceId.Timestamp().Unix(),begin.Unix(),) 16 | 17 | } -------------------------------------------------------------------------------- /version/gemmill.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ZhongAn Information Technology Services Co.,Ltd. 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 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "io/ioutil" 20 | "os" 21 | "path/filepath" 22 | "strings" 23 | 24 | "github.com/dappledger/AnnChain/gemmill" 25 | ) 26 | 27 | func getCommitHash() (hash string, err error) { 28 | 29 | goPath := os.Getenv("GOPATH") 30 | paths := strings.Split(goPath, ":") 31 | 32 | var bytez []byte 33 | for _, v := range paths { 34 | rootPwd := filepath.Join(v, "src", "github.com/dappledger/AnnChain/gemmill") 35 | bytez, err = ioutil.ReadFile(filepath.Join(rootPwd, ".git/HEAD")) 36 | if err != nil { 37 | continue 38 | } 39 | 40 | hash = string(bytez) 41 | prefix := hash[:4] 42 | if prefix == "ref:" { 43 | file := filepath.Join(rootPwd, ".git", hash[5:len(hash)-1]) 44 | bytez, err = ioutil.ReadFile(file) 45 | if err != nil { 46 | break 47 | } 48 | hash = string(bytez) 49 | } 50 | return 51 | } 52 | return 53 | } 54 | 55 | func main() { 56 | 57 | hash, _ := getCommitHash() 58 | if len(hash) > 8 { 59 | hash = hash[:8] 60 | } 61 | fmt.Printf("%s-%s\n", gemmill.Gversion, hash) 62 | } 63 | --------------------------------------------------------------------------------