Skip to content

Commit fb9a868

Browse files
committed
Implement addition of certificates to transactions
1 parent 0ca3d5d commit fb9a868

File tree

1 file changed

+17
-0
lines changed
  • cardano-wasm/src-lib/Cardano/Wasm/Api

1 file changed

+17
-0
lines changed

cardano-wasm/src-lib/Cardano/Wasm/Api/Tx.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE FlexibleContexts #-}
44
{-# LANGUAGE InstanceSigs #-}
55
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE PolyKinds #-}
67
{-# LANGUAGE ScopedTypeVariables #-}
78
{-# LANGUAGE StandaloneDeriving #-}
89
{-# LANGUAGE TypeFamilies #-}
@@ -15,6 +16,7 @@ module Cardano.Wasm.Api.Tx
1516
, newConwayTxImpl
1617
, addTxInputImpl
1718
, addSimpleTxOutImpl
19+
, appendCertificateToTxImpl
1820
, estimateMinFeeImpl
1921
, setFeeImpl
2022
, signWithPaymentKeyImpl
@@ -125,6 +127,21 @@ addSimpleTxOutImpl (UnsignedTxObject era (Exp.UnsignedTx tx)) destAddr lovelaceA
125127
(Api.AsAddressInEra Api.asType)
126128
(Text.pack destAddrStr)
127129

130+
-- | Append a certificate (in CBOR hex string format) to an unsigned transaction object.
131+
appendCertificateToTxImpl
132+
:: (HasCallStack, MonadThrow m) => UnsignedTxObject -> String -> m UnsignedTxObject
133+
appendCertificateToTxImpl (UnsignedTxObject era (Exp.UnsignedTx tx)) certCbor = do
134+
Exp.Certificate cert <- deserialiseCertificate era certCbor
135+
let tx' = tx & Ledger.bodyTxL . Ledger.certsTxBodyL %~ (<> StrictSeq.fromList [cert])
136+
return $ UnsignedTxObject era $ Exp.UnsignedTx tx'
137+
where
138+
deserialiseCertificate
139+
:: (HasCallStack, MonadThrow m) => Exp.Era era -> String -> m (Exp.Certificate (Exp.LedgerEra era))
140+
deserialiseCertificate era' certCbor' =
141+
obtainCommonConstraints era' $
142+
rightOrError $
143+
Api.deserialiseFromCBOR Exp.AsCertificate (Text.encodeUtf8 $ Text.pack certCbor')
144+
128145
-- | Set the fee for an unsigned transaction object.
129146
setFeeImpl :: UnsignedTxObject -> Ledger.Coin -> UnsignedTxObject
130147
setFeeImpl (UnsignedTxObject era (Exp.UnsignedTx tx)) fee =

0 commit comments

Comments
 (0)