singular-registry
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Singular.Registry.StateToken

Description

A registry is its state token and the release that made it. Everything a command needs — the seed, the state output and its datum, the pinned configuration, and the hashes of the six scripts the registry runs — is derived from those two and checked against the chain, refused by name when the chain disagrees with the release. Nothing is read from disk.

Reference outputs are a convenience found by hash: any live output whose reference script hashes to an expected hash serves, whoever made it. The hash is computed here from the output's own script; a hash a provider states is never read.

Synopsis

The release

data Release Source #

The compiled code a registry command needs from the blueprint.

Constructors

Release 

Fields

The state token

parseStateToken :: Text -> Either Text Asset Source #

A state token as the command line spells it, POLICY.NAME, each part in hex: a 28-byte policy and a 32-byte name. Any other shape is refused before any provider is asked.

renderStateToken :: Asset -> Text Source #

The POLICY.NAME spelling of a state token.

Reference roles and the hashes they must carry

data ReferenceRole Source #

The six scripts a registry runs, by the role their reference plays.

Instances

Instances details
Bounded ReferenceRole Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

minBound :: ReferenceRole Source #

maxBound :: ReferenceRole Source #

Enum ReferenceRole Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

succ :: ReferenceRole -> ReferenceRole Source #

pred :: ReferenceRole -> ReferenceRole Source #

toEnum :: Int -> ReferenceRole Source #

fromEnum :: ReferenceRole -> Int Source #

enumFrom :: ReferenceRole -> [ReferenceRole] Source #

enumFromThen :: ReferenceRole -> ReferenceRole -> [ReferenceRole] Source #

enumFromTo :: ReferenceRole -> ReferenceRole -> [ReferenceRole] Source #

enumFromThenTo :: ReferenceRole -> ReferenceRole -> ReferenceRole -> [ReferenceRole] Source #

Show ReferenceRole Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

showsPrec :: Int -> ReferenceRole -> ShowS Source #

show :: ReferenceRole -> String Source #

showList :: [ReferenceRole] -> ShowS Source #

Eq ReferenceRole Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

(==) :: ReferenceRole -> ReferenceRole -> Bool Source #

(/=) :: ReferenceRole -> ReferenceRole -> Bool Source #

Ord ReferenceRole Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

compare :: ReferenceRole -> ReferenceRole -> Ordering Source #

(<) :: ReferenceRole -> ReferenceRole -> Bool Source #

(<=) :: ReferenceRole -> ReferenceRole -> Bool Source #

(>) :: ReferenceRole -> ReferenceRole -> Bool Source #

(>=) :: ReferenceRole -> ReferenceRole -> Bool Source #

max :: ReferenceRole -> ReferenceRole -> ReferenceRole Source #

min :: ReferenceRole -> ReferenceRole -> ReferenceRole Source #

roleName :: ReferenceRole -> Text Source #

A role as receipts spell it.

parseRole :: Text -> Maybe ReferenceRole Source #

A role from its receipt spelling.

expectedReferences :: ApplicationPin -> Release -> Asset -> Map ReferenceRole ScriptHash Source #

The script hash each role must carry, derived from the release, the application pin and the token alone. The state hash is the release's state script; every other role is the release's script for it applied to the registry identity, state policy then token name. A pin read from state arrives as PinByHash of the datum's pin: resolveRegistry reads the datum first. A hash pin publishes no application reference (slice 2: its script bytes do not exist), so it omits that role; a script or compiled pin lists it as today.

Resolving a token into a registry

data ResolvedRegistry Source #

A registry exists only once every identity check has passed.

Constructors

ResolvedRegistry 

Fields

data PinField Source #

The datum policy a registry pins, in the order they are compared.

Instances

Instances details
Bounded PinField Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

minBound :: PinField Source #

maxBound :: PinField Source #

Enum PinField Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

succ :: PinField -> PinField Source #

pred :: PinField -> PinField Source #

toEnum :: Int -> PinField Source #

fromEnum :: PinField -> Int Source #

enumFrom :: PinField -> [PinField] Source #

enumFromThen :: PinField -> PinField -> [PinField] Source #

enumFromTo :: PinField -> PinField -> [PinField] Source #

enumFromThenTo :: PinField -> PinField -> PinField -> [PinField] Source #

Show PinField Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

