ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - mana-ethereum/ex_rlp: Elixir implementation of Ethereum's RLP (Recursive Length Prefix) encoding
Elixir implementation of Ethereum's RLP (Recursive Length Prefix) encoding - mana-ethereum/ex_rlp
Visit Site

GitHub - mana-ethereum/ex_rlp: Elixir implementation of Ethereum's RLP (Recursive Length Prefix) encoding

GitHub - mana-ethereum/ex_rlp: Elixir implementation of Ethereum's RLP (Recursive Length Prefix) encoding

ExRLP

CircleCI Module Version Hex Docs Total Download License Last Updated

Elixir implementation of Ethereum's RLP (Recursive Length Prefix) encoding.

The encoding's specification can be found in the yellow paper or in the ethereum wiki.

Installation

The easiest way to add ExRLP to your project is by using Mix.

Add :ex_rlp as a dependency to your project's mix.exs:

defp deps do
  [
    {:ex_rlp, "~> 0.6.0"}
  ]
end

And run:

$ mix deps.get

Basic Usage

Use ExRLP.encode/1 method to encode an item to RLP representation. An item can be non-negative integer, binary or list. List can contain integers, binaries or lists.

iex> "dog" |> ExRLP.encode(encoding: :hex)
"83646f67"

iex> "dog" |> ExRLP.encode(encoding: :binary)
<<0x83, 0x64, 0x6f, 0x67>>

iex> 1000 |> ExRLP.encode(encoding: :hex)
"8203e8"

# Default encoding is binary
iex> 1000 |> ExRLP.encode
<<0x82, 0x03, 0xe8>>

iex> [ [ [], [] ], [] ] |> ExRLP.encode(encoding: :hex)
"c4c2c0c0c0"

Use ExRLP.decode/1 method to decode a RLP encoded data. All items except lists are decoded as binaries so additional deserialization is needed if initially an item of another type was encoded.

iex> "83646f67" |> ExRLP.decode(encoding: :hex)
"dog"

iex> "8203e8" |> ExRLP.decode(encoding: :hex) |> :binary.decode_unsigned
1000

iex> "c4c2c0c0c0" |> ExRLP.decode(encoding: :hex)
[[[], []], []]

More examples can be found in test files.

Protocols

You can define protocols for encoding/decoding custom data types.

defmodule ExRLP.LogEntry do
  defstruct address: nil, topics: [], data: nil

  @type t :: %__MODULE__{
          address: EVM.address(),
          topics: [integer()],
          data: binary()
        }

  @spec new(binary, [integer()], binary()) :: t()
  def new(address, topics, data) do
    %__MODULE__{
      address: address,
      topics: topics,
      data: data
    }
  end

  def to_list(log) do
    [log.address, log.topics, log.data]
  end
end

defimpl ExRLP.Encode, for: ExRLP.LogEntry do
  alias ExRLP.{Encode, LogEntry}

  @spec encode(LogEntry.t(), keyword()) :: binary()
  def encode(log, options \\ []) do
    log
    |> LogEntry.to_list()
    |> Encode.encode(options)
  end
end

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

Ayrat Badykov (@ayrat555)

Copyright and License

Copyright (c) 2017 Geoffrey Hayes, Ayrat Badykov, Mason Forest

ExRLP is released under the MIT License. See the LICENSE.md file for further details.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory