Skip to content

bamorim/ex-cbsf2018

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}

About

Example code for my talk at CodeBEAM SF 2018

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages