I've been working to improve the developer experience for Steemex and this release does exactly that. I had to introduce some breaking changes but it was worth it. Stage.Blocks, Stage.RawOps and Statge.MungedOps GenStage producers now emit events with the following shape : %Steem.Event{data: ..., metadata: ...}` where data is a new Steem blockchain operation struct (or a map) and metadata includes timestamp, block height, source blockchain, type and if the operation data was munged.
All event producers follow GenStage spec which allows you to easily patch into the transformation pipeline at any step: block producer, ops producer or munged ops producer.
Repos and docs
Changelog
- breaking: event shape for GenStage pipeline changed from tuple to %Steemex.Event{} struct
- breaking: all API responses are now structs or atom keyed maps
- all stages now emit %Steemex.Event{data: ..., metadata: ...}
- added Steemex.Block struct
- added Steemex.Event struct
- Steemex.Stages.Ops.ProducerConsumer renamed to Steemex.Stages.RawOps
- Steemex.Stages.StructuredOps.ProducerConsumer renamed to Steemex.Stages.MungedOps
- timestamp strings are now parsed into NaiveDateTime
- example consumer was updated to match a new shape of events
- multiple various code improvements
A GenStage consumer example
defmodule Steemex.Stage.ExampleConsumer do
use GenStage
alias Steemex.MungedOps
require Logger
def start_link(args, options \\ []) do
GenStage.start_link(__MODULE__, args, options)
end
def init(state) do
Logger.info("Example consumer is initializing...")
{:consumer, state, subscribe_to: state[:subscribe_to]}
end
def handle_events(events, _from, state) do
for op <- events do
process_event(op)
end
{:noreply, [], state}
end
def process_event(%{data: %MungedOps.Reblog{} = data, metadata: %{height: h, timestamp: t} = metadata}) do
Logger.info """
New reblog:
#{inspect data}
with metadata
#{inspect metadata}
"""
end
def process_event(%{data: data, metadata: %{block_height: h, timestamp: t} = metadata}) do
Logger.info """
New operation:
#{inspect data}
with metadata
#{inspect metadata}
"""
end
end
Roadmap
- Add latest blockchain ops
- Add more structured ops and transformations
- Add transaction broadcast
About Elixir
Elixir is a functional programming language with superior concurrency primitives, distributed computation and fault tolerance capabilities based on Erlang/OTP.
Personally, I am really happy with my bet on Elixir to build cryptotokens related apps and strongly recommend every developer to try it.
Learning resources:
- ElixirConf Jose Valim Keynote
- ElixirConf 2016 Chris McCord Keynote
- Elixir School
- Elixir Crash Course
(∩o)⊃━☆゜.*