2017年6月19日月曜日

GO言語で始めるEthereumプログラミング(Gethを使ったアカウント管理編)

環境


OS : osx

目的

Gethの"Basic Use Case Documentation"にある3つをそれぞれ試す。
Ethereum開発に必要なClientであるGethの使い方を学ぶ。


始めに

  • アカウントを暗号化する際のパスワードを忘れるとそのアカウントにはアクセスできなくなるので注意
  • gethはaccountというサブコマンドによってアカウント管理できる
  • 鍵は<DATADIR>/keystore以下に保存される
    • 定期的なバックアップをオススメする
    • 鍵のバックアップに関する詳細:Backup & restore
  • ヘルプコマンド
    • geth account help <subcommand>


アカウント管理でできること

  • 新たなアカウントの作成
  • 既存アカウントのリスト化
  • 新たなアカウントに対する秘密鍵のインポート
  • 最新の鍵形式への移行とパスワード変更

アカウントの作成

新たなアカウントを作る

前回の投稿で作成したgo-ethereum内で作業を行う。
$ geth account new
WARN [06-18|10:42:55] No etherbase set and no accounts found as default 
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {2e9f6ce30074338fac346090d4bc6a1fd5506f38}

リスト化した情報を参照してみる。


$ geth account list
Account #0: {2e9f6ce30074338fac346090d4bc6a1fd5506f38} keystore:///Users/xxx/Library/Ethereum/keystore/UTC--2017-06-18T13-53-47.688998272Z--2e9f6ce30074338fac346090d4bc6a1fd5506f38

アカウント情報を暗号化形式で保存する。この時に指定するパスフレーズはアカウントをアンロックする時に必要なので決して忘れてはならない。
$ > personal.newAccount test

上記の作業前後でディレクトリ内には以下のような変化が。
(前)
$ ls
AUTHORS  build  core  les  rlp
COPYING  circle.yml crypto  light  rpc
COPYING.LESSER cmd  eth  log  swarm
Dockerfile common  ethclient metrics  tests
Makefile compression ethdb  miner  trie
README.md consensus ethstats mobile  vendor
VERSION  console  event  node  whisper
accounts containers interfaces.go p2p
appveyor.yml contracts internal params

(後)


$ ls
AUTHORS   console   metrics
COPYING   containers  miner
COPYING.LESSER  contracts  mobile
Dockerfile  core   node
Makefile  crypto   p2p
README.md  eth   params
VERSION   ethclient  personal.newAccount
accounts  ethdb   rlp
appveyor.yml  ethstats  rpc
build   event   swarm
circle.yml  interfaces.go  tests
cmd   internal  trie
common   les   vendor
compression  light   whisper
consensus  log
アカウントに関するファイルが生成されている。

秘密鍵のインポートによってアカウントを作る

暗号化されてない秘密鍵を使用する場合。これは不要なのでスキップする。

既存のアカウントをアップデートする

アカウントを暗号化形式で最新バージョンに保存する。
この時アカウントのロックを解除するためにパスフレーズを求められる。
$ geth account update 2e9f6ce30074338fac346090d4bc6a1fd5506f38
Unlocking account 2e9f6ce30074338fac346090d4bc6a1fd5506f38 | Attempt 1/3
Passphrase: 
INFO [06-19|22:07:53] Unlocked account                         address=0x2e9f6ce30074338fac346090d4bc6a1fd5506f38
Please give a new password. Do not forget this password.
Passphrase: 
Repeat passphrase: 

プリセールウォレットをインポートする

スキップ。

アカウントのリスト化と残高のチェック

現在のアカウントのリスト化

$ geth account list
Account #0: {2e9f6ce30074338fac346090d4bc6a1fd5506f38} keystore:///Users/kichino/Library/Ethereum/keystore/UTC--2017-06-18T13-53-47.688998272Z--2e9f6ce30074338fac346090d4bc6a1fd5506f38

2017年6月18日日曜日

GO言語で始めるEthereumプログラミング(ビルド編)

環境


OS : osx


インストール

以下入力コマンド。出力内容は最後のみ表示。

$ brew tap ethereum/ethereum

$ brew install ethereum

$ cd Desktop
$ mkdir ethe
$ cd ethe
$ git clone https://github.com/ethereum/go-ethereum

$ brew install go

$ cd go-ethereum

