module Singular.State.Refusal
( Refusal (..)
, CapacityLimit (..)
, capacityMessage
) where
import Data.ByteString (ByteString)
import Data.Text (Text)
import Data.Text qualified as Text
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Hashes (ScriptHash)
import Cardano.Ledger.TxIn (TxIn)
import Singular.Registry.TrieState (RegistryIdentity, TrieFailure)
data CapacityLimit
= TransactionSize Integer Integer
| ExecutionMemory Integer Integer
| ExecutionSteps Integer Integer
deriving stock (CapacityLimit -> CapacityLimit -> Bool
(CapacityLimit -> CapacityLimit -> Bool)
-> (CapacityLimit -> CapacityLimit -> Bool) -> Eq CapacityLimit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CapacityLimit -> CapacityLimit -> Bool
== :: CapacityLimit -> CapacityLimit -> Bool
$c/= :: CapacityLimit -> CapacityLimit -> Bool
/= :: CapacityLimit -> CapacityLimit -> Bool
Eq, Int -> CapacityLimit -> ShowS
[CapacityLimit] -> ShowS
CapacityLimit -> String
(Int -> CapacityLimit -> ShowS)
-> (CapacityLimit -> String)
-> ([CapacityLimit] -> ShowS)
-> Show CapacityLimit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CapacityLimit -> ShowS
showsPrec :: Int -> CapacityLimit -> ShowS
$cshow :: CapacityLimit -> String
show :: CapacityLimit -> String
$cshowList :: [CapacityLimit] -> ShowS
showList :: [CapacityLimit] -> ShowS
Show)
capacityMessage :: CapacityLimit -> Text
capacityMessage :: CapacityLimit -> Text
capacityMessage CapacityLimit
limit = String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ case CapacityLimit
limit of
TransactionSize Integer
used Integer
allowed ->
String
"the transaction size "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
used
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" bytes exceeds the limit "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
allowed
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" bytes"
ExecutionMemory Integer
used Integer
allowed ->
String
"the execution memory "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
used
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" exceeds the limit "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
allowed
ExecutionSteps Integer
used Integer
allowed ->
String
"the execution steps "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
used
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" exceed the limit "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
allowed
data Refusal
=
PayerHasNoFunding
|
PayerIsNotAKey
|
SeedNotAtPayer TxIn
|
ReferenceScriptMissing TxIn
|
ReferenceScriptMismatch TxIn (Maybe ScriptHash) ScriptHash
|
NoRegistryState RegistryIdentity
|
AmbiguousRegistryState Int
|
NotARegistryState TxIn
|
TrieRefused TrieFailure
|
NothingToFold
|
DuplicateRequest TxIn
|
DuplicateKey ByteString
|
KeyAlreadyRegistered ByteString
|
KeyNotActive ByteString
|
PendingNotFound TxIn
|
NotAPendingRegistration TxIn
|
PendingOfAnotherRegistry TxIn
|
DepositBelowHolding TxIn Coin Coin
|
ProcessingWindowClosed
|
BuildFailed Text
|
CapacityExceeded CapacityLimit
deriving stock (Refusal -> Refusal -> Bool
(Refusal -> Refusal -> Bool)
-> (Refusal -> Refusal -> Bool) -> Eq Refusal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Refusal -> Refusal -> Bool
== :: Refusal -> Refusal -> Bool
$c/= :: Refusal -> Refusal -> Bool
/= :: Refusal -> Refusal -> Bool
Eq, Int -> Refusal -> ShowS
[Refusal] -> ShowS
Refusal -> String
(Int -> Refusal -> ShowS)
-> (Refusal -> String) -> ([Refusal] -> ShowS) -> Show Refusal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Refusal -> ShowS
showsPrec :: Int -> Refusal -> ShowS
$cshow :: Refusal -> String
show :: Refusal -> String
$cshowList :: [Refusal] -> ShowS
showList :: [Refusal] -> ShowS
Show)