-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
71 changes: 67 additions & 4 deletions
71
cardano-api/internal/Cardano/Api/Experimental/UnsignedTx.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,76 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
|
||
module Cardano.Api.Experimental.UnsignedTx where | ||
|
||
import Cardano.Api.Eras | ||
import Cardano.Api.Experimental.Eras | ||
import Cardano.Api.ReexposeLedger (strictMaybeToMaybe) | ||
import Cardano.Api.Tx.Body | ||
|
||
import qualified Cardano.Ledger.Core as Ledger | ||
|
||
import Data.Bifunctor | ||
|
||
|
||
|
||
-- A transaction that contains everything | ||
-- except signing key witnesses | ||
data UnsignedTx era | ||
= UnsignedTx | ||
(Ledger.Tx (ToConstrainedEra era)) | ||
(Ledger.TxWits (ToConstrainedEra era)) | ||
newtype UnsignedTx era | ||
= UnsignedTx (Ledger.Tx (ToConstrainedEra era)) | ||
|
||
|
||
data UnsignedTxError | ||
= UnsignedTxError TxBodyError | ||
Check notice Code scanning / HLint Use newtype instead of data Note
cardano-api/internal/Cardano/Api/Experimental/UnsignedTx.hs:(23,1)-(24,31): Suggestion: Use newtype instead of data
Found: data UnsignedTxError = UnsignedTxError TxBodyError Perhaps: newtype UnsignedTxError = UnsignedTxError TxBodyError Note: decreases laziness |
||
|
||
makeUnsignedTx | ||
:: Era era | ||
-> TxBodyContent BuildTx (AvailableErasToSbe era) | ||
-> Either UnsignedTxError (UnsignedTx era) | ||
makeUnsignedTx era bc = do | ||
sbe <- maybe (Left $ error "") Right $ protocolVersionToSbe era | ||
|
||
-- Construct tx body | ||
let apiTxOuts = txOuts bc | ||
apiScriptWitnesses = collectTxBodyScriptWitnesses sbe bc | ||
apiScriptValidity = txScriptValidity bc | ||
apiMintValue = txMintValue bc | ||
apiProtocolParameters = txProtocolParams bc | ||
apiCollateralTxIns = txInsCollateral bc | ||
apiReferenceInputs = txInsReference bc | ||
apiExtraKeyWitnesses = txExtraKeyWits bc | ||
apiReturnCollateral = txReturnCollateral bc | ||
apiTotalCollateral = txTotalCollateral bc | ||
|
||
-- Ledger types | ||
collTxIns = convCollateralTxIns apiCollateralTxIns | ||
refTxIns = convReferenceInputs apiReferenceInputs | ||
returnCollateral = convReturnCollateral sbe apiReturnCollateral | ||
totalCollateral = convTotalCollateral apiTotalCollateral | ||
certs = convCertificates sbe $ txCertificates bc | ||
txAuxData = toAuxiliaryData sbe (txMetadata bc) (txAuxScripts bc) | ||
scripts = convScripts apiScriptWitnesses | ||
languages = convLanguages apiScriptWitnesses | ||
sData = convScriptData sbe apiTxOuts apiScriptWitnesses | ||
|
||
setUpdateProposal <- first UnsignedTxError $ convTxUpdateProposal sbe (txUpdateProposal bc) | ||
|
||
setInvalidBefore <- maybe (Left $ error "TODO") Right $ convValidityLowerBound (txValidityLowerBound bc) | ||
|
||
let setMint = convMintValue apiMintValue | ||
|
||
setScriptIntegrityHash <- maybe (Left $ error "TODO") Right $ strictMaybeToMaybe $ getScriptIntegrityHash apiProtocolParameters languages sData | ||
|
||
let setReqSignerHashes = convExtraKeyWitnesses apiExtraKeyWitnesses | ||
|
||
let ledgerTxBody = | ||
mkCommonTxBody sbe (txIns bc) (txOuts bc) (txFee bc) (txWithdrawals bc) txAuxData | ||
& A.certsTxBodyL sbe .~ certs | ||
& A.invalidHereAfterTxBodyL sbe .~ convValidityUpperBound sbe (txValidityUpperBound bc) | ||
|
||
-- TODO: Left off here | ||
undefined | ||
-- Construct script witnesses | ||
|
||
-- TODO: Left off here. Fill out this function and also | ||
-- create a function for signing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters