├── system ├── p2p │ ├── dht │ │ ├── readme.md │ │ ├── protocol │ │ │ ├── readme.md │ │ │ ├── broadcast │ │ │ │ ├── batchtx_test.go │ │ │ │ ├── const.go │ │ │ │ └── batchtx.go │ │ │ ├── peer │ │ │ │ ├── statistic_test.go │ │ │ │ └── statistic.go │ │ │ └── snow │ │ │ │ ├── util.go │ │ │ │ └── snow.go │ │ ├── load.go │ │ ├── extension │ │ │ ├── mdns_test.go │ │ │ ├── pubsub_test.go │ │ │ └── mdns.go │ │ ├── manage │ │ │ └── peerinfo_test.go │ │ └── types │ │ │ └── const.go │ └── init │ │ └── init.go ├── README.md ├── dapp │ ├── coins │ │ ├── cmd │ │ │ ├── Makefile │ │ │ └── build.sh │ │ ├── proto │ │ │ ├── Makefile │ │ │ ├── create_protobuf.sh │ │ │ └── coins.proto │ │ ├── plugin.go │ │ ├── autotest │ │ │ └── coins.go │ │ └── executor │ │ │ └── exec_del_local.go │ ├── manage │ │ ├── proto │ │ │ ├── Makefile │ │ │ ├── create_protobuf.sh │ │ │ └── manage.proto │ │ ├── executor │ │ │ ├── manage_test.go │ │ │ ├── kv.go │ │ │ └── exec_del_local.go │ │ ├── types │ │ │ ├── errors.go │ │ │ └── const.go │ │ └── plugin.go │ ├── none │ │ ├── proto │ │ │ ├── Makefile │ │ │ ├── create_protobuf.sh │ │ │ └── none.proto │ │ ├── executor │ │ │ ├── key.go │ │ │ ├── exec_del_local.go │ │ │ ├── exec_local.go │ │ │ ├── query.go │ │ │ └── exec.go │ │ ├── plugin.go │ │ └── README.md │ ├── init │ │ └── init.go │ └── commands │ │ ├── version.go │ │ └── system.go ├── store │ ├── mavl │ │ └── db │ │ │ ├── proto │ │ │ ├── Makefile │ │ │ ├── create_protobuf.sh │ │ │ └── ticket.chain33.proto │ │ │ ├── ticket │ │ │ └── ticket.go │ │ │ └── util.go │ ├── init │ │ └── init.go │ └── store.go ├── crypto │ ├── secp256k1eth │ │ └── proto │ │ │ └── create_protobuf.sh │ ├── sm2 │ │ └── test │ │ │ └── authdir │ │ │ └── crypto │ │ │ ├── keystore │ │ │ └── 751004e7c40c58b0cf28a6b6807d036322729053c937889f3a73cbf35abbcf14_sk │ │ │ ├── signcerts │ │ │ └── user1@org1-cert.pem │ │ │ ├── cacerts │ │ │ └── ca-cert.pem │ │ │ └── intermediatecerts │ │ │ └── org1-cert.pem │ ├── secp256r1 │ │ └── test │ │ │ └── authdir │ │ │ └── crypto │ │ │ ├── keystore │ │ │ └── 06ee57018012f4e3c354c0c321b3f3c08cc420c1973f91c93db9c867695e03a4_sk │ │ │ ├── signcerts │ │ │ └── user1@org1-cert.pem │ │ │ ├── cacerts │ │ │ └── org1@ca-cert.pem │ │ │ └── intermediatecerts │ │ │ └── org1-cert.pem │ ├── common │ │ ├── cert.chain33.proto │ │ └── authority │ │ │ └── core │ │ │ └── validator.go │ ├── btcscript │ │ └── script │ │ │ ├── sign.proto │ │ │ └── errors.go │ ├── init │ │ └── init.go │ └── none │ │ ├── none_test.go │ │ └── none.go ├── address │ ├── init.go │ └── btc │ │ └── utxo.go ├── mempool │ ├── doc.go │ ├── init │ │ └── init.go │ ├── timeline │ │ ├── timeline_test.go │ │ └── timeline.go │ ├── const.go │ ├── mempool.go │ ├── lasttx.go │ └── pipeline.go ├── consensus │ ├── snowman │ │ ├── utils │ │ │ └── util.go │ │ └── readme.md │ ├── init │ │ └── init.go │ └── finalize.go └── init.go ├── wallet ├── bipwallet │ ├── basen │ │ ├── .travis.yml │ │ ├── README │ │ └── LICENSE │ ├── transformer │ │ ├── btcbase │ │ │ ├── btc_wallet_gene.png │ │ │ ├── loader.go │ │ │ └── README.md │ │ └── transformer.go │ ├── btcutilecc │ │ ├── README.md │ │ ├── .gitignore │ │ ├── ecdh.go │ │ ├── keys.go │ │ ├── random.go │ │ ├── examples │ │ │ ├── ecdh │ │ │ │ └── ecdh.go │ │ │ └── blind │ │ │ │ └── blind.go │ │ ├── blind.go │ │ └── arith.go │ ├── go-bip39 │ │ ├── glide.yaml │ │ ├── glide.lock │ │ ├── .gitignore │ │ ├── README.md │ │ └── LICENSE │ ├── go-bip32 │ │ └── LICENSE │ └── go-bip44 │ │ ├── LICENSE │ │ └── bitLength_test.go ├── keys.go └── common │ ├── mine_status_report.go │ └── crypto.go ├── types ├── Makefile ├── proto │ ├── create_protobuf.sh │ ├── snowman.proto │ ├── evm_event.proto │ ├── push_tx_receipt.proto │ └── statistic.proto ├── doc.go ├── key_test.go ├── chaincfg │ └── cfg.go ├── log_test.go ├── jsonpb │ ├── regenerate.sh │ ├── parse.go │ └── jsonpb_proto │ │ └── test3.proto ├── sign_test.go ├── time.go ├── fork_test.go └── sign.md ├── cmd ├── miner_accounts │ ├── accounts │ │ ├── create_protobuf.sh │ │ └── account.proto │ ├── miner_accounts.toml │ └── test.txt ├── write │ └── write.toml ├── tools │ ├── tasks │ │ ├── tasks_test.go │ │ ├── task.go │ │ ├── taskbase.go │ │ ├── check_file_existed_task.go │ │ ├── format_dappsource_task.go │ │ └── create_file_from_str_template_task.go │ ├── gencode │ │ ├── const.go │ │ ├── base │ │ │ ├── codetype.go │ │ │ └── base.go │ │ ├── init.go │ │ └── dappcode │ │ │ ├── init.go │ │ │ ├── cmd │ │ │ └── cmd.go │ │ │ ├── commands │ │ │ └── commands.go │ │ │ └── plugin.go │ ├── doc.go │ ├── main.go │ ├── doc │ │ └── calculator.proto │ └── commands │ │ ├── createplugin.go │ │ ├── updateinit.go │ │ └── gendapp.go ├── cli │ ├── buildflags │ │ └── flags.go │ ├── cli.go │ └── autocomplete │ │ └── readme.md ├── chain33 │ ├── main.go │ ├── chain33.system.fork.toml │ └── chain33.fork.toml ├── autotest │ ├── autotest.toml │ ├── main.go │ └── types │ │ ├── simpleCase.go │ │ └── types.go └── dht_crawler │ └── bar.go ├── common ├── db │ ├── table │ │ ├── proto │ │ │ ├── create_protobuf.sh │ │ │ └── game.proto │ │ ├── error.go │ │ └── count_test.go │ └── mocks │ │ └── kv.go ├── crypto │ ├── sha3 │ │ ├── testdata │ │ │ └── keccakKats.json.deflate │ │ ├── keccakf_amd64.go │ │ ├── register.go │ │ ├── xor.go │ │ └── xor_generic.go │ ├── README.md │ └── client │ │ └── client_test.go ├── doc.go ├── log │ └── log15 │ │ ├── term │ │ ├── terminal_solaris.go │ │ ├── terminal_netbsd.go │ │ ├── terminal_openbsd.go │ │ ├── terminal_appengine.go │ │ ├── terminal_darwin.go │ │ ├── terminal_linux.go │ │ ├── terminal_freebsd.go │ │ ├── terminal_notwindows.go │ │ ├── terminal_windows.go │ │ └── LICENSE │ │ ├── LICENSE │ │ ├── handler_go14.go │ │ ├── handler_go13.go │ │ └── CONTRIBUTORS ├── address │ ├── README.md │ ├── types.go │ ├── util_test.go │ └── util.go ├── limits │ ├── limits_windows.go │ └── limits_plan9.go ├── utils │ ├── util_test.go │ └── ip.go ├── listmap │ └── listmap_test.go └── ntp_test.go ├── mempool ├── doc.go └── mempool.go ├── proto ├── .github ├── ISSUE_TEMPLATE │ ├── custom.md │ ├── feature_request.md │ └── bug_report.md └── workflows │ ├── manual_make_bin.yml │ └── release.yml ├── blockchain ├── doc.go ├── ntp_test.go ├── blockchain_test.go ├── push_design.md ├── mocks │ └── post_service.go ├── exec.go ├── reduce_real_test.go └── query.go ├── client ├── doc.go ├── mock_execs_test.go ├── mock_consensus_test.go └── mock_p2p_test.go ├── queue ├── client_test.go └── doc.go ├── appveyor.yml ├── doc.go ├── p2p └── utils │ └── utils.go ├── .clang-format ├── util ├── calccommit_test.go ├── calccommit.go └── exec_test.go ├── pluginmgr └── plugin.go ├── store └── store.go ├── executor ├── doc.go └── plugin_kvmvcc.go ├── metrics └── influxdb │ ├── README.md │ └── LICENSE ├── consensus └── consensus.go ├── rpc ├── ethrpc │ ├── web3 │ │ ├── web3_test.go │ │ └── web3.go │ └── net │ │ └── net.go └── types │ └── server.go ├── .gitignore ├── account └── genesis_test.go ├── LICENSE └── .releaserc.yml /system/p2p/dht/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /system/README.md: -------------------------------------------------------------------------------- 1 | ## dapp dir 2 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /wallet/bipwallet/basen/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /types/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd proto && ./create_protobuf.sh 3 | -------------------------------------------------------------------------------- /system/dapp/coins/cmd/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | bash build.sh $(OUT) $(FLAG) 3 | -------------------------------------------------------------------------------- /system/dapp/coins/proto/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | sh ./create_protobuf.sh 3 | -------------------------------------------------------------------------------- /system/dapp/manage/proto/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | sh ./create_protobuf.sh 3 | -------------------------------------------------------------------------------- /system/dapp/none/proto/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | sh ./create_protobuf.sh 3 | -------------------------------------------------------------------------------- /system/store/mavl/db/proto/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | sh ./create_protobuf.sh 3 | -------------------------------------------------------------------------------- /types/proto/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:../../../../../ ./*.proto 3 | -------------------------------------------------------------------------------- /cmd/miner_accounts/accounts/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:. ./*.proto* 3 | -------------------------------------------------------------------------------- /common/db/table/proto/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:. ./*.proto --proto_path=. 3 | -------------------------------------------------------------------------------- /mempool/doc.go: -------------------------------------------------------------------------------- 1 | package mempool 2 | 3 | //交易打包排序相关的模块 4 | //模块功能:模块主要的功能是实现共识排序的功能,包括完整的共识的实现。 5 | 6 | //接口设计: 7 | -------------------------------------------------------------------------------- /system/crypto/secp256k1eth/proto/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:../../../../../../../ ./*.proto 3 | -------------------------------------------------------------------------------- /system/dapp/manage/executor/manage_test.go: -------------------------------------------------------------------------------- 1 | package executor_test 2 | 3 | import ( 4 | _ "github.com/33cn/chain33/system" 5 | ) 6 | -------------------------------------------------------------------------------- /proto: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | myPath="$1/proto" 4 | if [ -d "$myPath" ]; then 5 | cd $myPath || exit 6 | echo "make $1 ..." 7 | make 8 | fi -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | 5 | --- 6 | 7 | 8 | -------------------------------------------------------------------------------- /common/crypto/sha3/testdata/keccakKats.json.deflate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/33cn/chain33/HEAD/common/crypto/sha3/testdata/keccakKats.json.deflate -------------------------------------------------------------------------------- /cmd/write/write.toml: -------------------------------------------------------------------------------- 1 | [userWriteConf] 2 | receiveAddr = "1KcdP2GJeeob69hjg5kzR2mSwXTkXF5Kgv" 3 | CurrentHeight = 0 4 | CurrentIndex = 0 5 | heightFile = "height.txt" -------------------------------------------------------------------------------- /wallet/bipwallet/transformer/btcbase/btc_wallet_gene.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/33cn/chain33/HEAD/wallet/bipwallet/transformer/btcbase/btc_wallet_gene.png -------------------------------------------------------------------------------- /system/crypto/sm2/test/authdir/crypto/keystore/751004e7c40c58b0cf28a6b6807d036322729053c937889f3a73cbf35abbcf14_sk: -------------------------------------------------------------------------------- 1 | 0x42e37115dec1d18568f9f4eae56d34ea1a8db07203c268b1a5e6ebdf7c07ccef -------------------------------------------------------------------------------- /system/crypto/secp256r1/test/authdir/crypto/keystore/06ee57018012f4e3c354c0c321b3f3c08cc420c1973f91c93db9c867695e03a4_sk: -------------------------------------------------------------------------------- 1 | 0xabaeb9eb3bb6d110bd655f0f8bd5f39a0900e35e8ba18b52b8ba3da9cb849a43 -------------------------------------------------------------------------------- /system/dapp/coins/proto/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. --proto_path="$GOPATH/src/github.com/33cn/chain33/types/proto/" 3 | -------------------------------------------------------------------------------- /system/dapp/manage/proto/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. --proto_path="$GOPATH/src/github.com/33cn/chain33/types/proto/" 3 | -------------------------------------------------------------------------------- /system/dapp/none/proto/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. --proto_path="$GOPATH/src/github.com/33cn/chain33/types/proto/" 3 | -------------------------------------------------------------------------------- /system/store/mavl/db/proto/create_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --go_out=plugins=grpc:../ticket ./*.proto --proto_path=. --proto_path="$GOPATH/src/github.com/33cn/chain33/types/proto/" 3 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/README.md: -------------------------------------------------------------------------------- 1 | btcutil 2 | ======= 3 | 4 | Utility functions for Bitcoin elliptic curve cryptography. 5 | 6 | Install with 7 | 8 | go get github.com/mndrix/btcutil 9 | -------------------------------------------------------------------------------- /cmd/tools/tasks/tasks_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 tasks 6 | -------------------------------------------------------------------------------- /system/address/init.go: -------------------------------------------------------------------------------- 1 | package address 2 | 3 | import ( 4 | _ "github.com/33cn/chain33/system/address/btc" //init btc address driver 5 | _ "github.com/33cn/chain33/system/address/eth" //init eth address driver 6 | ) 7 | -------------------------------------------------------------------------------- /wallet/bipwallet/basen/README: -------------------------------------------------------------------------------- 1 | basen (base-N) is a simple Go encoding package for representing bytes as big integers in arbitrary base-N encoding. 2 | 3 | See https://godoc.org/github.com/cmars/basen for package documentation. 4 | -------------------------------------------------------------------------------- /system/crypto/common/cert.chain33.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // TODO 这个结构需要迁移到crypto/types.go中 4 | message CertSignature { 5 | bytes signature = 1; 6 | bytes cert = 2; 7 | bytes uid = 3; 8 | } 9 | -------------------------------------------------------------------------------- /system/dapp/coins/cmd/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | strpwd=$(pwd) 4 | strcmd=${strpwd##*dapp/} 5 | strapp=${strcmd%/cmd*} 6 | 7 | OUT_DIR="${1}/system/$strapp" 8 | #FLAG=$2 9 | 10 | mkdir -p "${OUT_DIR}" 11 | cp ./build/* "${OUT_DIR}" 12 | -------------------------------------------------------------------------------- /types/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | //模块的主要功能:基本的数据结构的定义,各个模块可能都会共享这个数据结构 8 | //主要的数据结构的列表: 9 | -------------------------------------------------------------------------------- /common/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 common 6 | 7 | //common 模块的主要功能:模块共享的一些函数,类放到这个模块中来 8 | //common 主要的函数的列表: 9 | -------------------------------------------------------------------------------- /blockchain/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 blockchain 6 | 7 | //区块链相关的模块: 8 | //包括区块链的结构,区块链数据的存储 9 | //接口设计: 10 | -------------------------------------------------------------------------------- /system/mempool/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 mempool 6 | 7 | //mempool 模块的功能:实现交易暂存的功能。主要是解决共识模块可能比rpc模块速度慢的问题。 8 | //模块的接口的设计: 9 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip39/glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/FactomProject/go-bip39 2 | import: 3 | - package: golang.org/x/crypto 4 | subpackages: 5 | - pbkdf2 6 | testImport: 7 | - package: github.com/stretchr/testify 8 | version: ~1.1.4 9 | subpackages: 10 | - assert 11 | -------------------------------------------------------------------------------- /system/consensus/snowman/utils/util.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "errors" 4 | 5 | var ( 6 | // ErrBlockNotReady block not ready 7 | ErrBlockNotReady = errors.New("ErrBlockNotReady") 8 | // ErrValidatorSample sample validator error 9 | ErrValidatorSample = errors.New("ErrValidatorSample") 10 | ) 11 | -------------------------------------------------------------------------------- /client/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 client 6 | 7 | /* 8 | 封装模块间通过queue消息队列进行交互的调用,将其抽象成对应的接口QueueProtocolAPI 9 | 简化外部调用模块间通信的处理,并屏蔽对细节的感知 10 | */ 11 | -------------------------------------------------------------------------------- /common/db/table/proto/game.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package proto; 4 | 5 | option go_package = "proto"; 6 | 7 | message Game { 8 | string gameID = 1; 9 | int64 status = 2; 10 | } 11 | 12 | message GameAddr { 13 | string txhash = 1; 14 | string gameID = 2; 15 | string addr = 3; 16 | } -------------------------------------------------------------------------------- /system/mempool/init/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 init 6 | 7 | import ( 8 | _ "github.com/33cn/chain33/system/mempool/timeline" //最简单的排队模式,按照时间 9 | ) 10 | -------------------------------------------------------------------------------- /system/p2p/init/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 init init dht 6 | package init 7 | 8 | import ( 9 | _ "github.com/33cn/chain33/system/p2p/dht" //基于libp2p dht网络 10 | ) 11 | -------------------------------------------------------------------------------- /cmd/cli/buildflags/flags.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 buildflags build flags 6 | package buildflags 7 | 8 | // var 9 | var ( 10 | ParaName string 11 | RPCAddr string 12 | ) 13 | -------------------------------------------------------------------------------- /cmd/tools/gencode/const.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 gencode 6 | 7 | const ( 8 | //ProtoFileAppendService proto文件service 9 | ProtoFileAppendService = ` 10 | service ${EXECNAME} { 11 | 12 | }` 13 | ) 14 | -------------------------------------------------------------------------------- /system/store/init/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 init 初始化系统store包 6 | package init 7 | 8 | import ( 9 | // Register some standard stuff 10 | _ "github.com/33cn/chain33/system/store/mavl" 11 | ) 12 | -------------------------------------------------------------------------------- /cmd/tools/tasks/task.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 tasks 处理的事务任务 6 | package tasks 7 | 8 | // Task 处理的事务任务 9 | type Task interface { 10 | GetName() string 11 | Next() Task 12 | SetNext(t Task) 13 | 14 | Execute() error 15 | } 16 | -------------------------------------------------------------------------------- /wallet/keys.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 wallet 6 | 7 | const ( 8 | keyWalletPassKey = "WalletPassKey" 9 | ) 10 | 11 | // CalcWalletPassKey 获取钱包密码的数据库字段Key值 12 | func CalcWalletPassKey() []byte { 13 | return []byte(keyWalletPassKey) 14 | } 15 | -------------------------------------------------------------------------------- /wallet/common/mine_status_report.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 common 6 | 7 | // MineStatusReport 挖矿操作状态 8 | type MineStatusReport interface { 9 | IsAutoMining() bool 10 | // 返回挖矿买票锁的状态 11 | IsTicketLocked() bool 12 | PolicyName() string 13 | } 14 | -------------------------------------------------------------------------------- /cmd/chain33/main.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 main chain33程序入口 6 | package main 7 | 8 | import ( 9 | _ "github.com/33cn/chain33/system" 10 | "github.com/33cn/chain33/util/cli" 11 | ) 12 | 13 | func main() { 14 | cli.RunChain33("", "") 15 | } 16 | -------------------------------------------------------------------------------- /cmd/tools/gencode/base/codetype.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 base 6 | 7 | // DappCodeFile dapp code source 8 | type DappCodeFile struct { 9 | CodeFile 10 | } 11 | 12 | // GetCodeType get code type 13 | func (DappCodeFile) GetCodeType() string { 14 | return "dapp" 15 | } 16 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | # Editor temporary files 25 | *.swp 26 | -------------------------------------------------------------------------------- /system/consensus/init/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 init 初始化系统共识插件 6 | package init 7 | 8 | import ( 9 | // init snowman finalize consensus 10 | _ "github.com/33cn/chain33/system/consensus/snowman" 11 | //初始化 12 | _ "github.com/33cn/chain33/system/consensus/solo" 13 | ) 14 | -------------------------------------------------------------------------------- /cmd/tools/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | /* 6 | 更新初始化文件: 7 | 8 | 扫描指定path目录下所有的插件,根据扫描到的结果重新更新consensus、dapp和、store、mempool的初始化文件 init.go 9 | 使用方式:./tools updateinit -p $(YourPluginPath) 10 | 例子:./tools updateinit -p /GOPATH/src/github.com/33cn/chain33/cmd/tools/plugin 11 | */ 12 | package main 13 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_solaris.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 term 6 | 7 | import "golang.org/x/sys/unix" 8 | 9 | // IsTty returns true if the given file descriptor is a terminal. 10 | func IsTty(fd uintptr) bool { 11 | _, err := unix.IoctlGetTermios(int(fd), unix.TCGETA) 12 | return err == nil 13 | } 14 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_netbsd.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 term 6 | 7 | import "syscall" 8 | 9 | const ioctlReadTermios = syscall.TIOCGETA 10 | 11 | // Termios functions describe a general terminal interface that is 12 | // provided to control asynchronous communications ports. 13 | type Termios syscall.Termios 14 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_openbsd.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 term 6 | 7 | import "syscall" 8 | 9 | const ioctlReadTermios = syscall.TIOCGETA 10 | 11 | // Termios functions describe a general terminal interface that is 12 | // provided to control asynchronous communications ports. 13 | type Termios syscall.Termios 14 | -------------------------------------------------------------------------------- /queue/client_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 queue 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/stretchr/testify/assert" 11 | ) 12 | 13 | func TestSetTopic(t *testing.T) { 14 | client := &client{} 15 | hi := "hello" 16 | client.setTopic(hi) 17 | ret := client.getTopic() 18 | assert.Equal(t, hi, ret) 19 | } 20 | -------------------------------------------------------------------------------- /system/dapp/coins/proto/coins.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package types; 4 | 5 | import "transaction.proto"; 6 | 7 | option go_package = "types"; 8 | 9 | // message for execs.coins 10 | message CoinsAction { 11 | oneof value { 12 | AssetsTransfer transfer = 1; 13 | AssetsWithdraw withdraw = 4; 14 | AssetsGenesis genesis = 2; 15 | AssetsTransferToExec transferToExec = 5; 16 | } 17 | int32 ty = 3; 18 | } -------------------------------------------------------------------------------- /system/dapp/init/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 init 初始化系统dapp包 6 | package init 7 | 8 | import ( 9 | _ "github.com/33cn/chain33/system/dapp/coins" // register coins package 10 | _ "github.com/33cn/chain33/system/dapp/manage" // register manage package 11 | _ "github.com/33cn/chain33/system/dapp/none" // register none package 12 | ) 13 | -------------------------------------------------------------------------------- /system/dapp/manage/executor/kv.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import ( 8 | "fmt" 9 | 10 | mty "github.com/33cn/chain33/system/dapp/manage/types" 11 | "github.com/33cn/chain33/types" 12 | ) 13 | 14 | func managerIDKey(id string) []byte { 15 | return []byte(fmt.Sprintf("%s-%s", types.ManagePrefix+mty.ManageX+"-id", id)) 16 | } 17 | -------------------------------------------------------------------------------- /system/dapp/none/executor/key.go: -------------------------------------------------------------------------------- 1 | package executor 2 | 3 | /* 4 | * 用户合约存取kv数据时,key值前缀需要满足一定规范 5 | * 即key = keyPrefix + userKey 6 | * 需要字段前缀查询时,使用’-‘作为分割符号 7 | */ 8 | 9 | var ( 10 | //keyPrefixStateDB state db key必须前缀 11 | keyPrefixStateDB = "mavl-none-" 12 | //keyPrefixLocalDB local db的key必须前缀 13 | //keyPrefixLocalDB = "LODB-none-" 14 | ) 15 | 16 | // delay transaction hash key 17 | func formatDelayTxKey(txHash []byte) []byte { 18 | return append([]byte(keyPrefixStateDB), txHash...) 19 | } 20 | -------------------------------------------------------------------------------- /system/p2p/dht/load.go: -------------------------------------------------------------------------------- 1 | package dht 2 | 3 | import ( 4 | _ "github.com/33cn/chain33/system/p2p/dht/protocol/broadcast" //register init package 5 | _ "github.com/33cn/chain33/system/p2p/dht/protocol/download" //register init package 6 | _ "github.com/33cn/chain33/system/p2p/dht/protocol/p2pstore" //register init package 7 | _ "github.com/33cn/chain33/system/p2p/dht/protocol/peer" //register init package 8 | _ "github.com/33cn/chain33/system/p2p/dht/protocol/snow" // load package 9 | ) 10 | -------------------------------------------------------------------------------- /cmd/autotest/autotest.toml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #######该配置文件仅为示例,具体使用autotest时,根据需要调整配置 5 | 6 | 7 | #chain33的客户端文件 8 | cliCmd = "./chain33-cli" 9 | #发送一笔交易后等待回执的超时时间,单位秒 10 | checkTimeout = 60 11 | 12 | [[TestCaseFile]] 13 | dapp = "coins" 14 | filename = "coins.toml" 15 | 16 | [[TestCaseFile]] 17 | dapp = "token" 18 | filename = "token.toml" 19 | 20 | [[TestCaseFile]] 21 | dapp = "trade" 22 | filename = "trade.toml" 23 | 24 | 25 | [[TestCaseFile]] 26 | dapp = "privacy" 27 | filename = "privacy.toml" 28 | 29 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | 2 | os: Visual Studio 2019 3 | 4 | build: off 5 | 6 | clone_folder: c:\gopath\src\github.com\33cn\chain33 7 | 8 | environment: 9 | GOPATH: c:\gopath 10 | 11 | 12 | before_test: 13 | - set PATH=C:\go119\bin;%PATH% 14 | - set GOROOT=C:\go119 15 | 16 | 17 | test_script: 18 | - go version 19 | - go env 20 | - go env -w CGO_ENABLED=0 21 | - go build -o build/chain33.exe github.com/33cn/chain33/cmd/chain33 22 | - go build -o build/chain33-cli.exe github.com/33cn/chain33/cmd/cli 23 | 24 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | /* 6 | chain33 是由复杂美科技有限公司开发的区块链链框架 7 | 8 | 1. 高度可定制 9 | 10 | 2. 丰富的插件库 11 | 12 | 3. 创新的 合约 调用和组合方式 13 | */ 14 | 15 | package chain33 16 | 17 | //有些包国内需要翻墙才能下载,我们把部分参见的包含在这里 18 | import ( 19 | _ "golang.org/x/crypto/nacl/box" //register box package 20 | _ "golang.org/x/crypto/nacl/secretbox" 21 | _ "golang.org/x/crypto/ssh" 22 | ) 23 | -------------------------------------------------------------------------------- /system/crypto/btcscript/script/sign.proto: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // protoc --go_out=plugins=grpc:./ ./sign.proto 6 | 7 | syntax = "proto3"; 8 | 9 | package btcscript; 10 | option go_package = "../script"; 11 | 12 | message Signature { 13 | bytes lockScript = 1; 14 | bytes unlockScript = 2; 15 | int64 lockTime = 3; 16 | int64 utxoSequence = 4; 17 | } 18 | -------------------------------------------------------------------------------- /system/dapp/none/executor/exec_del_local.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import "github.com/33cn/chain33/types" 8 | 9 | /* 10 | * 实现区块回退时本地执行的数据清除 11 | */ 12 | 13 | // ExecDelLocal localdb kv数据自动回滚接口 14 | func (n *None) ExecDelLocal(tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { 15 | return nil, nil 16 | } 17 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/ecdh.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 btcutil 6 | 7 | import ( 8 | "crypto/ecdsa" 9 | "math/big" 10 | ) 11 | 12 | // ECDH Calculate a shared secret using elliptic curve Diffie-Hellman 13 | func ECDH(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey) *big.Int { 14 | x, _ := Secp256k1().ScalarMult(pub.X, pub.Y, priv.D.Bytes()) 15 | return x 16 | } 17 | -------------------------------------------------------------------------------- /queue/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 queue 6 | 7 | /* 8 | 主要的功能:实现消息队列的功能。 9 | 设计这个模块的原因: 10 | 为系统的分布式化,微服务化做准备。 11 | 每个模块相对来说独立,不是通过接口调用,而是通过消息进行通信。 12 | queue 的主要接口: 13 | type Client interface { 14 | Send(msg Message) (err error) //异步发送消息 15 | Wait() //等待消息处理完成 16 | Recv() chan Message 17 | Sub(topic string) (ch chan Message) //订阅消息 18 | } 19 | */ 20 | -------------------------------------------------------------------------------- /types/key_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestKeyCreate(t *testing.T) { 10 | assert.Equal(t, TotalFeeKey([]byte("1")), []byte("TotalFeeKey:1")) 11 | assert.Equal(t, CalcLocalPrefix([]byte("1")), []byte("LODB-1-")) 12 | assert.Equal(t, CalcStatePrefix([]byte("1")), []byte("mavl-1-")) 13 | assert.Equal(t, CalcRollbackKey([]byte("execer"), []byte("1")), []byte("LODB-execer-rollback-1")) 14 | assert.Equal(t, StatisticFlag(), []byte("Statistics:Flag")) 15 | } 16 | -------------------------------------------------------------------------------- /system/store/mavl/db/proto/ticket.chain33.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ticket; 3 | 4 | message Ticket { 5 | string ticketId = 1; 6 | // 0 -> 未成熟 1 -> 可挖矿 2 -> 已挖成功 3-> 已关闭 7 | int32 status = 2; 8 | // genesis 创建的私钥比较特殊 9 | bool isGenesis = 3; 10 | //创建时间 11 | int64 createTime = 4; 12 | //挖矿时间 13 | int64 minerTime = 5; 14 | //挖到的币的数目 15 | int64 minerValue = 8; 16 | string minerAddress = 6; 17 | // return wallet 18 | string returnAddress = 7; 19 | // miner Price 20 | int64 price = 9; 21 | } -------------------------------------------------------------------------------- /common/address/README.md: -------------------------------------------------------------------------------- 1 | # address 2 | >实现公钥到地址的转换, 支持实现自定义地址格式, 地址驱动插件化 3 | 4 | ## addressID 5 | > 地址驱动类型值 6 | - 每个地址驱动有唯一的类型及名称值 7 | - 类型值范围 [0, 8) 8 | - 底层相关设计, 参考chain33/types/sign.md 9 | 10 | ## 配置 11 | >地址驱动配置说明 12 | 13 | ### DefaultDriver 14 | >配置默认的地址驱动, 默认地址格式作为执行器以及未指定addressID时地址格式转换 15 | ```toml 16 | [address] #示例 17 | DefaultDriver="eth" 18 | ``` 19 | 20 | ### EnableHeight 21 | > 分叉高度配置, 即区块高度达到配置高度后启用插件, 不配置采用内置的启用高度, 负数表示不启用 22 | ```toml 23 | [address] #示例 24 | [address.enableHeight] 25 | "btc" = -1 26 | "eth"= 100 27 | ``` 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /common/limits/limits_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Copyright (c) 2013-2014 The btcsuite developers 6 | // Copyright (c) 2015-2016 The Decred developers 7 | // Use of this source code is governed by an ISC 8 | // license that can be found in the LICENSE file. 9 | 10 | package limits 11 | 12 | // SetLimits is a no-op on Windows since it's not required there. 13 | func SetLimits() error { 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /system/store/mavl/db/ticket/ticket.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 ticket 6 | 7 | var ( 8 | // TicketPrefix ticket prefix 9 | TicketPrefix = []byte("mavl-ticket-") 10 | ) 11 | 12 | const ( 13 | // StatusNewTicket new ticket status 14 | StatusNewTicket = 1 15 | // StatusMinerTicket Miner ticket status 16 | StatusMinerTicket = 2 17 | // StatusCloseTicket Close ticket status 18 | StatusCloseTicket = 3 19 | ) 20 | -------------------------------------------------------------------------------- /common/limits/limits_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Copyright (c) 2013-2014 The btcsuite developers 6 | // Copyright (c) 2015-2016 The Decred developers 7 | // Use of this source code is governed by an ISC 8 | // license that can be found in the LICENSE file. 9 | 10 | package limits 11 | 12 | // SetLimits is a no-op on Plan 9 due to the lack of process accounting. 13 | func SetLimits() error { 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /blockchain/ntp_test.go: -------------------------------------------------------------------------------- 1 | package blockchain 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/33cn/chain33/queue" 7 | "github.com/33cn/chain33/types" 8 | ) 9 | 10 | func TestCheckClockDrift(t *testing.T) { 11 | cfg := types.NewChain33Config(types.GetDefaultCfgstring()) 12 | q := queue.New("channel") 13 | q.SetConfig(cfg) 14 | 15 | blockchain := &BlockChain{} 16 | blockchain.client = q.Client() 17 | blockchain.checkClockDrift() 18 | 19 | cfg.GetModuleConfig().NtpHosts = append(cfg.GetModuleConfig().NtpHosts, types.NtpHosts...) 20 | blockchain.checkClockDrift() 21 | } 22 | -------------------------------------------------------------------------------- /system/dapp/none/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 none 系统级dapp,执行内容为空 6 | package none 7 | 8 | import ( 9 | "github.com/33cn/chain33/pluginmgr" 10 | "github.com/33cn/chain33/system/dapp/none/executor" 11 | ) 12 | 13 | func init() { 14 | pluginmgr.Register(&pluginmgr.PluginBase{ 15 | Name: "none", 16 | ExecName: executor.GetName(), 17 | Exec: executor.Init, 18 | Cmd: nil, 19 | RPC: nil, 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /system/mempool/timeline/timeline_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 timeline 6 | 7 | import ( 8 | "encoding/json" 9 | "testing" 10 | 11 | "github.com/33cn/chain33/system/mempool" 12 | "github.com/33cn/chain33/types" 13 | ) 14 | 15 | func TestNewMempool(t *testing.T) { 16 | sub, _ := json.Marshal(&mempool.SubConfig{PoolCacheSize: 2}) 17 | module := New(&types.Mempool{}, sub) 18 | mem := module.(*mempool.Mempool) 19 | mem.Close() 20 | } 21 | -------------------------------------------------------------------------------- /system/dapp/none/executor/exec_local.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import ( 8 | nty "github.com/33cn/chain33/system/dapp/none/types" 9 | "github.com/33cn/chain33/types" 10 | ) 11 | 12 | // ExecLocal_CommitDelayTx exec local commit delay tx 13 | func (n *None) ExecLocal_CommitDelayTx(commit *nty.CommitDelayTx, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { 14 | return nil, nil 15 | } 16 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_appengine.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Based on ssh/terminal: 6 | // Copyright 2013 The Go Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style 8 | // license that can be found in the LICENSE file. 9 | 10 | //go:build appengine 11 | // +build appengine 12 | 13 | package term 14 | 15 | // IsTty always returns false on AppEngine. 16 | func IsTty(fd uintptr) bool { 17 | return false 18 | } 19 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/keys.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 btcutil 6 | 7 | import ( 8 | "crypto/ecdsa" 9 | "io" 10 | ) 11 | 12 | // GenerateKey generates a public and private key pair 13 | func GenerateKey(rand io.Reader) (*ecdsa.PrivateKey, error) { 14 | return ecdsa.GenerateKey(Secp256k1(), rand) 15 | } 16 | 17 | // KeysEqual check key equal 18 | func KeysEqual(a, b *ecdsa.PublicKey) bool { 19 | return a.X.Cmp(b.X) == 0 && a.Y.Cmp(b.Y) == 0 20 | } 21 | -------------------------------------------------------------------------------- /cmd/cli/cli.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 main chain33-cli程序入口 6 | package main 7 | 8 | import ( 9 | 10 | // 这一步是必需的,目的时让插件源码有机会进行匿名注册 11 | "github.com/33cn/chain33/cmd/cli/buildflags" 12 | _ "github.com/33cn/chain33/system" 13 | "github.com/33cn/chain33/util/cli" 14 | ) 15 | 16 | func main() { 17 | if buildflags.RPCAddr == "" { 18 | buildflags.RPCAddr = "http://localhost:8801" 19 | } 20 | cli.Run(buildflags.RPCAddr, buildflags.ParaName, "") 21 | } 22 | -------------------------------------------------------------------------------- /common/crypto/sha3/keccakf_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Copyright 2015 The Go Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style 7 | // license that can be found in the LICENSE file. 8 | 9 | //go:build amd64 && !appengine && !gccgo 10 | // +build amd64,!appengine,!gccgo 11 | 12 | package sha3 13 | 14 | // This function is implemented in keccakf_amd64.s. 15 | 16 | //go:noescape 17 | 18 | func keccakF1600(a *[25]uint64) 19 | -------------------------------------------------------------------------------- /cmd/miner_accounts/miner_accounts.toml: -------------------------------------------------------------------------------- 1 | chain33host="http://120.79.156.149:8801" 2 | whitelist=["127.0.0.1", "192.168.0.114", "localhost"] 3 | jrpcBindAddr="localhost:8866" 4 | dataDir="/var/www/html/miner_accounts/" 5 | minerAddr=["1FB8L3DykVF7Y78bRfUrRcMZwesKue7CyR", "1Lw6QLShKVbKM6QvMaCQwTh5Uhmy4644CG", "1PSYYfCbtSeT1vJTvSKmQvhz8y6VhtddWi", "1BG9ZoKtgU5bhKLpcsrncZ6xdzFCgjrZud", "1G7s64AgX1ySDcUdSW5vDa8jTYQMnZktCd", "1FiDC6XWHLe7fDMhof8wJ3dty24f6aKKjK", "1AMvuuQ7V7FPQ4hkvHQdgNWy8wVL4d4hmp", "1ExRRLoJXa8LzXdNxnJvBkVNZpVw3QWMi4", "1KNGHukhbBnbWWnMYxu1C7YMoCj45Z3amm", "1AH9HRd4WBJ824h9PP1jYpvRZ4BSA4oN6Y"] 6 | coinPrecision=100000000 7 | -------------------------------------------------------------------------------- /common/log/log15/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 | -------------------------------------------------------------------------------- /system/crypto/common/authority/core/validator.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 core 6 | 7 | // Validator 证书校验器 8 | type Validator interface { 9 | Setup(config *AuthConfig) error 10 | 11 | Validate(cert []byte, pubKey []byte) error 12 | 13 | GetCertFromSignature(signature []byte) ([]byte, error) 14 | } 15 | 16 | // AuthConfig 校验器配置 17 | type AuthConfig struct { 18 | RootCerts [][]byte 19 | IntermediateCerts [][]byte 20 | RevocationList [][]byte 21 | } 22 | -------------------------------------------------------------------------------- /cmd/tools/gencode/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 gencode 6 | 7 | import ( 8 | "github.com/33cn/chain33/cmd/tools/gencode/base" 9 | _ "github.com/33cn/chain33/cmd/tools/gencode/dappcode" //init dapp code 10 | ) 11 | 12 | // GetCodeFilesWithType get code file with type 13 | func GetCodeFilesWithType(typeName string) []base.ICodeFile { 14 | 15 | if fileArr, ok := base.CodeFileManager[typeName]; ok { 16 | 17 | return fileArr 18 | } 19 | 20 | return nil 21 | } 22 | -------------------------------------------------------------------------------- /mempool/mempool.go: -------------------------------------------------------------------------------- 1 | package mempool 2 | 3 | import ( 4 | "github.com/33cn/chain33/queue" 5 | "github.com/33cn/chain33/system/mempool" 6 | "github.com/33cn/chain33/types" 7 | ) 8 | 9 | // New new mempool queue module 10 | func New(cfg *types.Chain33Config) queue.Module { 11 | mcfg := cfg.GetModuleConfig().Mempool 12 | sub := cfg.GetSubConfig().Mempool 13 | con, err := mempool.Load(mcfg.Name) 14 | if err != nil { 15 | panic("Unsupported mempool type:" + mcfg.Name + " " + err.Error()) 16 | } 17 | subcfg, ok := sub[mcfg.Name] 18 | if !ok { 19 | subcfg = nil 20 | } 21 | obj := con(mcfg, subcfg) 22 | return obj 23 | } 24 | -------------------------------------------------------------------------------- /common/address/types.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 address 6 | 7 | // Config address driver config 8 | // [address] 9 | // defaultDriver="btc" 10 | // [address.enableHeight] 11 | // btc=0 12 | // btcMultiSign=0 13 | // eth=-1 14 | type Config struct { 15 | 16 | // DefaultDriver config default driver 17 | DefaultDriver string `json:"defaultDriver,omitempty"` 18 | // EnableHeight enable driver at specific block height 19 | EnableHeight map[string]int64 `json:"enableHeight,omitempty"` 20 | } 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /blockchain/blockchain_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 blockchain 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestCalcHeightToBlockHeaderKey(t *testing.T) { 14 | key := calcHeightToBlockHeaderKey(1) 15 | require.Equal(t, key, []byte("HH:000000000001")) 16 | key = calcHeightToBlockHeaderKey(0) 17 | require.Equal(t, key, []byte("HH:000000000000")) 18 | key = calcHeightToBlockHeaderKey(10) 19 | require.Equal(t, key, []byte("HH:000000000010")) 20 | } 21 | -------------------------------------------------------------------------------- /system/mempool/const.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 mempool 6 | 7 | import ( 8 | "runtime" 9 | //log "github.com/33cn/chain33/common/log/log15" 10 | ) 11 | 12 | var ( 13 | poolCacheSize int64 = 10240 // mempool容量 14 | mempoolExpiredInterval int64 = 600 // mempool内交易过期时间,10分钟 15 | maxTxNumPerAccount int64 = 100 // TODO 每个账户在mempool中最大交易数量,10 16 | maxTxLast int64 = 10 17 | processNum int 18 | ) 19 | 20 | // TODO 21 | func init() { 22 | processNum = runtime.NumCPU() 23 | } 24 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/broadcast/batchtx_test.go: -------------------------------------------------------------------------------- 1 | package broadcast 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/33cn/chain33/types" 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func Test_batchTx(t *testing.T) { 11 | 12 | p, cancel := newTestProtocol() 13 | defer cancel() 14 | subChan := p.ps.Sub(psBroadcast) 15 | for i := 0; i < defaultMaxBatchTxNum+1; i++ { 16 | p.ps.Pub(&types.Transaction{}, psBatchTxTopic) 17 | } 18 | msg := <-subChan 19 | require.Equal(t, defaultMaxBatchTxNum, len(msg.(publishMsg).msg.(*types.Transactions).Txs)) 20 | msg = <-subChan 21 | require.Equal(t, 1, len(msg.(publishMsg).msg.(*types.Transactions).Txs)) 22 | } 23 | -------------------------------------------------------------------------------- /system/crypto/init/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 init 初始化系统加密包 6 | package init 7 | 8 | //系统级别的签名定义 9 | //为了安全考虑,默认情况下,我们希望只定义合约内部的签名,系统级别的签名对所有的合约都有效 10 | import ( 11 | //初始化 12 | _ "github.com/33cn/chain33/system/crypto/ed25519" 13 | _ "github.com/33cn/chain33/system/crypto/none" 14 | _ "github.com/33cn/chain33/system/crypto/secp256k1" 15 | _ "github.com/33cn/chain33/system/crypto/secp256k1eth" 16 | _ "github.com/33cn/chain33/system/crypto/secp256r1" 17 | _ "github.com/33cn/chain33/system/crypto/sm2" 18 | ) 19 | -------------------------------------------------------------------------------- /p2p/utils/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 utils p2p utils 6 | package utils 7 | 8 | const ( 9 | versionMask = 0xFFFF 10 | ) 11 | 12 | // CalcChannelVersion calc channel version 13 | func CalcChannelVersion(channel, version int32) int32 { 14 | return channel<<16 + version 15 | } 16 | 17 | // DecodeChannelVersion decode channel version 18 | func DecodeChannelVersion(channelVersion int32) (channel int32, version int32) { 19 | channel = channelVersion >> 16 20 | version = channelVersion & versionMask 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /blockchain/push_design.md: -------------------------------------------------------------------------------- 1 | # 使用流程 2 | ## 1.注册 3 | 分别注册区块(区块头)推送服务或者合约回执推送服务,注册成功之后就开始推送; 4 | 5 | 注册时使用rpc接口Chain33.AddPushSubscribe进行注册,一旦通过name完成注册,其他订阅用户就不能使用相同的名字进行订阅; 6 | 7 | 注册用户数最大上限为100个,超过100个,不能继续注册; 8 | 9 | ## 2.重新激活 10 | 当连续推送3次失败之后,就会停止向该用户进行推送; 11 | 如果接收应用程序重启后,需要继续接收数据,则直接通过原有注册信息激活即可,推送服务就会从上次推送成功处,继续推送; 12 | 13 | 当注册的名字name相同,不管url是否相同,会有以下几种情况,并做不同的处理: 14 | - URL不同 15 | 提示该name已经被注册,注册失败; 16 | 17 | - URL相同 18 | 如果推送已经停止,则重新开始推送; 19 | 如果推送正常,则继续推送; 20 | 21 | ## 3.注销 22 | 不能进行注销,为了防止恶意用户冒名他人进行注销或者错误地使用他人注册时的name进行注销 23 | 影响他们使用,又不想在此功能中引入身份管理功能,所以不能使用注销功能; 24 | 25 | 注销或停止接收的功能通过接收方三次拒绝接收,然后不再重新激活实现; 26 | 27 | ## 4.原有推送功能切换 28 | 该版本的推送功能被合入之后,原有的接收程序需要重新注册推送任务,但是推送的起始高度可以设置为当前接收高度; -------------------------------------------------------------------------------- /system/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 system 系统基础插件包 6 | package system 7 | 8 | import ( 9 | _ "github.com/33cn/chain33/system/address" // init address driver 10 | _ "github.com/33cn/chain33/system/consensus/init" //register consensus init package 11 | _ "github.com/33cn/chain33/system/crypto/init" 12 | _ "github.com/33cn/chain33/system/dapp/init" 13 | _ "github.com/33cn/chain33/system/mempool/init" 14 | _ "github.com/33cn/chain33/system/p2p/init" // init p2p plugin 15 | _ "github.com/33cn/chain33/system/store/init" 16 | ) 17 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip39/glide.lock: -------------------------------------------------------------------------------- 1 | hash: e1df5f2ebcb795e1a82f58d12b0740a0f8a8d45b7e83b2cd2f2b652e46202484 2 | updated: 2016-11-21T08:24:25.004085766-05:00 3 | imports: 4 | - name: golang.org/x/crypto 5 | version: 9477e0b78b9ac3d0b03822fd95422e2fe07627cd 6 | subpackages: 7 | - pbkdf2 8 | testImports: 9 | - name: github.com/davecgh/go-spew 10 | version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 11 | subpackages: 12 | - spew 13 | - name: github.com/pmezard/go-difflib 14 | version: d8ed2627bdf02c080bf22230dbb337003b7aba2d 15 | subpackages: 16 | - difflib 17 | - name: github.com/stretchr/testify 18 | version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 19 | subpackages: 20 | - assert 21 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | Language: 'Proto' 2 | BasedOnStyle: 'LLVM' 3 | AccessModifierOffset: '-1' 4 | AlignAfterOpenBracket: 'Align' 5 | AlignConsecutiveAssignments: 'true' 6 | AlignConsecutiveDeclarations: 'true' 7 | AlignEscapedNewlinesLeft: 'true' 8 | AlignOperands: 'true' 9 | AlignTrailingComments: 'true' 10 | AllowAllParametersOfDeclarationOnNextLine: 'true' 11 | AllowShortBlocksOnASingleLine: 'true' 12 | AllowShortCaseLabelsOnASingleLine: 'true' 13 | ColumnLimit: '200' 14 | IndentWidth: '4' 15 | ContinuationIndentWidth: '4' 16 | TabWidth: '4' 17 | TabWidth: '4' 18 | ReflowComments: 'true' 19 | SortIncludes: 'true' 20 | AllowShortFunctionsOnASingleLine: 'Empty' 21 | AllowShortIfStatementsOnASingleLine: 'true' 22 | -------------------------------------------------------------------------------- /cmd/tools/tasks/taskbase.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 tasks 6 | 7 | import "github.com/33cn/chain33/common/log/log15" 8 | 9 | var ( 10 | mlog = log15.New("module", "task") 11 | ) 12 | 13 | // TaskBase task base 14 | type TaskBase struct { 15 | NextTask Task 16 | } 17 | 18 | // Execute 执行 19 | func (t *TaskBase) Execute() error { 20 | return nil 21 | } 22 | 23 | // SetNext set next 24 | func (t *TaskBase) SetNext(task Task) { 25 | t.NextTask = task 26 | } 27 | 28 | // Next 获取next 29 | func (t *TaskBase) Next() Task { 30 | return t.NextTask 31 | } 32 | -------------------------------------------------------------------------------- /types/chaincfg/cfg.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 chaincfg 实现chain33的基础配置相关功能 6 | package chaincfg 7 | 8 | var configMap = make(map[string]string) 9 | 10 | // Register 注册配置 11 | func Register(name, cfg string) { 12 | if _, ok := configMap[name]; ok { 13 | panic("chain default config name " + name + " is exist") 14 | } 15 | configMap[name] = cfg 16 | } 17 | 18 | // Load 加载指定配置项 19 | func Load(name string) string { 20 | return configMap[name] 21 | } 22 | 23 | // LoadAll 加载所有配置项 24 | func LoadAll() map[string]string { 25 | return configMap 26 | } 27 | -------------------------------------------------------------------------------- /common/crypto/sha3/register.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Copyright 2014 The Go Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style 7 | // license that can be found in the LICENSE file. 8 | 9 | //go:build go1.4 10 | // +build go1.4 11 | 12 | package sha3 13 | 14 | import ( 15 | "crypto" 16 | ) 17 | 18 | func init() { 19 | crypto.RegisterHash(crypto.SHA3_224, New224) 20 | crypto.RegisterHash(crypto.SHA3_256, New256) 21 | crypto.RegisterHash(crypto.SHA3_384, New384) 22 | crypto.RegisterHash(crypto.SHA3_512, New512) 23 | } 24 | -------------------------------------------------------------------------------- /system/p2p/dht/extension/mdns_test.go: -------------------------------------------------------------------------------- 1 | package extension 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | "time" 7 | 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func Test_mdns(t *testing.T) { 12 | ctx, cancel := context.WithCancel(context.Background()) 13 | defer cancel() 14 | 15 | hosts := getNetHosts(2, t) 16 | _, err := NewMDNS(ctx, hosts[0], "33test123") 17 | require.Nil(t, err) 18 | tmdns, err := NewMDNS(ctx, hosts[1], "33test123") 19 | require.Nil(t, err) 20 | 21 | select { 22 | case peerinfo := <-tmdns.PeerChan(): 23 | require.Equal(t, hosts[0].ID(), peerinfo.ID) 24 | case <-time.After(time.Second * 10): 25 | t.Error("mdns discovery failed, timeout") 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /common/db/table/error.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 table 6 | 7 | import "errors" 8 | 9 | // table 中的错误处理 10 | var ( 11 | ErrEmptyPrimaryKey = errors.New("ErrEmptyPrimaryKey") 12 | ErrPrimaryKey = errors.New("ErrPrimaryKey") 13 | ErrIndexKey = errors.New("ErrIndexKey") 14 | ErrTooManyIndex = errors.New("ErrTooManyIndex") 15 | ErrTablePrefixOrTableName = errors.New("ErrTablePrefixOrTableName") 16 | ErrDupPrimaryKey = errors.New("ErrDupPrimaryKey") 17 | ErrNilValue = errors.New("ErrNilValue") 18 | ) 19 | -------------------------------------------------------------------------------- /wallet/bipwallet/transformer/btcbase/loader.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 btcbase 6 | 7 | import ( 8 | "github.com/33cn/chain33/wallet/bipwallet/transformer" 9 | ) 10 | 11 | // 不同币种的前缀版本号 12 | var coinPrefix = map[string][]byte{ 13 | "BTC": {0x00}, 14 | "BCH": {0x00}, 15 | "BTY": {0x00}, 16 | "YCC": {0x00}, 17 | "AS": {0x00}, 18 | "LTC": {0x30}, 19 | "ZEC": {0x1c, 0xb8}, 20 | "USDT": {0x00}, 21 | } 22 | 23 | func init() { 24 | //注册 25 | for name, prefix := range coinPrefix { 26 | transformer.Register(name, &btcBaseTransformer{prefix}) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /common/crypto/sha3/xor.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Copyright 2015 The Go Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style 7 | // license that can be found in the LICENSE file. 8 | 9 | //go:build (!amd64 && !386 && !ppc64le) || appengine 10 | // +build !amd64,!386,!ppc64le appengine 11 | 12 | package sha3 13 | 14 | var ( 15 | xorIn = xorInGeneric 16 | copyOut = copyOutGeneric 17 | xorInUnaligned = xorInGeneric 18 | copyOutUnaligned = copyOutGeneric 19 | ) 20 | 21 | //const xorImplementationUnaligned = "generic" 22 | -------------------------------------------------------------------------------- /system/dapp/manage/types/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | import "errors" 8 | 9 | var ( 10 | // ErrNoPrivilege defines a error string errnoprivilege 11 | ErrNoPrivilege = errors.New("ErrNoPrivilege") 12 | // ErrBadConfigKey defines a err string errbadconfigkey 13 | ErrBadConfigKey = errors.New("ErrBadConfigKey") 14 | // ErrBadConfigOp defines a err string errbadconfigop 15 | ErrBadConfigOp = errors.New("ErrBadConfigOp") 16 | // ErrBadConfigValue defines a err string errbadconfigvalue 17 | ErrBadConfigValue = errors.New("ErrBadConfigValue") 18 | ) 19 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Based on ssh/terminal: 6 | // Copyright 2013 The Go Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style 8 | // license that can be found in the LICENSE file. 9 | //go:build !appengine 10 | // +build !appengine 11 | 12 | package term 13 | 14 | import "syscall" 15 | 16 | const ioctlReadTermios = syscall.TIOCGETA 17 | 18 | // Termios functions describe a general terminal interface that is 19 | // provided to control asynchronous communications ports. 20 | type Termios syscall.Termios 21 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip39/.gitignore: -------------------------------------------------------------------------------- 1 | # Executable from build 2 | go-bip39 3 | 4 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 5 | *.o 6 | *.a 7 | *.so 8 | *.db 9 | 10 | # Temp files 11 | *~ 12 | *.kate-swp 13 | *.orig 14 | debug 15 | *.txt 16 | *.log 17 | .vscode/ 18 | .idea/ 19 | peers.json 20 | *.csv 21 | *.gz 22 | 23 | # Folders 24 | _obj 25 | _test 26 | bin 27 | pkg 28 | .vagrant 29 | vendor/ 30 | 31 | # Architecture specific extensions/prefixes 32 | *.[568vq] 33 | [568vq].out 34 | 35 | *.cgo1.go 36 | *.cgo2.c 37 | _cgo_defun.c 38 | _cgo_gotypes.go 39 | _cgo_export.* 40 | 41 | _testmain.go 42 | 43 | *.exe 44 | *.test 45 | *.block 46 | *.entry 47 | 48 | .DS_Store 49 | 50 | *.out 51 | .idea/ 52 | ----* 53 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Based on ssh/terminal: 6 | // Copyright 2013 The Go Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style 8 | // license that can be found in the LICENSE file. 9 | 10 | //go:build !appengine 11 | // +build !appengine 12 | 13 | package term 14 | 15 | import "syscall" 16 | 17 | const ioctlReadTermios = syscall.TCGETS 18 | 19 | // Termios functions describe a general terminal interface that is 20 | // provided to control asynchronous communications ports. 21 | type Termios syscall.Termios 22 | -------------------------------------------------------------------------------- /system/dapp/coins/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 coins 系统级coins dapp插件 6 | package coins 7 | 8 | import ( 9 | "github.com/33cn/chain33/pluginmgr" 10 | _ "github.com/33cn/chain33/system/dapp/coins/autotest" // register package 11 | "github.com/33cn/chain33/system/dapp/coins/executor" 12 | "github.com/33cn/chain33/system/dapp/coins/types" 13 | ) 14 | 15 | func init() { 16 | pluginmgr.Register(&pluginmgr.PluginBase{ 17 | Name: types.CoinsX, 18 | ExecName: executor.GetName(), 19 | Exec: executor.Init, 20 | Cmd: nil, 21 | RPC: nil, 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /cmd/tools/gencode/dappcode/init.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 dappcode 6 | 7 | import ( 8 | _ "github.com/33cn/chain33/cmd/tools/gencode/dappcode/cmd" //init cmd 9 | _ "github.com/33cn/chain33/cmd/tools/gencode/dappcode/commands" // init command 10 | _ "github.com/33cn/chain33/cmd/tools/gencode/dappcode/executor" // init executor 11 | _ "github.com/33cn/chain33/cmd/tools/gencode/dappcode/proto" // init proto 12 | _ "github.com/33cn/chain33/cmd/tools/gencode/dappcode/rpc" // init rpc 13 | _ "github.com/33cn/chain33/cmd/tools/gencode/dappcode/types" // init types 14 | ) 15 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/broadcast/const.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 broadcast 6 | 7 | import "errors" 8 | 9 | // TTL 10 | const ( 11 | 12 | // 默认最小区块轻广播的大小, 100KB 13 | defaultMinLtBlockSize = 100 14 | ) 15 | 16 | // P2pCacheTxSize p2pcache size of transaction 17 | const ( 18 | //接收的交易哈希过滤缓存设为mempool最大接收交易量 19 | txRecvFilterCacheNum = 10240 20 | blockRecvFilterCacheNum = 1024 21 | ) 22 | 23 | // pubsub error 24 | var ( 25 | errSnappyDecode = errors.New("errSnappyDecode") 26 | ) 27 | 28 | // peer msg id 29 | const ( 30 | blockReqMsgID = iota + 1 31 | blockRespMsgID 32 | ) 33 | -------------------------------------------------------------------------------- /util/calccommit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 util 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/stretchr/testify/assert" 11 | ) 12 | 13 | func TestGetMostCommit(t *testing.T) { 14 | commits := [][]byte{[]byte("aa"), []byte("bb"), []byte("aa"), []byte("aa")} 15 | 16 | most, key := GetMostCommit(commits) 17 | 18 | assert.Equal(t, 3, most) 19 | assert.Equal(t, "aa", key) 20 | } 21 | 22 | func TestIsCommitDone(t *testing.T) { 23 | done := IsCommitDone(4, 2) 24 | assert.Equal(t, false, done) 25 | 26 | done = IsCommitDone(4, 3) 27 | assert.Equal(t, true, done) 28 | 29 | } 30 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_freebsd.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 term 6 | 7 | import ( 8 | "syscall" 9 | ) 10 | 11 | const ioctlReadTermios = syscall.TIOCGETA 12 | 13 | // Termios functions describe a general terminal interface that is 14 | // provided to control asynchronous communications ports. 15 | // Go 1.2 doesn't include Termios for FreeBSD. This should be added in 1.3 and this could be merged with terminal_darwin. 16 | type Termios struct { 17 | Iflag uint32 18 | Oflag uint32 19 | Cflag uint32 20 | Lflag uint32 21 | Cc [20]uint8 22 | Ispeed uint32 23 | Ospeed uint32 24 | } 25 | -------------------------------------------------------------------------------- /cmd/tools/tasks/check_file_existed_task.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 tasks 6 | 7 | import ( 8 | "github.com/33cn/chain33/cmd/tools/util" 9 | ) 10 | 11 | // CheckFileExistedTask 检测文件是否存在 12 | type CheckFileExistedTask struct { 13 | TaskBase 14 | FileName string 15 | } 16 | 17 | // GetName 获取name 18 | func (c *CheckFileExistedTask) GetName() string { 19 | return "CheckFileExistedTask" 20 | } 21 | 22 | // Execute 执行 23 | func (c *CheckFileExistedTask) Execute() error { 24 | mlog.Info("Execute file existed task.", "file", c.FileName) 25 | _, err := util.CheckFileExists(c.FileName) 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /common/address/util_test.go: -------------------------------------------------------------------------------- 1 | package address 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestFormatAddrKey(t *testing.T) { 11 | 12 | addr1 := "0x6c0d7be0d2c8350042890a77393158181716b0d6" 13 | addr2 := "0x6c0d7BE0d2C8350042890a77393158181716b0d6" 14 | 15 | require.True(t, IsEthAddress(addr1)) 16 | require.False(t, IsEthAddress("12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv")) 17 | addrKey1 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr1)) 18 | addrKey2 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr2)) 19 | 20 | expect := fmt.Sprintf("%s:%s", "addrKey:", string(FormatAddrKey(FormatEthAddress(addr1)))) 21 | 22 | require.Equal(t, expect, addrKey1) 23 | require.Equal(t, expect, addrKey2) 24 | } 25 | -------------------------------------------------------------------------------- /pluginmgr/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 pluginmgr 6 | 7 | import ( 8 | "github.com/33cn/chain33/rpc/types" 9 | typ "github.com/33cn/chain33/types" 10 | wcom "github.com/33cn/chain33/wallet/common" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | // Plugin plugin module struct 15 | type Plugin interface { 16 | // 获取整个插件的包名,用以计算唯一值、做前缀等 17 | GetName() string 18 | // 获取插件中执行器名 19 | GetExecutorName() string 20 | // 初始化执行器时会调用该接口 21 | InitExec(cfg *typ.Chain33Config) 22 | InitWallet(wallet wcom.WalletOperate, sub map[string][]byte) 23 | AddCmd(rootCmd *cobra.Command) 24 | AddRPC(s types.RPCServer) 25 | } 26 | -------------------------------------------------------------------------------- /types/log_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/stretchr/testify/assert" 11 | ) 12 | 13 | func TestLogErr(t *testing.T) { 14 | var errlog LogErr = []byte("hello world") 15 | logty := LoadLog(nil, TyLogErr) 16 | assert.NotNil(t, logty) 17 | assert.Equal(t, logty.Name(), "LogErr") 18 | result, err := logty.Decode([]byte("hello world")) 19 | assert.Nil(t, err) 20 | assert.Equal(t, LogErr(result.(string)), errlog) 21 | 22 | //json test 23 | data, err := logty.JSON([]byte("hello world")) 24 | assert.Nil(t, err) 25 | assert.Equal(t, string(data), `"hello world"`) 26 | } 27 | -------------------------------------------------------------------------------- /system/dapp/manage/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 manage manage负责管理配置的插件 6 | // 1. 添加管理 7 | // 2. 添加运营人员 8 | // 3. (未来)修改某些配置项 9 | package manage 10 | 11 | import ( 12 | "github.com/33cn/chain33/pluginmgr" 13 | "github.com/33cn/chain33/system/dapp/manage/commands" 14 | "github.com/33cn/chain33/system/dapp/manage/executor" 15 | "github.com/33cn/chain33/system/dapp/manage/types" 16 | ) 17 | 18 | func init() { 19 | pluginmgr.Register(&pluginmgr.PluginBase{ 20 | Name: types.ManageX, 21 | ExecName: executor.GetName(), 22 | Exec: executor.Init, 23 | Cmd: commands.ConfigCmd, 24 | RPC: nil, 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /types/jsonpb/regenerate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2020 The Go Authors. All rights reserved. 3 | # Use of this source code is governed by a BSD-style 4 | # license that can be found in the LICENSE file. 5 | 6 | # NOTE: The integration scripts deliberately do not check to 7 | # make sure that the test protos have been regenerated. 8 | # It is intentional that older versions of the .pb.go files 9 | # are checked in to ensure that they continue to function. 10 | # 11 | # Versions used: 12 | # protoc: v3.9.1 13 | # protoc-gen-go: v1.3.2 14 | 15 | # shellcheck disable=SC1117,SC2046 16 | for X in $(find . -name "*.proto" | sed "s|^\./||"); do 17 | protoc -I$(pwd) --go_out=paths=source_relative:. "$X" 18 | done 19 | 20 | # migrate from https://github.com/golang/protobuf/tree/v1.4.3/jsonpb 21 | -------------------------------------------------------------------------------- /system/dapp/none/proto/none.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package types; 4 | option go_package = "../types"; 5 | 6 | message NoneAction { 7 | oneof value { 8 | CommitDelayTx commitDelayTx = 1; 9 | } 10 | int32 Ty = 2; 11 | } 12 | 13 | // 提交延时交易类型 14 | message CommitDelayTx { 15 | 16 | //延时交易, 16进制格式 17 | string delayTx = 1; 18 | // Deprecated:区块高度类型延时, 建议使用时间类型延时 19 | int64 relativeDelayHeight = 2; 20 | //相对延时时长, 单位秒 21 | int64 relativeDelayTime = 3; 22 | } 23 | 24 | // 提交延时交易回执 25 | message CommitDelayTxLog { 26 | // 提交者 27 | string submitter = 1; 28 | // 延时交易哈希 29 | string delayTxHash = 2; 30 | // Deprecated:延时开始区块高度, 建议使用时间类型 31 | int64 delayBeginHeight = 3; 32 | // 延时开始区块时间戳 33 | int64 delayBeginTimestamp = 4; 34 | } 35 | -------------------------------------------------------------------------------- /system/crypto/secp256r1/test/authdir/crypto/signcerts/user1@org1-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB2zCCAYKgAwIBAgIQS5G9Fzlwnnjgt8VSA/O/pDAKBggqhkjOPQQDAjBKMQ4w 3 | DAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAPBgNVBAcTCEhhbmd6 4 | aG91MRIwEAYDVQQDEwlDaGFpbjMzQ0EwHhcNMjEwMzA4MDgyODM5WhcNMjEwNjE2 5 | MDgyODM5WjBHMQ4wDAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAP 6 | BgNVBAcTCEhhbmd6aG91MQ8wDQYDVQQDEwZvcmcxQ0EwWTATBgcqhkjOPQIBBggq 7 | hkjOPQMBBwNCAAQ64rPEsUyLmMd5KyH10IFTUhBgdZlmTigQL8O7OP7oJqpRfRAk 8 | lAKuOWGIn7v2j9UYJKTFMYE4t9fxnnqJYdQLo00wSzAOBgNVHQ8BAf8EBAMCB4Aw 9 | DAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCAYJO6VEsEGyNpahR/2yGrofW8pQxvK 10 | /IWeJxYJlJvwnjAKBggqhkjOPQQDAgNHADBEAiAaJNb6589EMrSxJGfFROOJcP0/ 11 | O7YIW2qFYoluqGspNwIgFplsnAIOb1leHZLE9a84+9xX/hDx3+iHodbz9BwcXBc= 12 | -----END CERTIFICATE----- 13 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/peer/statistic_test.go: -------------------------------------------------------------------------------- 1 | package peer 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/33cn/chain33/queue" 7 | "github.com/33cn/chain33/system/p2p/dht/protocol" 8 | "github.com/33cn/chain33/types" 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func Test_statistic(t *testing.T) { 13 | q := queue.New("test") 14 | p, cancel := initEnv(t, q) 15 | defer cancel() 16 | require.Equal(t, false, p.checkDone()) 17 | remotePid := p.Host.Network().Conns()[0].RemotePeer() 18 | stream, err := p.Host.NewStream(p.Ctx, remotePid, statisticalInfo) 19 | require.Nil(t, err) 20 | defer protocol.CloseStream(stream) 21 | var resp types.Statistical 22 | err = protocol.ReadStream(&resp, stream) 23 | require.Nil(t, err) 24 | require.Equal(t, int32(0), resp.Nodeinfo.Outbounds) 25 | } 26 | -------------------------------------------------------------------------------- /blockchain/mocks/post_service.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import ( 6 | types "github.com/33cn/chain33/types" 7 | mock "github.com/stretchr/testify/mock" 8 | ) 9 | 10 | // PostService is an autogenerated mock type for the PostService type 11 | type PostService struct { 12 | mock.Mock 13 | } 14 | 15 | // PostData provides a mock function with given fields: subscribe, postdata, seq 16 | func (_m *PostService) PostData(subscribe *types.PushSubscribeReq, postdata []byte, seq int64) error { 17 | ret := _m.Called(subscribe, postdata, seq) 18 | 19 | var r0 error 20 | if rf, ok := ret.Get(0).(func(*types.PushSubscribeReq, []byte, int64) error); ok { 21 | r0 = rf(subscribe, postdata, seq) 22 | } else { 23 | r0 = ret.Error(0) 24 | } 25 | 26 | return r0 27 | } 28 | -------------------------------------------------------------------------------- /store/store.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 store store the world - state data 6 | package store 7 | 8 | import ( 9 | "github.com/33cn/chain33/queue" 10 | "github.com/33cn/chain33/system/store" 11 | "github.com/33cn/chain33/types" 12 | ) 13 | 14 | // New new store queue module 15 | func New(cfg *types.Chain33Config) queue.Module { 16 | mcfg := cfg.GetModuleConfig().Store 17 | sub := cfg.GetSubConfig().Store 18 | s, err := store.Load(mcfg.Name) 19 | if err != nil { 20 | panic("Unsupported store type:" + mcfg.Name + " " + err.Error()) 21 | } 22 | subcfg, ok := sub[mcfg.Name] 23 | if !ok { 24 | subcfg = nil 25 | } 26 | return s(mcfg, subcfg, cfg) 27 | } 28 | -------------------------------------------------------------------------------- /system/crypto/sm2/test/authdir/crypto/signcerts/user1@org1-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB3DCCAYKgAwIBAgIQBjdghSKOJoFdU6sBNJ1/PjAKBggqgRzPVQGDdTBKMQ4w 3 | DAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAPBgNVBAcTCEhhbmd6 4 | aG91MRIwEAYDVQQDEwlDaGFpbjMzQ0EwHhcNMjEwMzA4MDg0NjA1WhcNMjEwNjE2 5 | MDg0NjA1WjBHMQ4wDAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAP 6 | BgNVBAcTCEhhbmd6aG91MQ8wDQYDVQQDEwZvcmcxQ0EwWTATBgcqhkjOPQIBBggq 7 | gRzPVQGCLQNCAASKBToYuZehM7jfCFcc8lcLgBYd0wIyeSaJlLScSuPoZ7ATd1tX 8 | jqNcbvGlxJpH51rltLgnnAzFB/OpO062psXNo00wSzAOBgNVHQ8BAf8EBAMCB4Aw 9 | DAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCAFeeFSN2FDIjpwSRlhq1SHgeHYESBz 10 | Oi36uwelYj/2ADAKBggqgRzPVQGDdQNIADBFAiEA9ejRhk+vUltIBbftlqBxB4z8 11 | 60F+KgcUTP2thE3mhNQCIATwHYAtI5sUB72CJ2oUjY9qhYurjCSi5HOz1eIGkzo5 12 | -----END CERTIFICATE----- 13 | -------------------------------------------------------------------------------- /blockchain/exec.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 blockchain 6 | 7 | import ( 8 | "github.com/33cn/chain33/queue" 9 | "github.com/33cn/chain33/types" 10 | "github.com/33cn/chain33/util" 11 | ) 12 | 13 | // 执行区块将变成一个私有的函数 14 | func execBlock(client queue.Client, prevStateRoot []byte, block *types.Block, errReturn bool, sync bool) (*types.BlockDetail, []*types.Transaction, error) { 15 | return util.ExecBlock(client, prevStateRoot, block, errReturn, sync, true) 16 | } 17 | 18 | // 从本地执行区块 19 | func execBlockUpgrade(client queue.Client, prevStateRoot []byte, block *types.Block, sync bool) error { 20 | return util.ExecBlockUpgrade(client, prevStateRoot, block, sync) 21 | } 22 | -------------------------------------------------------------------------------- /system/dapp/manage/executor/exec_del_local.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import ( 8 | "github.com/33cn/chain33/types" 9 | ) 10 | 11 | // ExecDelLocal 重写基类 12 | func (c *Manage) ExecDelLocal(tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { 13 | return c.execAutoDelLocal(tx, receipt) 14 | } 15 | 16 | func (c *Manage) execAutoDelLocal(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) { 17 | kvs, err := c.DelRollbackKV(tx, tx.Execer) 18 | if err != nil { 19 | return nil, err 20 | } 21 | dbSet := &types.LocalDBSet{} 22 | dbSet.KV = append(dbSet.KV, kvs...) 23 | return dbSet, nil 24 | } 25 | -------------------------------------------------------------------------------- /system/crypto/none/none_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 none 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/33cn/chain33/common/crypto" 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | func Test_None(t *testing.T) { 15 | 16 | c := &Driver{} 17 | pub, err := c.PubKeyFromBytes([]byte("test")) 18 | require.Nil(t, pub) 19 | require.Nil(t, err) 20 | sig, err := c.SignatureFromBytes([]byte("test")) 21 | require.Nil(t, sig) 22 | require.Nil(t, err) 23 | require.Nil(t, c.Validate([]byte("test"), nil, nil)) 24 | _, err = crypto.Load(Name, -1) 25 | require.Nil(t, err) 26 | _, err = crypto.Load(Name, 0) 27 | require.Equal(t, crypto.ErrDriverNotEnable, err) 28 | } 29 | -------------------------------------------------------------------------------- /system/crypto/secp256r1/test/authdir/crypto/cacerts/org1@ca-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB8DCCAZegAwIBAgIQQ+x1KAz8NfgC0B37JMoPVTAKBggqhkjOPQQDAjBKMQ4w 3 | DAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAPBgNVBAcTCEhhbmd6 4 | aG91MRIwEAYDVQQDEwlDaGFpbjMzQ0EwHhcNMjEwMzA4MDgyODM5WhcNMjEwNjE2 5 | MDgyODM5WjBKMQ4wDAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAP 6 | BgNVBAcTCEhhbmd6aG91MRIwEAYDVQQDEwlDaGFpbjMzQ0EwWTATBgcqhkjOPQIB 7 | BggqhkjOPQMBBwNCAAQJG4ubiSuklCAl7TG3XTx2SHC2SDNmN+Ke7t/mlIIB3UO3 8 | cgykb6QOs2EVmjQuJK5B/KSqNVuPkCOMv3yqjChWo18wXTAOBgNVHQ8BAf8EBAMC 9 | AaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMBAf8EBTADAQH/MCkGA1UdDgQiBCCq 10 | 0lrTc5o0RvEosUEy14ImnFXQNiDM77/stsbdgiYGdjAKBggqhkjOPQQDAgNHADBE 11 | AiAA4D2s13bSFC6fXKPm2MH40sl1qUZHfemXD9G7i2h8aAIgGTIu+as9gp4TWegn 12 | uiyj7pZqdvGvvBCnm6DPwpqtd64= 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /system/crypto/sm2/test/authdir/crypto/cacerts/ca-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB8zCCAZigAwIBAgIRAPKOX/eTl8vyusy1iUhwTwwwCgYIKoEcz1UBg3UwSjEO 3 | MAwGA1UEBhMFQ2hpbmExETAPBgNVBAgTCFpoZWppYW5nMREwDwYDVQQHEwhIYW5n 4 | emhvdTESMBAGA1UEAxMJQ2hhaW4zM0NBMB4XDTIxMDMwODA4NDYwNVoXDTIxMDYx 5 | NjA4NDYwNVowSjEOMAwGA1UEBhMFQ2hpbmExETAPBgNVBAgTCFpoZWppYW5nMREw 6 | DwYDVQQHEwhIYW5nemhvdTESMBAGA1UEAxMJQ2hhaW4zM0NBMFkwEwYHKoZIzj0C 7 | AQYIKoEcz1UBgi0DQgAE/9nvE0lXE0sfRp/LM3C4XXLedsIy0KW7A/92BTwB4qNZ 8 | RrlKHHcgnYdx8UZxhVv5gPGJOF91SkF9rJTCStHdCaNfMF0wDgYDVR0PAQH/BAQD 9 | AgGmMA8GA1UdJQQIMAYGBFUdJQAwDwYDVR0TAQH/BAUwAwEB/zApBgNVHQ4EIgQg 10 | qmYSkbqPt/gDlIT+4NhYB1LuQVI6eaFlqssGgQvVQckwCgYIKoEcz1UBg3UDSQAw 11 | RgIhAIx+IVbnzahkWOdsjYPuCzW/6uhz5LFC1x5aRlpODsTTAiEA7HdS7+fLz6or 12 | oNbOYW/LU6q/ioNoQji+gDroBlEoW7M= 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /executor/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | /* 8 | 执行器就是状态机,根据交易类型,会有对应的执行器去执行。 9 | 执行器由一些原子的命令组成。 10 | 11 | 在执行交易的时候,会在一个虚拟的执行环境下,模拟执行。 12 | 错误的交易允许被执行,只要他的手续费是够的。 13 | 手续费不够的交易直接抛弃。 14 | 15 | 执行的过程中,会产生一些Event,Event作为交易的Receipt 16 | 17 | //input 18 | ReplyTxList 19 | 20 | //output 21 | Receipts->(IsOk, EventLogs, KVSet) 22 | 23 | var kvs types.KV 24 | var receipts types.Receipts 25 | for tx := range txs { 26 | storeSet, events, ok := execTx(tx) //对于错误的交易 events 就是:InvalidTx 27 | //执行的过程中,会更新内存模拟数据库,这里主要是余额信息 28 | } 29 | 30 | 执行器的设计原则: 31 | 32 | 1. 不改变存储状态 33 | 2. 无状态设计 34 | 35 | TODO: 36 | 37 | 执行器可以进一步分布式化: 38 | 39 | 1. 预分析,编译出执行指令 40 | 2. 分析指令的独立性。大部分可能非关联。 41 | */ 42 | -------------------------------------------------------------------------------- /system/crypto/secp256r1/test/authdir/crypto/intermediatecerts/org1-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB8DCCAZegAwIBAgIQPKYUBP07c0VLRA9HYx76uTAKBggqhkjOPQQDAjBKMQ4w 3 | DAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAPBgNVBAcTCEhhbmd6 4 | aG91MRIwEAYDVQQDEwlDaGFpbjMzQ0EwHhcNMjEwMzA4MDgyODM5WhcNMjEwNjE2 5 | MDgyODM5WjBKMQ4wDAYDVQQGEwVDaGluYTERMA8GA1UECBMIWmhlamlhbmcxETAP 6 | BgNVBAcTCEhhbmd6aG91MRIwEAYDVQQDEwlDaGFpbjMzQ0EwWTATBgcqhkjOPQIB 7 | BggqhkjOPQMBBwNCAAS9XrYPssxQ5fEouHde9vpwWWsHT9hy0RcXRfdnoL3oEx4T 8 | MiQeZz1j4DaLDxq348wpqF9a6G6WSjOlu7WoJXBPo18wXTAOBgNVHQ8BAf8EBAMC 9 | AaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMBAf8EBTADAQH/MCkGA1UdDgQiBCAY 10 | JO6VEsEGyNpahR/2yGrofW8pQxvK/IWeJxYJlJvwnjAKBggqhkjOPQQDAgNHADBE 11 | AiBMtXtBpGh1KJdMFwU7KhrwzRkat8MZG+h7Zqc017cdcwIgfYTa8xVhbz1GTtj/ 12 | w+UrD53a//uQ2bILh9VHke1ro4w= 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /types/jsonpb/parse.go: -------------------------------------------------------------------------------- 1 | package jsonpb 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | "unicode/utf8" 7 | 8 | "github.com/33cn/chain33/common" 9 | ) 10 | 11 | // ErrBytesFormat 错误的bytes 类型 12 | var ErrBytesFormat = errors.New("ErrBytesFormat") 13 | 14 | func parseBytes(jsonstr string, enableUTF8BytesToString bool) ([]byte, error) { 15 | if jsonstr == "" { 16 | return []byte{}, nil 17 | } 18 | if strings.HasPrefix(jsonstr, "str://") { 19 | return []byte(jsonstr[len("str://"):]), nil 20 | } 21 | if strings.HasPrefix(jsonstr, "0x") || strings.HasPrefix(jsonstr, "0X") { 22 | return common.FromHex(jsonstr) 23 | } 24 | //字符串不是 hex 格式, 也不是 str:// 格式,但是是一个普通的utf8 字符串 25 | //那么强制转化为bytes, 注意这个选项默认不开启. 26 | if utf8.ValidString(jsonstr) && enableUTF8BytesToString { 27 | return []byte(jsonstr), nil 28 | } 29 | return nil, ErrBytesFormat 30 | } 31 | -------------------------------------------------------------------------------- /util/calccommit.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 util 6 | 7 | // GetMostCommit 获取commits中最多的一个,数量和string 8 | func GetMostCommit(commits [][]byte) (int, string) { 9 | stats := make(map[string]int) 10 | n := len(commits) 11 | for i := 0; i < n; i++ { 12 | if _, ok := stats[string(commits[i])]; ok { 13 | stats[string(commits[i])]++ 14 | } else { 15 | stats[string(commits[i])] = 1 16 | } 17 | } 18 | most := -1 19 | var key string 20 | for k, v := range stats { 21 | if v > most { 22 | most = v 23 | key = k 24 | } 25 | } 26 | return most, key 27 | } 28 | 29 | // IsCommitDone 判断是否most 超过total*2/3 30 | func IsCommitDone(total, most int) bool { 31 | return 3*most > 2*total 32 | } 33 | -------------------------------------------------------------------------------- /client/mock_execs_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 client_test 6 | 7 | import ( 8 | "github.com/33cn/chain33/queue" 9 | "github.com/33cn/chain33/types" 10 | ) 11 | 12 | type mockExecs struct { 13 | } 14 | 15 | func (m *mockExecs) SetQueueClient(q queue.Queue) { 16 | go func() { 17 | topic := "execs" 18 | client := q.Client() 19 | client.Sub(topic) 20 | for msg := range client.Recv() { 21 | switch msg.Ty { 22 | case types.EventBlockChainQuery: 23 | msg.Reply(client.NewMessage(topic, types.EventBlockChainQuery, &types.Reply{})) 24 | default: 25 | msg.ReplyErr("Do not support", types.ErrNotSupport) 26 | } 27 | } 28 | }() 29 | } 30 | 31 | func (m *mockExecs) Close() { 32 | } 33 | -------------------------------------------------------------------------------- /system/crypto/sm2/test/authdir/crypto/intermediatecerts/org1-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB8jCCAZigAwIBAgIRAMMknvJdm6yI3c7je/fqzKswCgYIKoEcz1UBg3UwSjEO 3 | MAwGA1UEBhMFQ2hpbmExETAPBgNVBAgTCFpoZWppYW5nMREwDwYDVQQHEwhIYW5n 4 | emhvdTESMBAGA1UEAxMJQ2hhaW4zM0NBMB4XDTIxMDMwODA4NDYwNVoXDTIxMDYx 5 | NjA4NDYwNVowSjEOMAwGA1UEBhMFQ2hpbmExETAPBgNVBAgTCFpoZWppYW5nMREw 6 | DwYDVQQHEwhIYW5nemhvdTESMBAGA1UEAxMJQ2hhaW4zM0NBMFkwEwYHKoZIzj0C 7 | AQYIKoEcz1UBgi0DQgAESaDx1yvCU8tZXvtRh7RlaAR0ljnfbGAem4I/iSTNjeNJ 8 | K6UP4/mS+fYNJuR+ogG2LJfxCrVIuMnghRVNoRisV6NfMF0wDgYDVR0PAQH/BAQD 9 | AgGmMA8GA1UdJQQIMAYGBFUdJQAwDwYDVR0TAQH/BAUwAwEB/zApBgNVHQ4EIgQg 10 | BXnhUjdhQyI6cEkZYatUh4Hh2BEgczot+rsHpWI/9gAwCgYIKoEcz1UBg3UDSAAw 11 | RQIgWoXOU6T1yYb5PfGqUG/R+UXFyB2ulYit/FCX9J26wfwCIQDj1Y6B78gA9go3 12 | iQ4a/YQ2m+F6ErqI1VLvMc37YzKwbw== 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /system/dapp/commands/version.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 commands 系统级dapp相关命令包 6 | package commands 7 | 8 | import ( 9 | "github.com/33cn/chain33/rpc/jsonclient" 10 | "github.com/33cn/chain33/types" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | // VersionCmd version command 15 | func VersionCmd() *cobra.Command { 16 | cmd := &cobra.Command{ 17 | Use: "version", 18 | Short: "Get node version", 19 | Run: version, 20 | } 21 | 22 | return cmd 23 | } 24 | 25 | func version(cmd *cobra.Command, args []string) { 26 | rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") 27 | var res types.VersionInfo 28 | ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Version", nil, &res) 29 | ctx.Run() 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cmd/chain33/chain33.system.fork.toml: -------------------------------------------------------------------------------- 1 | [fork.system] 2 | ForkChainParamV1=110000 3 | ForkChainParamV2=1692674 4 | ForkCheckTxDup=75260 5 | ForkBlockHash=209186 6 | ForkMinerTime=350000 7 | ForkTransferExec=408400 8 | ForkExecKey=408400 9 | ForkWithdraw=480000 10 | ForkTxGroup=408400 11 | ForkResetTx0=453400 12 | ForkExecRollback=706531 13 | ForkTxHeight=806578 14 | ForkCheckBlockTime=1200000 15 | ForkMultiSignAddress=1298600 16 | ForkStateDBSet=1572391 17 | ForkBlockCheck=1560000 18 | ForkLocalDBAccess=1572391 19 | ForkTxGroupPara=1687250 20 | ForkBase58AddressCheck=1800000 21 | # 这个fork只影响平行链,注册类似user.p.x.exec的driver,新开的平行链设为0即可,老的平行链要设置新的高度 22 | ForkEnableParaRegExec=0 23 | ForkCacheDriver=2580000 24 | ForkTicketFundAddrV1=3350000 25 | ForkRootHash=4500000 26 | ForkFormatAddressKey=0 27 | ForkEthAddressFormat=0 28 | ForkCheckEthTxSort=0 29 | ForkProxyExec=0 30 | ForkMaxTxFeeV1=0 31 | -------------------------------------------------------------------------------- /system/dapp/none/README.md: -------------------------------------------------------------------------------- 1 | ## 存证合约 2 | 3 | 4 | ### 交易类型 5 | 6 | #### 普通存证交易 7 | 普通存证交易只在链上存储记录,不做业务逻辑执行 8 | 9 | #### 延时存证交易 10 | 将延时交易提交到链上,即交易的payload包含一个需要延时的交易 11 | 12 | 13 | ##### 交易请求 14 | 15 | ```proto 16 | message CommitDelayTx { 17 | 18 | string delayTx = 1; //延时交易, 16进制格式 19 | int64 relativeDelayHeight = 2; //相对延时时长,相对区块高度 20 | } 21 | ``` 22 | 23 | [Transaction结构定义](../../../types/proto/transaction.proto#L88) 24 | 25 | 26 | ##### 交易回执 27 | 28 | ```proto 29 | message CommitDelayTxLog { 30 | string submitter = 1; // 提交者 31 | string delayTxHash = 2; // 延时交易哈希 32 | int64 delayBeginHeight = 3; // 延时开始区块高度 33 | } 34 | ``` 35 | 36 | 37 | ##### 交易构造接口及参数 38 | 39 | - 创建交易通用json rpc接口,Chain33.CreateTransaction 40 | - execer: "none" 41 | - actionName: "CommitDelayTx" 42 | - payload: [CommitDelayTx](README.md#交易请求) 43 | 44 | -------------------------------------------------------------------------------- /cmd/dht_crawler/bar.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/libp2p/go-libp2p-kad-dht/crawler" 7 | "github.com/qianlnk/pgbar" 8 | ) 9 | 10 | var finished bool 11 | var barDone = make(chan struct{}) 12 | 13 | // 模拟显示进度条,并非真实进度 14 | // rate 100% (100/100) [================================================] 1.31 ps 00:01:15 in: 00:00:00 15 | func barRun(handleSuccess crawler.HandleQueryResult) { 16 | pgbar.Println("\ndht_crawler rate bar") 17 | bar := pgbar.NewBar(0, "rate", 100) 18 | go func() { 19 | for i := 0; i < 100; i++ { 20 | bar.Add(1) 21 | if finished { 22 | time.Sleep(time.Millisecond * 300) 23 | continue 24 | } 25 | if i < 80 { 26 | time.Sleep(time.Millisecond * 900) 27 | } else { 28 | time.Sleep(time.Millisecond * 1500) //超过80%进度以后,降低进度条的速率 29 | } 30 | } 31 | 32 | barDone <- struct{}{} 33 | 34 | }() 35 | } 36 | -------------------------------------------------------------------------------- /types/sign_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | package types 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/33cn/chain33/common/address" 10 | "github.com/33cn/chain33/common/crypto" 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | func TestAddressID(t *testing.T) { 15 | 16 | var cryptoID, addressID int32 17 | 18 | for ; cryptoID <= crypto.MaxManualTypeID; cryptoID++ { 19 | addressID = 0 20 | for ; addressID <= address.MaxID; addressID++ { 21 | signID := EncodeSignID(cryptoID, addressID) 22 | require.Equal(t, addressID, ExtractAddressID(signID)) 23 | require.Equal(t, cryptoID, ExtractCryptoID(signID)) 24 | dupSignID := EncodeSignID(signID, addressID) 25 | require.Equal(t, signID, dupSignID) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.github/workflows/manual_make_bin.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow that is manually triggered 2 | name: manually make bin for all branch 3 | 4 | # Controls when the action will run. Workflow runs when manually triggered using the UI 5 | # or API. 6 | on: [push,pull_request] 7 | 8 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 9 | jobs: 10 | automake: 11 | name: automake 12 | runs-on: ubuntu-22.04 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions/setup-go@v3 16 | with: 17 | go-version-file: 'go.mod' 18 | 19 | - name: compile binary 20 | run: make all-arch 21 | 22 | - name : Upload artifact bin 23 | uses: actions/upload-artifact@v4 24 | with: 25 | name: chain33-artifact 26 | path: | 27 | build/*.tar.gz 28 | build/*.zip 29 | -------------------------------------------------------------------------------- /system/mempool/timeline/timeline.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 timeline 6 | 7 | import ( 8 | "github.com/33cn/chain33/queue" 9 | drivers "github.com/33cn/chain33/system/mempool" 10 | "github.com/33cn/chain33/types" 11 | ) 12 | 13 | func init() { 14 | drivers.Reg("timeline", New) 15 | } 16 | 17 | // New 创建timeline cache 结构的 mempool 18 | func New(cfg *types.Mempool, sub []byte) queue.Module { 19 | c := drivers.NewMempool(cfg) 20 | var subcfg drivers.SubConfig 21 | types.MustDecode(sub, &subcfg) 22 | if subcfg.PoolCacheSize == 0 { 23 | subcfg.PoolCacheSize = cfg.PoolCacheSize 24 | } 25 | if subcfg.ProperFee == 0 { 26 | subcfg.ProperFee = cfg.MinTxFeeRate 27 | } 28 | c.SetQueueCache(drivers.NewSimpleQueue(subcfg)) 29 | return c 30 | } 31 | -------------------------------------------------------------------------------- /metrics/influxdb/README.md: -------------------------------------------------------------------------------- 1 | go-metrics-influxdb 2 | =================== 3 | 4 | This is a reporter for the [go-metrics](https://github.com/rcrowley/go-metrics) library which will post the metrics to [InfluxDB](https://influxdb.com/). 5 | 6 | Note 7 | ---- 8 | 9 | This is only compatible with InfluxDB 0.9+. 10 | 11 | Usage 12 | ----- 13 | 14 | ```go 15 | import "github.com/vrischmann/go-metrics-influxdb" 16 | 17 | go influxdb.InfluxDB( 18 | metrics.DefaultRegistry, // metrics registry 19 | time.Second * 10, // interval 20 | "http://localhost:8086", // the InfluxDB url 21 | "mydb", // your InfluxDB database 22 | "myuser", // your InfluxDB user 23 | "mypassword", // your InfluxDB password 24 | ) 25 | ``` 26 | 27 | License 28 | ------- 29 | 30 | go-metrics-influxdb is licensed under the MIT license. See the LICENSE file for details. 31 | -------------------------------------------------------------------------------- /system/dapp/manage/types/const.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | // ManageActionModifyConfig manager action 8 | const ( 9 | ManageActionModifyConfig = iota 10 | ManageActionApplyConfig 11 | ManageActionApproveConfig 12 | ) 13 | 14 | // TyLogModifyConfig log 15 | const ( 16 | TyLogModifyConfig = 410 17 | TyLogApplyConfig = 411 18 | TyLogApproveConfig = 412 19 | ) 20 | 21 | // ConfigItemArrayConfig config Item 22 | const ( 23 | ConfigItemArrayConfig = iota 24 | ) 25 | 26 | // ManageConfigStatus config status 27 | const ( 28 | ManageConfigStatusNone = 0 29 | ManageConfigStatusApply = 1 30 | ManageConfigStatusApproved = 2 31 | ) 32 | 33 | // OpAdd config op 34 | const ( 35 | OpAdd = "add" 36 | OpDelete = "delete" 37 | ) 38 | -------------------------------------------------------------------------------- /wallet/bipwallet/transformer/btcbase/README.md: -------------------------------------------------------------------------------- 1 | # btcbase模块 2 | 3 | 本模块实现基于比特币规则的公钥和地址的生成 4 | 5 | ## 涉及币种 6 | - BTC -- 版本号为0x00 7 | - BCH -- 版本号为0x00 8 | - LTC -- 版本号为0x30 9 | - ZEC -- 版本号为两个字节0x1c,0xb8 10 | - USDT -- 版本号为0x00,与比特币相同 11 | - BTY -- 版本号为0x00, 与比特币相同 12 | 13 | ## 依赖清单 14 | - github.com/mr-tron/base58/base58 15 | - github.com/haltingstate/secp256k1-go 16 | - golang.org/x/crypto/ripemd160 17 | 18 | ## 输入输出格式说明 19 | ```golang 20 | //传入32字节私钥,生成压缩形式的公钥 21 | func (t BtcBaseTransformer) PrivKeyToPub(priv []byte) (pub []byte, err error) 22 | ``` 23 | ```golang 24 | //传入压缩或非压缩形式的公钥,生成base58编码的地址(压缩和非压缩形式的公钥生成的地址是不同的,但都是合法的) 25 | func (t BtcBaseTransformer) PubKeyToAddress(pub []byte) (addr string, err error) 26 | ``` 27 | 28 | ## 生成规则 29 | 30 | ![地址生成流程](btc_wallet_gene.png) 31 | 32 | 不同币种的区别只在于版本号 33 | 34 | 详细介绍可以参考《精通比特币》的第四章: 35 | http://book.8btc.com/books/6/masterbitcoin2cn/_book/ch04.html 36 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_notwindows.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Based on ssh/terminal: 6 | // Copyright 2011 The Go Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style 8 | // license that can be found in the LICENSE file. 9 | 10 | //go:build (linux && !appengine) || darwin || freebsd || openbsd || netbsd 11 | // +build linux,!appengine darwin freebsd openbsd netbsd 12 | 13 | package term 14 | 15 | import ( 16 | "syscall" 17 | "unsafe" 18 | ) 19 | 20 | // IsTty returns true if the given file descriptor is a terminal. 21 | func IsTty(fd uintptr) bool { 22 | var termios Termios 23 | _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) 24 | return err == 0 25 | } 26 | -------------------------------------------------------------------------------- /system/store/mavl/db/util.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 mavl 6 | 7 | import ( 8 | "fmt" 9 | "strings" 10 | ) 11 | 12 | // PrintNode the in-memory children recursively. 13 | func PrintNode(node *Node) { 14 | fmt.Println("==== NODE") 15 | if node != nil { 16 | printNode(node, 0) 17 | } 18 | fmt.Println("==== END") 19 | } 20 | 21 | func printNode(node *Node, indent int) { 22 | indentPrefix := strings.Repeat(" ", indent) 23 | if node.rightNode != nil { 24 | printNode(node.rightNode, indent+1) 25 | } 26 | fmt.Printf("%s|-%s:%03d\n", indentPrefix, string(node.key), node.height) 27 | if node.leftNode != nil { 28 | printNode(node.leftNode, indent+1) 29 | } 30 | } 31 | 32 | func maxInt32(a, b int32) int32 { 33 | if a > b { 34 | return a 35 | } 36 | return b 37 | } 38 | -------------------------------------------------------------------------------- /consensus/consensus.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 consensus 共识相关的模块 6 | package consensus 7 | 8 | import ( 9 | "reflect" 10 | 11 | "github.com/33cn/chain33/queue" 12 | "github.com/33cn/chain33/system/consensus" 13 | "github.com/33cn/chain33/types" 14 | ) 15 | 16 | // New new consensus queue module 17 | func New(cfg *types.Chain33Config) queue.Module { 18 | mcfg := cfg.GetModuleConfig().Consensus 19 | sub := cfg.GetSubConfig().Consensus 20 | con, err := consensus.Load(mcfg.Name) 21 | if err != nil { 22 | panic("Unsupported consensus type:" + mcfg.Name + " " + err.Error()) 23 | } 24 | subcfg, ok := sub[mcfg.Name] 25 | if !ok { 26 | subcfg = nil 27 | } 28 | obj := con(mcfg, subcfg) 29 | consensus.QueryData.SetThis(mcfg.Name, reflect.ValueOf(obj)) 30 | return obj 31 | } 32 | -------------------------------------------------------------------------------- /common/log/log15/term/terminal_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Based on ssh/terminal: 6 | // Copyright 2011 The Go Authors. All rights reserved. 7 | // Use of this source code is governed by a BSD-style 8 | // license that can be found in the LICENSE file. 9 | 10 | //go:build windows 11 | // +build windows 12 | 13 | package term 14 | 15 | import ( 16 | "syscall" 17 | "unsafe" 18 | ) 19 | 20 | var kernel32 = syscall.NewLazyDLL("kernel32.dll") 21 | 22 | var ( 23 | procGetConsoleMode = kernel32.NewProc("GetConsoleMode") 24 | ) 25 | 26 | // IsTty returns true if the given file descriptor is a terminal. 27 | func IsTty(fd uintptr) bool { 28 | var st uint32 29 | r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0) 30 | return r != 0 && e == 0 31 | } 32 | -------------------------------------------------------------------------------- /common/address/util.go: -------------------------------------------------------------------------------- 1 | package address 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/ethereum/go-ethereum/common" 7 | ) 8 | 9 | // ForkFormatAddressKey 地址key格式化分叉名称,主要针对eth地址 10 | const ForkFormatAddressKey = "ForkFormatAddressKey" 11 | 12 | // ForkEthAddressFormat eth地址统一格式化 13 | const ForkEthAddressFormat = "ForkEthAddressFormat" 14 | 15 | // IsEthAddress verifies whether a string can represent 16 | // a valid hex-encoded eth address 17 | func IsEthAddress(addr string) bool { 18 | return common.IsHexAddress(addr) 19 | } 20 | 21 | // FormatEthAddress eth地址格式化 22 | func FormatEthAddress(addr string) string { 23 | return strings.ToLower(addr) 24 | } 25 | 26 | // FormatAddrKey format addr as db key 27 | func FormatAddrKey(addr string) []byte { 28 | 29 | // eth地址有大小写区分, 统一采用小写格式key存储(#1245) 30 | if IsEthAddress(addr) { 31 | ethDriver, _ := LoadDriver(2, -1) 32 | addr = ethDriver.FormatAddr(addr) 33 | } 34 | 35 | return []byte(addr) 36 | } 37 | -------------------------------------------------------------------------------- /cmd/miner_accounts/test.txt: -------------------------------------------------------------------------------- 1 | $ wget 127.0.0.1:8801 --post-data='{ "id":111, "method":"Chain33.GetBalance", "params":[{"addresses":["1FB8L3DykVF7Y78bRfUrRcMZwesKue7CyR"],"execer":"ticket", "stateHash" : "0xc408aae71495e36cc0e9195fd2dec7dceb1d76179af65f6718fc93d1361559c2"}] }' 2 | $ cat index.html.220 3 | {"id":111,"result":[{"currency":0,"balance":1801600000000,"frozen":3011343800000000,"addr":"1FB8L3DykVF7Y78bRfUrRcMZwesKue7CyR"}],"error":null} 4 | 5 | $ wget 127.0.0.1:8801 --post-file=GetBalance.json 6 | $ cat index.html.219 7 | {"id":111,"result":[{"currency":0,"balance":808200000000,"frozen":3000007200000000,"addr":"1FB8L3DykVF7Y78bRfUrRcMZwesKue7CyR"}],"error":null} 8 | 9 | $ wget 127.0.0.1:8866 --post-data='{ "id":111, "method":"ShowMinerAccount.Get", "params":[{ "timeAt" : "2018-05-31-08" } ] }' 10 | {"id":111,"result":{"minerAccounts":[{"addr":"1FB8L3DykVF7Y78bRfUrRcMZwesKue7CyR","total":"30132840.0000","increase":"828.0000"}],"seconds":3603},"error":null} 11 | -------------------------------------------------------------------------------- /system/mempool/mempool.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 mempool 6 | 7 | import ( 8 | "github.com/33cn/chain33/queue" 9 | "github.com/33cn/chain33/types" 10 | ) 11 | 12 | // Create 创建一个mempool模块 13 | type Create func(cfg *types.Mempool, sub []byte) queue.Module 14 | 15 | var regMempool = make(map[string]Create) 16 | 17 | // Reg 注册一个create 18 | func Reg(name string, create Create) { 19 | if create == nil { 20 | panic("Mempool: Register driver is nil") 21 | } 22 | if _, dup := regMempool[name]; dup { 23 | panic("Mempool: Register called twice for driver " + name) 24 | } 25 | regMempool[name] = create 26 | } 27 | 28 | // Load 加载一个create 29 | func Load(name string) (create Create, err error) { 30 | if driver, ok := regMempool[name]; ok { 31 | return driver, nil 32 | } 33 | return nil, types.ErrNotFound 34 | } 35 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/random.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 btcutil 6 | 7 | import ( 8 | "io" 9 | "math/big" 10 | ) 11 | 12 | var one = new(big.Int).SetInt64(1) 13 | 14 | // RandFieldElement returns a random element of the field underlying the given 15 | // curve using the procedure given in [NSA] A.2.1. 16 | // 17 | // Implementation copied from Go's crypto/ecdsa package since 18 | // the function wasn't public. Modified to always use secp256k1 curve. 19 | func RandFieldElement(rand io.Reader) (k *big.Int, err error) { 20 | params := Secp256k1().Params() 21 | b := make([]byte, params.BitSize/8+8) 22 | _, err = io.ReadFull(rand, b) 23 | if err != nil { 24 | return 25 | } 26 | 27 | k = new(big.Int).SetBytes(b) 28 | n := new(big.Int).Sub(params.N, one) 29 | k.Mod(k, n) 30 | k.Add(k, one) 31 | return 32 | } 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | - OS: [e.g. iOS] 25 | - Browser [e.g. chrome, safari] 26 | - Version [e.g. 22] 27 | 28 | **Smartphone (please complete the following information):** 29 | - Device: [e.g. iPhone6] 30 | - OS: [e.g. iOS8.1] 31 | - Browser [e.g. stock browser, safari] 32 | - Version [e.g. 22] 33 | 34 | **Additional context** 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /system/consensus/finalize.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 consensus 6 | 7 | import ( 8 | "github.com/33cn/chain33/queue" 9 | "github.com/33cn/chain33/types" 10 | ) 11 | 12 | // Finalizer block finalize 13 | type Finalizer interface { 14 | Initialize(ctx *Context) 15 | AddBlock(blk *types.Block) 16 | SubMsg(msg *queue.Message) 17 | } 18 | 19 | var finalizers = make(map[string]Finalizer) 20 | 21 | // RegFinalizer register committer 22 | func RegFinalizer(name string, f Finalizer) { 23 | 24 | if f == nil { 25 | panic("RegCommitter: committer is nil") 26 | } 27 | if _, dup := committers[name]; dup { 28 | panic("RegCommitter: duplicate committer " + name) 29 | } 30 | finalizers[name] = f 31 | } 32 | 33 | // LoadFinalizer load 34 | func LoadFinalizer(name string) Finalizer { 35 | 36 | return finalizers[name] 37 | } 38 | -------------------------------------------------------------------------------- /common/crypto/sha3/xor_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | // Copyright 2015 The Go Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style 7 | // license that can be found in the LICENSE file. 8 | 9 | package sha3 10 | 11 | import "encoding/binary" 12 | 13 | // xorInGeneric xors the bytes in buf into the state; it 14 | // makes no non-portable assumptions about memory layout 15 | // or alignment. 16 | func xorInGeneric(d *state, buf []byte) { 17 | n := len(buf) / 8 18 | 19 | for i := 0; i < n; i++ { 20 | a := binary.LittleEndian.Uint64(buf) 21 | d.a[i] ^= a 22 | buf = buf[8:] 23 | } 24 | } 25 | 26 | // copyOutGeneric copies ulint64s to a byte buffer. 27 | func copyOutGeneric(d *state, b []byte) { 28 | for i := 0; len(b) >= 8; i++ { 29 | binary.LittleEndian.PutUint64(b, d.a[i]) 30 | b = b[8:] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /common/db/table/count_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 table 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/33cn/chain33/util" 11 | "github.com/stretchr/testify/assert" 12 | ) 13 | 14 | func TestCount(t *testing.T) { 15 | dir, ldb, kvdb := util.CreateTestDB() 16 | defer util.CloseTestDB(dir, ldb) 17 | count := NewCount("prefix", "name#hello", kvdb) 18 | count.Inc() 19 | count.Dec() 20 | count.Inc() 21 | i, err := count.Get() 22 | assert.Nil(t, err) 23 | assert.Equal(t, i, int64(1)) 24 | kvs, err := count.Save() 25 | assert.Nil(t, err) 26 | util.SaveKVList(ldb, kvs) 27 | 28 | count = NewCount("prefix", "name#hello", kvdb) 29 | i, err = count.Get() 30 | assert.Nil(t, err) 31 | assert.Equal(t, i, int64(1)) 32 | 33 | count.Set(2) 34 | i, err = count.Get() 35 | assert.Nil(t, err) 36 | assert.Equal(t, i, int64(2)) 37 | } 38 | -------------------------------------------------------------------------------- /system/dapp/coins/autotest/coins.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 autotest 系统级coins dapp自动测试包 6 | package autotest 7 | 8 | import ( 9 | "reflect" 10 | 11 | "github.com/33cn/chain33/cmd/autotest/types" 12 | ) 13 | 14 | type coinsAutoTest struct { 15 | SimpleCaseArr []types.SimpleCase `toml:"SimpleCase,omitempty"` 16 | TransferCaseArr []TransferCase `toml:"TransferCase,omitempty"` 17 | WithdrawCaseArr []WithdrawCase `toml:"WithdrawCase,omitempty"` 18 | } 19 | 20 | func init() { 21 | 22 | types.RegisterAutoTest(coinsAutoTest{}) 23 | 24 | } 25 | 26 | // GetName return name = "coins" 27 | func (config coinsAutoTest) GetName() string { 28 | 29 | return "coins" 30 | } 31 | 32 | // GetTestConfigType return type of config 33 | func (config coinsAutoTest) GetTestConfigType() reflect.Type { 34 | 35 | return reflect.TypeOf(config) 36 | } 37 | -------------------------------------------------------------------------------- /types/time.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | import ( 8 | "sync/atomic" 9 | "time" 10 | ) 11 | 12 | var deltaTime int64 13 | 14 | // NtpHosts ntp hosts 15 | var NtpHosts = []string{ 16 | "ntp.aliyun.com:123", 17 | "time1.cloud.tencent.com:123", 18 | "time.ustc.edu.cn:123", 19 | "cn.ntp.org.cn:123", 20 | "time.apple.com:123", 21 | } 22 | 23 | // SetTimeDelta realtime - localtime 24 | // 超过60s 不做修正 25 | // 为了系统的安全,我们只做小范围时间错误的修复 26 | func SetTimeDelta(dt int64) { 27 | if dt > 300*int64(time.Second) || dt < -300*int64(time.Second) { 28 | dt = 0 29 | } 30 | atomic.StoreInt64(&deltaTime, dt) 31 | } 32 | 33 | // Now 获取当前时间戳 34 | func Now() time.Time { 35 | dt := time.Duration(atomic.LoadInt64(&deltaTime)) 36 | return time.Now().Add(dt) 37 | } 38 | 39 | // Since Since时间 40 | func Since(t time.Time) time.Duration { 41 | return Now().Sub(t) 42 | } 43 | -------------------------------------------------------------------------------- /common/log/log15/handler_go14.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | //go:build go1.4 6 | // +build go1.4 7 | 8 | package log15 9 | 10 | import "sync/atomic" 11 | 12 | // swapHandler wraps another handler that may be swapped out 13 | // dynamically at runtime in a thread-safe fashion. 14 | type swapHandler struct { 15 | handler atomic.Value 16 | } 17 | 18 | func (h *swapHandler) Log(r *Record) error { 19 | return (*h.handler.Load().(*Handler)).Log(r) 20 | } 21 | 22 | func (h *swapHandler) MaxLevel() int { 23 | return (*h.handler.Load().(*Handler)).MaxLevel() 24 | } 25 | 26 | func (h *swapHandler) SetMaxLevel(maxLevel int) { 27 | (*h.handler.Load().(*Handler)).SetMaxLevel(maxLevel) 28 | } 29 | 30 | func (h *swapHandler) Swap(newHandler Handler) { 31 | h.handler.Store(&newHandler) 32 | } 33 | 34 | func (h *swapHandler) Get() Handler { 35 | return *h.handler.Load().(*Handler) 36 | } 37 | -------------------------------------------------------------------------------- /client/mock_consensus_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 client_test 6 | 7 | import ( 8 | "github.com/33cn/chain33/queue" 9 | "github.com/33cn/chain33/types" 10 | ) 11 | 12 | type mockConsensus struct { 13 | } 14 | 15 | func (m *mockConsensus) SetQueueClient(q queue.Queue) { 16 | go func() { 17 | consensusKey := "consensus" 18 | client := q.Client() 19 | client.Sub(consensusKey) 20 | for msg := range client.Recv() { 21 | switch msg.Ty { 22 | case types.EventGetTicketCount: 23 | msg.Reply(client.NewMessage(consensusKey, types.EventReplyGetTicketCount, &types.Int64{})) 24 | case types.EventConsensusQuery: 25 | msg.Reply(client.NewMessage(consensusKey, types.EventReplyQuery, &types.Reply{})) 26 | default: 27 | msg.ReplyErr("Do not support", types.ErrNotSupport) 28 | } 29 | } 30 | }() 31 | } 32 | 33 | func (m *mockConsensus) Close() { 34 | } 35 | -------------------------------------------------------------------------------- /cmd/tools/main.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 main 6 | 7 | import ( 8 | "os" 9 | 10 | "github.com/33cn/chain33/cmd/tools/commands" 11 | "github.com/33cn/chain33/common/log" 12 | "github.com/spf13/cobra" 13 | ) 14 | 15 | //var ( 16 | // mlog = log15.New("module", "tools") 17 | //) 18 | 19 | func main() { 20 | log.SetLogLevel("debug") 21 | runCommands() 22 | } 23 | 24 | func addCommands(rootCmd *cobra.Command) { 25 | rootCmd.AddCommand( 26 | commands.ImportCmd(), 27 | commands.UpdateInitCmd(), 28 | commands.CreatePluginCmd(), 29 | commands.GenDappCmd(), 30 | ) 31 | } 32 | 33 | func runCommands() { 34 | rootCmd := &cobra.Command{ 35 | Use: "tools", 36 | Short: "chain33 tools", 37 | } 38 | addCommands(rootCmd) 39 | 40 | if err := rootCmd.Execute(); err != nil { 41 | //mlog.Error("Execute command failed.", "error", err) 42 | os.Exit(1) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /types/fork_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/stretchr/testify/assert" 11 | ) 12 | 13 | func TestForks(t *testing.T) { 14 | cfg := NewChain33Config(GetDefaultCfgstring()) 15 | cfg.forks.setLocalFork() 16 | assert.Equal(t, cfg.forks.IsFork(1, "ForkV1"), false) 17 | assert.Equal(t, cfg.forks.IsFork(1, "ForkV12"), false) 18 | assert.Equal(t, cfg.forks.IsFork(0, "ForkBlockHash"), false) 19 | assert.Equal(t, cfg.forks.IsFork(1, "ForkBlockHash"), true) 20 | assert.Equal(t, cfg.forks.IsFork(1, "ForkTransferExec"), true) 21 | assert.Equal(t, cfg.forks.IsFork(0, "ForkBlockHash"), false) 22 | assert.Equal(t, cfg.forks.IsFork(1, "ForkBlockHash"), true) 23 | } 24 | 25 | func TestParaFork(t *testing.T) { 26 | NewChain33Config(ReadFile("testdata/guodun.toml")) 27 | NewChain33Config(ReadFile("testdata/guodun2.toml")) 28 | } 29 | -------------------------------------------------------------------------------- /common/log/log15/handler_go13.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 | //go:build !go1.4 6 | // +build !go1.4 7 | 8 | package log15 9 | 10 | import ( 11 | "sync/atomic" 12 | "unsafe" 13 | ) 14 | 15 | // swapHandler wraps another handler that may be swapped out 16 | // dynamically at runtime in a thread-safe fashion. 17 | type swapHandler struct { 18 | handler unsafe.Pointer 19 | } 20 | 21 | func (h *swapHandler) Log(r *Record) error { 22 | return h.Get().Log(r) 23 | } 24 | 25 | func (h *swapHandler) MaxLevel() int { 26 | return h.Get().MaxLevel() 27 | } 28 | 29 | func (h *swapHandler) SetMaxLevel(maxLevel int) { 30 | h.Get().SetMaxLevel(maxLevel) 31 | } 32 | 33 | func (h *swapHandler) Get() Handler { 34 | return *(*Handler)(atomic.LoadPointer(&h.handler)) 35 | } 36 | 37 | func (h *swapHandler) Swap(newHandler Handler) { 38 | atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler)) 39 | } 40 | -------------------------------------------------------------------------------- /system/crypto/btcscript/script/errors.go: -------------------------------------------------------------------------------- 1 | package script 2 | 3 | import "errors" 4 | 5 | var ( 6 | 7 | // ErrInvalidMultiSigRequiredNum error required multi sig pub key num 8 | ErrInvalidMultiSigRequiredNum = errors.New("ErrInvalidMultiSigRequiredNum") 9 | // ErrInvalidBtcPubKey invalid bitcoin pubkey 10 | ErrInvalidBtcPubKey = errors.New("ErrInvalidBtcPubKey") 11 | // ErrBuildBtcScript build btc script error 12 | ErrBuildBtcScript = errors.New("ErrBuildBtcScript") 13 | // ErrNewBtcAddress new btc address pub key error 14 | ErrNewBtcAddress = errors.New("ErrNewBtcAddress") 15 | // ErrGetBtcTxInSig get btc tx input signature error 16 | ErrGetBtcTxInSig = errors.New("ErrGetBtcTxInSig") 17 | // ErrNewBtcScriptSig new btc script sig error 18 | ErrNewBtcScriptSig = errors.New("ErrNewBtcScriptSig") 19 | 20 | // ErrBtcKeyNotExist btc key not exist when sign 21 | ErrBtcKeyNotExist = errors.New("ErrBtcKeyNotExist") 22 | // ErrBtcScriptNotExist btc script not exist when sign 23 | ErrBtcScriptNotExist = errors.New("ErrBtcScriptNotExist") 24 | ) 25 | -------------------------------------------------------------------------------- /common/crypto/README.md: -------------------------------------------------------------------------------- 1 | # crypto 2 | 3 | ## 功能 4 | * 支持 ed25519, secp256k1, sm2 5 | * 统一的 PrivKey,Pubkey, Signature 接口, 详见 `crypto.go` 6 | 7 | ## 依赖 8 | * sm2 编译依赖 gmssl 2.0 版本 9 | * 安装:`bash ./deps/install_gmssl.sh` 10 | 11 | 12 | 13 | ## 配置 14 | >支持加密插件使能开启, 分叉高度等配置 15 | 16 | ### EnableTypes 17 | >指定开启若干加密插件(插件名称),不配置默认启用所有 18 | ```toml 19 | [crypto] #示例 20 | enableTypes=["secp256k1", "sm2"] 21 | ``` 22 | 23 | ### EnableHeight 24 | > 分叉高度配置, 即区块高度达到配置高度后启用插件, 不配置采用内置的启用高度, 负数表示不启用 25 | ```toml 26 | [crypto] #示例 27 | [crypto.enableHeight] 28 | "secp256k1" = 0 29 | "sm2"= 100 30 | ``` 31 | 32 | ## cryptoID 33 | 加密插件ID值, int32类型 34 | 35 | ### 手动指定 36 | 37 | >注册插件时, 支持手动指定插件ID(crypto.WithRegOptionTypeID(manualID)) 38 | 39 | * 手动指定ID范围, (0, 4096), 低位12位 40 | * 建议单元测试调用CryptoGetCryptoList接口查看已注册ID情况. 41 | 42 | 43 | ### 自动生成 44 | > 注册时未指定手动ID, 将根据插件名称随机生成, 存在冲突时需要手动指定解决 45 | 46 | 47 | ### 相关说明 48 | > cryptoID主要用于交易签名算法类型判定, cryptoID不等同于交易SignatureID 49 | 50 | * 接口chain33/types/ExtractCryptoID, 基于signID解析cryptoID 51 | * 底层设计, 参考chain33/types/sign.md 52 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/snow/util.go: -------------------------------------------------------------------------------- 1 | package snow 2 | 3 | import ( 4 | "github.com/33cn/chain33/queue" 5 | "github.com/33cn/chain33/types" 6 | ) 7 | 8 | const ( 9 | consensusTopic = "consensus" 10 | ) 11 | 12 | func consensusMsg(msgID int64, data interface{}) *queue.Message { 13 | 14 | return queue.NewMessage(msgID, consensusTopic, types.EventForFinalizer, data) 15 | } 16 | 17 | func (s *snowman) sendQueryFailedMsg(msgID int64, reqID uint32, peerName string) { 18 | 19 | msg := &types.SnowFailedQuery{ 20 | RequestID: reqID, 21 | PeerName: peerName, 22 | } 23 | 24 | err := s.QueueClient.Send(consensusMsg(msgID, msg), false) 25 | 26 | if err != nil { 27 | 28 | log.Error("sendQueryFailedMsg", "reqID", reqID, "send queue err", err) 29 | } 30 | } 31 | 32 | func (s *snowman) getBlock(hash []byte) (*types.Block, error) { 33 | 34 | details, err := s.API.GetBlockByHashes(&types.ReqHashes{Hashes: [][]byte{hash}}) 35 | if err != nil || len(details.GetItems()) < 1 { 36 | return nil, err 37 | } 38 | 39 | return details.GetItems()[0].GetBlock(), nil 40 | } 41 | -------------------------------------------------------------------------------- /common/utils/util_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func Test_spaceLimitCache(t *testing.T) { 10 | 11 | c := NewSpaceLimitCache(3, 10) 12 | assert.Equal(t, 3, c.capacity) 13 | assert.True(t, c.Add(1, 1, 1)) 14 | assert.True(t, c.Add(1, 1, 1)) 15 | assert.False(t, c.Add(2, 2, 20)) 16 | assert.Nil(t, c.Get(2)) 17 | assert.True(t, c.Add(2, 1, 10)) 18 | c.Add(3, 2, 2) 19 | c.Add(4, 2, 2) 20 | c.Add(5, 2, 2) 21 | c.Add(6, 2, 1) 22 | assert.False(t, c.Contains(3)) 23 | assert.Equal(t, 3, c.data.Len()) 24 | assert.Equal(t, 3, len(c.sizeMap)) 25 | assert.Equal(t, 5, c.currSize) 26 | assert.True(t, c.Contains(4)) 27 | assert.True(t, c.Contains(5)) 28 | assert.True(t, c.Add(7, 7, 8)) 29 | assert.True(t, c.Contains(7)) 30 | assert.Equal(t, 2, c.data.Len()) 31 | assert.Equal(t, 2, len(c.sizeMap)) 32 | assert.Equal(t, 9, c.currSize) 33 | _, exist := c.Remove(6) 34 | assert.True(t, exist) 35 | _, exist = c.Remove(5) 36 | assert.False(t, exist) 37 | assert.Equal(t, 8, c.currSize) 38 | } 39 | -------------------------------------------------------------------------------- /cmd/chain33/chain33.fork.toml: -------------------------------------------------------------------------------- 1 | [fork.system] 2 | ForkChainParamV1=110000 3 | ForkChainParamV2=1692674 4 | ForkCheckTxDup=75260 5 | ForkBlockHash=209186 6 | ForkMinerTime=350000 7 | ForkTransferExec=408400 8 | ForkExecKey=408400 9 | ForkWithdraw=480000 10 | ForkTxGroup=408400 11 | ForkResetTx0=453400 12 | ForkExecRollback=706531 13 | ForkTxHeight=806578 14 | ForkCheckBlockTime=1200000 15 | ForkMultiSignAddress=1298600 16 | ForkStateDBSet=1572391 17 | ForkBlockCheck=1560000 18 | ForkLocalDBAccess=1572391 19 | ForkTxGroupPara=1687250 20 | ForkBase58AddressCheck=1800000 21 | # 这个fork只影响平行链,注册类似user.p.x.exec的driver,新开的平行链设为0即可,老的平行链要设置新的高度 22 | ForkEnableParaRegExec=0 23 | ForkCacheDriver=2580000 24 | ForkTicketFundAddrV1=3350000 25 | ForkRootHash=4500000 26 | ForkFormatAddressKey=0 27 | ForkEthAddressFormat=0 28 | ForkCheckEthTxSort=0 29 | ForkProxyExec=0 30 | ForkMaxTxFeeV1=0 31 | [fork.sub.none] 32 | ForkUseTimeDelay=0 33 | 34 | [fork.sub.coins] 35 | Enable=0 36 | ForkFriendExecer=0 37 | [fork.sub.manage] 38 | Enable=120000 39 | ForkManageExec=400000 40 | ForkManageAutonomyEnable=10000000 41 | -------------------------------------------------------------------------------- /system/store/store.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 store store the world - state data 6 | package store 7 | 8 | import ( 9 | "github.com/33cn/chain33/queue" 10 | "github.com/33cn/chain33/types" 11 | ) 12 | 13 | // Storecreate store queue module 14 | type Storecreate func(cfg *types.Store, sub []byte, chain33cfg *types.Chain33Config) queue.Module 15 | 16 | var regStore = make(map[string]Storecreate) 17 | 18 | // Reg 注册 store driver 19 | func Reg(name string, create Storecreate) { 20 | if create == nil { 21 | panic("Store: Register driver is nil") 22 | } 23 | if _, dup := regStore[name]; dup { 24 | panic("Store: Register called twice for driver " + name) 25 | } 26 | regStore[name] = create 27 | } 28 | 29 | // Load load StoreCreate by name 30 | func Load(name string) (create Storecreate, err error) { 31 | if driver, ok := regStore[name]; ok { 32 | return driver, nil 33 | } 34 | return nil, types.ErrNotFound 35 | } 36 | -------------------------------------------------------------------------------- /types/proto/snowman.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package types; 4 | option go_package = "github.com/33cn/chain33/types"; 5 | 6 | message snowChits { 7 | 8 | uint32 requestID = 1; 9 | string peerName = 2; 10 | bytes preferredBlkHash = 3; 11 | bytes acceptedBlkHash = 4; 12 | } 13 | 14 | message snowGetBlock { 15 | 16 | uint32 requestID = 1; 17 | string peerName = 2; 18 | bytes blockHash = 3; 19 | } 20 | 21 | message snowPutBlock { 22 | 23 | uint32 requestID = 1; 24 | string peerName = 2; 25 | bytes blockHash = 3; 26 | bytes blockData = 4; 27 | } 28 | 29 | message snowPullQuery { 30 | 31 | uint32 requestID = 1; 32 | string peerName = 2; 33 | bytes blockHash = 3; 34 | } 35 | 36 | message snowPushQuery { 37 | 38 | uint32 requestID = 1; 39 | string peerName = 2; 40 | bytes blockData = 3; 41 | } 42 | 43 | message snowFailedQuery { 44 | uint32 requestID = 1; 45 | string peerName = 2; 46 | } 47 | 48 | message snowChoice { 49 | int64 height = 1; 50 | bytes hash = 2; 51 | } 52 | -------------------------------------------------------------------------------- /common/log/log15/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Aaron L 2 | Alan Shreve 3 | Andy Walker 4 | Andy Watson 5 | Carl Veazey 6 | Chris Hines 7 | Ciaran Downey 8 | Dmitry Chestnykh 9 | Evan Shaw 10 | Gonzalo Serrano 11 | Jeremy 12 | Jonathan Rudenberg 13 | Kang Seong-Min 14 | Kevin Burke 15 | Marc Abramowitz 16 | Nathan Baulch 17 | NotZippy 18 | Péter Szilágyi 19 | Robert Egorov 20 | Robert Starbuck 21 | Robert Zaremba 22 | Spencer Nelson 23 | Tomasz Grodzki 24 | Trevor Gattis 25 | Vincent Vanackere 26 | Will McGovern 27 | -------------------------------------------------------------------------------- /system/p2p/dht/manage/peerinfo_test.go: -------------------------------------------------------------------------------- 1 | package manage 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | 7 | "github.com/33cn/chain33/queue" 8 | "github.com/33cn/chain33/types" 9 | "github.com/libp2p/go-libp2p" 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestPeerInfoManager(t *testing.T) { 14 | h1, err := libp2p.New() 15 | require.Nil(t, err) 16 | q := queue.New("test") 17 | go sub(q.Client()) 18 | mgr := NewPeerInfoManager(context.Background(), h1, q.Client()) 19 | require.Nil(t, mgr.Fetch(h1.ID())) 20 | require.Nil(t, mgr.FetchAll()) 21 | mgr.Refresh(&types.Peer{ 22 | Name: h1.ID().Pretty(), 23 | Header: &types.Header{ 24 | Height: 888, 25 | }, 26 | }) 27 | require.NotNil(t, mgr.Fetch(h1.ID())) 28 | require.Equal(t, 1, len(mgr.FetchAll())) 29 | require.Equal(t, int64(888), mgr.PeerHeight(h1.ID())) 30 | mgr.prune() 31 | require.Equal(t, int64(888), mgr.PeerHeight(h1.ID())) 32 | } 33 | 34 | func sub(cli queue.Client) { 35 | cli.Sub("blockchain") 36 | for range cli.Recv() { 37 | cli.Reply(cli.NewMessage("", 0, &types.Header{Height: 10000})) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/examples/ecdh/ecdh.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 main 6 | 7 | import ( 8 | "crypto/rand" 9 | "fmt" 10 | 11 | btcutil "github.com/33cn/chain33/wallet/bipwallet/btcutilecc" 12 | ) 13 | 14 | func main() { 15 | // generate keys for Alice and Bob 16 | alice, err := btcutil.GenerateKey(rand.Reader) 17 | if err != nil { 18 | fmt.Println("Generate alice Key err", err) 19 | } 20 | bob, err := btcutil.GenerateKey(rand.Reader) 21 | if err != nil { 22 | fmt.Println("Generate bob Key err", err) 23 | } 24 | fmt.Printf("Alice:\t%x\n\t%x\n", alice.D, alice.PublicKey.X) 25 | fmt.Printf("Bob:\t%x\n\t%x\n", bob.D, bob.PublicKey.X) 26 | fmt.Println("") 27 | 28 | // Alice calculates shared secret 29 | aliceShared := btcutil.ECDH(alice, &bob.PublicKey) 30 | fmt.Printf("Alice: %x\n", aliceShared) 31 | 32 | // Bob calculates shared secret 33 | bobShared := btcutil.ECDH(bob, &alice.PublicKey) 34 | fmt.Printf("Bob: %x\n", bobShared) 35 | } 36 | -------------------------------------------------------------------------------- /cmd/tools/gencode/dappcode/cmd/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 cmd 6 | 7 | import ( 8 | "github.com/33cn/chain33/cmd/tools/gencode/base" 9 | ) 10 | 11 | func init() { 12 | 13 | base.RegisterCodeFile(cmdCodeFile{}) 14 | } 15 | 16 | type cmdCodeFile struct { 17 | base.DappCodeFile 18 | } 19 | 20 | func (cmdCodeFile) GetDirName() string { 21 | 22 | return "cmd" 23 | } 24 | 25 | func (cmdCodeFile) GetFiles() map[string]string { 26 | 27 | return map[string]string{ 28 | buildShellName: buildShellContent, 29 | makeFIleName: makeFileContent, 30 | } 31 | } 32 | 33 | var ( 34 | buildShellName = "build.sh" 35 | buildShellContent = `#!/bin/bash 36 | # 官方ci集成脚本 37 | strpwd=$(pwd) 38 | strcmd=${strpwd##*dapp/} 39 | strapp=${strcmd%/cmd*} 40 | 41 | OUT_DIR="${1}/$strapp" 42 | #FLAG=$2 43 | 44 | mkdir -p "${OUT_DIR}" 45 | cp ./build/* "${OUT_DIR}" 46 | ` 47 | makeFIleName = "Makefile" 48 | makeFileContent = `all: 49 | bash build.sh $(OUT) $(FLAG) 50 | ` 51 | ) 52 | -------------------------------------------------------------------------------- /executor/plugin_kvmvcc.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import ( 8 | "github.com/33cn/chain33/types" 9 | ) 10 | 11 | func init() { 12 | RegisterPlugin("mvcc", &mvccPlugin{}) 13 | } 14 | 15 | type mvccPlugin struct { 16 | pluginBase 17 | } 18 | 19 | func (p *mvccPlugin) CheckEnable(executor *executor, enable bool) (kvs []*types.KeyValue, ok bool, err error) { 20 | kvs, ok, err = p.checkFlag(executor, types.FlagKeyMVCC, enable) 21 | if err == types.ErrDBFlag { 22 | panic("mvcc config is enable, it must be synchronized from 0 height ") 23 | } 24 | return kvs, ok, err 25 | } 26 | 27 | func (p *mvccPlugin) ExecLocal(executor *executor, data *types.BlockDetail) (kvs []*types.KeyValue, err error) { 28 | kvs = AddMVCC(executor.localDB, data) 29 | return kvs, nil 30 | } 31 | 32 | func (p *mvccPlugin) ExecDelLocal(executor *executor, data *types.BlockDetail) ([]*types.KeyValue, error) { 33 | kvs := DelMVCC(executor.localDB, data) 34 | return kvs, nil 35 | } 36 | -------------------------------------------------------------------------------- /system/mempool/lasttx.go: -------------------------------------------------------------------------------- 1 | package mempool 2 | 3 | import ( 4 | "github.com/33cn/chain33/common/listmap" 5 | "github.com/33cn/chain33/types" 6 | ) 7 | 8 | // LastTxCache 最后放入cache的交易 9 | type LastTxCache struct { 10 | max int 11 | l *listmap.ListMap 12 | } 13 | 14 | // NewLastTxCache 创建最后交易的cache 15 | func NewLastTxCache(size int) *LastTxCache { 16 | return &LastTxCache{ 17 | max: size, 18 | l: listmap.New(), 19 | } 20 | } 21 | 22 | // GetLatestTx 返回最新十条加入到txCache的交易 23 | func (cache *LastTxCache) GetLatestTx() (txs []*types.Transaction) { 24 | cache.l.Walk(func(v interface{}) bool { 25 | txs = append(txs, v.(*types.Transaction)) 26 | return true 27 | }) 28 | return txs 29 | } 30 | 31 | // Remove remove tx of last cache 32 | func (cache *LastTxCache) Remove(txHash string) { 33 | cache.l.Remove(txHash) 34 | } 35 | 36 | // Push tx into LastTxCache 37 | func (cache *LastTxCache) Push(tx *types.Transaction, txHash string) { 38 | if cache.l.Size() >= cache.max { 39 | v := cache.l.GetTop() 40 | if v != nil { 41 | cache.Remove(string(v.(*types.Transaction).Hash())) 42 | } 43 | } 44 | cache.l.Push(txHash, tx) 45 | } 46 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/blind.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 btcutil 6 | 7 | import ( 8 | "crypto/ecdsa" 9 | "fmt" 10 | "math/big" 11 | ) 12 | 13 | // BlindSignature Based on algorithm described in An Efficient Blind Signature Scheme 14 | // Based on the Elliptic Curve Discrete Logarithm Problem by 15 | // Nikooghadam and Zakerolhosseini 16 | type BlindSignature struct { 17 | M, S *big.Int // called m and s in the paper 18 | F *ecdsa.PublicKey 19 | } 20 | 21 | // BlindVerify 不清楚干嘛的 22 | func BlindVerify(Q *ecdsa.PublicKey, sig *BlindSignature) bool { 23 | crv := Secp256k1().Params() 24 | 25 | // onlooker verifies signature (§4.5) 26 | sG := ScalarBaseMult(sig.S) 27 | rm := new(big.Int).Mul(new(big.Int).Mod(sig.F.X, crv.N), sig.M) 28 | rm.Mod(rm, crv.N) 29 | rmQ := ScalarMult(rm, Q) 30 | rmQplusF := Add(rmQ, sig.F) 31 | 32 | fmt.Println("") 33 | fmt.Printf("sG = %x\n", sG.X) 34 | fmt.Printf("rmQ + F = %x\n", rmQplusF.X) 35 | return KeysEqual(sG, rmQplusF) 36 | } 37 | -------------------------------------------------------------------------------- /metrics/influxdb/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Vincent Rischmann 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /system/dapp/none/executor/query.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import ( 8 | "encoding/hex" 9 | 10 | ntypes "github.com/33cn/chain33/system/dapp/none/types" 11 | "github.com/33cn/chain33/types" 12 | ) 13 | 14 | // Query_GetDelayTxInfo query delay tx delay begin height 15 | func (n *None) Query_GetDelayTxInfo(req *types.ReqBytes) (types.Message, error) { 16 | 17 | if len(req.GetData()) == 0 { 18 | return nil, types.ErrInvalidParam 19 | } 20 | 21 | val, err := n.GetStateDB().Get(formatDelayTxKey(req.GetData())) 22 | if err != nil { 23 | eLog.Error("Query_GetDelayBeginHeight", "txHash", hex.EncodeToString(req.GetData()), "get db err", err) 24 | return nil, types.ErrGetStateDB 25 | } 26 | info := &ntypes.CommitDelayTxLog{} 27 | 28 | err = types.Decode(val, info) 29 | if err != nil { 30 | eLog.Error("Query_GetDelayBeginHeight", "txHash", hex.EncodeToString(req.GetData()), "get db err", err) 31 | return nil, types.ErrDecode 32 | } 33 | return info, nil 34 | } 35 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip39/README.md: -------------------------------------------------------------------------------- 1 | # go-bip39 2 | 3 | A golang implementation of the BIP0039 spec for mnemonic seeds 4 | 5 | 6 | ## Credits 7 | 8 | English wordlist and test vectors are from the standard Python BIP0039 implementation 9 | from the Trezor guys: [https://github.com/trezor/python-mnemonic](https://github.com/trezor/python-mnemonic) 10 | 11 | ## Example 12 | 13 | ```go 14 | package main 15 | 16 | import ( 17 | "github.com/tyler-smith/go-bip39" 18 | "github.com/tyler-smith/go-bip32" 19 | "fmt" 20 | ) 21 | 22 | func main(){ 23 | // Generate a mnemonic for memorization or user-friendly seeds 24 | entropy, _ := bip39.NewEntropy(256) 25 | mnemonic, _ := bip39.NewMnemonic(entropy) 26 | 27 | // Generate a Bip32 HD wallet for the mnemonic and a user supplied password 28 | seed := bip39.NewSeed(mnemonic, "Secret Passphrase") 29 | 30 | masterKey, _ := bip32.NewMasterKey(seed) 31 | publicKey := masterKey.PublicKey() 32 | 33 | // Display mnemonic and keys 34 | fmt.Println("Mnemonic: ", mnemonic) 35 | fmt.Println("Master private key: ", masterKey) 36 | fmt.Println("Master public key: ", publicKey) 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /wallet/bipwallet/basen/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Casey Marshall 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 | -------------------------------------------------------------------------------- /common/crypto/client/client_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 client 6 | 7 | import ( 8 | "testing" 9 | "time" 10 | 11 | "github.com/33cn/chain33/queue" 12 | "github.com/33cn/chain33/types" 13 | "github.com/stretchr/testify/require" 14 | ) 15 | 16 | func TestModule(t *testing.T) { 17 | 18 | module := New() 19 | cfg := types.NewChain33Config(types.GetDefaultCfgstring()) 20 | q := queue.New("test") 21 | q.SetConfig(cfg) 22 | cli := q.Client() 23 | module.SetQueueClient(cli) 24 | defer q.Close() 25 | defer module.Close() 26 | 27 | for i := 0; i < 10; i++ { 28 | height := int64(i) 29 | err := cli.Send(cli.NewMessage("crypto", types.EventAddBlock, &types.Header{Height: height}), true) 30 | require.Nil(t, err) 31 | } 32 | module.Wait() 33 | sleep := 0 34 | for GetCryptoContext().CurrBlockHeight != 9 { 35 | if sleep >= 1000 { 36 | t.Errorf("expect=9, actual=%d", GetCryptoContext().CurrBlockHeight) 37 | return 38 | } 39 | time.Sleep(10 * time.Millisecond) 40 | sleep += 10 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /cmd/tools/tasks/format_dappsource_task.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 tasks 6 | 7 | import ( 8 | "os" 9 | "os/exec" 10 | "path" 11 | "path/filepath" 12 | ) 13 | 14 | // FormatDappSourceTask 利用Go工具,对生成出来的Go源码进行格式化 15 | type FormatDappSourceTask struct { 16 | TaskBase 17 | OutputFolder string 18 | } 19 | 20 | // GetName 获取name 21 | func (f *FormatDappSourceTask) GetName() string { 22 | return "FormatDappSourceTask" 23 | } 24 | 25 | // Execute 执行 26 | func (f *FormatDappSourceTask) Execute() error { 27 | mlog.Info("Execute format dapp source task.") 28 | err := filepath.Walk(f.OutputFolder, func(fpath string, info os.FileInfo, err error) error { 29 | if info == nil { 30 | return err 31 | } 32 | if info.IsDir() { 33 | return nil 34 | } 35 | ext := path.Ext(fpath) 36 | if ext != ".go" { // 仅对go的源码文件进行格式化 37 | return nil 38 | } 39 | cmd := exec.Command("gofmt", "-l", "-s", "-w", fpath) 40 | cmd.Stdout = os.Stdout 41 | cmd.Stderr = os.Stderr 42 | return cmd.Run() 43 | }) 44 | return err 45 | } 46 | -------------------------------------------------------------------------------- /common/log/log15/term/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Simon Eskildsen 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip32/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Tyler Smith 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. 22 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip39/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Tyler Smith 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. 22 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip44/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Factom Foundation 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. -------------------------------------------------------------------------------- /cmd/autotest/main.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 自动化系统回归测试工具,外部支持输入测试用例配置文件, 6 | // 输出测试用例执行结果并记录详细执行日志。 7 | // 内部代码支持用例扩展开发,继承并实现通用接口,即可自定义实现用例类型。 8 | package main 9 | 10 | import ( 11 | "flag" 12 | "fmt" 13 | "os" 14 | 15 | "github.com/33cn/chain33/cmd/autotest/testflow" 16 | //默认只导入系统dapp的AutoTest 17 | _ "github.com/33cn/chain33/system" 18 | ) 19 | 20 | var ( 21 | configFile string 22 | logFile string 23 | ) 24 | 25 | func init() { 26 | 27 | flag.StringVar(&configFile, "f", "autotest.toml", "-f configFile") 28 | flag.StringVar(&logFile, "l", "autotest.log", "-l logFile") 29 | flag.Parse() 30 | } 31 | 32 | func main() { 33 | 34 | testflow.InitFlowConfig(configFile, logFile) 35 | 36 | if testflow.StartAutoTest() { 37 | 38 | fmt.Println("========================================Succeed!============================================") 39 | os.Exit(0) 40 | } else { 41 | fmt.Println("==========================================Failed!============================================") 42 | os.Exit(1) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /types/jsonpb/jsonpb_proto/test3.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 | syntax = "proto3"; 6 | 7 | option go_package = "github.com/33cn/chain33/types/jsonpb/jsonpb_proto"; 8 | 9 | package jsonpb_test; 10 | 11 | message Simple3 { 12 | double dub = 1; 13 | } 14 | 15 | message SimpleSlice3 { 16 | repeated string slices = 1; 17 | } 18 | 19 | message SimpleMap3 { 20 | map stringy = 1; 21 | } 22 | 23 | message SimpleNull3 { 24 | Simple3 simple = 1; 25 | } 26 | 27 | enum Numeral { 28 | UNKNOWN = 0; 29 | ARABIC = 1; 30 | ROMAN = 2; 31 | } 32 | 33 | message Mappy { 34 | map nummy = 1; 35 | map strry = 2; 36 | map objjy = 3; 37 | map buggy = 4; 38 | map booly = 5; 39 | map enumy = 6; 40 | map s32booly = 7; 41 | map s64booly = 8; 42 | map u32booly = 9; 43 | map u64booly = 10; 44 | } 45 | -------------------------------------------------------------------------------- /system/dapp/commands/system.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 commands 系统级dapp相关命令包 6 | package commands 7 | 8 | import ( 9 | "github.com/33cn/chain33/rpc/jsonclient" 10 | rpctypes "github.com/33cn/chain33/rpc/types" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | // SystemCmd get system config command 15 | func SystemCmd() *cobra.Command { 16 | cmd := &cobra.Command{ 17 | Use: "system", 18 | Short: "Get node system info", 19 | Args: cobra.MinimumNArgs(1), 20 | } 21 | cmd.AddCommand( 22 | getConfigCmd(), 23 | ) 24 | return cmd 25 | } 26 | 27 | // SystemCmd get system config command 28 | func getConfigCmd() *cobra.Command { 29 | cmd := &cobra.Command{ 30 | Use: "config", 31 | Short: "Get node config", 32 | Run: config, 33 | } 34 | return cmd 35 | } 36 | 37 | func config(cmd *cobra.Command, args []string) { 38 | rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") 39 | var res rpctypes.ChainConfigInfo 40 | ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetChainConfig", nil, &res) 41 | ctx.Run() 42 | 43 | } 44 | -------------------------------------------------------------------------------- /rpc/ethrpc/web3/web3_test.go: -------------------------------------------------------------------------------- 1 | package web3 2 | 3 | import ( 4 | "testing" 5 | 6 | clientMocks "github.com/33cn/chain33/client/mocks" 7 | "github.com/33cn/chain33/queue" 8 | ctypes "github.com/33cn/chain33/types" 9 | "github.com/stretchr/testify/assert" 10 | ) 11 | 12 | var ( 13 | webObj *web3Handler 14 | qapi *clientMocks.QueueProtocolAPI 15 | q = queue.New("test") 16 | ) 17 | 18 | func init() { 19 | qapi = &clientMocks.QueueProtocolAPI{} 20 | cfg := ctypes.NewChain33Config(ctypes.GetDefaultCfgstring()) 21 | q.SetConfig(cfg) 22 | webObj = &web3Handler{} 23 | webObj.cfg = cfg 24 | webObj.cli.Init(q.Client(), qapi) 25 | 26 | } 27 | 28 | func TestWeb3Handler_Sha3(t *testing.T) { 29 | hash, err := webObj.Sha3("0x68656c6c6f20776f726c64") 30 | if err != nil { 31 | t.Log("err:", err) 32 | return 33 | } 34 | t.Log("hash:", hash) 35 | assert.Equal(t, hash, "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad") 36 | 37 | } 38 | 39 | func TestWeb3Handler_ClientVersion(t *testing.T) { 40 | verStr, err := webObj.ClientVersion() 41 | assert.Nil(t, err) 42 | t.Log(verStr) 43 | assert.Equal(t, verStr, "Geth/v1.8.15-omnibus-255989da/linux-amd64/go1.10.1") 44 | } 45 | -------------------------------------------------------------------------------- /system/address/btc/utxo.go: -------------------------------------------------------------------------------- 1 | package btc 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | 7 | "github.com/33cn/chain33/common/address" 8 | "github.com/btcsuite/btcd/wire" 9 | ) 10 | 11 | func init() { 12 | address.RegisterDriver(3, &utxo{}, 0) 13 | } 14 | 15 | var errAddressType = errors.New("ErrAddressType") 16 | 17 | type utxo struct{} 18 | 19 | // PubKeyToAddr public key to address 20 | func (u *utxo) PubKeyToAddr(_ []byte) string { 21 | panic("implement me") 22 | } 23 | 24 | // ValidateAddr address validation 25 | func (u *utxo) ValidateAddr(addr string) error { 26 | 27 | if !strings.Contains(addr, ":") { 28 | return errAddressType 29 | } 30 | _, err := wire.NewOutPointFromString(addr) 31 | if err != nil { 32 | return errAddressType 33 | } 34 | return nil 35 | } 36 | 37 | // GetName get driver name 38 | func (u *utxo) GetName() string { 39 | return "utxo" 40 | } 41 | 42 | // ToString trans to string format 43 | func (u *utxo) ToString(addr []byte) string { 44 | panic("implement me") 45 | } 46 | 47 | // FromString trans to byte format 48 | func (u *utxo) FromString(addr string) ([]byte, error) { 49 | panic("implement me") 50 | } 51 | 52 | func (u *utxo) FormatAddr(addr string) string { return addr } 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | clean.sh 2 | rm.sh 3 | top.txt 4 | top2.txt 5 | datadir* 6 | *.log 7 | *.exe 8 | *.orig 9 | *.bak 10 | .idea 11 | .vscode 12 | *.pprof 13 | *.test 14 | cmd/chain33/chain33 15 | cmd/tools/tools 16 | build/cert.pem 17 | build/key.pem 18 | build/chain33* 19 | build/datadir 20 | build/bityuan* 21 | build/para 22 | build/execblock 23 | build/relayd 24 | build/relayd.toml 25 | build/*.log 26 | build/fzm 27 | build/guodun 28 | build/main.sh 29 | build/main* 30 | build/para.sh 31 | build/ci 32 | nohup.out 33 | webhook 34 | cmd/execblock/execblock 35 | cmd/miner_accounts/miner_accounts 36 | cmd/write/write 37 | build/autotest/autotest 38 | build/autotest/local/* 39 | !build/autotest/local/autotest.sh 40 | plugin/consensus/raft/chain33_raft-1/ 41 | common/mavl/datastore 42 | .DS_Store 43 | common/.DS_Store 44 | common/config/.DS_Store 45 | executor/executor.test 46 | logs/ 47 | build/wallet 48 | consensus/drivers/raft/chain33_raft* 49 | plugin/store/kvmvcc/1.png 50 | plugin/store/kvmvcc/cpu.pprof 51 | plugin/store/kvmvcc/kvmvcc.test 52 | plugin/store/mpt/1.png 53 | plugin/store/mpt/cpu.pprof 54 | plugin/store/mpt/mpt.test 55 | system/store/mavl/1.png 56 | system/store/mavl/cpu.pprof 57 | system/store/mavl/mavl.test 58 | build/CHANGELOG.md -------------------------------------------------------------------------------- /system/mempool/pipeline.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 mempool 6 | 7 | import ( 8 | "sync" 9 | 10 | "github.com/33cn/chain33/queue" 11 | ) 12 | 13 | //pipeline 适用于 一个问题,分成很多步完成,每步的输出作为下一步的输入 14 | 15 | func step(done <-chan struct{}, in <-chan *queue.Message, cb func(*queue.Message) *queue.Message) <-chan *queue.Message { 16 | out := make(chan *queue.Message) 17 | go func() { 18 | defer close(out) 19 | for n := range in { 20 | select { 21 | case out <- cb(n): 22 | case <-done: 23 | return 24 | } 25 | } 26 | }() 27 | return out 28 | } 29 | 30 | func merge(done <-chan struct{}, cs []<-chan *queue.Message) <-chan *queue.Message { 31 | var wg sync.WaitGroup 32 | out := make(chan *queue.Message) 33 | output := func(c <-chan *queue.Message) { 34 | defer wg.Done() 35 | for n := range c { 36 | select { 37 | case out <- n: 38 | case <-done: 39 | return 40 | } 41 | } 42 | } 43 | wg.Add(len(cs)) 44 | for _, c := range cs { 45 | go output(c) 46 | } 47 | go func() { 48 | wg.Wait() 49 | close(out) 50 | }() 51 | return out 52 | } 53 | -------------------------------------------------------------------------------- /cmd/miner_accounts/accounts/account.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package accounts; 4 | 5 | message Account { 6 | string addr = 1; 7 | string frozen = 2; 8 | string balance = 3; 9 | } 10 | 11 | message MinerAccount { 12 | string addr = 1; 13 | string total = 2; 14 | string increase = 3; 15 | string frozen = 4; 16 | string expectIncrease = 5; 17 | string minerBtyDuring = 6; 18 | string expectMinerBlocks = 7; 19 | } 20 | message Accounts { 21 | repeated Account accounts = 1; 22 | } 23 | 24 | message MinerAccounts { 25 | repeated MinerAccount minerAccounts = 1; 26 | int64 seconds = 2; 27 | string totalIncrease = 3; 28 | int64 blocks = 4; 29 | int64 expectBlocks = 5; 30 | string expectTotalIncrease = 6; 31 | } 32 | 33 | message Config { 34 | repeated string whitelist = 1; 35 | string jrpcBindAddr = 2; 36 | string dataDir = 3; 37 | repeated string minerAddr = 4; 38 | string chain33host = 5; 39 | int64 coinPrecision = 6; // default 1e8 40 | } 41 | -------------------------------------------------------------------------------- /common/utils/ip.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "net" 5 | ) 6 | 7 | // IsPublicIP ... 8 | /* 9 | tcp/ip协议中,专门保留了三个IP地址区域作为私有地址,其地址范围如下: 10 | 10.0.0.0/8:10.0.0.0~10.255.255.255 11 | 172.16.0.0/12:172.16.0.0~172.31.255.255 12 | 192.168.0.0/16:192.168.0.0~192.168.255.255 13 | */ 14 | func IsPublicIP(ip string) bool { 15 | IP := net.ParseIP(ip) 16 | if IP == nil || IP.IsLoopback() || IP.IsLinkLocalMulticast() || IP.IsLinkLocalUnicast() { 17 | return false 18 | } 19 | if ip4 := IP.To4(); ip4 != nil { 20 | switch true { 21 | case ip4[0] == 10: 22 | return false 23 | case ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31: 24 | return false 25 | case ip4[0] == 192 && ip4[1] == 168: 26 | return false 27 | default: 28 | return true 29 | } 30 | } 31 | return false 32 | } 33 | 34 | // LocalIPv4s ... 35 | // LocalIPs return all non-loopback IPv4 addresses 36 | func LocalIPv4s() ([]string, error) { 37 | var ips []string 38 | addrs, err := net.InterfaceAddrs() 39 | if err != nil { 40 | return ips, err 41 | } 42 | 43 | for _, a := range addrs { 44 | if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil { 45 | ips = append(ips, ipnet.IP.String()) 46 | } 47 | } 48 | 49 | return ips, nil 50 | } 51 | -------------------------------------------------------------------------------- /cmd/tools/doc/calculator.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package types; 4 | // calculator 合约交易行为总类型 5 | message CalculatorAction { 6 | oneof value { 7 | Add add = 1; 8 | Subtract sub = 2; 9 | Multiply mul = 3; 10 | Divide div = 4; 11 | } 12 | int32 ty = 5; 13 | } 14 | 15 | message Add { 16 | int32 summand = 1; //被加数 17 | int32 addend = 2; //加数 18 | } 19 | message AddLog { 20 | int32 sum = 1; //和 21 | } 22 | 23 | message Subtract { 24 | int32 minuend = 1; //被减数 25 | int32 subtrahend = 2; //减数 26 | } 27 | message SubLog { 28 | int32 remainder = 1; //差 29 | } 30 | 31 | message Multiply { 32 | int32 faciend = 1; //被乘数 33 | int32 multiplier = 2; //乘数 34 | } 35 | message MultiplyLog { 36 | int32 product = 1; //积 37 | } 38 | 39 | message Divide { 40 | int32 dividend = 1; //被除数 41 | int32 divisor = 2; //除数 42 | } 43 | message DivideLog { 44 | int32 quotient = 1; //商 45 | int32 remain = 2; //余数 46 | } 47 | 48 | message ReqQueryCalcCount { 49 | string action = 1; 50 | } 51 | message ReplyQueryCalcCount { 52 | int32 count = 1; 53 | } 54 | 55 | service calculator { 56 | rpc QueryCalcCount(ReqQueryCalcCount) returns (ReplyQueryCalcCount) {} 57 | } 58 | -------------------------------------------------------------------------------- /cmd/tools/commands/createplugin.go: -------------------------------------------------------------------------------- 1 | //Copyright Fuzamei Corp. 2018 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 commands 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/33cn/chain33/cmd/tools/strategy" 11 | "github.com/33cn/chain33/cmd/tools/types" 12 | "github.com/spf13/cobra" 13 | ) 14 | 15 | // CreatePluginCmd 构造插件命令 16 | func CreatePluginCmd() *cobra.Command { 17 | cmd := &cobra.Command{ 18 | Use: "createplugin", 19 | Short: "Create chain33 plugin project mode", 20 | Run: createPlugin, 21 | } 22 | addCreatePluginFlag(cmd) 23 | return cmd 24 | } 25 | 26 | func addCreatePluginFlag(cmd *cobra.Command) { 27 | cmd.Flags().StringP("name", "n", "", "project name") 28 | cmd.MarkFlagRequired("name") 29 | 30 | } 31 | 32 | func createPlugin(cmd *cobra.Command, args []string) { 33 | projectName, _ := cmd.Flags().GetString("name") 34 | 35 | s := strategy.New(types.KeyCreatePlugin) 36 | if s == nil { 37 | fmt.Println(types.KeyCreatePlugin, "Not support") 38 | return 39 | } 40 | s.SetParam(types.KeyProjectName, projectName) 41 | s.SetParam(types.KeyExecutorName, projectName) 42 | s.SetParam(types.KeyClassName, projectName) 43 | s.Run() 44 | } 45 | -------------------------------------------------------------------------------- /wallet/bipwallet/go-bip44/bitLength_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 bip44_test 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/33cn/chain33/wallet/bipwallet" 11 | . "github.com/33cn/chain33/wallet/bipwallet/go-bip44" 12 | ) 13 | 14 | func TestBitLength(t *testing.T) { 15 | child, err := NewKeyFromMnemonic( 16 | "element fence situate special wrap snack method volcano busy ribbon neck sphere", 17 | bipwallet.TypeFactomFactoids, 18 | 2147483648, 19 | 0, 20 | 19, 21 | ) 22 | 23 | if err != nil { 24 | t.Errorf("%v", err) 25 | } 26 | if len(child.Key) != 32 { 27 | t.Errorf("len: %d, child.Key:%x\n", len(child.Key), child.Key) 28 | t.Errorf("%v", child.String()) 29 | } 30 | 31 | child, err = NewKeyFromMnemonic( 32 | "element fence situate special wrap snack method volcano busy ribbon neck sphere", 33 | bipwallet.TypeFactomFactoids, 34 | 2147483648, 35 | 1, 36 | 19, 37 | ) 38 | 39 | if err != nil { 40 | t.Errorf("%v", err) 41 | } 42 | if len(child.Key) != 32 { 43 | t.Errorf("len: %d, child.Key:%x\n", len(child.Key), child.Key) 44 | t.Errorf("%v", child.String()) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /system/crypto/none/none.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 none none driver 6 | package none 7 | 8 | import ( 9 | "github.com/33cn/chain33/common/crypto" 10 | ) 11 | 12 | // const 13 | const ( 14 | Name = "none" 15 | ID = 10 16 | ) 17 | 18 | func init() { 19 | // 默认启用高度-1, 不开启 20 | crypto.Register(Name, &Driver{}, crypto.WithRegOptionTypeID(ID), crypto.WithRegOptionDefaultDisable()) 21 | } 22 | 23 | // Driver 驱动 24 | type Driver struct{} 25 | 26 | // GenKey 生成私钥 27 | func (d Driver) GenKey() (crypto.PrivKey, error) { 28 | return nil, nil 29 | } 30 | 31 | // PrivKeyFromBytes 字节转为私钥 32 | func (d Driver) PrivKeyFromBytes(b []byte) (privKey crypto.PrivKey, err error) { 33 | return nil, nil 34 | } 35 | 36 | // PubKeyFromBytes 字节转为公钥 37 | func (d Driver) PubKeyFromBytes(b []byte) (pubKey crypto.PubKey, err error) { 38 | return nil, nil 39 | } 40 | 41 | // SignatureFromBytes 字节转为签名 42 | func (d Driver) SignatureFromBytes(b []byte) (sig crypto.Signature, err error) { 43 | return nil, nil 44 | } 45 | 46 | // Validate validate msg and signature 47 | func (d Driver) Validate(msg, pub, sig []byte) error { 48 | return nil 49 | } 50 | -------------------------------------------------------------------------------- /types/sign.md: -------------------------------------------------------------------------------- 1 | 2 | # 交易签名 3 | 4 | ## 签名类型 5 | >即签名结构中Ty字段, 以下统称为signID 6 | 7 | ```go 8 | type Signature struct { 9 | 10 | Ty int32 `protobuf:"varint,1,opt,name=ty,proto3" json:"ty,omitempty"` 11 | Pubkey []byte `protobuf:"bytes,2,opt,name=pubkey,proto3" json:"pubkey,omitempty"` 12 | Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"` 13 | } 14 | ``` 15 | 16 | #### 底层设计 17 | > 最初设计中, signID即cryptoID, 在引入多地址格式兼容(#1181)后, signID集成了cryptoID和addressID含义 18 | 19 | * addressID, 即签名公钥转换为地址时采用的地址类型ID, 在signID中占3位, 即低位第13~15位 20 | * cryptoID, 即签名对应的加密算法插件类型ID, 在signID中, 除addressID以外的其余位 21 | * 默认addressID为0, 此时cryptoID和signID值依然相等 22 | 23 | #### 集成算法 24 | > 通过位运算集成(兼容最初的signID逻辑, cryptoID只能作为低位) 25 | * signID = (addressID << 12) | cryptoID 26 | * addressID = 0x00007000 & signID >> 12 27 | * cryptoID = signID & 0xffff8fff 28 | 29 | 30 | #### 相关接口 31 | > signID, cryptoID, addressID转换接口 32 | 33 | * EncodeSignID, 基于cryptoID和addressID, 计算signID 34 | * ExtractAddressID, 基于signID, 提取addressID(主要用于交易的fromAddr计算) 35 | * ExtractCryptoID, 基于signID, 提取cryptoID 36 | * rpc, Chain33.GetChainConfig, 获取节点默认的地址ID配置 37 | 38 | 39 | #### 相关文档 40 | - 加密模块介绍, chain33/common/crypto/README.md 41 | - 地址模块介绍, chain33/common/address/README.md 42 | -------------------------------------------------------------------------------- /rpc/ethrpc/web3/web3.go: -------------------------------------------------------------------------------- 1 | package web3 2 | 3 | import ( 4 | "github.com/33cn/chain33/client" 5 | "github.com/33cn/chain33/common" 6 | "github.com/33cn/chain33/queue" 7 | rpcclient "github.com/33cn/chain33/rpc/client" 8 | ctypes "github.com/33cn/chain33/types" 9 | "github.com/ethereum/go-ethereum/common/hexutil" 10 | ) 11 | 12 | type web3Handler struct { 13 | cli rpcclient.ChannelClient 14 | cfg *ctypes.Chain33Config 15 | } 16 | 17 | // NewWeb3API nwe web3 api object 18 | func NewWeb3API(cfg *ctypes.Chain33Config, c queue.Client, api client.QueueProtocolAPI) interface{} { 19 | w := &web3Handler{} 20 | w.cli.Init(c, api) 21 | w.cfg = cfg 22 | return w 23 | } 24 | 25 | // Sha3 web3_sha3 26 | // Returns Keccak-256 (not the standardized SHA3-256) of the given data. 27 | func (w *web3Handler) Sha3(input string) (string, error) { 28 | data, err := common.FromHex(input) 29 | if err != nil { 30 | return "", err 31 | } 32 | return hexutil.Encode(common.Sha3(data)), nil 33 | } 34 | 35 | // ClientVersion ... 36 | // web3_clientVersion 37 | func (w *web3Handler) ClientVersion() (string, error) { 38 | var subcfg struct { 39 | Web3CliVer string `json:"web3CliVer,omitempty"` 40 | } 41 | 42 | ctypes.MustDecode(w.cfg.GetSubConfig().RPC["eth"], &subcfg) 43 | return subcfg.Web3CliVer, nil 44 | } 45 | -------------------------------------------------------------------------------- /system/consensus/snowman/readme.md: -------------------------------------------------------------------------------- 1 | 2 | ## 区块最终性共识 3 | 4 | 基于avlanche snowman共识引擎实现 5 | 6 | ### 使用配置 7 | 涉及blockchain, consensus 模块主要配置项 8 | 9 | ```toml 10 | 11 | [blockchain] 12 | # 启动高度, 作为初始共识高度 13 | blockFinalizeEnableHeight=0 14 | # 区块最终化启动后等待高度差, 达到启动高度后继续等待高度值, 最低1, 默认128 15 | blockFinalizeGapHeight=128 16 | 17 | 18 | [consensus] 19 | # 插件名称, 不配置则关闭最终化共识 20 | finalizer="snowman" 21 | 22 | # 共识参数, 通常无需配置, 采用默认即可 23 | [consensus.sub.snowman] 24 | # 单次投票参与节点数 25 | k=20 26 | # 单次投票通过最低票数, 需大于k/2 27 | alpha=15 28 | # 达成共识所需的连续投票成功次数 29 | betaVirtuous=15 30 | 31 | ``` 32 | 33 | 34 | ### 底层实现 35 | 36 | - 基于avalanchego v1.10.9, 并针对chain33做了简单改动适配, 主要包括整合区块哈希, 节点ID等数据格式保持一致, 移除跨平台编译不兼容依赖, 日志调整 37 | - replace github.com/ava-labs/avalanchego => github.com/bysomeone/avalanchego 38 | 39 | #### 模块简介 40 | 41 | > blockchain/finalize.go 42 | > 43 | snowman共识结果信息维护, 并根据本地主链打包情况进行状态校验, 分叉重置等处理 44 | 45 | > consensus/snowman 46 | > 47 | snowman共识引擎适配实现, 以下为主要文件介绍 48 | 49 | - snowman.go 共识入口, chain33 consensus finalizer插件实现, 事件接收分发调度 50 | - vm.go 链相关的功能适配, 衔接底层共识和blockchain交互, 涉及区块打包, 查询, 共识 51 | - validator.go 验证者功能适配, 主要实现节点抽样 52 | - sender.go 网络发送功能适配, 衔接底层p2p通信, 涉及共识交互 53 | - config.go 配置, 日志等底层接口依赖适配 54 | 55 | > dht/snow 56 | 57 | 底层p2p通信交互实现 58 | 59 | - EventHandler 处理本地消息事件 60 | - StreamHandler 处理网络消息事件 61 | -------------------------------------------------------------------------------- /wallet/bipwallet/transformer/transformer.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 transformer 通过私钥生成所选币种的公钥和地址 6 | package transformer 7 | 8 | import ( 9 | "fmt" 10 | "sync" 11 | ) 12 | 13 | // Transformer 过私钥生成所选币种的公钥和地址 14 | type Transformer interface { 15 | PrivKeyToPub(keyTy uint32, priv []byte) (pub []byte, err error) 16 | PubKeyToAddress(pub []byte) (add string, err error) 17 | } 18 | 19 | var ( 20 | driversMu sync.RWMutex 21 | drivers = make(map[string]Transformer) 22 | ) 23 | 24 | // Register 对不同币种的Transformer进行注册 25 | func Register(name string, driver Transformer) { 26 | driversMu.Lock() 27 | defer driversMu.Unlock() 28 | if driver == nil { 29 | panic("transformer: Register driver is nil") 30 | } 31 | if _, dup := drivers[name]; dup { 32 | panic("transformer: Register called twice for driver " + name) 33 | } 34 | drivers[name] = driver 35 | } 36 | 37 | // New 提供币种名称返回相应的Transformer对象 38 | func New(name string) (t Transformer, err error) { 39 | driversMu.RLock() 40 | defer driversMu.RUnlock() 41 | t, ok := drivers[name] 42 | if !ok { 43 | err = fmt.Errorf("unknown Transformer %q", name) 44 | return 45 | } 46 | 47 | return t, nil 48 | } 49 | -------------------------------------------------------------------------------- /cmd/tools/commands/updateinit.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 commands 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/33cn/chain33/cmd/tools/strategy" 11 | "github.com/33cn/chain33/cmd/tools/types" 12 | "github.com/spf13/cobra" 13 | ) 14 | 15 | // UpdateInitCmd 升级初始命令 16 | func UpdateInitCmd() *cobra.Command { 17 | cmd := &cobra.Command{ 18 | Use: "updateinit", 19 | Short: "Update chain33 plugin consensus、dapp、store、mempool init.go file", 20 | Run: updateInit, 21 | } 22 | cmd.Flags().StringP("path", "p", "plugin", "path of plugin") 23 | cmd.Flags().StringP("out", "o", "", "output new config file") 24 | cmd.Flags().StringP("packname", "", "", "project package name") 25 | return cmd 26 | } 27 | 28 | func updateInit(cmd *cobra.Command, args []string) { 29 | path, _ := cmd.Flags().GetString("path") 30 | packname, _ := cmd.Flags().GetString("packname") 31 | out, _ := cmd.Flags().GetString("out") 32 | 33 | s := strategy.New(types.KeyUpdateInit) 34 | if s == nil { 35 | fmt.Println(types.KeyUpdateInit, "Not support") 36 | return 37 | } 38 | s.SetParam("out", out) 39 | s.SetParam("path", path) 40 | s.SetParam("packname", packname) 41 | s.Run() 42 | } 43 | -------------------------------------------------------------------------------- /common/listmap/listmap_test.go: -------------------------------------------------------------------------------- 1 | package listmap 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/33cn/chain33/types" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestListMap(t *testing.T) { 11 | l := New() 12 | l.Push("1", "1") 13 | assert.Equal(t, 1, l.Size()) 14 | l.Push("1", "11") 15 | assert.Equal(t, 1, l.Size()) 16 | value, err := l.GetItem("1") 17 | assert.Equal(t, err, nil) 18 | assert.Equal(t, "11", value.(string)) 19 | l.Remove("1") 20 | assert.Equal(t, 0, l.Size()) 21 | assert.Equal(t, false, l.Exist("1")) 22 | 23 | v := l.GetTop() 24 | assert.Equal(t, nil, v) 25 | 26 | _, err = l.GetItem("11") 27 | assert.Equal(t, types.ErrNotFound, err) 28 | l.Push("1", "11") 29 | assert.Equal(t, true, l.Exist("1")) 30 | l.Push("2", "2") 31 | assert.Equal(t, "11", l.GetTop().(string)) 32 | 33 | var data [2]string 34 | i := 0 35 | l.Walk(func(value interface{}) bool { 36 | data[i] = value.(string) 37 | i++ 38 | return true 39 | }) 40 | assert.Equal(t, data[0], "11") 41 | assert.Equal(t, data[1], "2") 42 | 43 | var data2 [2]string 44 | i = 0 45 | l.Walk(func(value interface{}) bool { 46 | data2[i] = value.(string) 47 | i++ 48 | return false 49 | }) 50 | assert.Equal(t, data2[0], "11") 51 | assert.Equal(t, data2[1], "") 52 | 53 | l.Walk(nil) 54 | l.Remove("xxxx") 55 | } 56 | -------------------------------------------------------------------------------- /rpc/ethrpc/net/net.go: -------------------------------------------------------------------------------- 1 | package net 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/33cn/chain33/system/crypto/secp256k1eth" 7 | 8 | "github.com/33cn/chain33/client" 9 | "github.com/33cn/chain33/queue" 10 | rpcclient "github.com/33cn/chain33/rpc/client" 11 | "github.com/33cn/chain33/types" 12 | ctypes "github.com/33cn/chain33/types" 13 | "github.com/ethereum/go-ethereum/common/hexutil" 14 | ) 15 | 16 | type netHandler struct { 17 | cli rpcclient.ChannelClient 18 | cfg *ctypes.Chain33Config 19 | } 20 | 21 | // NewNetAPI create a net api 22 | func NewNetAPI(cfg *ctypes.Chain33Config, c queue.Client, api client.QueueProtocolAPI) interface{} { 23 | p := &netHandler{} 24 | p.cli.Init(c, api) 25 | p.cfg = cfg 26 | return p 27 | } 28 | 29 | // PeerCount net_peerCount 30 | func (n *netHandler) PeerCount() (string, error) { 31 | 32 | var in = types.P2PGetPeerReq{} 33 | reply, err := n.cli.PeerInfo(&in) 34 | if err != nil { 35 | return "0x0", err 36 | } 37 | 38 | numPeers := len(reply.Peers) 39 | return hexutil.EncodeUint64(uint64(numPeers)), nil 40 | } 41 | 42 | // Listening net_listening 43 | func (n *netHandler) Listening() (bool, error) { 44 | return true, nil 45 | } 46 | 47 | // Version net_version 48 | func (n *netHandler) Version() (string, error) { 49 | return strconv.FormatInt(secp256k1eth.GetEvmChainID(), 10), nil 50 | } 51 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/examples/blind/blind.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 main 6 | 7 | import ( 8 | "crypto/rand" 9 | "fmt" 10 | 11 | btcutil "github.com/33cn/chain33/wallet/bipwallet/btcutilecc" 12 | ) 13 | 14 | func main() { 15 | signer := new(btcutil.BlindSignerState) 16 | requester := new(btcutil.BlindRequesterState) 17 | 18 | // requester: message that needs to be blind signed 19 | m, err := btcutil.RandFieldElement(rand.Reader) 20 | maybePanic(err) 21 | fmt.Printf("m = %x\n", m) 22 | 23 | // requester: ask signer to start the protocol 24 | Q, R := btcutil.BlindSession(signer) 25 | fmt.Println("") 26 | 27 | // requester: blind message 28 | mHat := btcutil.BlindMessage(requester, Q, R, m) 29 | 30 | // signer: create blind signature 31 | sHat := btcutil.BlindSign(signer, R, mHat) 32 | 33 | // requester extracts real signature 34 | sig := btcutil.BlindExtract(requester, sHat) 35 | sig.M = m 36 | fmt.Printf("sig =\t%x\n\t%x\n", sig.S, sig.F.X) 37 | 38 | // onlooker verifies signature 39 | if btcutil.BlindVerify(Q, sig) { 40 | fmt.Printf("valid signature\n") 41 | } 42 | } 43 | 44 | func maybePanic(err error) { 45 | if err != nil { 46 | panic(err) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /system/p2p/dht/extension/pubsub_test.go: -------------------------------------------------------------------------------- 1 | package extension 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "testing" 7 | 8 | p2pty "github.com/33cn/chain33/system/p2p/dht/types" 9 | 10 | core "github.com/libp2p/go-libp2p/core" 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | func testMsg(topic string, msg SubMsg) { 15 | fmt.Println("testMsg", core.PeerID(msg.From).String(), "data", string(msg.Data)) 16 | } 17 | 18 | func Test_pubsub(t *testing.T) { 19 | ctx, cancel := context.WithCancel(context.Background()) 20 | defer cancel() 21 | hosts := getNetHosts(2, t) 22 | connect(t, hosts[0], hosts[1]) 23 | 24 | psub, err := NewPubSub(ctx, hosts[0], &p2pty.PubSubConfig{}) 25 | require.Nil(t, err) 26 | err = psub.JoinAndSubTopic("bztest", testMsg) 27 | require.Nil(t, err) 28 | 29 | err = psub.Publish("bztest", []byte("hello,world")) 30 | require.Nil(t, err) 31 | err = psub.Publish("bztest2", []byte("hello,world")) 32 | require.NotNil(t, err) 33 | topics := psub.GetTopics() 34 | require.Equal(t, 1, len(topics)) 35 | require.Equal(t, "bztest", topics[0]) 36 | require.False(t, psub.HasTopic("mytest")) 37 | peers := psub.FetchTopicPeers("mytest") 38 | t.Log(peers) 39 | require.Equal(t, 0, len(peers)) 40 | peers = psub.FetchTopicPeers("bztest") 41 | t.Log(peers) 42 | psub.RemoveTopic("bztest") 43 | require.Equal(t, 0, psub.TopicNum()) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /account/genesis_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 account 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/33cn/chain33/types" 11 | 12 | //"fmt" 13 | "github.com/33cn/chain33/common/address" 14 | "github.com/stretchr/testify/require" 15 | ) 16 | 17 | func TestGenesisInit(t *testing.T) { 18 | accCoin, _ := GenerAccDb() 19 | accCoin.GenerAccData() 20 | _, err := accCoin.GenesisInit(addr1, 100*types.DefaultCoinPrecision) 21 | require.NoError(t, err) 22 | //t.Logf("GenesisInit is %v", recp) 23 | t.Logf("GenesisInit [%d]", 24 | accCoin.LoadAccount(addr1).Balance) 25 | } 26 | 27 | func TestGenesisInitExec(t *testing.T) { 28 | accCoin, _ := GenerAccDb() 29 | execaddr := address.ExecAddress("coins") 30 | _, err := accCoin.GenesisInitExec(addr1, 10*types.DefaultCoinPrecision, execaddr) 31 | require.NoError(t, err) 32 | //t.Logf("GenesisInitExec Receipt is %v", Receipt) 33 | t.Logf("GenesisInitExec [%d]___[%d]", 34 | accCoin.LoadExecAccount(addr1, execaddr).Balance, 35 | accCoin.LoadAccount(execaddr).Balance) 36 | require.Equal(t, 10*types.DefaultCoinPrecision, accCoin.LoadExecAccount(addr1, execaddr).Balance) 37 | require.Equal(t, 10*types.DefaultCoinPrecision, accCoin.LoadAccount(execaddr).Balance) 38 | } 39 | -------------------------------------------------------------------------------- /system/p2p/dht/extension/mdns.go: -------------------------------------------------------------------------------- 1 | package extension 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/libp2p/go-libp2p/core/host" 7 | "github.com/libp2p/go-libp2p/core/peer" 8 | discovery "github.com/libp2p/go-libp2p/p2p/discovery/mdns" 9 | ) 10 | 11 | // MDNS mdns 12 | type MDNS struct { 13 | Service discovery.Service 14 | notifee *discoveryNotifee 15 | } 16 | 17 | // 用于局域网内节点发现 18 | type discoveryNotifee struct { 19 | PeerChan chan peer.AddrInfo 20 | } 21 | 22 | // HandlePeerFound is a interface to be called when new peer is found 23 | func (n *discoveryNotifee) HandlePeerFound(pi peer.AddrInfo) { 24 | n.PeerChan <- pi 25 | } 26 | 27 | // NewMDNS Initialize the MDNS service 28 | func NewMDNS(ctx context.Context, peerhost host.Host, serviceTag string) (*MDNS, error) { 29 | //register with service so that we get notified about peer discovery 30 | notifee := &discoveryNotifee{} 31 | notifee.PeerChan = make(chan peer.AddrInfo, 1) 32 | ser := discovery.NewMdnsService(peerhost, serviceTag, notifee) 33 | err := ser.Start() 34 | if err != nil { 35 | log.Error("NewMDNS", "start mdns service err", err) 36 | return nil, err 37 | } 38 | mnds := new(MDNS) 39 | mnds.Service = ser 40 | mnds.notifee = notifee 41 | return mnds, nil 42 | } 43 | 44 | // PeerChan returns a peer channel 45 | func (m *MDNS) PeerChan() chan peer.AddrInfo { 46 | return m.notifee.PeerChan 47 | } 48 | -------------------------------------------------------------------------------- /system/p2p/dht/types/const.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types dht public types 6 | package types 7 | 8 | import ( 9 | "errors" 10 | "time" 11 | ) 12 | 13 | const ( 14 | //Version P2P client version 15 | Version = "1.0.0" 16 | // DHTTypeName p2p插件名称,底层基于libp2p框架, dht结构化网络 17 | DHTTypeName = "dht" 18 | 19 | // DefaultP2PPort 默认端口 20 | DefaultP2PPort = 13803 21 | 22 | // MinPercentage ... 23 | MinPercentage = 10 24 | // MaxPercentage ... 25 | MaxPercentage = 100 26 | // DefaultPercentage ... 27 | DefaultPercentage = 30 28 | ) 29 | 30 | var ( 31 | // ErrLength err length 32 | ErrLength = errors.New("length not equal") 33 | // ErrInvalidMessageType invalid message type err 34 | ErrInvalidMessageType = errors.New("invalid message type") 35 | // ErrNotFound not found err 36 | ErrNotFound = errors.New("not found") 37 | // ErrInvalidParam invalid param err 38 | ErrInvalidParam = errors.New("invalid parameter") 39 | // ErrWrongSignature wrong signature err 40 | ErrWrongSignature = errors.New("wrong signature") 41 | // ErrInvalidResponse invalid response error 42 | ErrInvalidResponse = errors.New("invalid response") 43 | 44 | // RefreshInterval refresh interval 45 | RefreshInterval = time.Hour * 3 46 | ) 47 | -------------------------------------------------------------------------------- /cmd/cli/autocomplete/readme.md: -------------------------------------------------------------------------------- 1 | 2 | ## 安装 3 | 4 | ``` 5 | $ sudo install chain33-cli.bash /usr/share/bash-completion/completions/chain33-cli 6 | ``` 7 | 8 | 不安装 9 | ``` 10 | . chain33-cli.bash 11 | ``` 12 | 13 | ``` 14 | # 重新开个窗口就有用了 15 | $ ./chain33/chain33-cli 16 | account bty coins evm hashlock mempool privacy retrieve send ticket trade version 17 | block close config exec help net relay seed stat token tx wallet 18 | ``` 19 | 20 | ## 演示 21 | ``` 22 | linj@linj-TM1701:~$ ./chain33/chain33-cli 23 | account bty coins evm hashlock mempool privacy retrieve send ticket trade version 24 | block close config exec help net relay seed stat token tx wallet 25 | linj@linj-TM1701:~$ ./chain33/chain33-cli b 26 | block bty 27 | linj@linj-TM1701:~$ ./chain33/chain33-cli bty 28 | priv2priv priv2pub pub2priv send transfer txgroup withdraw 29 | linj@linj-TM1701:~$ ./chain33/chain33-cli bty t 30 | transfer txgroup 31 | linj@linj-TM1701:~$ ./chain33/chain33-cli bty transfer - 32 | -a --amount -h --help -n --note --para --rpc -t --to 33 | ``` 34 | 35 | 36 | ## 原理 37 | 38 | 地址 https://confluence.33.cn/pages/viewpage.action?pageId=5967798 39 | -------------------------------------------------------------------------------- /blockchain/reduce_real_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 blockchain_test 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/33cn/chain33/blockchain" 11 | "github.com/33cn/chain33/util" 12 | "github.com/33cn/chain33/util/testnode" 13 | "github.com/stretchr/testify/require" 14 | ) 15 | 16 | func TestTryReduceLocalDB(t *testing.T) { 17 | cfg := testnode.GetDefaultConfig() 18 | mock33 := testnode.NewWithConfig(cfg, nil) 19 | //发送交易 20 | chain := mock33.GetBlockChain() 21 | db := chain.GetDB() 22 | kvs := getAllKeys(db) 23 | require.Equal(t, len(kvs), kvCount) 24 | defer mock33.Close() 25 | 26 | blockchain.ReduceHeight = 0 27 | defer func() { 28 | blockchain.ReduceHeight = 10000 29 | }() 30 | 31 | var flagHeight int64 32 | count := 10 33 | for i := 0; i < 2; i++ { 34 | txs := util.GenCoinsTxs(cfg, mock33.GetGenesisKey(), int64(count)) 35 | for j := 0; j < len(txs); j++ { 36 | reply, err := mock33.GetAPI().SendTx(txs[j]) 37 | require.Nil(t, err) 38 | require.Equal(t, reply.IsOk, true) 39 | waitH := i*count + (j + 1) 40 | mock33.WaitHeight(int64(waitH)) 41 | } 42 | flagHeight = chain.TryReduceLocalDB(flagHeight, int64(count)) 43 | require.Equal(t, flagHeight, int64((i+1)*count+1)) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /client/mock_p2p_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 client_test 6 | 7 | import ( 8 | "github.com/33cn/chain33/queue" 9 | "github.com/33cn/chain33/types" 10 | ) 11 | 12 | type mockP2P struct { 13 | } 14 | 15 | func (m *mockP2P) SetQueueClient(q queue.Queue) { 16 | go func() { 17 | p2pKey := "p2p" 18 | client := q.Client() 19 | client.Sub(p2pKey) 20 | for msg := range client.Recv() { 21 | switch msg.Ty { 22 | case types.EventPeerInfo: 23 | msg.Reply(client.NewMessage(p2pKey, types.EventPeerList, &types.PeerList{})) 24 | case types.EventGetNetInfo: 25 | msg.Reply(client.NewMessage(p2pKey, types.EventPeerList, &types.NodeNetInfo{})) 26 | case types.EventDialPeer, types.EventClosePeer: 27 | setpeer, ok := msg.GetData().(*types.SetPeer) 28 | if !ok || setpeer.GetPeerAddr() == "" { 29 | msg.Reply(client.NewMessage(p2pKey, types.EventReply, &types.Reply{IsOk: false, Msg: []byte(types.ErrInvalidParam.Error())})) 30 | break 31 | } 32 | msg.Reply(client.NewMessage(p2pKey, types.EventReply, &types.Reply{IsOk: true, Msg: []byte("success")})) 33 | default: 34 | msg.ReplyErr("Do not support", types.ErrNotSupport) 35 | } 36 | } 37 | }() 38 | } 39 | 40 | func (m *mockP2P) Close() { 41 | } 42 | -------------------------------------------------------------------------------- /system/dapp/manage/proto/manage.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "executor.proto"; 4 | 5 | package types; 6 | option go_package = "../types"; 7 | 8 | //申请修改配置项 9 | message ApplyConfig { 10 | ModifyConfig config = 1; 11 | } 12 | 13 | //批准配置项 14 | message ApproveConfig { 15 | string applyConfigId = 1; //修改配置项申请ID 16 | string autonomyItemId = 2; // autonomy 合約批准的 item ID 17 | } 18 | 19 | message ManageAction { 20 | oneof value { 21 | ModifyConfig modify = 1; 22 | ApplyConfig apply = 3; 23 | ApproveConfig approve = 4; 24 | } 25 | int32 Ty = 2; 26 | } 27 | 28 | message ConfigStatus { 29 | string id = 1; //申请ID 30 | ModifyConfig config = 2; 31 | int32 status = 3; 32 | string proposer = 4; 33 | 34 | // 状态 35 | int64 height = 8; 36 | int32 index = 9; 37 | } 38 | 39 | message ReceiptApplyConfig { 40 | ConfigStatus status = 1; 41 | } 42 | 43 | message ReceiptApproveConfig { 44 | ConfigStatus pre = 1; 45 | ConfigStatus cur = 2; 46 | } 47 | 48 | // query 49 | message ReqQueryConfigList { 50 | 51 | int32 status = 1; 52 | string proposer = 2; 53 | int32 count = 3; 54 | int32 direction = 4; 55 | int64 height = 5; 56 | int32 index = 6; 57 | } 58 | 59 | message ReplyQueryConfigList { 60 | repeated ConfigStatus lists = 1; 61 | } 62 | -------------------------------------------------------------------------------- /wallet/bipwallet/btcutilecc/arith.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 btcutil Utility functions for Bitcoin elliptic curve cryptography. 6 | package btcutil 7 | 8 | import ( 9 | "crypto/ecdsa" 10 | "math/big" 11 | ) 12 | 13 | // ScalarBaseMult Multiplies the base G by a large integer. The resulting 14 | // point is represented as an ECDSA public key since that's 15 | // typically how they're used. 16 | func ScalarBaseMult(k *big.Int) *ecdsa.PublicKey { 17 | key := new(ecdsa.PublicKey) 18 | key.Curve = Secp256k1() 19 | key.X, key.Y = Secp256k1().ScalarBaseMult(k.Bytes()) 20 | return key 21 | } 22 | 23 | // ScalarMult Multiply a large integer and a point. The resulting point 24 | // is represented as an ECDSA public key. 25 | func ScalarMult(k *big.Int, B *ecdsa.PublicKey) *ecdsa.PublicKey { 26 | key := new(ecdsa.PublicKey) 27 | key.Curve = Secp256k1() 28 | key.X, key.Y = Secp256k1().ScalarMult(B.X, B.Y, k.Bytes()) 29 | return key 30 | } 31 | 32 | // Add Adds two points to create a third. Points are represented as 33 | // ECDSA public keys. 34 | func Add(a, b *ecdsa.PublicKey) *ecdsa.PublicKey { 35 | key := new(ecdsa.PublicKey) 36 | key.Curve = Secp256k1() 37 | key.X, key.Y = Secp256k1().Add(a.X, a.Y, b.X, b.Y) 38 | return key 39 | } 40 | -------------------------------------------------------------------------------- /cmd/autotest/types/simpleCase.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 定义autotest包基础结构体、接口、以及函数 6 | package types 7 | 8 | import ( 9 | "errors" 10 | "strings" 11 | ) 12 | 13 | //simple case just executes without checking, suitable for init situation 14 | 15 | // SimpleCase 简单用例 16 | type SimpleCase struct { 17 | BaseCase 18 | } 19 | 20 | // SimplePack 简单pack 21 | type SimplePack struct { 22 | BaseCasePack 23 | } 24 | 25 | // SendCommand 发送cmd 26 | func (testCase *SimpleCase) SendCommand(packID string) (PackFunc, error) { 27 | 28 | output, err := RunChain33Cli(strings.Fields(testCase.GetCmd())) 29 | if err != nil { 30 | return nil, errors.New(output) 31 | } 32 | testPack := &SimplePack{} 33 | pack := testPack.GetBasePack() 34 | pack.TxHash = output 35 | pack.TCase = testCase 36 | 37 | pack.PackID = packID 38 | pack.CheckTimes = 0 39 | return testPack, nil 40 | 41 | } 42 | 43 | // CheckResult simple case needn't check 44 | func (pack *SimplePack) CheckResult(handlerMap interface{}) (bCheck bool, bSuccess bool) { 45 | 46 | bCheck = true 47 | bSuccess = true 48 | if strings.Contains(pack.TxHash, "Err") || strings.Contains(pack.TxHash, "connection refused") { 49 | 50 | bSuccess = false 51 | } 52 | 53 | return bCheck, bSuccess 54 | } 55 | -------------------------------------------------------------------------------- /cmd/autotest/types/types.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | import "reflect" 8 | 9 | // var 10 | var ( 11 | CliCmd string //chain33 cli可执行文件名 12 | CheckTimeout int //用例check时超时次数 13 | autoTestItems = make(map[string]AutoTest) //保存注册的dapp测试类型 14 | ) 15 | 16 | // AutoTest dapp实现auto test的接口,需要提供每个dapp对应的测试配置类型,并注册 17 | type AutoTest interface { 18 | GetName() string 19 | GetTestConfigType() reflect.Type 20 | } 21 | 22 | // Init 超时次数等于总超时时间除以每次check时睡眠时间 23 | func Init(cliCmd string, checkTimeout int) { 24 | 25 | CliCmd = cliCmd 26 | CheckTimeout = checkTimeout 27 | } 28 | 29 | // RegisterAutoTest 注册测试配置类型 30 | func RegisterAutoTest(at AutoTest) { 31 | 32 | if at == nil || len(at.GetName()) == 0 { 33 | return 34 | } 35 | dapp := at.GetName() 36 | 37 | if _, ok := autoTestItems[dapp]; ok { 38 | panic("Register Duplicate Dapp, name = " + dapp) 39 | } 40 | autoTestItems[dapp] = at 41 | } 42 | 43 | // GetAutoTestConfig 获取测试配置类型 44 | func GetAutoTestConfig(dapp string) reflect.Type { 45 | 46 | if len(dapp) == 0 { 47 | 48 | return nil 49 | } 50 | 51 | if config, ok := autoTestItems[dapp]; ok { 52 | 53 | return config.GetTestConfigType() 54 | } 55 | 56 | return nil 57 | } 58 | -------------------------------------------------------------------------------- /rpc/types/server.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 types 6 | 7 | import ( 8 | "context" 9 | "net/rpc" 10 | 11 | "github.com/33cn/chain33/account" 12 | "github.com/33cn/chain33/client" 13 | "github.com/33cn/chain33/queue" 14 | "github.com/33cn/chain33/types" 15 | "google.golang.org/grpc" 16 | ) 17 | 18 | // RPCServer interface 19 | type RPCServer interface { 20 | GetQueueClient() queue.Client 21 | GRPC() *grpc.Server 22 | JRPC() *rpc.Server 23 | Context() context.Context 24 | } 25 | 26 | // ChannelClient interface 27 | type ChannelClient struct { 28 | client.QueueProtocolAPI 29 | accountdb *account.DB 30 | grpc interface{} 31 | jrpc interface{} 32 | } 33 | 34 | // Init init function 35 | func (c *ChannelClient) Init(name string, s RPCServer, jrpc, grpc interface{}) { 36 | if c.QueueProtocolAPI == nil { 37 | c.QueueProtocolAPI, _ = client.New(s.GetQueueClient(), nil) 38 | } 39 | if jrpc != nil { 40 | s.JRPC().RegisterName(name, jrpc) 41 | } 42 | c.grpc = grpc 43 | c.jrpc = jrpc 44 | types.AssertConfig(c.QueueProtocolAPI) 45 | c.accountdb = account.NewCoinsAccount(c.GetConfig()) 46 | } 47 | 48 | // GetCoinsAccountDB return accountdb 49 | func (c *ChannelClient) GetCoinsAccountDB() *account.DB { 50 | return c.accountdb 51 | } 52 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/peer/statistic.go: -------------------------------------------------------------------------------- 1 | package peer 2 | 3 | import ( 4 | "github.com/33cn/chain33/system/p2p/dht/protocol" 5 | "github.com/33cn/chain33/types" 6 | "github.com/libp2p/go-libp2p/core/network" 7 | ) 8 | 9 | const ( 10 | //p2p statistical information 11 | statisticalInfo = "/chain33/statistical/1.0.0" 12 | ) 13 | 14 | // handlerStreamStatistical 返回当前连接的节点信息以及网络带宽信息 15 | func (p *Protocol) handlerStreamStatistical(stream network.Stream) { 16 | defer protocol.CloseStream(stream) 17 | var statistical types.Statistical 18 | statistical.Peers = p.PeerInfoManager.FetchAll() 19 | insize, outsize := p.ConnManager.BoundSize() 20 | statistical.Nodeinfo = &types.NodeNetInfo{} 21 | statistical.Nodeinfo.Inbounds = int32(insize) 22 | statistical.Nodeinfo.Outbounds = int32(outsize) 23 | statistical.Nodeinfo.Peerstore = int32(len(p.Host.Peerstore().PeersWithAddrs())) 24 | statistical.Nodeinfo.Routingtable = int32(p.RoutingTable.Size()) 25 | netstat := p.ConnManager.GetNetRate() 26 | statistical.Nodeinfo.Ratein = p.ConnManager.RateCalculate(netstat.RateIn) 27 | statistical.Nodeinfo.Rateout = p.ConnManager.RateCalculate(netstat.RateOut) 28 | statistical.Nodeinfo.Ratetotal = p.ConnManager.RateCalculate(netstat.RateOut + netstat.RateIn) 29 | 30 | err := protocol.WriteStream(&statistical, stream) 31 | if err != nil { 32 | log.Error("handleStreamPeerInfoOld", "WriteStream error", err) 33 | return 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /cmd/tools/gencode/dappcode/commands/commands.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 commands 6 | 7 | import ( 8 | "github.com/33cn/chain33/cmd/tools/gencode/base" 9 | "github.com/33cn/chain33/cmd/tools/types" 10 | ) 11 | 12 | func init() { 13 | 14 | base.RegisterCodeFile(commandsCodeFile{}) 15 | } 16 | 17 | type commandsCodeFile struct { 18 | base.DappCodeFile 19 | } 20 | 21 | func (c commandsCodeFile) GetDirName() string { 22 | 23 | return "commands" 24 | } 25 | 26 | func (c commandsCodeFile) GetFiles() map[string]string { 27 | 28 | return map[string]string{ 29 | commandsFileName: commandsFileContent, 30 | } 31 | } 32 | 33 | func (c commandsCodeFile) GetFileReplaceTags() []string { 34 | return []string{types.TagExecName} 35 | } 36 | 37 | var ( 38 | commandsFileName = "commands.go" 39 | commandsFileContent = `/*Package commands implement dapp client commands*/ 40 | package commands 41 | 42 | import ( 43 | "github.com/spf13/cobra" 44 | ) 45 | 46 | /* 47 | * 实现合约对应客户端 48 | */ 49 | 50 | // Cmd ${EXECNAME} client command 51 | func Cmd() *cobra.Command { 52 | cmd := &cobra.Command{ 53 | Use: "${EXECNAME}", 54 | Short: "${EXECNAME} command", 55 | Args: cobra.MinimumNArgs(1), 56 | } 57 | cmd.AddCommand( 58 | //add sub command 59 | ) 60 | return cmd 61 | } 62 | ` 63 | ) 64 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/broadcast/batchtx.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 broadcast 6 | 7 | import ( 8 | "time" 9 | 10 | "github.com/33cn/chain33/types" 11 | ) 12 | 13 | const ( 14 | defaultMaxBatchTxNum = 100 15 | defaultMaxBatchTxInterval = 100 // ms 16 | ) 17 | 18 | func (p *broadcastProtocol) handleSendBatchTx(batchChan chan interface{}) { 19 | 20 | interval := time.Millisecond * time.Duration(p.cfg.MaxBatchTxInterval) 21 | batchNum := p.cfg.MaxBatchTxNum 22 | ticker := time.NewTicker(interval) 23 | 24 | defer p.ps.Unsub(batchChan) 25 | txs := &types.Transactions{Txs: make([]*types.Transaction, 0, batchNum)} 26 | readySend := false 27 | for { 28 | 29 | select { 30 | case <-p.Ctx.Done(): 31 | ticker.Stop() 32 | return 33 | case msg := <-batchChan: 34 | txs.Txs = append(txs.Txs, msg.(*types.Transaction)) 35 | if len(txs.Txs) >= batchNum { 36 | readySend = true 37 | } 38 | case <-ticker.C: 39 | readySend = true 40 | } 41 | 42 | if !readySend || len(txs.Txs) == 0 { 43 | continue 44 | } 45 | p.ps.Pub(publishMsg{msg: txs, topic: psBatchTxTopic}, psBroadcast) 46 | ticker.Reset(interval) 47 | // 异步处理, 需要重新申请对象 48 | txs = &types.Transactions{Txs: make([]*types.Transaction, 0, batchNum)} 49 | readySend = false 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /wallet/common/crypto.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 common 6 | 7 | import ( 8 | "crypto/aes" 9 | "crypto/cipher" 10 | ) 11 | 12 | // CBCEncrypterPrivkey 使用钱包的password对私钥进行aes cbc加密,返回加密后的privkey 13 | func CBCEncrypterPrivkey(password []byte, privkey []byte) []byte { 14 | key := make([]byte, 32) 15 | Encrypted := make([]byte, len(privkey)) 16 | if len(password) > 32 { 17 | key = password[0:32] 18 | } else { 19 | copy(key, password) 20 | } 21 | 22 | block, err := aes.NewCipher(key) 23 | if err != nil { 24 | return nil 25 | } 26 | iv := key[:block.BlockSize()] 27 | 28 | encrypter := cipher.NewCBCEncrypter(block, iv) 29 | encrypter.CryptBlocks(Encrypted, privkey) 30 | 31 | return Encrypted 32 | } 33 | 34 | // CBCDecrypterPrivkey 使用钱包的password对私钥进行aes cbc解密,返回解密后的privkey 35 | func CBCDecrypterPrivkey(password []byte, privkey []byte) []byte { 36 | key := make([]byte, 32) 37 | if len(password) > 32 { 38 | key = password[0:32] 39 | } else { 40 | copy(key, password) 41 | } 42 | block, err := aes.NewCipher(key) 43 | if err != nil { 44 | return nil 45 | } 46 | iv := key[:block.BlockSize()] 47 | decryptered := make([]byte, len(privkey)) 48 | decrypter := cipher.NewCBCDecrypter(block, iv) 49 | decrypter.CryptBlocks(decryptered, privkey) 50 | return decryptered 51 | } 52 | -------------------------------------------------------------------------------- /cmd/tools/gencode/dappcode/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 dappcode 6 | 7 | import ( 8 | "github.com/33cn/chain33/cmd/tools/gencode/base" 9 | "github.com/33cn/chain33/cmd/tools/types" 10 | ) 11 | 12 | func init() { 13 | 14 | base.RegisterCodeFile(pluginCodeFile{}) 15 | } 16 | 17 | type pluginCodeFile struct { 18 | base.DappCodeFile 19 | } 20 | 21 | func (c pluginCodeFile) GetFiles() map[string]string { 22 | 23 | return map[string]string{ 24 | pluginName: pluginContent, 25 | } 26 | } 27 | 28 | func (c pluginCodeFile) GetFileReplaceTags() []string { 29 | 30 | return []string{types.TagExecName, types.TagImportPath, types.TagClassName} 31 | } 32 | 33 | var ( 34 | pluginName = "plugin.go" 35 | pluginContent = ` 36 | package types 37 | 38 | import ( 39 | "${IMPORTPATH}/${EXECNAME}/commands" 40 | ${EXECNAME}types "${IMPORTPATH}/${EXECNAME}/types" 41 | "${IMPORTPATH}/${EXECNAME}/executor" 42 | "${IMPORTPATH}/${EXECNAME}/rpc" 43 | "github.com/33cn/chain33/pluginmgr" 44 | ) 45 | 46 | /* 47 | * 初始化dapp相关的组件 48 | */ 49 | 50 | func init() { 51 | pluginmgr.Register(&pluginmgr.PluginBase{ 52 | Name: ${EXECNAME}types.${CLASSNAME}X, 53 | ExecName: executor.GetName(), 54 | Exec: executor.Init, 55 | Cmd: commands.Cmd, 56 | RPC: rpc.Init, 57 | }) 58 | }` 59 | ) 60 | -------------------------------------------------------------------------------- /cmd/tools/gencode/base/base.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 base 6 | 7 | var ( 8 | //CodeFileManager 类型文件 9 | CodeFileManager = map[string][]ICodeFile{} 10 | ) 11 | 12 | // ICodeFile code file interface 13 | type ICodeFile interface { 14 | GetCodeType() string 15 | GetDirName() string 16 | GetFiles() map[string]string //key:filename, val:file content 17 | GetDirReplaceTags() []string 18 | GetFileReplaceTags() []string 19 | } 20 | 21 | // RegisterCodeFile regeister code file 22 | func RegisterCodeFile(filer ICodeFile) { 23 | 24 | codeType := filer.GetCodeType() 25 | fileArr := CodeFileManager[codeType] 26 | fileArr = append(fileArr, filer) 27 | CodeFileManager[codeType] = fileArr 28 | } 29 | 30 | // CodeFile 基础类 31 | type CodeFile struct { 32 | } 33 | 34 | // GetCodeType get cody type 35 | func (CodeFile) GetCodeType() string { 36 | return "" 37 | } 38 | 39 | // GetDirName get directory name 40 | func (CodeFile) GetDirName() string { 41 | 42 | return "" 43 | } 44 | 45 | // GetFiles get files 46 | func (CodeFile) GetFiles() map[string]string { 47 | 48 | return nil 49 | } 50 | 51 | // GetDirReplaceTags get directory replace tags 52 | func (CodeFile) GetDirReplaceTags() []string { 53 | 54 | return nil 55 | } 56 | 57 | // GetFileReplaceTags get file replace tags 58 | func (CodeFile) GetFileReplaceTags() []string { 59 | 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | name: Build 12 | runs-on: ubuntu-22.04 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | fetch-depth: 0 17 | persist-credentials: false # <--- this 18 | - uses: actions/setup-go@v3 19 | with: 20 | go-version-file: 'go.mod' 21 | - uses: actions/setup-node@v3 22 | with: 23 | node-version: 14 24 | - name: Semantic Release 25 | uses: cycjimmy/semantic-release-action@v4 26 | id: semantic 27 | with: 28 | branch: master 29 | extra_plugins: | 30 | conventional-changelog/conventional-changelog-jshint 31 | semantic-release-replace-plugin@1.2.7 32 | @semantic-release/exec@6 33 | @semantic-release/changelog@6 34 | @semantic-release/git@10 35 | env: 36 | GH_TOKEN: ${{ secrets.GH_TOKEN }} 37 | 38 | - name: Do something when a new release published 39 | if: steps.semantic.outputs.new_release_published == 'true' 40 | run: | 41 | echo ${{ steps.semantic.outputs.new_release_version }} 42 | echo ${{ steps.semantic.outputs.new_release_major_version }} 43 | echo ${{ steps.semantic.outputs.new_release_minor_version }} 44 | echo ${{ steps.semantic.outputs.new_release_patch_version }} 45 | -------------------------------------------------------------------------------- /types/proto/evm_event.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // import "common.proto"; 4 | import "transaction.proto"; 5 | 6 | package types; 7 | option go_package = "github.com/33cn/chain33/types"; 8 | 9 | // 一条evm event log数据 10 | message EVMLog { 11 | repeated bytes topic = 1; 12 | bytes data = 2; 13 | } 14 | 15 | // 多条evm event log数据 16 | message EVMLogsPerTx { 17 | repeated EVMLog logs = 1; 18 | } 19 | 20 | message EVMTxAndLogs { 21 | Transaction tx = 1; 22 | EVMLogsPerTx logsPerTx = 2; 23 | } 24 | 25 | //一个块中包含的多条evm event log数据 26 | message EVMTxLogPerBlk { 27 | repeated EVMTxAndLogs txAndLogs = 1; 28 | int64 height = 2; 29 | bytes blockHash = 3; 30 | bytes parentHash = 4; 31 | bytes previousHash = 5; 32 | int32 addDelType = 6; 33 | int64 seqNum = 7; 34 | } 35 | 36 | //多个块中包含的多条evm event log数据 37 | message EVMTxLogsInBlks { 38 | repeated EVMTxLogPerBlk logs4EVMPerBlk = 1; 39 | } 40 | 41 | // 创建/调用合约的请求结构 42 | message EVMContractAction4Chain33 { 43 | // 转账金额 44 | uint64 amount = 1; 45 | // 消耗限制,默认为Transaction.Fee 46 | uint64 gasLimit = 2; 47 | // gas价格,默认为1 48 | uint32 gasPrice = 3; 49 | // 合约数据 50 | bytes code = 4; 51 | //交易参数 52 | bytes para = 5; 53 | // 合约别名,方便识别 54 | string alias = 6; 55 | // 交易备注 56 | string note = 7; 57 | // 调用合约地址 58 | string contractAddr = 8; 59 | } 60 | -------------------------------------------------------------------------------- /cmd/tools/commands/gendapp.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 commands 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/33cn/chain33/cmd/tools/strategy" 11 | "github.com/33cn/chain33/cmd/tools/types" 12 | "github.com/spf13/cobra" 13 | ) 14 | 15 | // GenDappCmd advance cmd 16 | func GenDappCmd() *cobra.Command { 17 | cmd := &cobra.Command{ 18 | Use: "gendapp", 19 | Short: "Auto generate dapp basic code", 20 | Run: genDapp, 21 | } 22 | addGenDappFlag(cmd) 23 | return cmd 24 | } 25 | 26 | func addGenDappFlag(cmd *cobra.Command) { 27 | cmd.Flags().StringP("name", "n", "", "dapp name") 28 | cmd.MarkFlagRequired("name") 29 | cmd.Flags().StringP("proto", "p", "", "dapp protobuf file path") 30 | cmd.MarkFlagRequired("proto") 31 | cmd.Flags().StringP("output", "o", "", "go package for output (default github.com/33cn/plugin/plugin/dapp/)") 32 | 33 | } 34 | 35 | func genDapp(cmd *cobra.Command, args []string) { 36 | 37 | dappName, _ := cmd.Flags().GetString("name") 38 | outDir, _ := cmd.Flags().GetString("output") 39 | propFile, _ := cmd.Flags().GetString("proto") 40 | 41 | s := strategy.New(types.KeyGenDapp) 42 | if s == nil { 43 | fmt.Println(types.KeyGenDapp, "Not support") 44 | return 45 | } 46 | 47 | s.SetParam(types.KeyExecutorName, dappName) 48 | s.SetParam(types.KeyDappOutDir, outDir) 49 | s.SetParam(types.KeyProtobufFile, propFile) 50 | s.Run() 51 | } 52 | -------------------------------------------------------------------------------- /util/exec_test.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/33cn/chain33/types" 8 | ) 9 | 10 | const length = 1e4 11 | const repeat = 2 12 | 13 | func BenchmarkDelDupKeyOld(b *testing.B) { 14 | kvs := make([]*types.KeyValue, 0, repeat*length) 15 | for r := 0; r < repeat; r++ { 16 | for i := 0; i < length; i++ { 17 | kvs = append(kvs, &types.KeyValue{Key: []byte(fmt.Sprintf("12kezKA11ZDcEuYukFV43oKqX89koycuHY:0x0dfed23208a15efe272d5095cce5fbc9a74ffa79c157564e239f6112e6eb6974:0000000000:test%d", i))}) 18 | } 19 | } 20 | b.ResetTimer() 21 | for i := 0; i < b.N; i++ { 22 | DelDupKeyOld(kvs) 23 | } 24 | } 25 | 26 | func BenchmarkDelDupKeyNew(b *testing.B) { 27 | kvs := make([]*types.KeyValue, 0, repeat*length) 28 | for r := 0; r < repeat; r++ { 29 | for i := 0; i < length; i++ { 30 | kvs = append(kvs, &types.KeyValue{Key: []byte(fmt.Sprintf("12kezKA11ZDcEuYukFV43oKqX89koycuHY:0x0dfed23208a15efe272d5095cce5fbc9a74ffa79c157564e239f6112e6eb6974:0000000000:test%d", i))}) 31 | } 32 | } 33 | b.ResetTimer() 34 | for i := 0; i < b.N; i++ { 35 | DelDupKey(kvs) 36 | } 37 | } 38 | 39 | // DelDupKey 删除重复的key 40 | func DelDupKeyOld(kvs []*types.KeyValue) []*types.KeyValue { 41 | dupindex := make(map[string]int) 42 | n := 0 43 | for _, kv := range kvs { 44 | skey := string(kv.Key) 45 | if index, ok := dupindex[skey]; ok { 46 | //重复的key 替换老的key 47 | kvs[index] = kv 48 | } else { 49 | dupindex[skey] = n 50 | kvs[n] = kv 51 | n++ 52 | } 53 | } 54 | return kvs[0:n] 55 | } 56 | -------------------------------------------------------------------------------- /system/dapp/none/executor/exec.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import ( 8 | "github.com/33cn/chain33/common" 9 | nty "github.com/33cn/chain33/system/dapp/none/types" 10 | "github.com/33cn/chain33/types" 11 | ) 12 | 13 | // Exec_CommitDelayTx exec commit dealy transaction 14 | func (n *None) Exec_CommitDelayTx(commit *nty.CommitDelayTx, tx *types.Transaction, index int) (*types.Receipt, error) { 15 | 16 | receipt := &types.Receipt{Ty: types.ExecOk} 17 | delayInfo := &nty.CommitDelayTxLog{} 18 | delayTx := &types.Transaction{} 19 | txByte, err := common.FromHex(commit.GetDelayTx()) 20 | if err != nil || types.Decode(txByte, delayTx) != nil { 21 | return nil, errDecodeDelayTx 22 | } 23 | delayTxHash := delayTx.Hash() 24 | cfg := n.GetAPI().GetConfig() 25 | if cfg.IsDappFork(n.GetHeight(), nty.NoneX, nty.ForkUseTimeDelay) { 26 | delayInfo.DelayBeginTimestamp = n.GetBlockTime() 27 | } else { 28 | delayInfo.DelayBeginHeight = n.GetHeight() 29 | } 30 | 31 | delayInfo.Submitter = tx.From() 32 | receipt.KV = append(receipt.KV, 33 | &types.KeyValue{Key: formatDelayTxKey(delayTxHash), Value: types.Encode(delayInfo)}) 34 | 35 | // 交易哈希只做回执展示信息,不需要保存到链上 36 | delayInfo.DelayTxHash = common.ToHex(delayTxHash) 37 | receipt.Logs = append(receipt.Logs, 38 | &types.ReceiptLog{Ty: nty.TyCommitDelayTxLog, Log: types.Encode(delayInfo)}) 39 | 40 | return receipt, nil 41 | } 42 | -------------------------------------------------------------------------------- /blockchain/query.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 blockchain 6 | 7 | import ( 8 | "sync" 9 | 10 | "github.com/33cn/chain33/client" 11 | dbm "github.com/33cn/chain33/common/db" 12 | "github.com/33cn/chain33/queue" 13 | "github.com/33cn/chain33/types" 14 | ) 15 | 16 | // Query 检索 17 | type Query struct { 18 | db dbm.DB 19 | stateHash []byte 20 | client queue.Client 21 | mu sync.Mutex 22 | api client.QueueProtocolAPI 23 | } 24 | 25 | // NewQuery new 26 | func NewQuery(db dbm.DB, qclient queue.Client, stateHash []byte) *Query { 27 | var err error 28 | query := &Query{db: db, client: qclient, stateHash: stateHash} 29 | query.api, err = client.New(qclient, nil) 30 | if err != nil { 31 | panic("NewQuery client.New err") 32 | } 33 | return query 34 | } 35 | 36 | // Query 检索 37 | func (q *Query) Query(driver string, funcname string, param types.Message) (types.Message, error) { 38 | query := &types.ChainExecutor{ 39 | Driver: driver, 40 | FuncName: funcname, 41 | Param: types.Encode(param), 42 | StateHash: q.getStateHash(), 43 | } 44 | return q.api.QueryChain(query) 45 | } 46 | 47 | func (q *Query) updateStateHash(stateHash []byte) { 48 | q.mu.Lock() 49 | defer q.mu.Unlock() 50 | q.stateHash = stateHash 51 | } 52 | 53 | func (q *Query) getStateHash() (stateHash []byte) { 54 | q.mu.Lock() 55 | defer q.mu.Unlock() 56 | return q.stateHash 57 | } 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, 33.cn 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (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 | -------------------------------------------------------------------------------- /cmd/tools/tasks/create_file_from_str_template_task.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Fuzamei Corp. 2018 All Rights Reserved. 3 | * Use of this source code is governed by a BSD-style 4 | * license that can be found in the LICENSE file. 5 | */ 6 | 7 | package tasks 8 | 9 | import ( 10 | "fmt" 11 | "strings" 12 | 13 | "github.com/33cn/chain33/cmd/tools/util" 14 | ) 15 | 16 | // CreateFileFromStrTemplateTask 从指定的模板字符串中创建目标文件的任务 17 | type CreateFileFromStrTemplateTask struct { 18 | TaskBase 19 | SourceStr string 20 | OutputFile string 21 | BlockStrBegin string // Block会将SourceStr包含在内部 22 | BlockStrEnd string 23 | ReplaceKeyPairs map[string]string 24 | fileContent string 25 | } 26 | 27 | // GetName 获取name 28 | func (c *CreateFileFromStrTemplateTask) GetName() string { 29 | return "CreateFileFromStrTemplateTask" 30 | } 31 | 32 | // Execute 执行 33 | func (c *CreateFileFromStrTemplateTask) Execute() error { 34 | if len(c.BlockStrBegin) > 0 && len(c.BlockStrEnd) > 0 { 35 | c.SourceStr = fmt.Sprintf("%s%s%s", c.BlockStrBegin, c.SourceStr, c.BlockStrEnd) 36 | } 37 | c.fileContent = c.SourceStr 38 | for key, value := range c.ReplaceKeyPairs { 39 | c.fileContent = strings.Replace(c.fileContent, key, value, -1) 40 | } 41 | if err := util.MakeDir(c.OutputFile); err != nil { 42 | return err 43 | } 44 | util.DeleteFile(c.OutputFile) 45 | len, err := util.WriteStringToFile(c.OutputFile, c.fileContent) 46 | if err == nil { 47 | mlog.Info("Create file success.", "file", c.OutputFile, "file len", len) 48 | } else { 49 | mlog.Info("Create file falied.", "error", err) 50 | } 51 | return err 52 | } 53 | -------------------------------------------------------------------------------- /common/ntp_test.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 common 6 | 7 | import ( 8 | "testing" 9 | "time" 10 | 11 | "github.com/stretchr/testify/assert" 12 | ) 13 | 14 | var NtpHosts = []string{ 15 | "time.windows.com:123", 16 | "ntp.ubuntu.com:123", 17 | "pool.ntp.org:123", 18 | "cn.pool.ntp.org:123", 19 | "time.apple.com:123", 20 | } 21 | 22 | // 在单元测试中对网络时间和本地时间进行单元测试的功能是没有意义的 23 | // 只有在实际运行过程中,通过网络时间来纠正本地时间 24 | // 本测试用例有概率导致误差大于1秒从而让测试用例运行失败 25 | func TestGetRealTime(t *testing.T) { 26 | hosts := NtpHosts 27 | nettime := GetRealTimeRetry(hosts, 10) 28 | now := time.Now() 29 | //get nettime error, ignore 30 | if nettime.IsZero() { 31 | return 32 | } 33 | nettime2 := GetRealTimeRetry(hosts, 10) 34 | //get nettime error, ignore 35 | delt := time.Since(now) 36 | if nettime2.IsZero() { 37 | return 38 | } 39 | assert.Equal(t, nettime2.Sub(nettime)/time.Second, delt/time.Second) 40 | } 41 | 42 | func TestSubList(t *testing.T) { 43 | sub := maxSubList([]time.Duration{1, 2, 3, 10, 21, 22, 23, 24, 35}, time.Duration(10)) 44 | assert.Equal(t, len(sub), 4) 45 | assert.Equal(t, sub[0], time.Duration(1)) 46 | 47 | sub = maxSubList([]time.Duration{2, 3, 10, 21, 22, 23, 24, 35}, time.Duration(10)) 48 | assert.Equal(t, len(sub), 4) 49 | assert.Equal(t, sub[0], time.Duration(21)) 50 | 51 | sub = maxSubList([]time.Duration{2, 3, 10, 21, 22, 23, 24}, time.Duration(10)) 52 | assert.Equal(t, len(sub), 4) 53 | assert.Equal(t, sub[0], time.Duration(21)) 54 | } 55 | -------------------------------------------------------------------------------- /.releaserc.yml: -------------------------------------------------------------------------------- 1 | { "branches": [ "master", "next" ], 2 | "plugins": [ 3 | [ 4 | "@semantic-release/commit-analyzer", 5 | { 6 | "preset": "jshint" 7 | } 8 | ], 9 | [ 10 | "@semantic-release/release-notes-generator", 11 | { 12 | "preset": "jshint" 13 | } 14 | ], 15 | [ 16 | "semantic-release-replace-plugin", 17 | { 18 | "replacements": [ 19 | { 20 | "files": [ "common/version/version.go" ], 21 | "from": "var Version.*", 22 | "to": 'var Version = "${nextRelease.version}"', 23 | "results": [ 24 | { 25 | "file": "common/version/version.go", 26 | "hasChanged": true, 27 | "numMatches": 1, 28 | "numReplacements": 1 29 | } 30 | ], 31 | "countMatches": true 32 | } 33 | ] 34 | } 35 | ], 36 | [ 37 | "@semantic-release/changelog", 38 | { "changelogFile": "CHANGELOG.md", "changelogTitle": "changelog" }, 39 | ], 40 | # "@semantic-release/npm", #Default 3 41 | # "@semantic-release/github", #Default 4 42 | [ 43 | "@semantic-release/github", 44 | { "assets": [ "build/*.tar.gz","build/*.zip" ] } 45 | ], 46 | [ 47 | "@semantic-release/git", 48 | { 49 | "assets": [ "common/version/version.go","CHANGELOG.md" ], 50 | } 51 | ], 52 | [ 53 | "@semantic-release/exec", { 54 | "prepareCmd": "make all-arch VERSION=${nextRelease.version}" 55 | } 56 | ] 57 | ] 58 | } 59 | -------------------------------------------------------------------------------- /common/db/mocks/kv.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // KV is an autogenerated mock type for the KV type 8 | type KV struct { 9 | mock.Mock 10 | } 11 | 12 | // Begin provides a mock function with given fields: 13 | func (_m *KV) Begin() { 14 | _m.Called() 15 | } 16 | 17 | // Commit provides a mock function with given fields: 18 | func (_m *KV) Commit() error { 19 | ret := _m.Called() 20 | 21 | var r0 error 22 | if rf, ok := ret.Get(0).(func() error); ok { 23 | r0 = rf() 24 | } else { 25 | r0 = ret.Error(0) 26 | } 27 | 28 | return r0 29 | } 30 | 31 | // Get provides a mock function with given fields: key 32 | func (_m *KV) Get(key []byte) ([]byte, error) { 33 | ret := _m.Called(key) 34 | 35 | var r0 []byte 36 | if rf, ok := ret.Get(0).(func([]byte) []byte); ok { 37 | r0 = rf(key) 38 | } else { 39 | if ret.Get(0) != nil { 40 | r0 = ret.Get(0).([]byte) 41 | } 42 | } 43 | 44 | var r1 error 45 | if rf, ok := ret.Get(1).(func([]byte) error); ok { 46 | r1 = rf(key) 47 | } else { 48 | r1 = ret.Error(1) 49 | } 50 | 51 | return r0, r1 52 | } 53 | 54 | // Rollback provides a mock function with given fields: 55 | func (_m *KV) Rollback() { 56 | _m.Called() 57 | } 58 | 59 | // Set provides a mock function with given fields: key, value 60 | func (_m *KV) Set(key []byte, value []byte) error { 61 | ret := _m.Called(key, value) 62 | 63 | var r0 error 64 | if rf, ok := ret.Get(0).(func([]byte, []byte) error); ok { 65 | r0 = rf(key, value) 66 | } else { 67 | r0 = ret.Error(0) 68 | } 69 | 70 | return r0 71 | } 72 | -------------------------------------------------------------------------------- /system/dapp/coins/executor/exec_del_local.go: -------------------------------------------------------------------------------- 1 | // Copyright Fuzamei Corp. 2018 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 executor 6 | 7 | import ( 8 | "github.com/33cn/chain33/types" 9 | ) 10 | 11 | // ExecDelLocal_Transfer delete transfer of local exec 12 | func (c *Coins) ExecDelLocal_Transfer(transfer *types.AssetsTransfer, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { 13 | kv, err := updateAddrReciver(c.GetLocalDB(), tx.GetRealToAddr(), transfer.Amount, false) 14 | if err != nil { 15 | return nil, err 16 | } 17 | return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil 18 | } 19 | 20 | // ExecDelLocal_TransferToExec delete transfer of local exec to exec 21 | func (c *Coins) ExecDelLocal_TransferToExec(transfer *types.AssetsTransferToExec, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { 22 | kv, err := updateAddrReciver(c.GetLocalDB(), tx.GetRealToAddr(), transfer.Amount, false) 23 | if err != nil { 24 | return nil, err 25 | } 26 | return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil 27 | } 28 | 29 | // ExecDelLocal_Withdraw delete withdraw of local exec 30 | func (c *Coins) ExecDelLocal_Withdraw(withdraw *types.AssetsWithdraw, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { 31 | from := tx.From() 32 | kv, err := updateAddrReciver(c.GetLocalDB(), from, withdraw.Amount, false) 33 | if err != nil { 34 | return nil, err 35 | } 36 | return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil 37 | } 38 | -------------------------------------------------------------------------------- /system/p2p/dht/protocol/snow/snow.go: -------------------------------------------------------------------------------- 1 | package snow 2 | 3 | import ( 4 | "github.com/33cn/chain33/common/log/log15" 5 | "github.com/33cn/chain33/system/p2p/dht/protocol" 6 | "github.com/33cn/chain33/types" 7 | ) 8 | 9 | const ( 10 | snowChitsID = "/chain33/snowman/chits/1.0" 11 | snowGetBlock = "/chain33/snowman/get/1.0" 12 | //snowPutBlock = "/chain33/snowman/put/1.0" 13 | snowPullQuery = "/chain33/snowman/pullq/1.0" 14 | snowPushQuery = "/chain33/snowman/pushq/1.0" 15 | ) 16 | 17 | var log = log15.New("module", "dht.snowman") 18 | 19 | func init() { 20 | protocol.RegisterProtocolInitializer(InitProtocol) 21 | } 22 | 23 | type snowman struct { 24 | *protocol.P2PEnv 25 | } 26 | 27 | // InitProtocol init protocol 28 | func InitProtocol(env *protocol.P2PEnv) { 29 | new(snowman).init(env) 30 | } 31 | 32 | func (s *snowman) init(env *protocol.P2PEnv) { 33 | 34 | s.P2PEnv = env 35 | protocol.RegisterEventHandler(types.EventSnowmanChits, s.handleEventChits) 36 | protocol.RegisterEventHandler(types.EventSnowmanGetBlock, s.handleEventGetBlock) 37 | //protocol.RegisterEventHandler(types.EventSnowmanPutBlock, s.handleEventPutBlock) 38 | protocol.RegisterEventHandler(types.EventSnowmanPullQuery, s.handleEventPullQuery) 39 | protocol.RegisterEventHandler(types.EventSnowmanPushQuery, s.handleEventPushQuery) 40 | 41 | protocol.RegisterStreamHandler(s.Host, snowChitsID, s.handleStreamChits) 42 | protocol.RegisterStreamHandler(s.Host, snowGetBlock, s.handleStreamGetBlock) 43 | protocol.RegisterStreamHandler(s.Host, snowPullQuery, s.handleStreamPullQuery) 44 | protocol.RegisterStreamHandler(s.Host, snowPushQuery, s.handleStreamPushQuery) 45 | } 46 | -------------------------------------------------------------------------------- /types/proto/push_tx_receipt.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // import "common.proto"; 4 | import "transaction.proto"; 5 | import "blockchain.proto"; 6 | import "evm_event.proto"; 7 | 8 | package types; 9 | option go_package = "github.com/33cn/chain33/types"; 10 | 11 | message TxReceipts4SubscribePerBlk { 12 | repeated Transaction tx = 1; 13 | repeated ReceiptData receiptData = 2; 14 | // repeated KeyValue KV = 3; 15 | int64 height = 4; 16 | bytes blockHash = 5; 17 | bytes parentHash = 6; 18 | bytes previousHash = 7; 19 | int32 addDelType = 8; 20 | int64 seqNum = 9; 21 | } 22 | 23 | message TxReceipts4Subscribe { 24 | repeated TxReceipts4SubscribePerBlk txReceipts = 1; 25 | } 26 | 27 | message TxHashWithReceiptType { 28 | bytes hash = 1; 29 | int32 ty = 2; 30 | } 31 | 32 | message TxResultPerBlock { 33 | repeated TxHashWithReceiptType items = 1; 34 | int64 height = 2; 35 | bytes blockHash = 3; 36 | bytes parentHash = 4; 37 | int32 addDelType = 5; 38 | int64 seqNum = 6; 39 | } 40 | 41 | message TxResultSeqs { 42 | repeated TxResultPerBlock items = 1; 43 | } 44 | 45 | message PushData { 46 | string name = 1; 47 | oneof value { 48 | BlockSeqs blockSeqs = 2; 49 | HeaderSeqs headerSeqs = 3; 50 | TxReceipts4Subscribe txReceipts = 4; 51 | TxResultSeqs txResult = 5; 52 | EVMTxLogsInBlks evmLogs = 6; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /types/proto/statistic.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package types; 4 | option go_package = "github.com/33cn/chain33/types"; 5 | 6 | //手续费 7 | message TotalFee { 8 | int64 fee = 1; 9 | int64 txCount = 2; 10 | } 11 | 12 | //查询symbol代币总额 13 | message ReqGetTotalCoins { 14 | string symbol = 1; 15 | bytes stateHash = 2; 16 | bytes startKey = 3; 17 | int64 count = 4; 18 | string execer = 5; 19 | } 20 | 21 | //查询symbol代币总额应答 22 | message ReplyGetTotalCoins { 23 | int64 count = 1; 24 | int64 num = 2; 25 | int64 amount = 3; 26 | bytes nextKey = 4; 27 | } 28 | 29 | //迭代查询symbol代币总额 30 | message IterateRangeByStateHash { 31 | bytes stateHash = 1; 32 | bytes start = 2; 33 | bytes end = 3; 34 | int64 count = 4; 35 | } 36 | 37 | message TotalAmount { 38 | // 统计的总数 39 | int64 total = 1; 40 | } 41 | 42 | //查询symbol在合约中的代币总额,如果execAddr为空,则为查询symbol在所有合约中的代币总额 43 | message ReqGetExecBalance { 44 | string symbol = 1; 45 | bytes stateHash = 2; 46 | bytes addr = 3; 47 | bytes execAddr = 4; 48 | string execer = 5; 49 | int64 count = 6; 50 | bytes nextKey = 7; 51 | } 52 | 53 | message ExecBalanceItem { 54 | bytes execAddr = 1; 55 | int64 frozen = 2; 56 | int64 active = 3; 57 | } 58 | 59 | //查询symbol在合约中的代币总额应答 60 | message ReplyGetExecBalance { 61 | int64 amount = 1; 62 | int64 amountFrozen = 2; 63 | int64 amountActive = 3; 64 | bytes nextKey = 4; 65 | repeated ExecBalanceItem items = 5; 66 | } 67 | --------------------------------------------------------------------------------