Skip to content

Commit

Permalink
Merge pull request #154 from kommitters/v0.6
Browse files Browse the repository at this point in the history
Release for v0.6
  • Loading branch information
Juan Hurtado authored Mar 21, 2022
2 parents ca3ce7d + f5c0de4 commit 2d10c5f
Show file tree
Hide file tree
Showing 30 changed files with 2,013 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.6.0 (21.03.2022)
* XDR types for LedgerEntryExtension, ClaimableBalanceEntry, ClaimableBalanceFlags, DataEntry, TrustLineEntry and OfferEntryFlags.

## 0.5.0 (09.02.2022)
* Add support for encoding/decoding ed25519 muxed accounts.
* XDR types for AccountFlags, TrustLineFlags, ThresholdIndexes and Liabilities.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You should only use **`stellar_base`** if you are planning to build on top of it
```elixir
def deps do
[
{:stellar_base, "~> 0.5.0"}
{:stellar_base, "~> 0.6.0"}
]
end
```
Expand Down
138 changes: 138 additions & 0 deletions lib/xdr/ledger_entries/claimable_balance_entry.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
defmodule StellarBase.XDR.ClaimableBalanceEntry do
@moduledoc """
Representation of Stellar `ClaimableBalanceEntry` type.
"""
alias StellarBase.XDR.{ClaimableBalanceID, Claimant, Asset, Int64, ClaimableBalanceEntryExt}

@behaviour XDR.Declaration

@struct_spec XDR.Struct.new(
claimable_balance_id: ClaimableBalanceID,
claimant: Claimant,
asset: Asset,
amount: Int64,
claimable_balance_entry_ext: ClaimableBalanceEntryExt
)

@type t :: %__MODULE__{
claimable_balance_id: ClaimableBalanceID.t(),
claimant: Claimant.t(),
asset: Asset.t(),
amount: Int64.t(),
claimable_balance_entry_ext: ClaimableBalanceEntryExt.t()
}

defstruct [:claimable_balance_id, :claimant, :asset, :amount, :claimable_balance_entry_ext]

@spec new(
claimable_balance_id :: ClaimableBalanceID.t(),
claimant :: Claimant.t(),
asset :: Asset.t(),
amount :: Int64.t(),
claimable_balance_entry_ext :: ClaimableBalanceEntryExt.t()
) :: t()
def new(
%ClaimableBalanceID{} = claimable_balance_id,
%Claimant{} = claimant,
%Asset{} = asset,
%Int64{} = amount,
%ClaimableBalanceEntryExt{} = claimable_balance_entry_ext
),
do: %__MODULE__{
claimable_balance_id: claimable_balance_id,
claimant: claimant,
asset: asset,
amount: amount,
claimable_balance_entry_ext: claimable_balance_entry_ext
}

@impl true
def encode_xdr(%__MODULE__{
claimable_balance_id: claimable_balance_id,
claimant: claimant,
asset: asset,
amount: amount,
claimable_balance_entry_ext: claimable_balance_entry_ext
}) do
[
claimable_balance_id: claimable_balance_id,
claimant: claimant,
asset: asset,
amount: amount,
claimable_balance_entry_ext: claimable_balance_entry_ext
]
|> XDR.Struct.new()
|> XDR.Struct.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{
claimable_balance_id: claimable_balance_id,
claimant: claimant,
asset: asset,
amount: amount,
claimable_balance_entry_ext: claimable_balance_entry_ext
}) do
[
claimable_balance_id: claimable_balance_id,
claimant: claimant,
asset: asset,
amount: amount,
claimable_balance_entry_ext: claimable_balance_entry_ext
]
|> XDR.Struct.new()
|> XDR.Struct.encode_xdr!()
end

@impl true
def decode_xdr(bytes, struct \\ @struct_spec)

def decode_xdr(bytes, struct) do
case XDR.Struct.decode_xdr(bytes, struct) do
{:ok,
{%XDR.Struct{
components: [
claimable_balance_id: claimable_balance_id,
claimant: claimant,
asset: asset,
amount: amount,
claimable_balance_entry_ext: claimable_balance_entry_ext
]
}, rest}} ->
{:ok,
{new(
claimable_balance_id,
claimant,
asset,
amount,
claimable_balance_entry_ext
), rest}}

error ->
error
end
end

@impl true
def decode_xdr!(bytes, struct \\ @struct_spec)

def decode_xdr!(bytes, struct) do
{%XDR.Struct{
components: [
claimable_balance_id: claimable_balance_id,
claimant: claimant,
asset: asset,
amount: amount,
claimable_balance_entry_ext: claimable_balance_entry_ext
]
}, rest} = XDR.Struct.decode_xdr!(bytes, struct)

