Example code for my talk at CodeBEAM SF 2018
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config format Mar 15, 2018
lib format Mar 15, 2018
priv/repo/migrations initial commit Mar 14, 2018
test format Mar 15, 2018
.formatter.exs initial commit Mar 14, 2018
.gitignore initial commit Mar 14, 2018
.tool-versions
README.md migrations instructions on README Mar 15, 2018
mix.exs format Mar 15, 2018
mix.lock initial commit Mar 14, 2018

README.md

Coins

Coins is an example app using CQRS and Event Sourcing.

It uses:

Using

Setup the databases with mix setup_db and then run iex -S mix

iex> Coins.mine_coin("me", 1)
{:error, :invalid_nonce}

iex> Coins.mine_coin("me", 190)
:ok

iex> Coins.mine_coin("me", 190)
{:error, :used_nonce}

iex> Coins.mine_coin("me", 443)
:ok

iex> Coins.richest |> Map.take([:account_id, :balance])
%{account_id: "me", balance: 1}

iex> [488, 1442, 1597] |> Enum.map(&(Coin.mine_coin("you" &1)))
[:ok, :ok, :ok]

iex> Coins.richest |> Map.take([:account_id, :balance])
%{account_id: "you", balance: 3}

iex> Coins.send_coins("you", "me", 99999)
{:error, :not_enough_coins}

iex> Coins.send_coins("you", "me", 3)
:ok

iex> Coins.richest |> Map.take([:account_id, :balance])
%{account_id: "me", balance: 5}