Skip to content

Commit

Permalink
Merge pull request #11 from Anthony-Tresallet/master
Browse files Browse the repository at this point in the history
Add cardano_preview network
  • Loading branch information
vladimirvolek committed Nov 29, 2022
2 parents b1f8ea7 + 47d8016 commit a24a808
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/blockfrost.ex
Expand Up @@ -21,7 +21,7 @@ defmodule Blockfrost do
**Required options:**
* `:name` - the name of the Blockfrost client. Defaults to `Blockfrost`
* `:network` - the network for this client. Either `:cardano_mainnet`, `cardano_testnet` or `:ipfs`
* `:network` - the network for this client. Either `:cardano_mainnet`, `:cardano_preprod`, `:cardano_preview`, `:cardano_testnet` or `:ipfs`
* `:api_key` - Your Blockfrost API key
**Other options:**
Expand Down
2 changes: 2 additions & 0 deletions lib/blockfrost/config.ex
Expand Up @@ -19,6 +19,8 @@ defmodule Blockfrost.Config do

@networks %{
cardano_mainnet: URI.parse("https://cardano-mainnet.blockfrost.io/api/v0"),
cardano_preprod: URI.parse("https://cardano-preprod.blockfrost.io/api/v0"),
cardano_preview: URI.parse("https://cardano-preview.blockfrost.io/api/v0"),
cardano_testnet: URI.parse("https://cardano-testnet.blockfrost.io/api/v0"),
ipfs: URI.parse("https://ipfs.blockfrost.io/api/v0")
}
Expand Down
3 changes: 3 additions & 0 deletions lib/blockfrost/http.ex
Expand Up @@ -221,6 +221,9 @@ defmodule Blockfrost.HTTP do
%{status: 403} ->
{:error, :unauthenticated}

%{status: 404} ->
{:error, :not_found}

%{status: 418} ->
{:error, :ip_banned}

Expand Down
3 changes: 2 additions & 1 deletion lib/blockfrost/utils.ex
Expand Up @@ -21,7 +21,8 @@ defmodule Blockfrost.Utils do
end

def validate_ipfs!(name), do: validate_network!(name, [:ipfs])
def validate_cardano!(name), do: validate_network!(name, [:cardano_mainnet, :cardano_testnet])
def validate_cardano!(name),
do: validate_network!(name, [:cardano_mainnet, :cardano_preprod, :cardano_preview, :cardano_testnet])

def validate_network!(name, allowed_networks) do
%{network: network} = Blockfrost.config(name)
Expand Down
2 changes: 2 additions & 0 deletions test/blockfrost/http_test.exs
Expand Up @@ -6,6 +6,8 @@ defmodule Blockfrost.HTTPTest do

setup_all do
start_supervised!({Blockfrost, name: TestNet, api_key: "apikey", network: :cardano_testnet})
start_supervised!({Blockfrost, name: PreviewNet, api_key: "apikey", network: :cardano_preview})
start_supervised!({Blockfrost, name: PreprodNet, api_key: "apikey", network: :cardano_preprod})
start_supervised!({Blockfrost, name: MainNet, api_key: "apikey", network: :cardano_mainnet})
:ok
end
Expand Down

0 comments on commit a24a808

Please sign in to comment.