Steemex v0.11 released: now with producer of structured operations [open source Elixir library for Steem]

in #steemdev7 years ago (edited)


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:

(∩^o^)⊃━☆゜.*

Sort:  

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?

yours is very benefits to me

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 62441.36
ETH 2940.53
USDT 1.00
SBD 3.59