-
Notifications
You must be signed in to change notification settings - Fork 7
/
Shelley.hs
118 lines (101 loc) · 2.5 KB
/
Shelley.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_HADDOCK prune #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} -- needed for {#- HLINT ... #-}
module Data.UTxO.Transaction.Cardano.Shelley
(
-- * Initialization
mkInit
, mainnetMagic
, testnetMagic
, Network (..)
-- * Constructing Primitives
, mkInput
-- Internal
, Shelley
) where
import Cardano.Api.Typed
( TxIn (..), TxOut (..) )
import Cardano.Crypto.Hash.Class
( Hash (UnsafeHash) )
import Data.ByteString
( ByteString )
import Data.ByteString.Short
( toShort )
import Data.UTxO.Transaction
( MkPayment (..) )
import Data.Word
( Word32 )
import Shelley.Spec.Ledger.BaseTypes
( Network (..) )
import qualified Cardano.Api.Typed as Cardano
import qualified Data.ByteString as BS
-- | Construct a payment 'Init' for /Shelley/ from primitive types.
--
-- __examples__:
--
-- >>> mkInit Mainnet == mainnetMagic
-- True
--
-- >>> mkInit Testnet == testnetMagic
-- True
--
-- @since 2.0.0
mkInit
:: Network
-- ^ A network tag
-> Init Shelley
mkInit net = net
-- | Pre-defined 'Init' magic for /Shelley/ MainNet.
--
-- @since 2.0.0
mainnetMagic :: Init Shelley
mainnetMagic = mkInit Mainnet
-- | Pre-defined 'Init' magic for /Shelley/ TestNet.
--
-- @since 2.0.0
testnetMagic :: Init Shelley
testnetMagic = mkInit Testnet
--
-- MkPayment instance
--
-- Type-level constructor capturing types for 'Shelley'.
data Shelley
instance MkPayment Shelley where
type Init Shelley = Network
type Input Shelley = TxIn
type Output Shelley = TxOut Cardano.Shelley
type SignKey Shelley = ()
type CoinSel Shelley =
(Network, [TxIn], [TxOut Cardano.Shelley])
type Tx Shelley = ()
empty = undefined
addInput = undefined
addOutput = undefined
lock = undefined
signWith = undefined
serialize = undefined
-- | Construct a payment 'Input' for /Shelley/ from primitive types.
--
-- __example__:
--
-- >>> mkInput 14 =<< fromBase16 "3b402651...aad1c0b7"
-- Just (Input ...)
--
-- @since 2.0.0
mkInput
:: Word32
-- ^ Input index.
-> ByteString
-- ^ Input transaction id. See also: 'fromBase16'.
-> Maybe (Input Shelley)
mkInput ix bytes =
if BS.length bytes == 32 then
Just $ Cardano.TxIn
(Cardano.TxId $ UnsafeHash $ toShort bytes)
(Cardano.TxIx (fromIntegral ix))
else
Nothing