Packages

A library for encoding, decoding and validating transactions used for the OMG Network Plasma contracts.

Current section

Files

Jump to
ex_plasma lib ex_plasma in_flight_exit.ex
Raw

lib/ex_plasma/in_flight_exit.ex

defmodule ExPlasma.InFlightExit do
@moduledoc """
Represents an in-flight exit (IFE).
"""
use Bitwise, only_operators: true
alias ExPlasma.Crypto
@doc """
Derive the in-flight exit ID from its transaction bytes.
See https://github.com/omisego/plasma-contracts/blob/v1.0.3/plasma_framework/contracts/src/exits/utils/ExitId.sol#L53-L55
"""
@spec tx_bytes_to_id(binary()) :: pos_integer()
def tx_bytes_to_id(tx_bytes) do
tx_bytes
|> Crypto.keccak_hash()
|> :binary.decode_unsigned()
|> Bitwise.>>>(105)
|> set_bit(151)
end
defp set_bit(data, bit_position) do
data ||| 1 <<< bit_position
end
end