cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cometa.Transaction.Body

Description

Transaction bodies with typed semantic fields and exact imported identity. Construct a minimal body, update its typed fields, then retain EncodedBody for hashing or signing. Reassembling semantic fields deliberately produces a fresh encoding and can change a transaction identifier.

minimal = body [] [] 0
Synopsis

Documentation

data Body Source #

Semantic transaction-body data. Equality includes field presence, list order, and exact encodings of embedded hash-bearing data. It does not compare the imported containing-body encoding. No ledger-state validation is implied.

Constructors

Body 

Fields

Instances

Instances details
Show Body Source # 
Instance details

Defined in Cometa.Transaction.Body

Methods

showsPrec :: Int -> Body -> ShowS #

show :: Body -> String #

showList :: [Body] -> ShowS #

Eq Body Source # 
Instance details

Defined in Cometa.Transaction.Body

Methods

(==) :: Body -> Body -> Bool #

(/=) :: Body -> Body -> Bool #

body :: [Input] -> [Output] -> Word64 -> Body Source #

Assemble required references, ordered outputs and fee with optional fields absent. Empty input/output lists are representable but may fail ledger rules.

fee :: Body -> Word64 Source #

Fee measured in lovelace.

setFee :: Word64 -> Body -> Body Source #

Set a fee in lovelace. Other semantic fields remain independent. Construct a fresh EncodedBody before signing this edited body.

setFeeEncoded :: Word64 -> EncodedBody -> EncodedBody Source #

Edit only a validated body's fee, retaining exact nested field bytes. An unchanged fee returns the exact original body. A changed fee uses a fresh definite outer map in numeric key order; other fields keep their original encodings, including imported historical empty collections. The input snapshot remains independent. Any signatures over the previous identifier need renewal.

encodeCbor :: Body -> Either Error ByteString Source #

Encode a fresh definite map in numeric field order, using shortest numbers and tag 258 on sets. Present empty or duplicate guards return InvalidTransactionField. Embedded inline data and subtransactions retain exact identity. Importing an existing signed body should use toCbor instead.

encodeCborWith :: SetEncoding -> Body -> Either Error ByteString Source #

Encode fresh body fields with the requested set tags. Embedded values keep their own encoding choices. Protocol validity is the caller's responsibility.

data SetField Source #

Set-valued fields in this body schema. Outputs and maps are not sets.

Constructors

Inputs

Spending inputs.

Certificates

Stake and governance certificates.

Guards

Required signer or guard credentials.

ReferenceInputs

Reference inputs.

Proposals

Governance proposals.

CollateralInputs

Collateral inputs.

SubTransactions

Included subtransactions; their internal encodings are unchanged.

setEncoding :: SetField -> EncodedBody -> Maybe SetEncoding Source #

Observe one field's set tag. An absent optional field returns Nothing.

inputsAreTagged :: EncodedBody -> Bool Source #

Whether the encoded spending-input collection carries set tag 258. Other tagged collections do not affect this result; an absent input field returns False. This observes the exact body snapshot without re-encoding.

withSetEncoding :: SetField -> SetEncoding -> EncodedBody -> EncodedBody Source #

Change one present field's set tag. Absence and an unchanged tag preserve the exact original body. A change rebuilds the outer map in numeric key order, retaining all other field bytes and the selected array's contents. It can change the body hash: signatures over the previous body must be renewed.

data EncodedBody Source #

Exact transaction-body bytes paired with semantic data. Equality compares bytes, so alternative integer widths, tags and map order remain distinguishable.

Instances

Instances details
Show EncodedBody Source # 
Instance details

Defined in Cometa.Transaction.Body

Eq EncodedBody Source # 
Instance details

Defined in Cometa.Transaction.Body

decodeCbor :: ByteString -> Either Error EncodedBody Source #

Decode all pinned native body fields, including typed Dijkstra fields 23-27. Unknown keys, repeated keys, missing inputsoutputsfee, malformed nested data, and trailing bytes return a structured error. Definite and indefinite maps, nonminimal numbers and optional set tags retain their original byte identity.

fromBody :: Body -> Either Error EncodedBody Source #

Validate fresh assembly and pair semantic data with its encoding. Present empty guards or repeated guard credentials return InvalidTransactionField.

toBody :: EncodedBody -> Body Source #

Inspect semantic fields without changing the original body bytes.

toCbor :: EncodedBody -> ByteString Source #

Exact imported or freshly encoded ledger transaction-body bytes.

hash :: EncodedBody -> IO (Either Error TransactionId) Source #

Hash the exact body bytes with native BLAKE2b-256. This operation does not normalize or rebuild the body. Native failures remain NativeError.