$ make geth
build/env.sh go run build/ci.go install ./cmd/geth
>>> /usr/local/Cellar/go/1.8.1/libexec/bin/go install -ldflags -X main.gitCommit=431cf2a1e453346bcc627ac1fb9df3950a6c3499 -s -v ./cmd/geth
github.com/ethereum/go-ethereum/common/hexutil
github.com/ethereum/go-ethereum/common/math
github.com/ethereum/go-ethereum/rlp
github.com/ethereum/go-ethereum/crypto/sha3
github.com/ethereum/go-ethereum/crypto/secp256k1
github.com/ethereum/go-ethereum/common
github.com/ethereum/go-ethereum/vendor/github.com/go-stack/stack
github.com/ethereum/go-ethereum/log
github.com/ethereum/go-ethereum/params
github.com/ethereum/go-ethereum/vendor/github.com/rcrowley/go-metrics
github.com/ethereum/go-ethereum/vendor/gopkg.in/karalabe/cookiejar.v2/collections/prque
github.com/ethereum/go-ethereum/vendor/github.com/aristanetworks/goarista/monotime
github.com/ethereum/go-ethereum/common/mclock
github.com/ethereum/go-ethereum/event
github.com/ethereum/go-ethereum/crypto/randentropy
github.com/ethereum/go-ethereum/vendor/github.com/pborman/uuid
github.com/ethereum/go-ethereum/vendor/github.com/rjeczalik/notify
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/pbkdf2
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/scrypt
github.com/ethereum/go-ethereum/cmd/internal/browser
github.com/ethereum/go-ethereum/vendor/github.com/edsrzf/mmap-go
github.com/ethereum/go-ethereum/common/bitutil
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/util
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/cache
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/comparer
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/storage
github.com/ethereum/go-ethereum/trie
github.com/ethereum/go-ethereum/vendor/github.com/rcrowley/go-metrics/exp
github.com/ethereum/go-ethereum/metrics
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/errors
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/filter
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/iterator
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/journal
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/opt
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/memdb
github.com/ethereum/go-ethereum/vendor/github.com/golang/snappy
github.com/ethereum/go-ethereum/vendor/github.com/hashicorp/golang-lru/simplelru
github.com/ethereum/go-ethereum/vendor/github.com/hashicorp/golang-lru
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/table
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/context
github.com/ethereum/go-ethereum/vendor/github.com/rs/xhandler
github.com/ethereum/go-ethereum/vendor/github.com/rs/cors
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/websocket
github.com/ethereum/go-ethereum/vendor/gopkg.in/fatih/set.v0
github.com/ethereum/go-ethereum/rpc
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/ripemd160
github.com/ethereum/go-ethereum/ethdb
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/httpu
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/scpd
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/soap
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/ssdp
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html/atom
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/internal/identifier
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/transform
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/internal
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/charmap
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/japanese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/korean
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/simplifiedchinese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/traditionalchinese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/internal/utf8internal
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/runes
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/internal/tag
github.com/ethereum/go-ethereum/vendor/github.com/jackpal/go-nat-pmp
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/language
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/unicode
github.com/ethereum/go-ethereum/p2p/netutil
github.com/ethereum/go-ethereum/vendor/gopkg.in/sourcemap.v1/base64vlq
github.com/ethereum/go-ethereum/vendor/gopkg.in/sourcemap.v1
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/token
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/dbg
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/file
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/ast
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/registry
github.com/ethereum/go-ethereum/vendor/github.com/karalabe/hid
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/parser
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/htmlindex
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html/charset
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/dcps/internetgateway1
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/dcps/internetgateway2
github.com/ethereum/go-ethereum/p2p/nat
github.com/ethereum/go-ethereum/log/term
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-colorable
github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1
github.com/ethereum/go-ethereum/les/flowcontrol
github.com/ethereum/go-ethereum/internal/jsre/deps
github.com/ethereum/go-ethereum/internal/debug
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-isatty
github.com/ethereum/go-ethereum/vendor/github.com/fatih/color
github.com/ethereum/go-ethereum/internal/web3ext
github.com/ethereum/go-ethereum/vendor/github.com/peterh/liner
github.com/ethereum/go-ethereum/vendor/golang.org/x/tools/go/ast/astutil
github.com/ethereum/go-ethereum/vendor/golang.org/x/tools/imports
github.com/ethereum/go-ethereum/vendor/github.com/maruel/panicparse/stack
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-runewidth
github.com/ethereum/go-ethereum/vendor/github.com/mitchellh/go-wordwrap
github.com/ethereum/go-ethereum/vendor/github.com/nsf/termbox-go
github.com/ethereum/go-ethereum/vendor/github.com/naoina/go-stringutil
github.com/ethereum/go-ethereum/vendor/github.com/gizak/termui
github.com/ethereum/go-ethereum/vendor/github.com/naoina/toml/ast
github.com/ethereum/go-ethereum/vendor/github.com/naoina/toml
github.com/ethereum/go-ethereum/internal/jsre
github.com/ethereum/go-ethereum/console
github.com/ethereum/go-ethereum/crypto
github.com/ethereum/go-ethereum/crypto/ecies
github.com/ethereum/go-ethereum/core/types
github.com/ethereum/go-ethereum/p2p/discover
github.com/ethereum/go-ethereum/p2p/discv5
github.com/ethereum/go-ethereum/accounts/abi
github.com/ethereum/go-ethereum
github.com/ethereum/go-ethereum/core/state
github.com/ethereum/go-ethereum/accounts
github.com/ethereum/go-ethereum/core/vm
github.com/ethereum/go-ethereum/accounts/keystore
github.com/ethereum/go-ethereum/consensus
github.com/ethereum/go-ethereum/consensus/misc
github.com/ethereum/go-ethereum/consensus/clique
github.com/ethereum/go-ethereum/consensus/ethash
github.com/ethereum/go-ethereum/eth/downloader
github.com/ethereum/go-ethereum/eth/fetcher
github.com/ethereum/go-ethereum/p2p
github.com/ethereum/go-ethereum/core
github.com/ethereum/go-ethereum/accounts/usbwallet
github.com/ethereum/go-ethereum/accounts/abi/bind
github.com/ethereum/go-ethereum/ethclient
github.com/ethereum/go-ethereum/node
github.com/ethereum/go-ethereum/whisper/whisperv5
github.com/ethereum/go-ethereum/eth/filters
github.com/ethereum/go-ethereum/internal/ethapi
github.com/ethereum/go-ethereum/miner
github.com/ethereum/go-ethereum/light
github.com/ethereum/go-ethereum/eth/gasprice
github.com/ethereum/go-ethereum/eth
github.com/ethereum/go-ethereum/les
github.com/ethereum/go-ethereum/ethstats
github.com/ethereum/go-ethereum/contracts/release
github.com/ethereum/go-ethereum/cmd/utils
github.com/ethereum/go-ethereum/cmd/geth
Done building.
Run "build/bin/geth" to launch geth.

