LoginSignup
2
2

More than 3 years have passed since last update.

【初心者向け】BlockchainをGolangで実装する

Last updated at Posted at 2019-07-21

【初心者向け】BlockchainをGolangで実装*する

想定レベル

  • pythonを多少触れる人
  • Html,CSS,JSを触れる人
  • ブロックチェーンの基礎が分かってる人

達成目標

  • Goを学ぶ(Goで立てる)
  • BlockChainをコードから学ぶ(可視化する)

タイムスケジュール

時間 内容
13:30 - 開場・受付開始
14:00 - 14:05 オープニング
14:05 - 14:30 自己紹介 全員
14:30- 16:00 Goでブロックチェーンの実装を行う
16:00 - 16:30 成果発表(フリートーク)
16:30 - 16:40 クロージング (アンケート)

資料

『WEBbench事前資料1』image.png
『事前資料2』image.png
『ブロックチェーンオンライン学習サイト作ったので紹介』


メモメモ

事前1=Goをインストール=

まず、Goとは、、、
Google社によって開発されたシンプルな言語(プログラマーの生産性を向上するために作られた)
特徴として、表現力豊かにコードを簡潔に記述することが可能で、軽量な並列処理でマルチコアやネットワーク化された複雑なシステムを構築するのに向いている言語。

■手順
Homebrewをinstallしているので、以下実行。

terminal.view
$ brew install go
〜インストールだらだら〜
$ go version
go version go1.12.7 darwin/amd64

install完了。gRPCの関係上go 1.6以上をinstallすること。(最新版をinstallしてればよい。)

事前2=gRPCをインストール=

まず、gRPCとは、、、
Googleによって開発されたRPC (Remote Procedure Call) を実現するためにプロトコルの1つ。
特徴としてProtocol Buffers を使ってデータをシリアライズし、高速な通信を実現できる。

■手順
以下実行

terminal.view
$ go get -u google.golang.org/grpc

Go用のprotocをinstall&PATHを通す。

terminal.view
$ go get -u github.com/golang/protobuf/protoc-gen-go
$ export PATH=$PATH:$GOPATH/bin

サーバを立ち上げるために、まずblockchain.protを ~~/go/prot配下に作成。

blackchain.prot
syntax = "proto3";

package proto;

// The blockchain service definition
service Blockchain {
    // Sends a AddBlockRequest Return AddBlockResponse
    rpc AddBlock(AddBlockRequest) returns (AddBlockResponse) {}
    rpc GetBlockChain(GetBlockchainRequest) returns (GetBlockchainResponse) {}
}

// The request AddBlockRequest containing the data
message AddBlockRequest {
    string data = 1;
}

// The request AddBlockResponse containing the hash
message AddBlockResponse {
    string hash = 1;
}

message GetBlockchainRequest {}

message Block {
    string hash = 1;
    string prevBlockHash = 2;
    string data = 3;
}

message GetBlockchainResponse {
    repeated Block blocks = 1;
}

protoコマンドがinstallされてないので、

terminal.view
$ brew install protobuf

blockchain.protをコンパイル

terminal.view
protoc --go_out=plugins=grpc:. prot/blockchain.prot
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2