module Hydra.API.ClientInput where
import Hydra.Prelude
import Hydra.Tx (ConfirmedSnapshot, IsTx (..), Snapshot (..), TxIdType, getSnapshot)
import Hydra.Tx.Accumulator qualified as Accumulator
data ClientInput tx
= Init
| NewTx {forall tx. ClientInput tx -> tx
transaction :: tx}
| Recover {forall tx. ClientInput tx -> TxIdType tx
recoverTxId :: TxIdType tx}
| Decommit {forall tx. ClientInput tx -> tx
decommitTx :: tx}
| Close
| SafeClose
| Contest
| Fanout
|
PartialFanout {forall tx. ClientInput tx -> UTxOType tx
utxoToFanout :: UTxOType tx}
| SideLoadSnapshot {forall tx. ClientInput tx -> ConfirmedSnapshot tx
snapshot :: ConfirmedSnapshot tx}
deriving stock ((forall x. ClientInput tx -> Rep (ClientInput tx) x)
-> (forall x. Rep (ClientInput tx) x -> ClientInput tx)
-> Generic (ClientInput tx)
forall x. Rep (ClientInput tx) x -> ClientInput tx
forall x. ClientInput tx -> Rep (ClientInput tx) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall tx x. Rep (ClientInput tx) x -> ClientInput tx
forall tx x. ClientInput tx -> Rep (ClientInput tx) x
$cfrom :: forall tx x. ClientInput tx -> Rep (ClientInput tx) x
from :: forall x. ClientInput tx -> Rep (ClientInput tx) x
$cto :: forall tx x. Rep (ClientInput tx) x -> ClientInput tx
to :: forall x. Rep (ClientInput tx) x -> ClientInput tx
Generic)
deriving stock instance IsTx tx => Eq (ClientInput tx)
deriving stock instance IsTx tx => Show (ClientInput tx)
deriving anyclass instance IsTx tx => ToJSON (ClientInput tx)
deriving anyclass instance IsTx tx => FromJSON (ClientInput tx)
instance IsTx tx => ToCBOR (ClientInput tx) where
toCBOR :: ClientInput tx -> Encoding
toCBOR = ClientInput tx -> Encoding
forall a. (Generic a, GToCBOR (Rep a)) => a -> Encoding
genericToCBOR
instance IsTx tx => FromCBOR (ClientInput tx) where
fromCBOR :: forall s. Decoder s (ClientInput tx)
fromCBOR = Decoder s (ClientInput tx)
forall a s. (Generic a, GFromCBOR (Rep a)) => Decoder s a
genericFromCBOR
validateClientInput :: IsTx tx => ClientInput tx -> Either (Int, Int) (ClientInput tx)
validateClientInput :: forall tx.
IsTx tx =>
ClientInput tx -> Either (Int, Int) (ClientInput tx)
validateClientInput = \case
input :: ClientInput tx
input@SideLoadSnapshot{ConfirmedSnapshot tx
$sel:snapshot:Init :: forall tx. ClientInput tx -> ConfirmedSnapshot tx
snapshot :: ConfirmedSnapshot tx
snapshot} ->
let Snapshot{HydraAccumulator
accumulator :: HydraAccumulator
$sel:accumulator:Snapshot :: forall tx. Snapshot tx -> HydraAccumulator
accumulator, HydraAccumulator
appliedAccumulator :: HydraAccumulator
$sel:appliedAccumulator:Snapshot :: forall tx. Snapshot tx -> HydraAccumulator
appliedAccumulator} = ConfirmedSnapshot tx -> Snapshot tx
forall tx. IsTx tx => ConfirmedSnapshot tx -> Snapshot tx
getSnapshot ConfirmedSnapshot tx
snapshot
in ClientInput tx
input
ClientInput tx
-> Either (Int, Int) () -> Either (Int, Int) (ClientInput tx)
forall a b. a -> Either (Int, Int) b -> Either (Int, Int) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (HydraAccumulator -> Either (Int, Int) ())
-> [HydraAccumulator] -> Either (Int, Int) ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_
HydraAccumulator -> Either (Int, Int) ()
Accumulator.checkAccumulatorSize
[HydraAccumulator
accumulator, HydraAccumulator
appliedAccumulator]
ClientInput tx
input -> ClientInput tx -> Either (Int, Int) (ClientInput tx)
forall a b. b -> Either a b
Right ClientInput tx
input