Skip to content

Commit

Permalink
Add redeemer pointer map to ShelleyTxBody
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 authored and newhoggy committed May 27, 2021
1 parent 48a3c5b commit aab18d4
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 47 deletions.
5 changes: 3 additions & 2 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Cardano.Api.ProtocolParameters (
toShelleyUpdate,
toLedgerPParams,
fromShelleyPParams,
toShelleyPParams,
fromShelleyPParamsUpdate,
fromShelleyProposedPPUpdates,
fromShelleyUpdate,
Expand Down Expand Up @@ -914,7 +915,7 @@ toShelleyPParams pparams =
{ Shelley._protocolVersion = let (maj, minor) = protocolParamProtocolVersion pparams
in Shelley.ProtVer maj minor
, Shelley._d = Shelley.unitIntervalFromRational $ protocolParamDecentralization pparams
, Shelley._extraEntropy = toShelleyNonce $ protocolParamExtraPraosEntropy pparams
, Shelley._extraEntropy = toShelleyNonce $ protocolParamExtraPraosEntropy pparams
, Shelley._maxBHSize = protocolParamMaxBlockHeaderSize pparams
, Shelley._maxBBSize = protocolParamMaxBlockBodySize pparams
, Shelley._maxTxSize = protocolParamMaxTxSize pparams
Expand All @@ -937,7 +938,7 @@ toAlonzoPParams pparams =
{ Alonzo._protocolVersion = let (maj, minor) = protocolParamProtocolVersion pparams
in Alonzo.ProtVer maj minor
, Alonzo._d = Shelley.unitIntervalFromRational $ protocolParamDecentralization pparams
, Alonzo._extraEntropy = toShelleyNonce $ protocolParamExtraPraosEntropy pparams
, Alonzo._extraEntropy = toShelleyNonce $ protocolParamExtraPraosEntropy pparams
, Alonzo._maxBHSize = protocolParamMaxBlockHeaderSize pparams
, Alonzo._maxBBSize = protocolParamMaxBlockBodySize pparams
, Alonzo._maxTxSize = protocolParamMaxTxSize pparams
Expand Down
25 changes: 14 additions & 11 deletions cardano-api/src/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS

import Data.Functor.Identity (Identity)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Vector as Vector
Expand Down Expand Up @@ -96,6 +97,8 @@ import qualified Shelley.Spec.Ledger.Keys as Shelley
import qualified Shelley.Spec.Ledger.Tx as Shelley

import qualified Cardano.Ledger.Alonzo as Alonzo
import qualified Cardano.Ledger.Alonzo.Data as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.TxWitness as Alonzo

import Cardano.Api.Address
Expand Down Expand Up @@ -431,6 +434,7 @@ getTxBody (ShelleyTx era tx) =
ShelleyTxBody era txbody
(Map.elems msigWits)
(strictMaybeToMaybe txAuxiliaryData)
mempty

getAlonzoTxBody :: forall ledgerera.
ShelleyLedgerEra era ~ ledgerera
Expand All @@ -445,15 +449,13 @@ getTxBody (ShelleyTx era tx) =
_bootWits
txscripts
_txdats
_txrdmrs,
(Alonzo.Redeemers rdmrPtrMap),
Shelley.auxiliaryData = auxiliaryData
} =
ShelleyTxBody era txbody
(Map.elems txscripts)
(strictMaybeToMaybe auxiliaryData)
--TODO: we will probably want to put the Alonzo data and
-- redeemer in the tx body here, and so that will use
-- the _txdats and _txrdmrs above.
rdmrPtrMap

getTxWitnesses :: forall era. Tx era -> [KeyWitness era]
getTxWitnesses (ByronTx Byron.ATxAux { Byron.aTaWitness = witnesses }) =
Expand Down Expand Up @@ -516,12 +518,12 @@ makeSignedTransaction witnesses (ByronTxBody txbody) =
(unAnnotated txbody)
(Vector.fromList [ w | ByronKeyWitness w <- witnesses ])

makeSignedTransaction witnesses (ShelleyTxBody era txbody txscripts txmetadata) =
makeSignedTransaction witnesses (ShelleyTxBody era txbody txscripts txmetadata rdmrMap) =
case era of
ShelleyBasedEraShelley -> makeShelleySignedTransaction txbody
ShelleyBasedEraAllegra -> makeShelleySignedTransaction txbody
ShelleyBasedEraMary -> makeShelleySignedTransaction txbody
ShelleyBasedEraAlonzo -> makeAlonzoSignedTransaction txbody
ShelleyBasedEraAlonzo -> makeAlonzoSignedTransaction txbody rdmrMap
where
makeShelleySignedTransaction
:: forall ledgerera.
Expand Down Expand Up @@ -553,8 +555,9 @@ makeSignedTransaction witnesses (ShelleyTxBody era txbody txscripts txmetadata)
=> Shelley.ShelleyBased ledgerera
=> Shelley.ValidateScript ledgerera
=> Ledger.TxBody ledgerera
-> Map Alonzo.RdmrPtr (Alonzo.Data (ShelleyLedgerEra era), Alonzo.ExUnits)
-> Tx era
makeAlonzoSignedTransaction txbody' =
makeAlonzoSignedTransaction txbody' redeemers =
ShelleyTx era $
Shelley.Tx
txbody'
Expand All @@ -564,7 +567,7 @@ makeSignedTransaction witnesses (ShelleyTxBody era txbody txscripts txmetadata)
(Map.fromList [ (Ledger.hashScript @ledgerera sw, sw)
| sw <- txscripts ])
(error "TODO alonzo: makeAlonzoSignedTransaction: datums")
(error "TODO alonzo: makeAlonzoSignedTransaction: redeemers"))
(Alonzo.Redeemers redeemers))
(maybeToStrictMaybe txmetadata)


Expand All @@ -574,7 +577,7 @@ makeByronKeyWitness :: forall key.
-> TxBody ByronEra
-> SigningKey key
-> KeyWitness ByronEra
makeByronKeyWitness _ (ShelleyTxBody era _ _ _) = case era of {}
makeByronKeyWitness _ (ShelleyTxBody era _ _ _ _) = case era of {}
makeByronKeyWitness nw (ByronTxBody txbody) =
let txhash :: Byron.Hash Byron.Tx
txhash = Byron.hashDecoded txbody
Expand Down Expand Up @@ -625,7 +628,7 @@ makeShelleyBootstrapWitness :: forall era.
makeShelleyBootstrapWitness _ ByronTxBody{} _ =
case shelleyBasedEra :: ShelleyBasedEra era of {}

makeShelleyBootstrapWitness nwOrAddr (ShelleyTxBody era txbody _ _) sk =
makeShelleyBootstrapWitness nwOrAddr (ShelleyTxBody era txbody _ _ _) sk =
case era of
ShelleyBasedEraShelley ->
makeShelleyBasedBootstrapWitness era nwOrAddr txbody sk
Expand Down Expand Up @@ -738,7 +741,7 @@ makeShelleyKeyWitness :: forall era
=> TxBody era
-> ShelleyWitnessSigningKey
-> KeyWitness era
makeShelleyKeyWitness (ShelleyTxBody era txbody _ _) =
makeShelleyKeyWitness (ShelleyTxBody era txbody _ _ _) =
case era of
ShelleyBasedEraShelley -> makeShelleyBasedKeyWitness txbody
ShelleyBasedEraAllegra -> makeShelleyBasedKeyWitness txbody
Expand Down
Loading

0 comments on commit aab18d4

Please sign in to comment.