LoginSignup
5
0

More than 5 years have passed since last update.

Mac使ってOmiseGO sdk 無知識から試してみた

Last updated at Posted at 2018-03-03

スターっと

最近流行りのブロックチェーン、大体ほとんど中国製♬
いきなり始めるOmiseGO。書いてある文書ほとんど英語。
Cしか知らない俺が来た。プログラミングはみな兄弟!多分できると俺に期待。
YOメーン

と言う事で、Qiitaの初陣はラップをかましてみて
やった事ないだらけの事をやって見ようと言う事で、
ブロックチェーンの中でもスマートコントラクトとか言うのの最新ものに
手を出してみました。
参考は、こちら[https://github.com/omisego/ewallet]
って単なるGitHubのReadmeじゃん

環境準備

何とMacを使用
全く真っ赤ーではない。未だにコントロールCとコマンドCが分からない
あと、かなと英数のボタン、あれもイライラする…真っ赤ーをディスっている場合じゃないな
マックのバージョンの見方はこうだ。さっきQiitaで調べた

$sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.3
BuildVersion:   17D47

インストール

先ほどのサイトをgoogle先生に翻訳させて、「Installing the dependencies」のとこから
ImageMagick以外は必要っぽいな・・(いや全部必要だろ!!)必要になった時に準備しよう。そもそもElixirって何やねん読んでもわからんわ。
知らん子ばっかりやし何も準備せずに、ノーガードで突っ込むことにした。

コード取ってくる

git clone https://github.com/omisego/ewallet && cd ./ewallet

Gitやね。これは楽勝。と思い行きや

Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.

何やよくわからんけど、須藤(sudo)すれば良いやね

sudo xcodebuild -license

Noとは言えない日本人。全く読まずにagreeした。

次は、

$ mix deps.get
-bash: mix: command not found

はい初見です。dependece達の中にも君いませんでしたよね
どうやらこの子がエリクシールらしい。早速インストールしないとね。
マックはbrewとかMacPortsでアプリをインストールするらしい
apt-getとかyumの仲間ね。←ちょい古い

brew install elixir
==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2n: 1,792 files, 12.3MB

お・・ビール・・何とマックは醸造しているらしい。と言うことでmixが出来ました。

$ which mix
/usr/local/bin/mix
$ mix deps.get
Could not find Hex, which is needed to build dependency :credo
Shall I install Hex? (if running non-interactively, use "mix local.hex --force") [Yn] Y

何やかんやでここまでOK
DBが何や、ごちゃごちゃ書いているので、先にpostgresを入れることにする。
デフォルトでいれといたら大丈夫っしょ

$ brew install postgresql
==> Downloading https://homebrew.bintray.com/bottles/postgresql-10.3.high_sierra

と言うことで、環境的にはこんな感じ

$sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.3
BuildVersion:   17D47

$elixir -v
Erlang/OTP 20 [erts-9.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]


↓こいつでは動かないので注意
Elixir 1.6.2 (compiled with OTP 20)
$psql --version
psql (PostgreSQL) 10.3

テスト実行

さあ、実験を始めよう。なんか環境変数の設定みたいなコマンドだがこの中でテスト用の
テーブルを作って、テストして結果がわかると言うスグレモノコマンドらしい。

MIX_ENV=test mix do ecto.create, ecto.migrate
・・・
==> url_dispatcher
Compiling 4 files (.ex)
Generated url_dispatcher app

12:14:19.469 [error] GenServer #PID<0.6290.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection) lib/db_connection/connection.ex:163: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
** (Mix) The database for LocalLedgerDB.Repo couldn't be created: an exception was raised:
    ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
        (db_connection) lib/db_connection/connection.ex:163: DBConnection.Connection.connect/2
        (connection) lib/connection.ex:622: Connection.enter_connect/5
        (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

こけた・・ワッツアップ
こんな時は「you can get in touch with us on Rocket!」
聞いてこいってことなので、早速問い合わせ。
返事がない・・まるで屍のようだ。初歩的すぎたか。
ちょまてよ。connection refused
YOメーン、よう読めー。接続できてねーのか・・・
接続できねーポートが空いてねー多分DB起動してねー
こんな初歩的ミスでぐーるぐる。

$ psql -l
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

ですよね。DB起動してなければ繋がらねーっすよね

$ postgres -D /usr/local/var/postgres

もう一度、DB起動確認!おっけ

$ psql -l
                                      List of databases
       Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-------------------+----------+----------+-------------+-------------+-----------------------
 ewallet_test      | leesatoh | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

さあ気を取り直して、実験を始めよう

MIX_ENV=test mix do ecto.create, ecto.migrate

問題発生

テストのいくつかがfailure。とりあえず問い合わせた。

MIX test was failure.
Please help me what to do.
==> ewallet_db


  1) test update/2 prevents changing of provider_user_id (EWalletDB.UserTest)
     test/ewallet_db/user_test.exs:50
     ** (ExMachina.UndefinedFactoryError) No factory defined for :_user.

     Please check for typos or define your factory:

         def _user_factory do
           ...
         end

     code: test_update_prevents_changing User, :provider_user_id
     stacktrace:
       (ex_machina) lib/ex_machina.ex:170: ExMachina.build/3
       (ex_machina) lib/ex_machina/ecto.ex:109: ExMachina.Ecto.params_for/3
       test/ewallet_db/user_test.exs:50: (test)
.. and more.


——— DB error
2018-03-03 13:37:34.807 JST [60770] ERROR:  duplicate key value violates unique constraint "balance_address_index"
2018-03-03 13:37:34.807 JST [60770] DETAIL:  Key (address)=(address) already exists.
.. and more.

今日はここまで

新情報

elixirのバージョンが1.5系でないとダメない様子。なぜ1.6だとduplicate keyになるのか。ほんまにーと思いながら

バージョンダウン

既存はこれ

$ brew info elixir
elixir: stable 1.6.2 (bottled), HEAD
Functional metaprogramming aware language built on Erlang VM
https://elixir-lang.org/
/usr/local/Cellar/elixir/1.6.2 (411 files, 5.4MB) *
  Poured from bottle on 2018-03-03 at 11:30:36
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/elixir.rb
==> Dependencies
Required: erlang ✔
==> Options
--HEAD
    Install HEAD version

こうして

$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/
$ git log elixir.rb 


commit 1c209787aebece32195ff8540a258cda50be9dc0
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Tue Jan 9 17:15:47 2018 +0000

    elixir: update 1.5.3_1 bottle.

1.5の辺りを見つけて、こうする

$ git checkout 1c209787aebece32195ff8540a258cda50be9dc0 elixir.rb 

最新版は見ないように

$ brew unlink elixir
Unlinking /usr/local/Cellar/elixir/1.6.2... 14 symlinks removed

$ HOMEBREW_NO_AUTO_UPDATE=1 brew install elixir
・・・

🍺  /usr/local/Cellar/elixir/1.5.3_1: 400 files, 5MB

これでよし

$ elixir -v
Erlang/OTP 20 [erts-9.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.5.3

テスト再開

$ mix test
==> local_ledger_db
.........................................................

Finished in 0.9 seconds
57 tests, 0 failures

Randomized with seed 889971
==> ewallet_db
.........................................................................................................................................................................................................................................................

Finished in 3.8 seconds
249 tests, 0 failures

Randomized with seed 889971
==> local_ledger
........................

Finished in 1.5 seconds
24 tests, 0 failures

Randomized with seed 889971
==> ewallet
.............................................................................................................................................

Finished in 5.2 seconds
141 tests, 0 failures

良いねー良いねー

Randomized with seed 889971
==> admin_api
...........

  1) test /admin.upload_avatar removes the avatar from a user with empty string (AdminAPI.V1.AdminControllerTest)
     test/admin_api/v1/controllers/admin_controller_test.exs:150
     ** (EXIT from #PID<0.2758.0>) an exception was raised:
         ** (Arc.MissingExecutableError) Cannot locate executable: convert

             (arc) lib/arc/transformations/convert.ex:22: Arc.Transformations.Convert.ensure_executable_exists!/1
             (arc) lib/arc/transformations/convert.ex:7: Arc.Transformations.Convert.apply/3
             (arc) lib/arc/actions/store.ex:57: Arc.Actions.Store.put_version/3
             (elixir) lib/task/supervised.ex:85: Task.Supervised.do_apply/2
             (elixir) lib/task/supervised.ex:36: Task.Supervised.reply/5
             (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3




................................................................................................

Finished in 5.6 seconds
184 tests, 8 failures

Randomized with seed 889971
==> ewallet_api
......................................................................................................................................

Finished in 6.0 seconds
134 tests, 0 failures

Randomized with seed 889971
==> url_dispatcher
There are no tests to run

あ・・コケた。admin言うてる・・やっぱマジック何とか要るんか

$ brew install imagemagick

==> Pouring imagemagick-7.0.7-25.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/imagemagick/7.0.7-25: 1,526 files, 23.2MB

サクッとインストールして、はい次

$ mix test
==> local_ledger_db
.........................................................

Finished in 1.0 seconds
57 tests, 0 failures

Randomized with seed 219385
==> ewallet_db
.........................................................................................................................................................................................................................................................

Finished in 3.5 seconds
249 tests, 0 failures

Randomized with seed 219385
==> local_ledger
........................

Finished in 1.4 seconds
24 tests, 0 failures

Randomized with seed 219385
==> ewallet
.............................................................................................................................................

Finished in 5.2 seconds
141 tests, 0 failures

Randomized with seed 219385
==> admin_api
........................................................................................................................................................................................

Finished in 5.9 seconds
184 tests, 0 failures

Randomized with seed 219385
==> ewallet_api
......................................................................................................................................

Finished in 5.9 seconds
134 tests, 0 failures

Randomized with seed 219385
==> url_dispatcher
There are no tests to run

So Good.see you!

5
0
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
5
0