2017年6月11日日曜日

IOTA whitepaperの概要

ペーパーを第3章まで読んでざっくりと内容をまとめてみる。
ここには個人的な意見も含むことを注意してほしい。
http://iotatoken.com/IOTA_Whitepaper.pdf

目的

IOT向けマイクロペイメントの実現

現状の課題(述べられていること)

ビットコインでは手数料が高く少額の支払いに向いていない

現状の課題(個人的)

取引承認にかかる時間、スケーラビリティ

何をするのか

  • Blockchainless
  • DAGでTxチェーンを作成
    • これをtangleと呼んでいるらしい

どう動くのか

  • Txの発行・承認・伝搬の役割が参加者で別れておりTxがTxを承認する
    • 理想的な状態では承認が重複せずスケールアウトする?
  • Txを発行するには、ユーザーは他のTxを承認する必要がある
  • 新しいTxはランダムに選ばれる前の2つのTxを承認する必要がある
  • 全てのTxは台帳に入りうる
    • Orphanのような存在も救われるようにしている
  • 各ノードはTxを伝搬させる役割を持つ 
    • そのインセンティブはネットワークに参加できること
    • あまりにも怠惰であるとドロップされる
  • 自らのTxを参照する空Txションを作成することでtipからの承認を受ける確率をあげることが望まれる
    • 不要なTxの増加を誘発させないか?
  • Spam対策
    • 大きなweightがあるものほどノードが承認しやすいならば、spamは承認されづらくなる 
      • しかしそれでは新たなtipsが承認されなくなってしまうのでは?
      • spamに承認されてるTxはなるべく承認されないようになっているのでは?

言葉の定義

tips:未承認のTx
site:tangleグラフ上に表されるTx
node:ネットワーを構成しているもの、Txを発行するエンティティ
height:genesisまで最長指向経路の長さ
depth:いくつかの先端までの最長の逆向き経路の長さ
score:全てのTxのweightの合計
cumulative weight:全ての取引のweightの合計
weights:Txスコアの元になる
cutset:ある時点におけるtipsの集合

2017年6月3日土曜日

MacOSXでbitcoindを設定する時に出るエラーとその対処法

ある端末でセットアップしようとした時にいくつかつまずいた点をまとめておく。

<事象>
configure: error: No working boost sleep implementation found.

<対応>
$ brew install autoconf automake libtool berkeley-db4 boost miniupnpc openssl pkg-config protobuf qt

<結果>
$ make
....
net.cpp:1066:15: error: no matching function for call to 'upnpDiscover'
    devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);
              ^~~~~~~~~~~~
/usr/local/include/miniupnpc/miniupnpc.h:62:1: note: candidate function not
      viable: requires 7 arguments, but 6 were provided
