go-blockchain

所属分类:加密解密
开发工具:GO
文件大小:67KB
下载次数:0
上传日期:2021-05-12 21:17:30
上 传 者sh-1993
说明:  一个完全去中心化的点对点区块链,用从头开始写。使用工作证明来保护分类账...
(A fully decentralized peer-to-peer blockchain written in Go from scratch. The ledger is secured using a proof-of-work consensus mechanism while being fully transparent using a sync algorithm.)

文件列表:
LICENSE (35149, 2021-05-13)
cmd (0, 2021-05-13)
cmd\.DS_Store (6148, 2021-05-13)
cmd\gochain (0, 2021-05-13)
cmd\gochain\balances.go (1393, 2021-05-13)
cmd\gochain\main.go (1455, 2021-05-13)
cmd\gochain\run.go (2275, 2021-05-13)
cmd\gochain\version.go (363, 2021-05-13)
cmd\gochain\wallet.go (2469, 2021-05-13)
database (0, 2021-05-13)
database\block.go (1460, 2021-05-13)
database\database.go (900, 2021-05-13)
database\fs.go (1273, 2021-05-13)
database\genesis.go (751, 2021-05-13)
database\state.go (5232, 2021-05-13)
database\tx.go (1759, 2021-05-13)
fs (0, 2021-05-13)
fs\fs.go (828, 2021-05-13)
fs\unicode.go (172, 2021-05-13)
go.mod (254, 2021-05-13)
go.sum (67184, 2021-05-13)
node (0, 2021-05-13)
node\http_routes.go (3467, 2021-05-13)
node\http_utils.go (1515, 2021-05-13)
node\miner.go (2013, 2021-05-13)
node\miner_test.go (2762, 2021-05-13)
node\node.go (7175, 2021-05-13)
node\node_test.go (17484, 2021-05-13)
node\sync.go (4268, 2021-05-13)
wallet (0, 2021-05-13)
wallet\wallet.go (2600, 2021-05-13)
wallet\wallet_test.go (3482, 2021-05-13)

# GoChain ## Installation ### Install Go 1.16 or higher Follow the official docs or use your favorite dependency manager to install Go: [https://golang.org/doc/install](https://golang.org/doc/install) Verify your `$GOPATH` is correctly set before continuing! ### Setup this repository Go is bit picky about where you store your repositories. The convention is to store: - the source code inside the `$GOPATH/src` - the compiled program binaries inside the `$GOPATH/bin` You can `clone` the repository or use `go get` to install it. #### Using Git ```bash mkdir -p $GOPATH/src/github.com/ethanblumenthal cd $GOPATH/src/github.com/ethanblumenthal git clone git@github.com:ethanblumenthal/golang-blockchain.git ``` PS: Make sure you actually clone it inside the `src/github.com/ethanblumenthal` directory, not your own, otherwise it won't compile. Go rules. #### Using Go get ```bash go get -u github.com/ethanblumenthal/golang-blockchain ``` ## Usage ### Install ``` go install ./cmd/... ``` ## CLI ### Show available commands and flags ```bash gochain help ``` #### Show available run settings ```bash gochain run --help Launches the GoChain node and its HTTP API. Usage: gochain run [flags] Flags: --bootstrap-account string default GoChain bootstrap's Genesis account with 1M GoChain tokens (default "0x09ee50f2f37fcba1845de6fe5c762e83e65e755c") --bootstrap-ip string default GoChain bootstrap's server to interconnect peers (default "node.gochain.bootstrap") --bootstrap-port uint default GoChain bootstrap's server port to interconnect peers (default 443) --datadir string Absolute path to your node's data dir where the DB will be/is stored --disable-ssl should the HTTP API SSL certificate be disabled? (default false) -h, --help help for run --ip string your node's public IP to communication with other peers (default "127.0.0.1") --miner string your node's miner account to receive the block rewards (default "0x0000000000000000000000000000000000000000") --port uint your node's public HTTP port for communication with other peers (configurable if SSL is disabled) (default 443) ``` ### Run a GoChain node connected to the official GoChain test network If you are running the node on your localhost, just disable the SSL with `--disable-ssl` flag. ``` gochain version > Version: 1.0.0-beta GoChain Ledger gochain run --datadir=$HOME/.gochain --ip=127.0.0.1 --port=8081 --miner=0x_YOUR_WALLET_ACCOUNT --disable-ssl ``` ### Run a GoChain bootstrap node in isolation, on your localhost only ``` gochain run --datadir=$HOME/.gochain_boostrap --ip=127.0.0.1 --port=8080 --bootstrap-ip=127.0.0.1 --bootstrap-port=8080 --disable-ssl ``` #### Run a second GoChain node connecting to your first one ``` gochain run --datadir=$HOME/.gochain --ip=127.0.0.1 --port=8081 --bootstrap-ip=127.0.0.1 --bootstrap-port=8080 --disable-ssl ``` ### Create a new account ``` gochain wallet new-account --datadir=$HOME/.gochain ``` ### Run a GoChain node with SSL The default node's HTTP port is 443. The SSL certificate is generated automatically as long as the DNS A/AAAA records point at your server. #### Official Testing Bootstrap Server Example how the official GoChain bootstrap node is launched. Customize the `--datadir`, `--miner`, and `--ip` values to match your server. ```bash /usr/local/bin/gochain run --datadir=/home/ec2-user/.gochain --miner=0x09ee50f2f37fcba1845de6fe5c762e83e65e755c --ip=node.gochain.bootstrap --port=443 --ssl-email=ethan.blumenthal@gmail.com --bootstrap-ip=node.gochain.bootstrap --bootstrap-port=443 --bootstrap-account=0x09ee50f2f37fcba1845de6fe5c762e83e65e755c ``` ## HTTP ### List all balances ``` curl http://localhost:8080/balances/list | jq ``` ### Send a signed TX ``` curl --location --request POST 'http://localhost:8080/tx/add' \ --header 'Content-Type: application/json' \ --data-raw '{ "from": "0x22ba1F80452E6220c7cc6ea2D1e3EEDDaC5F694A", "from_pwd": "security123", "to": "0x26F046f26aED65BFf31386c5b6bDe1557E***C584", "value": 100 }' ``` ### Check node's status (latest block, known peers, pending TXs) ``` curl http://localhost:8080/node/status | jq ``` ## Tests Run all tests with verbosity but one at a time, without timeout, to avoid ports collisions: ``` go test -v -p=1 -timeout=0 ./... ``` Run an individual test: ``` go test -timeout=0 ./node -test.v -test.run ^TestNode_Mining$ ``` **Note:** Majority are integration tests and take time. Expect the test suite to finish in ~30 mins.

近期下载者

相关文件


收藏者