Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chores, add Sanchonet #43

Merged
merged 16 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion blockfrost-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Version [next](https://github.com/blockfrost/blockfrost-haskell/compare/api-0.8.1.0-master) (2023-mm-dd)

* Allow servant `0.20`
* Allow servant `0.20` [#41](https://github.com/blockfrost/blockfrost-haskell/pull/41)
* Additions [#43](https://github.com/blockfrost/blockfrost-haskell/pull/43)
* `Env` enum extended with `Sanchonet` for `cardano-sanchonet` network
* `/accounts/:stake_address/addresses/total` endpoint and `AddressAssociatedTotal` type
* `/addresses/:address/extended` endpoint and `AddressInfoExtended` type (uses `AmountExtended` type)
* `/pools/extended` endpoint and `Pool` type
* `/utils` API
* `/utils/addresses/xpub/:xpub/:role/:index` endpoint and `DerivedAddress` type
* `/utils/txs/evaluate` endpoint
* `/utils/txs/evaluate/utxos` endpoint
* `TxEval`, `TxEvalResult`, `TxEvalBudget`, `TxEvalInput` types for the two above

# Version [0.8.1.0](https://github.com/blockfrost/blockfrost-haskell/compare/api-0.8.0.0...api-0.8.1.0) (2023-09-18)

Expand Down
3 changes: 3 additions & 0 deletions blockfrost-api/blockfrost-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ library
, Blockfrost.API.Cardano.Pools
, Blockfrost.API.Cardano.Scripts
, Blockfrost.API.Cardano.Transactions
, Blockfrost.API.Cardano.Utils
, Blockfrost.API.IPFS
, Blockfrost.API.NutLink
, Blockfrost.Auth
Expand All @@ -92,6 +93,7 @@ library
, Blockfrost.Types.Cardano.Pools
, Blockfrost.Types.Cardano.Scripts
, Blockfrost.Types.Cardano.Transactions
, Blockfrost.Types.Cardano.Utils
, Blockfrost.Types.IPFS
, Blockfrost.Types.NutLink
, Blockfrost.Types.Shared
Expand Down Expand Up @@ -153,6 +155,7 @@ test-suite blockfrost-api-tests
, Cardano.Pools
, Cardano.Scripts
, Cardano.Transactions
, Cardano.Utils
, IPFS
, NutLink
build-depends: base >= 4.7 && < 5
Expand Down
5 changes: 5 additions & 0 deletions blockfrost-api/src/Blockfrost/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ data CardanoAPI route =
:> "submit"
:> ReqBody '[CBOR] CBORString
:> Post '[JSON] TxHash
, _utils
:: route
:- "utils"
:> Tag "Cardano » Utilities"
:> ToServantApi UtilsAPI
} deriving (Generic)

type ServantBlockfrostAPI = ToServantApi BlockfrostAPI
Expand Down
2 changes: 2 additions & 0 deletions blockfrost-api/src/Blockfrost/API/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Blockfrost.API.Cardano
, module Blockfrost.API.Cardano.Pools
, module Blockfrost.API.Cardano.Scripts
, module Blockfrost.API.Cardano.Transactions
, module Blockfrost.API.Cardano.Utils
) where

import Blockfrost.API.Cardano.Accounts
Expand All @@ -27,3 +28,4 @@ import Blockfrost.API.Cardano.Network
import Blockfrost.API.Cardano.Pools
import Blockfrost.API.Cardano.Scripts
import Blockfrost.API.Cardano.Transactions
import Blockfrost.API.Cardano.Utils
11 changes: 11 additions & 0 deletions blockfrost-api/src/Blockfrost/API/Cardano/Accounts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,15 @@ data AccountsAPI route =
:> Pagination
:> Sorting
:> Get '[JSON] [Amount]
, _accountAssociatedTotal
:: route
:- Summary "Detailed information about account associated addresses"
:> Description "Obtain summed details about all addresses associated with a given account. \
\Be careful, as an account could be part of a mangled address and does not \
\necessarily mean the addresses are owned by user as the account."
:> Capture "stake_address" Address
:> "addresses"
:> "total"
:> Get '[JSON] AddressAssociatedTotal

} deriving (Generic)
7 changes: 7 additions & 0 deletions blockfrost-api/src/Blockfrost/API/Cardano/Addresses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ data AddressesAPI route =
:> Description "Obtain information about a specific address."
:> Capture "address" Address
:> Get '[JSON] AddressInfo
, _addressInfoExtended
:: route
:- Summary "Specific address - extended"
:> Description "Obtain extended information about a specific address."
:> Capture "address" Address
:> "extended"
:> Get '[JSON] AddressInfoExtended
, _addressDetails
:: route
:- Summary "Address details"
Expand Down
8 changes: 8 additions & 0 deletions blockfrost-api/src/Blockfrost/API/Cardano/Pools.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ data PoolsAPI route =
:> Pagination
:> Sorting
:> Get '[JSON] [PoolId]
, _listPoolsExtended
:: route
:- Summary "List of stake pools with additional information"
:> Description "List of registered stake pools with additional information."
:> "extended"
:> Pagination
:> Sorting
:> Get '[JSON] [Pool]
, _listRetiredPools
:: route
:- Summary "List of retired stake pools"
Expand Down
50 changes: 50 additions & 0 deletions blockfrost-api/src/Blockfrost/API/Cardano/Utils.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- | Cardano utility endpoints

