Skip to content

Commit

Permalink
Merge pull request #194 from kommitters/v0.8
Browse files Browse the repository at this point in the history
Release v0.8
  • Loading branch information
miguelnietoa authored Jul 27, 2022
2 parents 50024e1 + b64a4dd commit 0abdd4b
Show file tree
Hide file tree
Showing 39 changed files with 1,577 additions and 15 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: StellarSDK CD

on:
release:
types:
[published]

jobs:
publish:
name: Publish Release to HEX PM
runs-on: ubuntu-latest
strategy:
matrix:
otp: ['23.3']
elixir: ['1.11']
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-elixir@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Install Dependencies
run: |
rm -rf deps _build
mix deps.get
- name: Publish
run: HEX_API_KEY=$HEX_API_KEY mix hex.publish --yes
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
env:
MIX_ENV: test
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
- uses: actions/checkout@v3
- uses: erlef/setup-elixir@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog

## 0.7.1 (25.07.2022)
## 0.8.0 (27.07.2022)
* Add Fee Stats, Paths, and Order Books endpoints.
* Add `Keypair.valid_signature?/3` function.
* Fix documentation examples to create accounts and payments.
* Automate publishing of new releases to Hex.pm using CD.

- Add security policy to the repository
## 0.7.1 (25.07.2022)
* Add security policy to the repository

## 0.7.0 (27.05.2022)
* Add CreateClaimableBalance, ClaimClaimableBalance, RevokeSponsorship operations.
Expand Down
72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The **Stellar SDK** is composed of two complementary components: **`TxBuild`** +
```elixir
def deps do
[
{:stellar_sdk, "~> 0.7.1"}
{:stellar_sdk, "~> 0.8.0"}
]
end
```
Expand Down Expand Up @@ -655,6 +655,76 @@ Stellar.Horizon.Effects.all(limit: 10, order: :asc)

