Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data TxSizeLinear = TxSizeLinear !Lovelace !Rational
- txSizeLinearMinValue ∷ TxSizeLinear → Lovelace
- calculateTxSizeLinear ∷ TxSizeLinear → Natural → Either LovelaceError Lovelace
- data TxFeePolicy = TxFeePolicyTxSizeLinear !TxSizeLinear
- data NetworkMagic
- makeNetworkMagic ∷ AProtocolMagic a → NetworkMagic
- newtype MerkleRoot a = MerkleRoot {}
- data MerkleTree a
- = MerkleEmpty
- | MerkleTree !Word32 !(MerkleNode a)
- mtRoot ∷ MerkleTree a → MerkleRoot a
- mkMerkleTree ∷ EncCBOR a ⇒ [a] → MerkleTree a
- mkMerkleTreeDecoded ∷ [Annotated a ByteString] → MerkleTree a
- data MerkleNode a
- = MerkleBranch !(MerkleRoot a) !(MerkleNode a) !(MerkleNode a)
- | MerkleLeaf !(MerkleRoot a) a
- mkBranch ∷ MerkleNode a → MerkleNode a → MerkleNode a
- mkLeaf ∷ ∀ a. EncCBOR a ⇒ a → MerkleNode a
- mkLeafDecoded ∷ Annotated a ByteString → MerkleNode a
- data LovelacePortion
- rationalToLovelacePortion ∷ Rational → LovelacePortion
- lovelacePortionToRational ∷ LovelacePortion → Rational
- data Lovelace
- data LovelaceError
- maxLovelaceVal ∷ Word64
- mkLovelace ∷ Word64 → Either LovelaceError Lovelace
- mkKnownLovelace ∷ ∀ n. (KnownNat n, n <= 45000000000000000) ⇒ Lovelace
- lovelaceF ∷ Format r (Lovelace → r)
- unsafeGetLovelace ∷ Lovelace → Word64
- lovelaceToInteger ∷ Lovelace → Integer
- integerToLovelace ∷ Integer → Either LovelaceError Lovelace
- sumLovelace ∷ (Foldable t, Functor t) ⇒ t Lovelace → Either LovelaceError Lovelace
- addLovelace ∷ Lovelace → Lovelace → Either LovelaceError Lovelace
- subLovelace ∷ Lovelace → Lovelace → Either LovelaceError Lovelace
- scaleLovelace ∷ Integral b ⇒ Lovelace → b → Either LovelaceError Lovelace
- scaleLovelaceRational ∷ Lovelace → Rational → Lovelace
- scaleLovelaceRationalUp ∷ Lovelace → Rational → Lovelace
- divLovelace ∷ Integral b ⇒ Lovelace → b → Either LovelaceError Lovelace
- modLovelace ∷ Integral b ⇒ Lovelace → b → Either LovelaceError Lovelace
- newtype KeyHash = KeyHash {}
- hashKey ∷ VerificationKey → KeyHash
- data CompactAddress
- toCompactAddress ∷ Address → CompactAddress
- fromCompactAddress ∷ CompactAddress → Address
- unsafeGetCompactAddress ∷ CompactAddress → ShortByteString
- newtype ChainDifficulty = ChainDifficulty {}
- dropChainDifficulty ∷ Dropper s
- encodeKnownCborDataItem ∷ EncCBOR a ⇒ a → Encoding
- encodeUnknownCborDataItem ∷ LByteString → Encoding
- knownCborDataItemSizeExpr ∷ Size → Size
- unknownCborDataItemSizeExpr ∷ Size → Size
- decodeKnownCborDataItem ∷ DecCBOR a ⇒ Decoder s a
- decodeUnknownCborDataItem ∷ Decoder s ByteString
- encodeCrcProtected ∷ EncCBOR a ⇒ a → Encoding
- encodedCrcProtectedSizeExpr ∷ ∀ a. EncCBOR a ⇒ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy a → Size
- decodeCrcProtected ∷ ∀ s a. DecCBOR a ⇒ Decoder s a
- newtype BlockCount = BlockCount {}
- newtype UnparsedFields = UnparsedFields (Map Word8 ByteString)
- data Attributes h = Attributes {
- attrData ∷ !h
- attrRemain ∷ !UnparsedFields
- attributesAreKnown ∷ Attributes a → Bool
- unknownAttributesLength ∷ Attributes a → Int
- encCBORAttributes ∷ ∀ t. [(Word8, t → ByteString)] → Attributes t → Encoding
- decCBORAttributes ∷ ∀ t s. t → (Word8 → ByteString → t → Decoder s (Maybe t)) → Decoder s (Attributes t)
- mkAttributes ∷ h → Attributes h
- dropAttributes ∷ Dropper s
- dropEmptyAttributes ∷ Dropper s
- type AddressHash = AbstractHash Blake2b_224
- addressHash ∷ EncCBOR a ⇒ a → AddressHash a
- unsafeAddressHash ∷ EncCBOR a ⇒ a → AddressHash b
- data Address = Address {}
- newtype Address' = Address' {}
- addressF ∷ Format r (Address → r)
- addressDetailedF ∷ Format r (Address → r)
- decCBORTextAddress ∷ Text → Either DecoderError Address
- checkAddrSpendingData ∷ AddrSpendingData → Address → Bool
- checkVerKeyAddress ∷ VerificationKey → Address → Bool
- checkRedeemAddress ∷ RedeemVerificationKey → Address → Bool
- addrToBase58 ∷ Address → ByteString
- encCBORAddr ∷ Address → Encoding
- encCBORAddrCRC32 ∷ Address → Encoding
- decodeAddressBase58 ∷ Text → Either DecoderError Address
- encodeAddressBase58 ∷ Address → Text
- addrAttributesUnwrapped ∷ Address → AddrAttributes
- addrNetworkMagic ∷ Address → NetworkMagic
- isRedeemAddress ∷ Address → Bool
- makeAddress ∷ AddrSpendingData → AddrAttributes → Address
- makeVerKeyAddress ∷ NetworkMagic → VerificationKey → Address
- makeVerKeyHdwAddress ∷ NetworkMagic → HDAddressPayload → VerificationKey → Address
- makeRedeemAddress ∷ NetworkMagic → RedeemVerificationKey → Address
- data AddrSpendingData
- data AddrType
- addrSpendingDataToType ∷ AddrSpendingData → AddrType
- data AddrAttributes = AddrAttributes {}
- newtype HDAddressPayload = HDAddressPayload {}
Documentation
data TxSizeLinear Source #
A linear equation on the transaction size. Represents the s -> a + b*s
function where s
is the transaction size in bytes, a
and b
are
constant coefficients.
Instances
data TxFeePolicy Source #
Transaction fee policy represents a formula to compute the minimal allowed Fee for a transaction. Transactions with lesser fees won't be accepted. The Minimal fee may depend on the properties of a transaction (for example, its Size in bytes), so the policy can't be represented simply as a number.
Recall that a transaction fee is the difference between the sum of its
Inputs and the sum of its outputs. The transaction is accepted when
minimal_fee(tx) <= fee(tx)
, where minimal_fee
is the function defined
By the policy.
The policy can change during the lifetime of the blockchain (using the Update mechanism). At the moment we have just one policy type (a linear Equation on the transaction size), but in the future other policies may Be added. To make this future-proof, we also have an "unknown" policy used By older node versions (the ones that haven't updated yet).
Instances
data NetworkMagic Source #
Instances
MerkleRoot
newtype MerkleRoot a Source #
Data type for root of Merkle tree
MerkleRoot | |
|
Instances
MerkleTree
data MerkleTree a Source #
Instances
mtRoot ∷ MerkleTree a → MerkleRoot a Source #
Returns root of Merkle tree
mkMerkleTree ∷ EncCBOR a ⇒ [a] → MerkleTree a Source #
Smart constructor for MerkleTree
mkMerkleTreeDecoded ∷ [Annotated a ByteString] → MerkleTree a Source #
Reconstruct a MerkleTree
from a decoded list of items
MerkleNode
data MerkleNode a Source #
MerkleBranch !(MerkleRoot a) !(MerkleNode a) !(MerkleNode a) | MerkleBranch mRoot mLeft mRight |
MerkleLeaf !(MerkleRoot a) a | MerkleLeaf mRoot mVal |
Instances
mkBranch ∷ MerkleNode a → MerkleNode a → MerkleNode a Source #
mkLeaf ∷ ∀ a. EncCBOR a ⇒ a → MerkleNode a Source #
mkLeafDecoded ∷ Annotated a ByteString → MerkleNode a Source #
data LovelacePortion Source #
LovelacePortion
is a legacy Byron type that we keep only for
compatibility. It was originally intended to represent a fraction of stake
in the system. It is used only for the thresholds used in the update system
rules, most of which are now themselves unused. The remaining case is no
longer interpreted as a fraction of all stake, but as a fraction of the
number of genesis keys.
It has enormous precision, due to the fact that it was originally intended to represent a fraction of all stake and can cover the precision of all the Lovelace in the system.
It is represented as a rational nominator with a fixed implicit denominator
of 1e15. So the nominator must be in the range [0..1e15]
. This is also the
representation used on-chain (in update proposals) and in the JSON
genesis file.
It is interpreted as a Rational
via the provided conversion functions.
Instances
rationalToLovelacePortion ∷ Rational → LovelacePortion Source #
Make a LovelacePortion
from a Rational
which must be in the range [0..1]
.
lovelacePortionToRational ∷ LovelacePortion → Rational Source #
Turn a LovelacePortion
into a Rational
in the range [0..1]
.
Lovelace
Lovelace is the least possible unit of currency
Instances
data LovelaceError Source #
LovelaceOverflow Word64 | |
LovelaceTooLarge Integer | |
LovelaceTooSmall Integer | |
LovelaceUnderflow Word64 Word64 |
Instances
maxLovelaceVal ∷ Word64 Source #
Maximal possible value of Lovelace
Constructors
mkLovelace ∷ Word64 → Either LovelaceError Lovelace Source #
Constructor for Lovelace
returning LovelaceError
when c
exceeds
maxLovelaceVal
mkKnownLovelace ∷ ∀ n. (KnownNat n, n <= 45000000000000000) ⇒ Lovelace Source #
Construct a Lovelace
from a KnownNat
, known to be less than
maxLovelaceVal
Formatting
Conversions
unsafeGetLovelace ∷ Lovelace → Word64 Source #
Unwraps Lovelace
. It's called “unsafe” so that people wouldn't use it
willy-nilly if they want to sum lovelace or something. It's actually safe.
Arithmetic operations
sumLovelace ∷ (Foldable t, Functor t) ⇒ t Lovelace → Either LovelaceError Lovelace Source #
Compute sum of all lovelace in container. Result is Integer
as a
protection against possible overflow.
addLovelace ∷ Lovelace → Lovelace → Either LovelaceError Lovelace Source #
Addition of lovelace, returning LovelaceError
in case of overflow
subLovelace ∷ Lovelace → Lovelace → Either LovelaceError Lovelace Source #
Subtraction of lovelace, returning LovelaceError
on underflow
scaleLovelace ∷ Integral b ⇒ Lovelace → b → Either LovelaceError Lovelace Source #
Scale a Lovelace
by an Integral
factor, returning LovelaceError
when
the result is too large
scaleLovelaceRational ∷ Lovelace → Rational → Lovelace Source #
Scale a Lovelace
by a rational factor, rounding down.
scaleLovelaceRationalUp ∷ Lovelace → Rational → Lovelace Source #
Scale a Lovelace
by a rational factor, rounding up.
divLovelace ∷ Integral b ⇒ Lovelace → b → Either LovelaceError Lovelace Source #
modLovelace ∷ Integral b ⇒ Lovelace → b → Either LovelaceError Lovelace Source #
A KeyHash
refers to a VerificationKey
Instances
Show KeyHash Source # | |
DecCBOR KeyHash Source # | |
EncCBOR KeyHash Source # | |
NFData KeyHash Source # | |
Defined in Cardano.Chain.Common.KeyHash | |
Buildable KeyHash Source # | |
Eq KeyHash Source # | |
Ord KeyHash Source # | |
Defined in Cardano.Chain.Common.KeyHash | |
HeapWords KeyHash Source # | |
NoThunks KeyHash Source # | |
MonadError SchemaError m ⇒ FromObjectKey m KeyHash Source # | |
Defined in Cardano.Chain.Common.KeyHash | |
Monad m ⇒ ToObjectKey m KeyHash Source # | |
Defined in Cardano.Chain.Common.KeyHash toObjectKey ∷ KeyHash → m JSString Source # |
data CompactAddress Source #
A compact in-memory representation for an Address
.
Convert using toCompactAddress
and fromCompactAddress
.
Instances
newtype ChainDifficulty Source #
Chain difficulty represents necessary effort to generate a chain. In the simplest case it can be number of blocks in chain.
Instances
CBOR in CBOR
These utilities are is used in the Byron-era chain encodings in cases where there are extensible parts of the encoding. In thse cases we have to be able to handle unknown extensions and thus decode values where we do not know the concrete type.
To solve this, the serialised representation uses nested CBOR-in-CBOR https://tools.ietf.org/html/rfc7049#section-2.4.4.1. The nesting means that the size is known without having to decode the body in those cases where we cannot decode the body.
The functions in this module handle the encoding and decoding for the cases of the known and unknown types.
encodeKnownCborDataItem ∷ EncCBOR a ⇒ a → Encoding Source #
This is an alias for encodeNestedCbor
.
This function is used to handle the case of a known type, but compatible
with the encoding used by encodeUnknownCborDataItem
.
encodeUnknownCborDataItem ∷ LByteString → Encoding Source #
This is an alias for encodeNestedCborBytes
, so all its details apply.
This function is used to handle the case of an unknown type, so it takes an opaque blob that is the representation of the value of the unknown type.
decodeKnownCborDataItem ∷ DecCBOR a ⇒ Decoder s a Source #
This is an alias for decodeNestedCbor
.
This function is used to handle the case of a known type, but compatible
with the encoding used by decodeUnknownCborDataItem
.
decodeUnknownCborDataItem ∷ Decoder s ByteString Source #
This is an alias for decodeNestedCborBytes
, so all its details apply.
This function is used to handle the case of an unknown type, so it returns an opaque blob that is the representation of the value of the unknown type.
Cyclic redundancy check
The Byron era address format includes a CRC to help resist accidental corruption. These functions deal with encoding and decoding the format that is used.
encodeCrcProtected ∷ EncCBOR a ⇒ a → Encoding Source #
Encodes a value of type a
, protecting it from accidental corruption by
protecting it with a CRC.
encodedCrcProtectedSizeExpr ∷ ∀ a. EncCBOR a ⇒ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy a → Size Source #
decodeCrcProtected ∷ ∀ s a. DecCBOR a ⇒ Decoder s a Source #
Decodes a CBOR blob into a value of type a
, checking the serialised CRC
corresponds to the computed one
newtype BlockCount Source #
Instances
newtype UnparsedFields Source #
Representation of unparsed fields in Attributes. Newtype wrapper is used for clear backward compatibility between previous representation (which was just a single ByteString) during transition from Store to CBOR.
Instances
data Attributes h Source #
Convenient wrapper for the datatype to represent it (in binary format) as k-v map
Attributes | |
|
Instances
attributesAreKnown ∷ Attributes a → Bool Source #
Check whether all data from Attributes
is known, i. e. was successfully
parsed into some structured data
encCBORAttributes ∷ ∀ t. [(Word8, t → ByteString)] → Attributes t → Encoding Source #
decCBORAttributes ∷ ∀ t s. t → (Word8 → ByteString → t → Decoder s (Maybe t)) → Decoder s (Attributes t) Source #
mkAttributes ∷ h → Attributes h Source #
dropAttributes ∷ Dropper s Source #
dropEmptyAttributes ∷ Dropper s Source #
Drop `Attributes ()` making sure that the UnparsedFields
are empty
type AddressHash = AbstractHash Blake2b_224 Source #
Hash used to identify address.
addressHash ∷ EncCBOR a ⇒ a → AddressHash a Source #
unsafeAddressHash ∷ EncCBOR a ⇒ a → AddressHash b Source #
Address
is where you can send Lovelace
Address | |
|
Instances
Hash of this data is stored in Address
. This type exists mostly
for internal usage.
Instances
Generic Address' Source # | |
Show Address' Source # | |
FromCBOR Address' Source # | |
ToCBOR Address' Source # | |
DecCBOR Address' Source # | |
EncCBOR Address' Source # | |
Eq Address' Source # | |
type Rep Address' Source # | |
Defined in Cardano.Chain.Common.Address type Rep Address' = D1 ('MetaData "Address'" "Cardano.Chain.Common.Address" "cardano-ledger-byron-1.0.2.0-inplace" 'True) (C1 ('MetaCons "Address'" 'PrefixI 'True) (S1 ('MetaSel ('Just "unAddress'") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (AddrType, AddrSpendingData, Attributes AddrAttributes)))) |
Formatting
decCBORTextAddress ∷ Text → Either DecoderError Address Source #
Deprecated: Use decodeAddressBase58 instead
A function which decodes base58-encoded Address
Spending data checks
checkAddrSpendingData ∷ AddrSpendingData → Address → Bool Source #
Check whether given AddrSpendingData
corresponds to given Address
checkVerKeyAddress ∷ VerificationKey → Address → Bool Source #
Check if given Address
is created from given VerificationKey
checkRedeemAddress ∷ RedeemVerificationKey → Address → Bool Source #
Check if given Address
is created from given RedeemVerificationKey
Encoding/Decoding
decodeAddressBase58 ∷ Text → Either DecoderError Address Source #
Decode an address from Base58 encoded Text.
encodeAddressBase58 ∷ Address → Text Source #
Encode an address to Text. `decodeAddressBase58 (encodeAddressBase58 x) === Right x`
Utilities
addrAttributesUnwrapped ∷ Address → AddrAttributes Source #
Get AddrAttributes
from Address
addrNetworkMagic ∷ Address → NetworkMagic Source #
Get NetworkMagic
from Address
Pattern-matching helpers
Construction
makeAddress ∷ AddrSpendingData → AddrAttributes → Address Source #
Make an Address
from spending data and attributes.
makeVerKeyAddress ∷ NetworkMagic → VerificationKey → Address Source #
A function for making an address from VerificationKey
∷ NetworkMagic | |
→ HDAddressPayload | Derivation path |
→ VerificationKey | |
→ Address |
A function for making an HDW address
makeRedeemAddress ∷ NetworkMagic → RedeemVerificationKey → Address Source #
A function for making an address from RedeemVerificationKey
data AddrSpendingData Source #
Data which is bound to an address and must be revealed in order to spend lovelace belonging to this address.
VerKeyASD !VerificationKey | Funds can be spent by revealing a |
RedeemASD !RedeemVerificationKey | Funds can be spent by revealing a |
Instances
Type of an address. It corresponds to constructors of AddrSpendingData
.
It's separated, because Address
doesn't store AddrSpendingData
, but we
want to know its type.
Instances
addrSpendingDataToType ∷ AddrSpendingData → AddrType Source #
Convert AddrSpendingData
to the corresponding AddrType
data AddrAttributes Source #
Additional information stored along with address. It's intended
to be put into Attributes
data type to make it extensible with
softfork.
Instances
newtype HDAddressPayload Source #
HDAddressPayload is a specific address attribute that was used by the Cardano wallet at mainnet launch, prior to moving to a BIP-44 style scheme.
It consisted of
- serialized and encrypted using HDPassphrase derivation path from the root key to given descendant key (using ChaChaPoly1305 algorithm)
- cryptographic tag
It is still distinguished as an attribute, but not used by the ledger, because the attributes size limits treat this attribute specially.