{-# OPTIONS_HADDOCK hide #-}

module Blockfrost.API.Cardano.Utils
where

import Data.Text
import Servant.API
import Servant.API.Generic

import Blockfrost.Types.Cardano.Utils
import Blockfrost.Types.Shared.CBOR

data UtilsAPI route =
UtilsAPI
{
_deriveAddr
:: route
:- Summary "Derive an address"
:> Description "Derive Shelley address from an xpub."
:> "addresses"
:> "xpub"
:> Capture "xpub" Text
:> Capture "role" Integer
:> Capture "Index" Integer
:> Get '[JSON] DerivedAddress

, _txEvaluate
:: route
:- Summary "Submit a transaction for execution units evaluation"
:> Description "Submit an already serialized transaction to evaluate \
\how much execution units it requires."
:> "txs"
:> "evaluate"
:> ReqBody '[CBOR] CBORString
:> Post '[JSON] TxEval

, _txEvaluateUTXOs
:: route
:- Summary "Submit a transaction for execution units evaluation (additional UTXO set)"
:> Description "Submit a JSON payload with transaction CBOR and additional UTXO set \
\to evaluate how much execution units it requires."
:> "txs"
:> "evaluate"
:> "utxos"
:> ReqBody '[JSON] TxEvalInput
:> Post '[JSON] TxEval

} deriving (Generic)
3 changes: 2 additions & 1 deletion blockfrost-api/src/Blockfrost/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data Env =
| Testnet
| Preprod
| Preview
| Sanchonet
| Localhost
deriving (Eq, Read, Show, Ord, Generic)

Expand All @@ -30,4 +31,4 @@ parseEnv tEnv = case Text.Read.readMaybe (Data.Text.unpack $ Data.Text.toTitle t
Nothing ->
Left
$ "Unknown environment: `" <> tEnv <> "`"
<> " expecting one of `ipfs`, `mainnet`, `testnet`, `localhost`"
<> " expecting one of `ipfs`, `mainnet`, `testnet`, `preprod`, `preview`, `sanchonet`, `localhost`"
2 changes: 2 additions & 0 deletions blockfrost-api/src/Blockfrost/Types/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Blockfrost.Types.Cardano
, module Blockfrost.Types.Cardano.Pools
, module Blockfrost.Types.Cardano.Scripts
, module Blockfrost.Types.Cardano.Transactions
, module Blockfrost.Types.Cardano.Utils
) where

import Blockfrost.Types.Cardano.Accounts
Expand All @@ -25,3 +26,4 @@ import Blockfrost.Types.Cardano.Network
import Blockfrost.Types.Cardano.Pools
import Blockfrost.Types.Cardano.Scripts
import Blockfrost.Types.Cardano.Transactions
import Blockfrost.Types.Cardano.Utils
35 changes: 35 additions & 0 deletions blockfrost-api/src/Blockfrost/Types/Cardano/Accounts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ module Blockfrost.Types.Cardano.Accounts
, AccountWithdrawal (..)
, AccountMir (..)
, AddressAssociated (..)
, AddressAssociatedTotal (..)
) where

import Blockfrost.Types.Shared
import Deriving.Aeson
import qualified Money
import Servant.Docs (ToSample (..), samples, singleSample)

-- | Information about an account, identified by its stake address
Expand Down Expand Up @@ -230,3 +232,36 @@ instance ToSample AddressAssociated where
[ AddressAssociated "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"
, AddressAssociated "addr1q8j55h253zcvl326sk5qdt2n8z7eghzspe0ekxgncr796s2f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sjmd35m"
]

