| License | Apache-2.0 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Singular.State.Fold
Description
Anyone may fold the acceptable pending requests of a registry. The folder reads its public state and trie history, skips individually unfoldable requests and keeps the first foldable request per key in take order. A registration proves its key absent and mints its token into the committed holding; a termination proves its key active and burns its token. The batch consumes the requests and their approvals, continues the state and writes the new root. The booker contributes only the public request: no file, key or local record.
What a pending request is, how it is spent and how its approval is burned belong to the application. The application hands the builder those three things; the builder owns everything the state validator decides.
Synopsis
- data Registration = Registration {
- regRegistry :: RegistryIdentity
- regKey :: ByteString
- regHolding :: Addr
- regDatum :: Data
- regDeposit :: Coin
- regDeadline :: Integer
- data Request
- = RegistrationRequest Registration
- | TerminationRequest RegistryIdentity ByteString
- requestKey :: Request -> ByteString
- data Folded = Folded {
- foldedRequest :: TxIn
- foldedApproval :: AssetName
- foldedRegistry :: RegistryIdentity
- foldedKey :: ByteString
- foldedHolding :: Maybe Word32
- data Application = Application {
- appPolicy :: PolicyID
- appDecode :: RegistryIdentity -> [ByteString] -> TxOut ConwayEra -> Maybe Request
- appIsConfiguration :: TxOut ConwayEra -> Bool
- appReferences :: [(TxIn, TxOut ConwayEra)]
- appFold :: [Folded] -> Program ()
- data PendingRequest = PendingRequest {
- pendingRef :: TxIn
- pendingOutput :: TxOut ConwayEra
- pendingRequest :: Request
- pendingApproval :: AssetName
- data SkippedHolder = SkippedHolder {
- skippedRef :: TxIn
- skippedReason :: SkipReason
- data SkipReason
- discoverPending :: Session NoWitness IO -> Application -> RegistryIdentity -> [ByteString] -> IO ([PendingRequest], [SkippedHolder])
- data FoldResult = FoldResult {
- foldTransaction :: ConwayTx
- foldSelected :: [PendingRequest]
- foldSkipped :: [SkippedHolder]
- foldLeft :: Int
- foldBoundary :: Maybe CapacityLimit
- data FoldFailure = FoldFailure {
- foldFailureReason :: Refusal
- foldFailureObserved :: Maybe ([SkippedHolder], Int)
- pendingTake :: PendingRequest -> Coin
- buildFold :: Session NoWitness IO -> StateScript -> Application -> RegistryIdentity -> [TxIn] -> Addr -> Maybe Word32 -> IO (Either Refusal FoldResult)
- attemptFold :: Session NoWitness IO -> StateScript -> Application -> RegistryIdentity -> [TxIn] -> Addr -> Maybe Word32 -> IO (Either FoldFailure FoldResult)
- buildRegistrationFold :: Session NoWitness IO -> StateScript -> Application -> RegistryIdentity -> [TxIn] -> Addr -> IO (Either Refusal ConwayTx)
- foldedRequests :: ConwayTx -> [(TxIn, ByteString)]
Documentation
data Registration Source #
What the fold needs to know of a pending registration, as the application publishes it in the registration's datum.
Constructors
| Registration | |
Fields
| |
Instances
| Show Registration Source # | |
Defined in Singular.State.Fold Methods showsPrec :: Int -> Registration -> ShowS Source # show :: Registration -> String Source # showList :: [Registration] -> ShowS Source # | |
| Eq Registration Source # | |
Defined in Singular.State.Fold Methods (==) :: Registration -> Registration -> Bool Source # (/=) :: Registration -> Registration -> Bool Source # | |
An application request, decoded from public data.
Constructors
| RegistrationRequest Registration | |
| TerminationRequest RegistryIdentity ByteString |
Instances
| Show Request Source # | |
Defined in Singular.State.Fold | |
| Eq Request Source # | |
Defined in Singular.State.Fold | |
requestKey :: Request -> ByteString Source #
A request being folded, with a holding output only for registration.
Constructors
| Folded | |
Fields
| |
Instances
| Show Folded Source # | |
Defined in Singular.State.Fold | |
| Eq Folded Source # | |
Defined in Singular.State.Fold | |
data Application Source #
What the application contributes to a fold.
Constructors
| Application | |
Fields
| |
data PendingRequest Source #
A request and its exact output, authenticated from public chain data.
Constructors
| PendingRequest | |
Fields
| |
Instances
| Show PendingRequest Source # | |
Defined in Singular.State.Fold Methods showsPrec :: Int -> PendingRequest -> ShowS Source # show :: PendingRequest -> String Source # showList :: [PendingRequest] -> ShowS Source # | |
| Eq PendingRequest Source # | |
Defined in Singular.State.Fold Methods (==) :: PendingRequest -> PendingRequest -> Bool Source # (/=) :: PendingRequest -> PendingRequest -> Bool Source # | |
data SkippedHolder Source #
A holder omitted from an automatic fold, with its public reference and reason.
Constructors
| SkippedHolder | |
Fields
| |
Instances
| Show SkippedHolder Source # | |
Defined in Singular.State.Fold Methods showsPrec :: Int -> SkippedHolder -> ShowS Source # show :: SkippedHolder -> String Source # showList :: [SkippedHolder] -> ShowS Source # | |
| Eq SkippedHolder Source # | |
Defined in Singular.State.Fold Methods (==) :: SkippedHolder -> SkippedHolder -> Bool Source # (/=) :: SkippedHolder -> SkippedHolder -> Bool Source # | |
data SkipReason Source #
Why an approval holder is omitted from an automatic fold.
Constructors
| HeldAtKeyAddress | |
| DecodedForAnotherRegistry | |
| NotAcceptedByApplication | |
| UnfoldableRequest Refusal |
Instances
| Show SkipReason Source # | |
Defined in Singular.State.Fold Methods showsPrec :: Int -> SkipReason -> ShowS Source # show :: SkipReason -> String Source # showList :: [SkipReason] -> ShowS Source # | |
| Eq SkipReason Source # | |
Defined in Singular.State.Fold Methods (==) :: SkipReason -> SkipReason -> Bool Source # (/=) :: SkipReason -> SkipReason -> Bool Source # | |
discoverPending :: Session NoWitness IO -> Application -> RegistryIdentity -> [ByteString] -> IO ([PendingRequest], [SkippedHolder]) Source #
Find requests using one complete policy query. The caller supplies keys from the registry's public replay; neither a wallet nor a local booking record participates. An output the application names as its configuration is in neither list. A failed read is thrown with its provider evidence intact.
data FoldResult Source #
The actual built batch and the complete discovery accounting.
Constructors
| FoldResult | |
Fields
| |
Instances
| Show FoldResult Source # | |
Defined in Singular.State.Fold Methods showsPrec :: Int -> FoldResult -> ShowS Source # show :: FoldResult -> String Source # showList :: [FoldResult] -> ShowS Source # | |
| Eq FoldResult Source # | |
Defined in Singular.State.Fold Methods (==) :: FoldResult -> FoldResult -> Bool Source # (/=) :: FoldResult -> FoldResult -> Bool Source # | |
data FoldFailure Source #
A refusal, retaining complete discovery accounting when it was observed.
Constructors
| FoldFailure | |
Fields
| |
Instances
| Show FoldFailure Source # | |
Defined in Singular.State.Fold Methods showsPrec :: Int -> FoldFailure -> ShowS Source # show :: FoldFailure -> String Source # showList :: [FoldFailure] -> ShowS Source # | |
| Eq FoldFailure Source # | |
Defined in Singular.State.Fold Methods (==) :: FoldFailure -> FoldFailure -> Bool Source # (/=) :: FoldFailure -> FoldFailure -> Bool Source # | |
pendingTake :: PendingRequest -> Coin Source #
The folder's take from the observed request, matching natural subtraction.
buildFold :: Session NoWitness IO -> StateScript -> Application -> RegistryIdentity -> [TxIn] -> Addr -> Maybe Word32 -> IO (Either Refusal FoldResult) Source #
Discover and build the greatest fitting prefix, optionally capped. A nonempty named batch is built as named, without a cap or trimming. Automatic selection first skips individually unfoldable requests, then later foldable requests for an already selected key. Capacity alone permits a shorter prefix; other construction and public-read failures retain their own identity.
attemptFold :: Session NoWitness IO -> StateScript -> Application -> RegistryIdentity -> [TxIn] -> Addr -> Maybe Word32 -> IO (Either FoldFailure FoldResult) Source #
Build with the same rules as buildFold, retaining observed holders even
when nothing is eligible or a later build refuses. Failed reads still throw.
buildRegistrationFold :: Session NoWitness IO -> StateScript -> Application -> RegistryIdentity -> [TxIn] -> Addr -> IO (Either Refusal ConwayTx) Source #
Fold named requests, or discover them from approvals when none is named. The payer funds the transaction and keeps what each registration holds above its deposit and what each termination holds in full.
foldedRequests :: ConwayTx -> [(TxIn, ByteString)] Source #
Requests named by the fold redeemer of a built transaction.