{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

module Bitcoin.Core.RPC.Generating (
    generateToAddress,
) where

import Data.Proxy (Proxy (..))
import Data.Text (Text)
import Data.Word (Word32)
import Haskoin.Block (BlockHash)

import Servant.Bitcoind (
    BitcoindClient,
    BitcoindEndpoint,
    C,
    I,
    O,
    toBitcoindClient,
 )

type GeneratingRpc = BitcoindEndpoint "generatetoaddress" (I Word32 -> I Text -> O Word32 -> C [BlockHash])

-- | Generate blocks in @regtest@ mode
generateToAddress ::
    -- | number of blocks to generate
    Word32 ->
    -- | address for the coinbase reward
    Text ->
    -- | how many iterations to try
    Maybe Word32 ->
    BitcoindClient [BlockHash]
generateToAddress :: Word32 -> Text -> Maybe Word32 -> BitcoindClient [BlockHash]
generateToAddress = Proxy GeneratingRpc
-> Word32 -> Text -> Maybe Word32 -> BitcoindClient [BlockHash]
forall x (p :: * -> *).
HasBitcoindClient x =>
p x -> TheBitcoindClient x
toBitcoindClient (Proxy GeneratingRpc
 -> Word32 -> Text -> Maybe Word32 -> BitcoindClient [BlockHash])
-> Proxy GeneratingRpc
-> Word32
-> Text
-> Maybe Word32
-> BitcoindClient [BlockHash]
forall a b. (a -> b) -> a -> b
$ Proxy GeneratingRpc
forall k (t :: k). Proxy t
Proxy @GeneratingRpc