See [**Stellar.Horizon.Effects**](https://hexdocs.pm/stellar_sdk/Stellar.Horizon.Effects.html#content) for more details.

### FeeStats
```elixir
# retrieve fee stats
Stellar.Horizon.FeeStats.retrieve()
```

See [**Stellar.Horizon.FeeStats**](https://developers.stellar.org/api/aggregations/fee-stats/single/) for more details.

### Paths

#### List paths
This will return information about potential path payments:
- [Required] source_account. The Stellar address of the sender.
- [Required] destination_asset_type. The type for the destination asset, **native**, **credit_alphanum4**, or **credit_alphanum12**.
- [Required] destination_amount. The destination amount specified in the search that found this path.
- [Optional] destination_account. The Stellar address of the reciever.
- [Optional] destination_asset_issuer. The Stellar address of the issuer of the destination asset. Required if the destination_asset_type is not **native**.
- [Optional] destination_asset_code. The code for the destination asset.

```elixir
Stellar.Horizon.PaymentPaths.list_paths(source_account: "GBRSLTT74SKP62KJ7ENTMP5V4R7UGB6E5UQESNIIRWUNRCCUO4ZMFM4C", destination_asset_type: :native, destination_amount: 5)
```

#### List strict receive payment paths
- [Required] destination_asset_type. The type for the destination asset, **native**, **credit_alphanum4**, or **credit_alphanum12**.
- [Required] destination_amount. The amount of the destination asset that should be received.
- [Optional] source_account. The Stellar address of the sender.
- [Optional] source_assets. A comma-separated list of assets available to the sender.
- [Optional] destination_asset_issuer. The Stellar address of the issuer of the destination asset. Required if the **destination_asset_type** is not **native**
- [Optional] destination_asset_code. The code for the destination asset. Required if the **destination_asset_type** is not **native**.

```elixir
Stellar.Horizon.PaymentPaths.list_receive_paths(destination_asset_type: :native, destination_amount: 5, source_account: "GBTKSXOTFMC5HR25SNL76MOVQW7GA3F6CQEY622ASLUV4VMLITI6TCOO")
```

#### List strict send payment paths
- [Required] source_asset_type. The type for the source asset, **native**, **credit_alphanum4**, or **credit_alphanum12**.
- [Required] source_amount. The amount of the source asset that should be sent.
- [Optional] source_asset_issuer. The Stellar address of the issuer of the source asset. Required if the **source_asset_type** is not native.
- [Optional] source_asset_code. The code for the source asset. Required if the **source_asset_type** is not **native**.
- [Optional] destination_account. The Stellar address of the reciever.
- [Optional] destination_assets. A comma-separated list of assets that the recipient can receive.

```elixir
Stellar.Horizon.PaymentPaths.list_send_paths(source_asset_type: :native, source_amount: 5, destination_assets: "TEST:GA654JC6QLA3ZH4O5V7X5NPM7KEWHKRG5GJA4PETK4SOFBUJLCCN74KQ")
```

See [**Stellar.Horizon.Paths**](https://developers.stellar.org/api/aggregations/paths/) for more details.

### Order Books

#### Retrieve order Books
Provides an order book’s bids and asks:
- [Required] selling_asset. **:native** or **[code: "SELLING_ASSET_CODE", issuer: "SELLING_ASSET_ISSUER" ]**.
- [Required] buying_asset. **:native** or **[code: "BUYING_ASSET_CODE", issuer: "BUYING_ASSET_ISSUER" ]**.
- [Optional] limit. The maximum number of records returned

```elixir
Stellar.Horizon.OrderBooks.retrieve(selling_asset: :native, buying_asset: :native)
Stellar.Horizon.OrderBooks.retrieve(selling_asset: :native,
buying_asset: [
code: "BB1",
issuer: "GD5J6HLF5666X4AZLTFTXLY46J5SW7EXRKBLEYPJP33S33MXZGV6CWFN"
],
limit: 2
)
```

See [**Stellar.Horizon.OrderBooks**](https://developers.stellar.org/api/aggregations/order-books/) for more details.

---

## Development
Expand Down
5 changes: 3 additions & 2 deletions docs/examples/create_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ signer_key_pair = Stellar.KeyPair.from_secret_seed("SECRET_SEED")
signature = Stellar.TxBuild.Signature.new(signer_key_pair)

# 5. submit the transaction to Horizon
{:ok, tx} =
{:ok, base64_envelope} =
source_account
|> Stellar.TxBuild.new(sequence_number: sequence_number)
|> Stellar.TxBuild.add_operation(operation)
|> Stellar.TxBuild.sign(signature)
|> Stellar.TxBuild.envelope()
|> Stellar.Horizon.Transactions.create()

{:ok, submitted_tx} = Stellar.Horizon.Transactions.create(base64_envelope)
```
12 changes: 7 additions & 5 deletions docs/examples/payments.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ signer_key_pair = Stellar.KeyPair.from_secret_seed("SECRET_SEED")
signature = Stellar.TxBuild.Signature.new(signer_key_pair)

# 5. submit the transaction to Horizon
{:ok, tx} =
{:ok, base64_envelope} =
source_account
|> Stellar.TxBuild.new(sequence_number: sequence_number)
|> Stellar.TxBuild.add_operation(operation)
|> Stellar.TxBuild.sign(signature)
|> Stellar.TxBuild.envelope()
|> Stellar.Horizon.Transactions.create()

{:ok, submitted_tx} = Stellar.Horizon.Transactions.create(base64_envelope)
```

## Alphanum asset payment
Expand All @@ -53,11 +54,12 @@ signer_key_pair = Stellar.KeyPair.from_secret_seed("SECRET_SEED")
signature = Stellar.TxBuild.Signature.new(signer_key_pair)

# 5. submit the transaction to Horizon
{:ok, tx} =
{:ok, base64_envelope} =
source_account
|> Stellar.TxBuild.new(sequence_number: sequence_number)
|> Stellar.TxBuild.add_operation(operation)
|> Stellar.TxBuild.sign(signature)
|> Stellar.TxBuild.envelope()
|> Stellar.Horizon.Transactions.create()
```

{:ok, submitted_tx} = Stellar.Horizon.Transactions.create(base64_envelope)
```
40 changes: 40 additions & 0 deletions lib/horizon/fee_stat.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule Stellar.Horizon.FeeStat do
@moduledoc """
Represents a `FeeStat` resource from Horizon API.
"""

@behaviour Stellar.Horizon.Resource

alias Stellar.Horizon.Mapping

@type t :: %__MODULE__{
last_ledger: non_neg_integer(),
last_ledger_base_fee: non_neg_integer(),
ledger_capacity_usage: float(),
fee_charged: map(),
max_fee: map()
}

defstruct [
:last_ledger,
:last_ledger_base_fee,
:ledger_capacity_usage,
:fee_charged,
:max_fee
]

@mapping [
last_ledger: :integer,
last_ledger_base_fee: :integer,
ledger_capacity_usage: :float
]

@impl true
def new(attrs, opts \\ [])

def new(attrs, _opts) do
%__MODULE__{}
|> Mapping.build(attrs)
|> Mapping.parse(@mapping)
end
end
34 changes: 34 additions & 0 deletions lib/horizon/fee_stats.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule Stellar.Horizon.FeeStats do
@moduledoc """
Exposes functions to interact with FeeStats in Horizon.
You can:
* Retrieve the fee stats.
Horizon API reference: https://developers.stellar.org/api/aggregations/fee-stats/
"""

alias Stellar.Horizon.{Error, FeeStat, Request}

@type resource :: FeeStat.t()
@type response :: {:ok, resource()} | {:error, Error.t()}

@endpoint "fee_stats"

@doc """
Retrieves information of the fee stats.
## Examples
iex> FeeStats.retrieve()
{:ok, %FeeStat{}}
"""

@spec retrieve :: response()
def retrieve do
:get
|> Request.new(@endpoint)
|> Request.perform()
|> Request.results(as: FeeStat)
end
end
38 changes: 38 additions & 0 deletions lib/horizon/order_book.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule Stellar.Horizon.OrderBook do
@moduledoc """
Represents an `OrderBook` resource from Horizon API.
"""

@behaviour Stellar.Horizon.Resource

alias Stellar.Horizon.Mapping
alias Stellar.Horizon.OrderBook.Price

@type t :: %__MODULE__{
bids: list(Price.t()),
asks: list(Price.t()),
base: map(),
counter: map()
}

defstruct [
:bids,
:asks,
:base,
:counter
]

@mapping [
bids: {:list, :struct, Price},
asks: {:list, :struct, Price}
]

@impl true
def new(attrs, opts \\ [])

def new(attrs, _opts) do
%__MODULE__{}
|> Mapping.build(attrs)
|> Mapping.parse(@mapping)
end
end
35 changes: 35 additions & 0 deletions lib/horizon/order_book/price.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Stellar.Horizon.OrderBook.Price do
@moduledoc """
Represents a `Price` for an order book.
"""

@behaviour Stellar.Horizon.Resource

alias Stellar.Horizon.Mapping

@type t :: %__MODULE__{
price_r: map(),
price: float(),
amount: float()
}

defstruct [
:price_r,
:price,
:amount
]

@mapping [
price: :float,
amount: :float
]

@impl true
def new(attrs, opts \\ [])

def new(attrs, _opts) do
%__MODULE__{}
|> Mapping.build(attrs)
|> Mapping.parse(@mapping)
end
end
Loading

0 comments on commit 0abdd4b

Please sign in to comment.