Más contenido relacionado
La actualidad más candente (20)
Similar a C# でブロックチェーン実装 (20)
C# でブロックチェーン実装
- 3. 開発に参加する人むけに必要な具材
● .NET Core SDK
今日使うコードベースは.NET Core 向けに書かれていますゆえ
https://www.microsoft.com/net/download/core
(.NET Core でググると出てくると思います)
● MinChain リポジトリ
以下のリポジトリのソースコードをネタに解説を進めます
https://github.com/yutopio/MinChain
プルリク歓迎します
● スライド http://bit.ly/2nfyb7z
- 8. システム構成
Redis Cache
● 口座画面 / 販売所
● Lightning
● chainFlyer
● マーケット処理
● 取引約定
● バッチ処理
Web Apps
Worker Roles
SQL Server
Web Roles
● fundFlyer
● BTC News
● セッション管理
Storage Queue
バックアップへ
- 13. 暗号面での強い味方
● Bouncy Castle PCL
https://www.nuget.org/packages/Portable.BouncyCastle/
System.Security.Cryptography 名前空間下の実装を行う強い味方
● たとえば Bitcoin でアドレス生成に使うハッシュ関数
.NET Fx : System.Security.Cryptography.RIPEMD160
.NET Core : なし
BC PCL : Org.BouncyCastle.Crypto.Digests.RipeMD160Digest
- 14. I Can Has .NET Core
.NET Core へ移行可能か
調べることができる
https://icanhasdot.net/
- 19. ビルドする
.NET Core SDK が必要です
https://www.microsoft.com/net/download/core
VS2017 ユーザは .NET Core tools を入れれば
VS からビルドできるようになります
- 20. ビルドする
$ dotnet restore (依存する Nuget パッケージの取得)
Restoring packages for D:MinChainMinChainMinChain.csproj...
Generating MSBuild file D:MinChainMinChainobjMinChain.csproj.nuget.g.props.
Generating MSBuild file D:MinChainMinChainobjMinChain.csproj.nuget.g.targets.
Writing lock file to disk. Path: D:MinChainMinChainobjproject.assets.json
Restore completed in 946.64 ms for D:MinChainMinChainMinChain.csproj.
NuGet Config files used:
C:UsersyutoAppDataRoamingNuGetNuGet.Config
C:Program Files (x86)NuGetConfigMicrosoft.VisualStudio.Offline.config
Feeds used:
https://api.nuget.org/v3/index.json
C:Program Files (x86)Microsoft SDKsNuGetPackages
- 21. ビルドする
$ dotnet build (ビルドする)
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
MinChain -> D:MinChainMinChainbinDebugnetcoreapp1.0MinChain.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.00
- 22. 鍵を生成する
ビルドしたバイナリがいるディレクトリに移動して実行
$ dotnet MinChain.dll genkey > key.json (自分のアドレス用の口座を作成する)
$ cat key.json
{
"pub": "WAAAAAEAAAAQAAAANAAAACAAAAAEj0MOwNeLA9b4gXYbURcyF5c8YPtZekJcliWafKduNy
AAAAACMFgRiBxSiu3wB3/g3biz9UN8zvNGI2n/HIg88EVn8A==",
"prv": "D4TuwVREhf5T3GTs4Y1psaUoHHKy3hb4gllunB2x5l8=",
"addr": "MDyDMxi1ynxe1206ANBRXWOjP7o/IeQHakRDilyYrtI="
}
- 23. Genesis ブロックを作る
(自分のチェーンを作る場合。今回は行いません!)
$ dotnet MinChain.dll genesis key.json genesis.bin
Creating new genesis block.
{
"id": "00011702146098209132fa4990686f41f3e6b9859c607c1e5c93c0204ff9d8ec",
"prev": "0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": 2E-05,
"nonce": 2538555750346862341,
"timestamp": "2017-03-10T09:20:20.2375851Z",
"root": "DS5gHGHSJh0f5qmxgk2PDuI6a7J4LZ7pfy3K6JorH8U=",
"height": 0,
"txs": [
{
"id": "e44e859fe93bf48652b2dfc2386d987e544940f768379779da631fcd7206ac66",
"timestamp": "2017-03-10T09:20:19.5205851Z",
"in": [],
"out": [
{
"to": "303c833318b5ca7c5ed76d3a00d0515d63a33fba3f21e4076a44438a5c98aed2",
"val": 1000000
}
... (略)
key.json 記載のアドレスに
マイニング報酬を送るような
原始ブロックを作成し
genesis.bin に保存する
マイニングするので
少し時間かかる
- 24. config を作成する
(デフォルト config を生成できる。今回は行いません!)
$ dotnet MinChain.dll config > config.json
$ cat config.json
{
"listen": "0.0.0.0:9333",
"peers": [
"127.0.0.1:9333"
],
"keypair": "<YOUR OWN KEYPAIR>.json",
"genesis": "<GENESIS BLOCK>.bin"
}
前のステップで生成した
鍵ペアファイル (key.json) と
原始ブロック (genesis.bin) とに
それぞれ、ファイル名を変える
- 27. Blockchain by C#
● やっと安定したマルチ プラットフォーム対応!
○ 暗号系ライブラリなども揃っている
○ ソースが見える安心感
○ Bitcoin Core などとの高い運用性
● ブロックチェーンの実装が C# + .NET Core でできた!
○ 基本的なところはほぼ外部依存なし
○ Azure にデプロイして、Mac および Linux でも動きました!
● エンジニア募集中