-- | Detailed information about account associated addresses
data AddressAssociatedTotal = AddressAssociatedTotal {
_addressAssociatedTotalStakeAddress :: Address -- ^ Bech32 encoded address
, _addressAssociatedTotalReceivedSum :: [Amount]
, _addressAssociatedTotalSentSum :: [Amount]
, _addressAssociatedTotalTxCount :: Integer -- ^ Count of all transactions for all addresses associated with the account
} deriving stock (Show, Eq, Generic)
deriving (FromJSON, ToJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressAssociatedTotal", CamelToSnake]] AddressAssociatedTotal

instance ToSample AddressAssociatedTotal where
toSamples = pure $ singleSample
AddressAssociatedTotal
{ _addressAssociatedTotalStakeAddress = "stake1u9l5q5jwgelgagzyt6nuaasefgmn8pd25c8e9qpeprq0tdcp0e3uk"
, _addressAssociatedTotalReceivedSum =
[ AdaAmount 42000000
, AssetAmount
$ Money.mkSomeDiscrete
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
unitScale
12
]
, _addressAssociatedTotalSentSum =
[ AdaAmount 123
, AssetAmount
$ Money.mkSomeDiscrete
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
unitScale
1
]
, _addressAssociatedTotalTxCount = 2
}
33 changes: 33 additions & 0 deletions blockfrost-api/src/Blockfrost/Types/Cardano/Addresses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Blockfrost.Types.Cardano.Addresses
( AddressInfo (..)
, AddressInfoExtended (..)
, AddressType (..)
, AddressDetails (..)
, AddressUtxo (..)
Expand Down Expand Up @@ -43,6 +44,38 @@ instance ToSample AddressInfo where
, _addressInfoScript = False
}

-- | Information about Cardano address
data AddressInfoExtended = AddressInfoExtended
{ _addressInfoExtendedAddress :: Address -- ^ Bech32 encoded addresses
, _addressInfoExtendedAmount :: [AmountExtended] -- ^ Lovelaces or tokens stored on this address
, _addressInfoExtendedStakeAddress :: Maybe Address -- ^ Stake address that controls the key
, _addressInfoExtendedType :: AddressType -- ^ Address era
, _addressInfoExtendedScript :: Bool -- ^ True if this is a script address
} deriving stock (Show, Eq, Generic)
deriving (FromJSON, ToJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressInfoExtended", CamelToSnake]] AddressInfoExtended

instance ToSample AddressInfoExtended where
toSamples = pure $ singleSample
AddressInfoExtended
{ _addressInfoExtendedAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressInfoExtendedAmount =
[ AdaAmountExtended 42000000
, AssetAmountExtended
{ assetAmountExtendedDecimals = Nothing
, assetAmountExtendedHasNftOnchainMetadata = True
, assetAmountExtendedValue =
Money.toSomeDiscrete
(12 :: Money.Discrete'
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
'(1,1))
}
]
, _addressInfoExtendedStakeAddress = pure "stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7"
, _addressInfoExtendedType = Shelley
, _addressInfoExtendedScript = False
}

-- | Type (era) of an address
data AddressType = Byron | Shelley
deriving stock (Show, Eq, Generic)
Expand Down
36 changes: 35 additions & 1 deletion blockfrost-api/src/Blockfrost/Types/Cardano/Pools.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
-- | Cardano Pools reponses

module Blockfrost.Types.Cardano.Pools
( PoolEpoch (..)
( Pool (..)
, PoolEpoch (..)
, PoolInfo (..)
, PoolHistory (..)
, PoolMetadata (..)
Expand All @@ -19,6 +20,39 @@ import Servant.Docs (ToSample (..), samples, singleSample)

import Blockfrost.Types.Shared

-- | Extended pool info
data Pool = Pool
{ _poolPoolId :: PoolId -- ^ Bech32 encoded pool ID
, _poolHex :: Text -- ^ Hexadecimal pool ID.
, _poolActiveStake :: Lovelaces -- ^ Active delegated amount
, _poolLiveStake :: Lovelaces -- ^ Currently delegated amount
}
deriving stock (Show, Eq, Generic)
deriving (FromJSON, ToJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "_pool", CamelToSnake]] Pool

instance ToSample Pool where
toSamples = pure $ samples
[ Pool
{ _poolPoolId = "pool19u64770wqp6s95gkajc8udheske5e6ljmpq33awxk326zjaza0q"
, _poolHex = "2f355f79ee007502d116ecb07e36f985b34cebf2d84118f5c6b455a1"
, _poolActiveStake = 1541200000
, _poolLiveStake = 1541400000
}
, Pool
{ _poolPoolId = "pool1dvla4zq98hpvacv20snndupjrqhuc79zl6gjap565nku6et5zdx"
, _poolHex = "6b3fda88053dc2cee18a7c2736f032182fcc78a2fe912e869aa4edcd"
, _poolActiveStake = 22200000
, _poolLiveStake = 48955550
}
, Pool
{ _poolPoolId = "pool1wvccajt4eugjtf3k0ja3exjqdj7t8egsujwhcw4tzj4rzsxzw5w"
, _poolHex = "73318ec975cf1125a6367cbb1c9a406cbcb3e510e49d7c3aab14aa31"
, _poolActiveStake = 9989541215
, _poolLiveStake = 168445464878
}
]

-- | Retirement epoch for pool
data PoolEpoch = PoolEpoch
{ _poolEpochPoolId :: PoolId -- ^ Bech32 encoded pool ID
Expand Down
Loading