upnpDiscover(int delay, const char * multicastif,
^
1 error generated.
make[2]: *** [net.o] Error 1
make[1]: *** [check-recursive] Error 1
make: *** [check-recursive] Error 1

<判定>
どうやら選択しているバージョンが古いらしい。今までは
v0.9.5
を選択していた。リストの最下部に出てくるので最新かと思いきや。
$ git tag
で選択可能なバージョンを見直してみると
$ git tag
v0.1.5
v0.1.6test1
v0.10.0
v0.10.0rc1
v0.10.0rc2
v0.10.0rc3
v0.10.0rc4
v0.10.1
v0.10.1rc1
v0.10.1rc2
v0.10.1rc3
v0.10.2
v0.10.2rc1
v0.10.3
v0.10.3rc1
v0.10.3rc2
v0.10.4
v0.10.4rc1
v0.10.5
v0.11.0
v0.11.0rc1
v0.11.0rc2
v0.11.0rc3
v0.11.1
v0.11.1rc1
v0.11.1rc2
v0.11.2
v0.11.2rc1
v0.11.3
v0.12.0
v0.12.0rc1
v0.12.0rc2
v0.12.0rc3
v0.12.0rc4
v0.12.0rc5
v0.12.1
v0.12.1rc1
v0.12.1rc2
v0.13.0
v0.13.0rc1
v0.13.0rc2
v0.13.0rc3
v0.13.1
v0.13.1rc1
v0.13.1rc2
v0.13.1rc3
v0.13.2
v0.13.2rc1
v0.14.0
v0.14.0rc1
v0.14.0rc2
v0.14.0rc3
v0.14.1
v0.14.1rc1
v0.14.1rc2
v0.2.0
v0.2.10
v0.2.11
v0.2.12
v0.2.13
v0.2.2
v0.2.4
v0.2.5
v0.2.6
v0.2.7
v0.2.8
v0.2.9
v0.2rc2
v0.3.0
v0.3.1
v0.3.10
v0.3.11_notexact
v0.3.12
v0.3.13
v0.3.14
v0.3.15
v0.3.17
v0.3.18
v0.3.19
v0.3.1rc1
v0.3.2
v0.3.20
v0.3.20.01_closest
v0.3.20.2
v0.3.20.2_closest
v0.3.21
v0.3.21rc
v0.3.22
v0.3.22rc1
v0.3.22rc2
v0.3.22rc3
v0.3.22rc4
v0.3.22rc5
v0.3.22rc6
v0.3.23
v0.3.23rc1
v0.3.24
v0.3.24rc1
v0.3.24rc2
v0.3.24rc3
v0.3.3
v0.3.6
v0.3.7
v0.3.8
v0.3rc1
v0.3rc2
v0.3rc4
v0.4.0
v0.4.00rc1
v0.4.00rc2
v0.5.0
v0.5.0rc1
v0.5.0rc2
v0.5.0rc3
v0.5.0rc4
v0.5.0rc5
v0.5.0rc6
v0.5.0rc7
v0.5.1
v0.5.1rc1
v0.5.1rc2
v0.5.2
v0.5.3
v0.5.3rc4
v0.6.0
v0.6.0rc1
v0.6.0rc2
v0.6.0rc3
v0.6.0rc4
v0.6.0rc5
v0.6.0rc6
v0.6.1
v0.6.1rc1
v0.6.1rc2
v0.6.2
v0.6.2.1
v0.6.2.2
v0.6.3
v0.6.3rc1
v0.7.0
v0.7.0rc1
v0.7.0rc2
v0.7.0rc3
v0.7.1
v0.7.1rc1
v0.7.2
v0.7.2rc2
v0.8.0
v0.8.0rc1
v0.8.1
v0.8.2
v0.8.2rc1
v0.8.2rc2
v0.8.2rc3
v0.8.3
v0.8.4
v0.8.4rc2
v0.8.5
v0.8.6
v0.8.6rc1
v0.9.0
v0.9.0rc1
v0.9.0rc2
v0.9.0rc3
v0.9.1
v0.9.2
v0.9.2.1
v0.9.2rc1
v0.9.2rc2
v0.9.3
v0.9.3rc1
v0.9.3rc2
v0.9.4
v0.9.5
v0.9.5rc1
v0.9.5rc2

<対応> バージョンを最新にした。
$ git checkout v0.14.1

<結果>
$ ./configure
configure: error: libevent not found.

<対応>
依存関係のあるパッケージがまたひとつ抜けているらしいので。
$ brew install libevent
$ make

<結果>
Making all in doc/man
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `all-am'.
$ sudo make install
Making install in doc/man
make[2]: Nothing to be done for `install-exec-am'.
 ../../build-aux/install-sh -c -d '/usr/local/share/man/man1'
 /usr/bin/install -c -m 644 bitcoind.1 bitcoin-qt.1 bitcoin-cli.1 bitcoin-tx.1 '/usr/local/share/man/man1'
make[2]: Nothing to be done for `install-exec-am'.
 build-aux/install-sh -c -d '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 libbitcoinconsensus.pc '/usr/local/lib/pkgconfig'

<確認>
$ which bitcoind
/usr/local/bin/bitcoind