{new(
claimable_balance_id,
claimant,
asset,
amount,
claimable_balance_entry_ext
), rest}
end
end
61 changes: 61 additions & 0 deletions lib/xdr/ledger_entries/claimable_balance_entry_ext.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
defmodule StellarBase.XDR.ClaimableBalanceEntryExt do
@moduledoc """
Representation of Stellar `ClaimableBalanceEntryExt` type.
"""
@behaviour XDR.Declaration

alias StellarBase.XDR.{Void, ClaimableBalanceEntryExtV1}

@arms %{0 => Void, 1 => ClaimableBalanceEntryExtV1}

@type value :: Void.t() | ClaimableBalanceEntryExtV1.t()

@type t :: %__MODULE__{value: value(), type: non_neg_integer()}

defstruct [:value, :type]

@spec new(value :: value(), type :: non_neg_integer()) :: t()
def new(value, type),
do: %__MODULE__{value: value, type: type}

@impl true
def encode_xdr(%__MODULE__{value: value, type: type}) do
type
|> XDR.Int.new()
|> XDR.Union.new(@arms, value)
|> XDR.Union.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{value: value, type: type}) do
type
|> XDR.Int.new()
|> XDR.Union.new(@arms, value)
|> XDR.Union.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ union_spec())

def decode_xdr(bytes, spec) do
case XDR.Union.decode_xdr(bytes, spec) do
{:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ union_spec())

def decode_xdr!(bytes, spec) do
{{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec)
{new(value, type), rest}
end

@spec union_spec() :: XDR.Union.t()
defp union_spec do
0
|> XDR.Int.new()
|> XDR.Union.new(@arms)
end
end
55 changes: 55 additions & 0 deletions lib/xdr/ledger_entries/claimable_balance_entry_ext_v1.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
defmodule StellarBase.XDR.ClaimableBalanceEntryExtV1 do
@moduledoc """
Representation of Stellar `ClaimableBalanceEntryExtV1` type.
"""
alias StellarBase.XDR.{Ext, UInt32}

@behaviour XDR.Declaration

@struct_spec XDR.Struct.new(ext: Ext, flags: UInt32)

@type t :: %__MODULE__{ext: Ext.t(), flags: UInt32.t()}

defstruct [:ext, :flags]

@spec new(ext :: Ext.t(), flags :: UInt32.t()) :: t()
def new(%Ext{} = ext, %UInt32{} = flags),
do: %__MODULE__{ext: ext, flags: flags}

@impl true
def encode_xdr(%__MODULE__{ext: ext, flags: flags}) do
[ext: ext, flags: flags]
|> XDR.Struct.new()
|> XDR.Struct.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{ext: ext, flags: flags}) do
[ext: ext, flags: flags]
|> XDR.Struct.new()
|> XDR.Struct.encode_xdr!()
end

@impl true
def decode_xdr(bytes, struct \\ @struct_spec)

def decode_xdr(bytes, struct) do
case XDR.Struct.decode_xdr(bytes, struct) do
{:ok, {%XDR.Struct{components: [ext: ext, flags: flags]}, rest}} ->
{:ok, {new(ext, flags), rest}}

error ->
error
end
end

@impl true
def decode_xdr!(bytes, struct \\ @struct_spec)

def decode_xdr!(bytes, struct) do
{%XDR.Struct{components: [ext: ext, flags: flags]}, rest} =
XDR.Struct.decode_xdr!(bytes, struct)

{new(ext, flags), rest}
end
end
51 changes: 51 additions & 0 deletions lib/xdr/ledger_entries/claimable_balance_flags.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
defmodule StellarBase.XDR.ClaimableBalanceFlags do
@moduledoc """
Representation of Stellar `ClaimableBalanceFlags` type.
"""
@behaviour XDR.Declaration

@declarations [
CLAIMABLE_BALANCE_CLAWBACK_ENABLED_FLAG: 0x1
]

@enum_spec %XDR.Enum{declarations: @declarations, identifier: nil}

@type t :: %__MODULE__{identifier: atom()}

defstruct [:identifier]

@spec new(type :: atom() | nil) :: t()
def new(type \\ nil), do: %__MODULE__{identifier: type}

@impl true
def encode_xdr(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ @enum_spec)

def decode_xdr(bytes, spec) do
case XDR.Enum.decode_xdr(bytes, spec) do
{:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ @enum_spec)

def decode_xdr!(bytes, spec) do
{%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec)
{new(type), rest}
end
end
Loading

0 comments on commit 2d10c5f

Please sign in to comment.