/
Transaction.purs
179 lines (142 loc) · 5 KB
/
Transaction.purs
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
module Types.Transaction where
import Prelude
import Data.BigInt as BigInt
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\), type (/\))
import Data.Map (Map(..))
import Data.Generic.Rep (class Generic)
import Data.Show.Generic (genericShow)
newtype Transaction = Transaction {
body :: TxBody,
witness_set :: TransactionWitnessSet,
is_valid :: Boolean,
auxiliary_data :: Maybe AuxiliaryData
}
newtype TxBody = TxBody
{ inputs :: Array TransactionInput,
outputs :: Array TransactionOutput,
fee :: Coin,
ttl :: Maybe Slot,
certs :: Maybe Unit, -- Certificates,
withdrawals :: Maybe Unit, -- Withdrawals,
update :: Maybe Unit, -- Update,
auxiliary_data_hash :: Maybe String, -- AuxiliaryDataHash, - script hashes
validity_start_interval :: Maybe Slot,
mint :: Maybe Value, -- Mint
script_data_hash :: Maybe String, -- ScriptDataHash,
collateral :: Maybe (Array TransactionInput),
required_signers :: Maybe (Array RequiredSigner),
network_id :: Maybe NetworkId
}
newtype TransactionWitnessSet = TransactionWitnessSet
{ vkeys :: Maybe (Array Vkeywitness),
native_scripts :: Maybe Unit, -- NativeScripts,
bootstraps :: Maybe Unit, -- BootstrapWitnesses,
plutus_scripts :: Maybe (Array PlutusScript),
plutus_data :: Maybe (Array PlutusData),
redeemers :: Maybe (Array Redeemer)
}
newtype NetworkId = NetworkId Int
newtype RequiredSigner = RequiredSigner String
newtype CurrencySymbol = CurrencySymbol String
derive instance genericCurrencySymbol :: Generic CurrencySymbol _
instance showCurrencySymbol :: Show CurrencySymbol where
show = genericShow
newtype TokenName = TokenName String
derive instance genericTokenName :: Generic TokenName _
instance showTokenName :: Show TokenName where
show = genericShow
newtype Value = Value (Map CurrencySymbol (Map TokenName BigInt.BigInt))
derive instance genericValue :: Generic Value _
instance showValue :: Show Value where
show = genericShow
newtype Vkeywitness = Vkeywitness (Vkey /\ Ed25519Signature)
newtype Vkey = Vkey String -- (bech32)
newtype Ed25519Signature = Ed25519Signature String -- (bech32)
newtype PlutusScript = PlutusScript String
newtype PlutusData = PlutusData String
-- TODO - we need a capability to encode/decode Datum from/to serialized format
-- see `makeIsDataIndexed`
newtype Redeemer = Redeemer
{ tag :: RedeemerTag, -- ScriptPurpose: 'spending' 'minting' etc
index :: BigInt.BigInt,
data :: PlutusData,
ex_units :: (MemExUnits /\ CpuExUnits)
}
newtype MemExUnits = MemExUnits BigInt.BigInt
newtype CpuExUnits = CpuExUnits BigInt.BigInt
data RedeemerTag = Spend | Mint | Cert | Reward
type AuxiliaryData = Unit -- this is big and weird in serialization-lib
newtype TransactionInput = TransactionInput
{ transaction_id :: String, -- TransactionHash
index :: BigInt.BigInt -- u32 TransactionIndex
}
newtype TransactionOutput = TransactionOutput
{ address :: Address,
amount :: Value,
data_hash :: Maybe String -- DataHash>,
}
newtype Coin = Coin BigInt.BigInt
newtype Slot = Slot BigInt.BigInt
newtype Address = Address
{ "AddrType" :: BaseAddress
}
newtype BaseAddress = BaseAddress
{ network :: Int, -- u8,
stake :: Credential,
payment :: Credential
}
newtype Credential = Credential String
newtype TransactionUnspentOutput = TransactionUnspentOutput
{ input :: TransactionInput
, output :: TransactionOutput
}
-- Addresspub struct Address(AddrType);
-- AddrType
-- enum AddrType {
-- Base(BaseAddress),
-- Ptr(PointerAddress),
-- Enterprise(EnterpriseAddress),
-- Reward(RewardAddress),
-- Byron(ByronAddress),
-- }
-- pub struct BaseAddress {
-- network: u8,
-- payment: StakeCredential,
-- stake: StakeCredential,
-- }
-- pub struct StakeCredential(StakeCredType);
-- Both of these are strings:
-- enum StakeCredType {
-- Key(Ed25519KeyHash),
-- Script(ScriptHash),
-- }
-- Option<Certificates>,
-- these are the constructors, but this will generally be an Empty Option in our initial efforts
-- StakeRegistration(StakeRegistration),
-- StakeDeregistration(StakeDeregistration),
-- StakeDelegation(StakeDelegation),
-- PoolRegistration(PoolRegistration),
-- PoolRetirement(PoolRetirement),
-- GenesisKeyDelegation(GenesisKeyDelegation),
-- MoveInstantaneousRewardsCert(MoveInstantaneousRewardsCert),
-- Option<Withdrawals>,
-- also mainly empty to start
-- pub struct RewardAddress {
-- network: u8,
-- payment: StakeCredential,
-- Option<Update>,
-- again this will be empty
-- pub struct Update {
-- proposed_protocol_parameter_updates: ProposedProtocolParameterUpdates,
-- epoch: Epoch,
-- }
-- Option<AuxiliaryDataHash> -- String
-- Option<Slot> -- Intege
-- Option<Mint> -- BTreeMap PolicyId MintAssets
-- MintAssets :: BTreeMap AssetName Int32
-- Option<ScriptDataHash> -- String
-- Option<TransactionInputs> -- for collateral
-- Option<RequiredSigners> -- Array String (Ed25519 signatures)
-- Option<NetworkId>
-- { networkIdKind :: Testnet | Mainnet }