showsPrec :: Int -> PinField -> ShowS Source #

show :: PinField -> String Source #

showList :: [PinField] -> ShowS Source #

Eq PinField Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

(==) :: PinField -> PinField -> Bool Source #

(/=) :: PinField -> PinField -> Bool Source #

Ord PinField Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

compare :: PinField -> PinField -> Ordering Source #

(<) :: PinField -> PinField -> Bool Source #

(<=) :: PinField -> PinField -> Bool Source #

(>) :: PinField -> PinField -> Bool Source #

(>=) :: PinField -> PinField -> Bool Source #

max :: PinField -> PinField -> PinField Source #

min :: PinField -> PinField -> PinField Source #

data IdentityRefusal Source #

Why a state token is not a registry of this release, in checking order.

Constructors

StateTokenForeignRelease ScriptHash

The token's policy is not this release's state script

StateTokenNotFound

The provider has no record of the asset

StateTokenBurned Integer

The supply is not one: the supply found

StateTokenSeedMismatch TxId

The minting transaction spends no seed of the token's name

StateOutputMissing

No output holds the token at the state address with a state datum

RegistryPinMismatch PinField

A datum pin differs from the hash the release and token derive

NetworkMismatch Network

The provider's network is not the release's

IdentityUnreadable ReadFailure

The provider could not be read; no identity fact was decided

Instances

Instances details
Show IdentityRefusal Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

showsPrec :: Int -> IdentityRefusal -> ShowS Source #

show :: IdentityRefusal -> String Source #

showList :: [IdentityRefusal] -> ShowS Source #

Eq IdentityRefusal Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

(==) :: IdentityRefusal -> IdentityRefusal -> Bool Source #

(/=) :: IdentityRefusal -> IdentityRefusal -> Bool Source #

resolveRegistry :: Monad m => Application -> Release -> Asset -> Session w m -> m (Either IdentityRefusal ResolvedRegistry) Source #

Resolve a state token into a registry, refusing by name in the checking order. No file is read. The application pin is compared with the state datum only for a script pin; a pin read from state is taken from the datum, and the three witness pins are compared as always.

findStateOutput :: Monad m => Asset -> Session w m -> m (Either IdentityRefusal (TxIn, TxOut ConwayEra, OnChainTokenState)) Source #

The output that holds the token at the state address of the token's policy, with its state datum. The provider's answer to who holds the token is unverified: each listed output is admitted only if its own value holds the token. A command reads the state again through this after it has resolved the registry, since every transition moves the state output.

renderIdentityRefusal :: IdentityRefusal -> Text Source #

The refusal's name, then what it found.

References found by hash

data ReferenceRefusal Source #

Why a command cannot run the scripts it needs.

Constructors

ReferenceMissing ReferenceRole ScriptHash

No source found a carrier of this role's hash

ReferenceUnreadable ReadFailure

A source could not be read

Instances

Instances details
Show ReferenceRefusal Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

showsPrec :: Int -> ReferenceRefusal -> ShowS Source #

show :: ReferenceRefusal -> String Source #

showList :: [ReferenceRefusal] -> ShowS Source #

Eq ReferenceRefusal Source # 
Instance details

Defined in Singular.Registry.StateToken

Methods

(==) :: ReferenceRefusal -> ReferenceRefusal -> Bool Source #

(/=) :: ReferenceRefusal -> ReferenceRefusal -> Bool Source #

carriesReference :: ScriptHash -> TxOut ConwayEra -> Bool Source #

Whether the output carries a reference script whose hash, computed here from the script itself, is the expected one.

findReferences Source #

Arguments

:: Monad m 
=> Session w m 
-> Maybe Addr

The actor's wallet, when the command has one

-> Map ReferenceRole ScriptHash 
-> Set ReferenceRole

The roles the command's transaction runs

-> m (Either ReferenceRefusal (Map ReferenceRole (TxIn, TxOut ConwayEra))) 

Find a carrier for each needed role: from the provider's existence query, then the actor's wallet, read only when the provider carries none of some role. A carrier is admitted only by carriesReference; among the admitted carriers of the first source that has any, the lowest output reference is chosen. A command that runs no reference script reads nothing.

renderReferenceRefusal :: ReferenceRefusal -> Text Source #

The refusal, with the remedy.