-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Redeemer
type to Write.Tx.Redeemers
module
#4047
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
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,6 +1,8 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TupleSections #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
@@ -15,22 +17,29 @@ | |
module Cardano.Wallet.Write.Tx.Redeemers | ||
( assignScriptRedeemers | ||
, ErrAssignRedeemers (..) | ||
, Redeemer (..) | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Api | ||
( StakeAddress, serialiseToBech32 ) | ||
import Cardano.Crypto.Hash.Class | ||
( Hash ) | ||
import Cardano.Ledger.Alonzo.TxInfo | ||
( TranslationError ) | ||
import Cardano.Ledger.Api | ||
( Tx, bodyTxL, rdmrsTxWitsL, scriptIntegrityHashTxBodyL, witsTxL ) | ||
import Cardano.Ledger.Mary.Value | ||
( PolicyID (..) ) | ||
import Cardano.Ledger.Shelley.API | ||
( StrictMaybe (..) ) | ||
( ScriptHash (..), StrictMaybe (..) ) | ||
import Cardano.Slotting.EpochInfo | ||
( EpochInfo, hoistEpochInfo ) | ||
import Cardano.Wallet.Primitive.Types.Redeemer | ||
( Redeemer, redeemerData ) | ||
import Cardano.Wallet.Shelley.Compatibility | ||
( toScriptPurpose ) | ||
import Cardano.Wallet.Primitive.Types.TokenPolicy | ||
( TokenPolicyId ) | ||
import Cardano.Wallet.Shelley.Compatibility.Ledger | ||
( Convert (..) ) | ||
import Cardano.Wallet.Write.Tx | ||
( IsRecentEra (recentEra) | ||
, PParams | ||
|
@@ -59,6 +68,8 @@ import Control.Monad.Trans.State.Strict | |
( StateT (..), execStateT, get, modify', put ) | ||
import Data.Bifunctor | ||
( bimap ) | ||
import Data.ByteString | ||
( ByteString ) | ||
import Data.Function | ||
( (&) ) | ||
import Data.Generics.Internal.VL.Lens | ||
|
@@ -67,17 +78,25 @@ import Data.Generics.Labels | |
() | ||
import Data.Map.Strict | ||
( Map, (!) ) | ||
import Data.Maybe | ||
( fromMaybe ) | ||
import Fmt | ||
( Buildable (..) ) | ||
import GHC.Generics | ||
( Generic ) | ||
|
||
import qualified Cardano.Api as Cardano | ||
import qualified Cardano.Api.Shelley as Cardano | ||
import qualified Cardano.Crypto.Hash as Crypto | ||
import qualified Cardano.Ledger.Alonzo.PlutusScriptApi as Alonzo | ||
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo | ||
import qualified Cardano.Ledger.Alonzo.Scripts.Data as Alonzo | ||
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo | ||
import qualified Cardano.Ledger.Alonzo.TxWits as Alonzo | ||
import qualified Cardano.Ledger.Api as Ledger | ||
import qualified Cardano.Wallet.Primitive.Types.Hash as W | ||
import qualified Cardano.Wallet.Primitive.Types.TokenPolicy as W | ||
import qualified Cardano.Wallet.Primitive.Types.Tx.TxIn as W | ||
import qualified Data.ByteString.Lazy as BL | ||
import qualified Data.Map as Map | ||
import qualified Data.Map.Merge.Strict as Map | ||
|
@@ -223,6 +242,50 @@ assignScriptRedeemers pparams timeTranslation utxo redeemers tx = | |
, Just l <- [Alonzo.language script] | ||
] | ||
|
||
-- | ||
-- The 'Redeemer' type | ||
-- TODO: Move back to the wallet and/or retire | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👆 We should (probably) work with the redeemers a part of the partial tx CBOR instead. In that case we'd need to add logic for updating the tx without invalidating the existing ix-based pointers. |
||
-- | ||
|
||
data Redeemer | ||
= RedeemerSpending ByteString W.TxIn | ||
| RedeemerMinting ByteString TokenPolicyId | ||
| RedeemerRewarding ByteString StakeAddress | ||
deriving (Eq, Generic, Show) | ||
|
||
instance Buildable Redeemer where | ||
build = \case | ||
RedeemerSpending _ input -> | ||
"spending(" <> build input <> ")" | ||
RedeemerMinting _ pid -> | ||
"minting(" <> build pid <> ")" | ||
RedeemerRewarding _ addr -> | ||
"rewarding(" <> build (serialiseToBech32 addr) <> ")" | ||
|
||
redeemerData :: Redeemer -> ByteString | ||
redeemerData = \case | ||
RedeemerSpending bytes _ -> bytes | ||
RedeemerMinting bytes _ -> bytes | ||
RedeemerRewarding bytes _ -> bytes | ||
|
||
toScriptPurpose :: Redeemer -> Alonzo.ScriptPurpose StandardCrypto | ||
toScriptPurpose = \case | ||
RedeemerSpending _ txin -> | ||
Alonzo.Spending (toLedger txin) | ||
RedeemerMinting _ pid -> | ||
Alonzo.Minting (toPolicyID pid) | ||
RedeemerRewarding _ (Cardano.StakeAddress ntwrk acct) -> | ||
Alonzo.Rewarding (Ledger.RewardAcnt ntwrk acct) | ||
|
||
toPolicyID :: W.TokenPolicyId -> PolicyID StandardCrypto | ||
toPolicyID (W.UnsafeTokenPolicyId (W.Hash bytes)) = | ||
PolicyID (ScriptHash (unsafeHashFromBytes bytes)) | ||
where | ||
unsafeHashFromBytes :: Crypto.HashAlgorithm h => ByteString -> Hash h a | ||
unsafeHashFromBytes = | ||
fromMaybe (error "unsafeHashFromBytes: wrong length") | ||
. Crypto.hashFromBytes | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Utils | ||
-------------------------------------------------------------------------------- | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have the
cardano-api
importsqualified as Cardano
instead.