My goal for this release was to significantly simplify handling of blockchain event streams by extracting custom ops into their own structs, parsing values out of strings and adding block metadata. As one example, you can now pattern match against reblog or follows.
Structured ops event producer follows GenStage spec which allows you to easily patch into the transformation pipeline at any step: block producer, ops producer or structured ops producer.
Repos and docs
Changelog
- added
Steemex.Stage.StructuredOps.ProducerConsumer
module - To susbcribe use the following GenStage option:
subscribe_to: Steemex.Stage.StructuredOps.ProducerConsumer
. All producers use BroadcastDispatcher -- blockchain event wills be sent to all subscribed consumers. - added multiple structured ops structs
- added multiple transformation functions and tests for each
- event shape of structured ops producer has changed to
{op_data, op_metadata}
where op_data can be matched against ops structs - event shape of ops producer has been changed to
{op_type, op_data, op_metadata}
- transfer value strings are now parsed into operation struct fields
- tags, app fields are added to structured comment struct
- op_metadata is now available with
%{height: h, timestamp: t}
fields - updated supervisor module for GenStage producers
- updated example of GenStage consumer for structured steem operation with pattern matching on structs and metadata
A GenStage consumer example
defmodule Steemex.StructuredStage.Ops.ExampleConsumer do
use GenStage
alias Steemex.StructuredOps
require Logger
def start_link(args, options \\ []) do
GenStage.start_link(__MODULE__, args, options)
end
def init(state) do
{: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({%StructuredOps.Reblog{} = op_data, %{height: h, timestamp: t} = op_metadata}) do
Logger.info """
New reblog:
#{inspect op_data} at height #{h} and time #{t}
"""
end
def process_event({op_data, %{height: h, timestamp: t} = op_metadata}) do
Logger.info """
New operation:
#{inspect op_data} at height #{h} and time #{t}
"""
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
Seems Good :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This post received a 78% upvote from @randowhale thanks to @jesta! For more information on @randowhale click here!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hello, I'm interested in elixir language, can you please tag posts related to elixir?
Also, I wonder what environment do you use to write code/test program in elixir?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
yours is very benefits to me
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Do what?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit