@@ -57,19 +57,17 @@ module Cardano.Wallet.Primitive.Ledger.Convert
57
57
58
58
import Prelude
59
59
60
- import Cardano.Address.Script
60
+ import Cardano.Address.KeyHash
61
61
( KeyHash (.. )
62
62
, KeyRole (.. )
63
- , Script (.. )
63
+ )
64
+ import Cardano.Address.Script
65
+ ( Script (.. )
64
66
)
65
67
import Cardano.Crypto.Hash
66
68
( hashFromBytes
67
69
, hashToBytes
68
70
)
69
- import Cardano.Ledger.Api
70
- ( Babbage
71
- , Conway
72
- )
73
71
import Cardano.Slotting.Slot
74
72
( SlotNo (.. )
75
73
)
@@ -147,9 +145,8 @@ import Numeric.Natural
147
145
( Natural
148
146
)
149
147
import Ouroboros.Consensus.Shelley.Eras
150
- ( StandardBabbage
151
- , StandardConway
152
- , StandardCrypto
148
+ ( BabbageEra
149
+ , ConwayEra
153
150
)
154
151
155
152
import qualified Cardano.Crypto.Hash.Class as Crypto
@@ -165,7 +162,7 @@ import qualified Cardano.Ledger.DRep as Ledger
165
162
import qualified Cardano.Ledger.Keys as Ledger
166
163
import qualified Cardano.Ledger.Mary.Value as Ledger
167
164
import qualified Cardano.Ledger.Plutus.Language as Ledger
168
- import qualified Cardano.Ledger.SafeHash as SafeHash
165
+ import qualified Cardano.Ledger.Hashes as Hashes
169
166
import qualified Cardano.Ledger.Shelley.API as Ledger
170
167
import qualified Cardano.Ledger.Shelley.Scripts as Scripts
171
168
import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
@@ -217,16 +214,16 @@ toWalletCoin (Ledger.Coin c) = Coin.unsafeFromIntegral c
217
214
-- that is similar to the wallet's 'TokenBundle' type. The ada quantity is
218
215
-- stored as a separate value, and asset quantities are stored in a nested map.
219
216
220
- instance Convert TokenBundle ( Ledger. MaryValue StandardCrypto ) where
217
+ instance Convert TokenBundle Ledger. MaryValue where
221
218
toLedger = toLedgerTokenBundle
222
219
toWallet = toWalletTokenBundle
223
220
224
- toLedgerTokenBundle :: TokenBundle -> Ledger. MaryValue StandardCrypto
221
+ toLedgerTokenBundle :: TokenBundle -> Ledger. MaryValue
225
222
toLedgerTokenBundle bundle =
226
223
Ledger. MaryValue ledgerAda ledgerTokens
227
224
where
228
225
ledgerAda = toLedgerCoin $ TokenBundle. getCoin bundle
229
- ledgerTokens :: Ledger. MultiAsset StandardCrypto
226
+ ledgerTokens :: Ledger. MultiAsset
230
227
ledgerTokens = bundle
231
228
& view # tokens
232
229
& TokenMap. toNestedMap
@@ -237,7 +234,7 @@ toLedgerTokenBundle bundle =
237
234
& Map. mapKeys toLedgerAssetName
238
235
& Map. map toLedgerTokenQuantity
239
236
240
- toWalletTokenBundle :: Ledger. MaryValue StandardCrypto -> TokenBundle
237
+ toWalletTokenBundle :: Ledger. MaryValue -> TokenBundle
241
238
toWalletTokenBundle
242
239
(Ledger. MaryValue ledgerAda (Ledger. MultiAsset ledgerTokens)) =
243
240
TokenBundle. fromNestedMap (walletAda, walletTokens)
@@ -270,11 +267,11 @@ toWalletAssetName (Ledger.AssetName bytes) =
270
267
-- Conversions for 'TokenPolicyId'
271
268
--------------------------------------------------------------------------------
272
269
273
- instance Convert TokenPolicyId ( Ledger. PolicyID StandardCrypto ) where
270
+ instance Convert TokenPolicyId Ledger. PolicyID where
274
271
toLedger = toLedgerTokenPolicyId
275
272
toWallet = toWalletTokenPolicyId
276
273
277
- toLedgerTokenPolicyId :: TokenPolicyId -> Ledger. PolicyID StandardCrypto
274
+ toLedgerTokenPolicyId :: TokenPolicyId -> Ledger. PolicyID
278
275
toLedgerTokenPolicyId p@ (UnsafeTokenPolicyId (Hash bytes)) =
279
276
case hashFromBytes bytes of
280
277
Just hash ->
@@ -286,7 +283,7 @@ toLedgerTokenPolicyId p@(UnsafeTokenPolicyId (Hash bytes)) =
286
283
, pretty p
287
284
]
288
285
289
- toWalletTokenPolicyId :: Ledger. PolicyID StandardCrypto -> TokenPolicyId
286
+ toWalletTokenPolicyId :: Ledger. PolicyID -> TokenPolicyId
290
287
toWalletTokenPolicyId (Ledger. PolicyID (Ledger. ScriptHash hash)) =
291
288
UnsafeTokenPolicyId (Hash (hashToBytes hash))
292
289
@@ -316,20 +313,20 @@ toWalletTokenQuantity q
316
313
-- Conversions for 'TxIn'
317
314
--------------------------------------------------------------------------------
318
315
319
- instance Convert TxIn ( Ledger. TxIn StandardCrypto ) where
316
+ instance Convert TxIn Ledger. TxIn where
320
317
toLedger (TxIn tid ix) =
321
318
Ledger. TxIn (toLedgerHash tid) (toEnum $ intCast ix)
322
319
where
323
320
toLedgerHash (Hash h) =
324
321
Ledger. TxId
325
- $ SafeHash . unsafeMakeSafeHash
322
+ $ Hashes . unsafeMakeSafeHash
326
323
$ Crypto. UnsafeHash
327
324
$ toShort h
328
325
329
326
toWallet (Ledger. TxIn (Ledger. TxId tid) ix) =
330
327
TxIn (convertId tid) (convertIx ix)
331
328
where
332
- convertId = Hash . Crypto. hashToBytes . SafeHash . extractHash
329
+ convertId = Hash . Crypto. hashToBytes . Hashes . extractHash
333
330
334
331
convertIx = fromMaybe err . intCastMaybe . fromEnum
335
332
where
@@ -343,19 +340,19 @@ instance Convert TxIn (Ledger.TxIn StandardCrypto) where
343
340
-- Conversions for 'Address'
344
341
--------------------------------------------------------------------------------
345
342
346
- instance Convert Address ( Ledger. Addr StandardCrypto ) where
343
+ instance Convert Address Ledger. Addr where
347
344
toLedger = toLedgerAddress
348
345
toWallet = toWalletAddress
349
346
350
- toLedgerAddress :: Address -> Ledger. Addr StandardCrypto
347
+ toLedgerAddress :: Address -> Ledger. Addr
351
348
toLedgerAddress (Address bytes) = case Ledger. decodeAddrLenient bytes of
352
349
Just addr -> addr
353
350
Nothing -> error $ unwords
354
351
[ " toLedger @Address: Invalid address:"
355
352
, pretty (Address bytes)
356
353
]
357
354
358
- toWalletAddress :: Ledger. Addr StandardCrypto -> Address
355
+ toWalletAddress :: Ledger. Addr -> Address
359
356
toWalletAddress = Address . Ledger. serialiseAddr
360
357
361
358
--------------------------------------------------------------------------------
@@ -364,7 +361,7 @@ toWalletAddress = Address . Ledger.serialiseAddr
364
361
365
362
toBabbageTxOut
366
363
:: TxOut
367
- -> Babbage. BabbageTxOut StandardBabbage
364
+ -> Babbage. BabbageTxOut BabbageEra
368
365
toBabbageTxOut (TxOut addr bundle) =
369
366
Babbage. BabbageTxOut
370
367
(toLedger addr)
@@ -374,7 +371,7 @@ toBabbageTxOut (TxOut addr bundle) =
374
371
375
372
toConwayTxOut
376
373
:: TxOut
377
- -> Babbage. BabbageTxOut StandardConway
374
+ -> Babbage. BabbageTxOut ConwayEra
378
375
toConwayTxOut (TxOut addr bundle) =
379
376
Babbage. BabbageTxOut
380
377
(toLedger addr)
@@ -384,14 +381,14 @@ toConwayTxOut (TxOut addr bundle) =
384
381
385
382
-- NOTE: Inline scripts and datums will be lost in the conversion.
386
383
fromConwayTxOut
387
- :: Babbage. BabbageTxOut StandardConway
384
+ :: Babbage. BabbageTxOut ConwayEra
388
385
-> TxOut
389
386
fromConwayTxOut (Babbage. BabbageTxOut addr val _ _)
390
387
= TxOut (toWallet addr) (toWallet val)
391
388
392
389
-- NOTE: Inline scripts and datums will be lost in the conversion.
393
390
fromBabbageTxOut
394
- :: Babbage. BabbageTxOut StandardBabbage
391
+ :: Babbage. BabbageTxOut BabbageEra
395
392
-> TxOut
396
393
fromBabbageTxOut (Babbage. BabbageTxOut addr val _ _)
397
394
= TxOut (toWallet addr) (toWallet val)
@@ -400,22 +397,22 @@ fromBabbageTxOut (Babbage.BabbageTxOut addr val _ _)
400
397
-- Conversions for 'UTxO'
401
398
--------------------------------------------------------------------------------
402
399
403
- toLedgerUTxOBabbage :: UTxO -> Ledger. UTxO Babbage
400
+ toLedgerUTxOBabbage :: UTxO -> Ledger. UTxO BabbageEra
404
401
toLedgerUTxOBabbage (UTxO m) = Ledger. UTxO
405
402
$ Map. mapKeys toLedger
406
403
$ Map. map toBabbageTxOut m
407
404
408
- toLedgerUTxOConway :: UTxO -> Ledger. UTxO Conway
405
+ toLedgerUTxOConway :: UTxO -> Ledger. UTxO ConwayEra
409
406
toLedgerUTxOConway (UTxO m) = Ledger. UTxO
410
407
$ Map. mapKeys toLedger
411
408
$ Map. map toConwayTxOut m
412
409
413
- toWalletUTxOBabbage :: Ledger. UTxO Babbage -> UTxO
410
+ toWalletUTxOBabbage :: Ledger. UTxO BabbageEra -> UTxO
414
411
toWalletUTxOBabbage (Ledger. UTxO m) = UTxO
415
412
$ Map. mapKeys toWallet
416
413
$ Map. map fromBabbageTxOut m
417
414
418
- toWalletUTxOConway :: Ledger. UTxO Conway -> UTxO
415
+ toWalletUTxOConway :: Ledger. UTxO ConwayEra -> UTxO
419
416
toWalletUTxOConway (Ledger. UTxO m) = UTxO
420
417
$ Map. mapKeys toWallet
421
418
$ Map. map fromConwayTxOut m
@@ -516,7 +513,7 @@ toLedgerTimelockScript s = case s of
516
513
toLedgerDelegatee
517
514
:: Maybe PoolId
518
515
-> Maybe DRep
519
- -> Conway. Delegatee StandardCrypto
516
+ -> Conway. Delegatee
520
517
toLedgerDelegatee poolM vaM = case (poolM, vaM) of
521
518
(Just poolId, Nothing ) ->
522
519
Conway. DelegStake (toKeyHash poolId)
@@ -534,7 +531,7 @@ toLedgerDelegatee poolM vaM = case (poolM, vaM) of
534
531
toKeyHash (PoolId pid) = Ledger. KeyHash . Crypto. UnsafeHash $ toShort pid
535
532
536
533
toLedgerDRep
537
- :: DRep -> Ledger. DRep StandardCrypto
534
+ :: DRep -> Ledger. DRep
538
535
toLedgerDRep = \ case
539
536
Abstain -> Ledger. DRepAlwaysAbstain
540
537
NoConfidence -> Ledger. DRepAlwaysNoConfidence
0 commit comments