diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs index c2f65d92891..458d62dbe8c 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs @@ -122,6 +122,9 @@ module Internal.Cardano.Write.Tx , datumHashFromBytes , datumHashToBytes + -- ** Rewards + , RewardAccount + -- ** Script , Script , Alonzo.isPlutusScript @@ -557,6 +560,7 @@ type TxOutInBabbage = Babbage.BabbageTxOut (Babbage.BabbageEra StandardCrypto) type Address = Ledger.Addr StandardCrypto +type RewardAccount = Ledger.RewardAcnt StandardCrypto type Script = AlonzoScript type Value = MaryValue StandardCrypto diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Redeemers.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Redeemers.hs index a5b0bf7306e..4bb16c11ac3 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Redeemers.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Redeemers.hs @@ -22,9 +22,6 @@ module Internal.Cardano.Write.Tx.Redeemers import Prelude -import Cardano.Crypto.Hash.Class - ( Hash - ) import Cardano.Ledger.Alonzo.TxInfo ( TranslationError ) @@ -35,12 +32,8 @@ import Cardano.Ledger.Api , scriptIntegrityHashTxBodyL , witsTxL ) -import Cardano.Ledger.Mary.Value - ( PolicyID (..) - ) import Cardano.Ledger.Shelley.API - ( ScriptHash (..) - , StrictMaybe (..) + ( StrictMaybe (..) ) import Cardano.Slotting.EpochInfo ( EpochInfo @@ -86,9 +79,6 @@ import Data.Map.Strict ( Map , (!) ) -import Data.Maybe - ( fromMaybe - ) import Fmt ( Buildable (..) ) @@ -97,10 +87,13 @@ import GHC.Generics ) import Internal.Cardano.Write.Tx ( PParams + , PolicyId , RecentEra , RecentEraLedgerConstraints + , RewardAccount , ShelleyLedgerEra , StandardCrypto + , TxIn , UTxO , txBody , withConstraints @@ -111,19 +104,13 @@ import Internal.Cardano.Write.Tx.TimeTranslation , systemStartTime ) -import qualified Cardano.Api as CardanoApi import qualified Cardano.Api.Shelley as CardanoApi -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 Cardano.Wallet.Shelley.Compatibility.Ledger as Convert import qualified Data.ByteString.Lazy as BL import qualified Data.Map as Map import qualified Data.Map.Merge.Strict as Map @@ -273,19 +260,19 @@ assignScriptRedeemers era pparams timeTranslation utxo redeemers tx = -- data Redeemer - = RedeemerSpending ByteString W.TxIn - | RedeemerMinting ByteString W.TokenPolicyId - | RedeemerRewarding ByteString CardanoApi.StakeAddress + = RedeemerSpending ByteString TxIn + | RedeemerMinting ByteString PolicyId + | RedeemerRewarding ByteString RewardAccount deriving (Eq, Generic, Show) instance Buildable Redeemer where build = \case RedeemerSpending _ input -> - "spending(" <> build input <> ")" + "spending(" <> build (show input) <> ")" RedeemerMinting _ pid -> - "minting(" <> build pid <> ")" - RedeemerRewarding _ addr -> - "rewarding(" <> build (CardanoApi.serialiseToBech32 addr) <> ")" + "minting(" <> build (show pid) <> ")" + RedeemerRewarding _ acc -> + "rewarding(" <> build (show acc) <> ")" redeemerData :: Redeemer -> ByteString redeemerData = \case @@ -296,20 +283,11 @@ redeemerData = \case toScriptPurpose :: Redeemer -> Alonzo.ScriptPurpose StandardCrypto toScriptPurpose = \case RedeemerSpending _ txin -> - Alonzo.Spending (Convert.toLedger txin) + Alonzo.Spending txin RedeemerMinting _ pid -> - Alonzo.Minting (toPolicyID pid) - RedeemerRewarding _ (CardanoApi.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 + Alonzo.Minting pid + RedeemerRewarding _ acc -> + Alonzo.Rewarding acc -------------------------------------------------------------------------------- -- Utils diff --git a/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs index 9b78ed28eeb..9d95165dd15 100644 --- a/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs +++ b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs @@ -160,10 +160,16 @@ import Cardano.Api , toNetworkMagic , unNetworkMagic ) +import Cardano.Api.Shelley + ( StakeAddress (..) + ) import Cardano.BM.Tracing ( HasPrivacyAnnotation (..) , HasSeverityAnnotation (..) ) +import Cardano.Ledger.Address + ( RewardAcnt (..) + ) import Cardano.Mnemonic ( SomeMnemonic ) @@ -4936,11 +4942,11 @@ fromExternalInput ApiExternalInput fromApiRedeemer :: ApiRedeemer n -> Redeemer fromApiRedeemer = \case ApiRedeemerSpending (ApiBytesT bytes) (ApiT i) -> - RedeemerSpending bytes i + RedeemerSpending bytes (toLedger i) ApiRedeemerMinting (ApiBytesT bytes) (ApiT p) -> - RedeemerMinting bytes p - ApiRedeemerRewarding (ApiBytesT bytes) r -> - RedeemerRewarding bytes r + RedeemerMinting bytes (toLedger p) + ApiRedeemerRewarding (ApiBytesT bytes) (StakeAddress x y) -> + RedeemerRewarding bytes (RewardAcnt x y) {------------------------------------------------------------------------------- Api Layer diff --git a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs index edded7e3514..1ccac8e242b 100644 --- a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs +++ b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs @@ -742,7 +742,9 @@ spec_balanceTransaction = describe "balanceTransaction" $ do -- With ix 1 instead of 0, making it point to an input which -- doesn't exist in the tx. let faultyRedeemer = - RedeemerSpending (unsafeFromHex "D87A80") (W.TxIn tid 1) + RedeemerSpending + (unsafeFromHex "D87A80") + (Convert.toLedger (W.TxIn tid 1)) let withFaultyRedeemer = over #redeemers $ mapFirst $ const faultyRedeemer @@ -2487,7 +2489,9 @@ pingPong_2 = PartialTx ) ] , redeemers = - [ RedeemerSpending (unsafeFromHex "D87A80") (W.TxIn (W.Hash tid) 0) + [ RedeemerSpending + (unsafeFromHex "D87A80") + (Convert.toLedger (W.TxIn (W.Hash tid) 0)) ] } where