|
12 | 12 | module Cardano.Rpc.Server.Internal.Orphans () where |
13 | 13 |
|
14 | 14 | import Cardano.Api.Address |
| 15 | +import Cardano.Api.Block (SlotNo (..)) |
15 | 16 | import Cardano.Api.Era |
16 | 17 | import Cardano.Api.Error |
17 | 18 | import Cardano.Api.Ledger qualified as L |
@@ -79,15 +80,34 @@ instance Inject (ReferenceScript era) (Proto UtxoRpc.Script) where |
79 | 80 | inject ReferenceScriptNone = defMessage |
80 | 81 | inject (ReferenceScript _ (ScriptInAnyLang _ script)) = |
81 | 82 | case script of |
82 | | - SimpleScript _ -> |
83 | | - defMessage & #native .~ serialiseToCBOR script |
| 83 | + SimpleScript ss -> |
| 84 | + defMessage & #native .~ inject ss |
84 | 85 | PlutusScript PlutusScriptV1 ps -> |
85 | 86 | defMessage & #plutusV1 .~ serialiseToRawBytes ps |
86 | 87 | PlutusScript PlutusScriptV2 ps -> |
87 | 88 | defMessage & #plutusV2 .~ serialiseToRawBytes ps |
88 | 89 | PlutusScript PlutusScriptV3 ps -> |
89 | 90 | defMessage & #plutusV3 .~ serialiseToRawBytes ps |
90 | 91 |
|
| 92 | +instance Inject SimpleScript (Proto UtxoRpc.NativeScript) where |
| 93 | + inject = \case |
| 94 | + RequireSignature paymentKeyHash -> |
| 95 | + defMessage & #scriptPubkey .~ serialiseToRawBytes paymentKeyHash |
| 96 | + RequireTimeBefore (SlotNo slotNo) -> |
| 97 | + defMessage & #invalidHereafter .~ slotNo |
| 98 | + RequireTimeAfter (SlotNo slotNo) -> |
| 99 | + defMessage & #invalidBefore .~ slotNo |
| 100 | + RequireAllOf scripts -> |
| 101 | + defMessage & #scriptAll . #items .~ map inject scripts |
| 102 | + RequireAnyOf scripts -> |
| 103 | + defMessage & #scriptAny . #items .~ map inject scripts |
| 104 | + RequireMOf k scripts -> do |
| 105 | + let nScriptsOf = |
| 106 | + defMessage |
| 107 | + & #k .~ fromIntegral k |
| 108 | + & #scripts .~ map inject scripts |
| 109 | + defMessage & #scriptNOfK .~ nScriptsOf |
| 110 | + |
91 | 111 | instance Inject ScriptData (Proto UtxoRpc.PlutusData) where |
92 | 112 | inject = \case |
93 | 113 | ScriptDataBytes bs -> |
@@ -120,7 +140,7 @@ instance IsCardanoEra era => Inject (UTxO era) [Proto UtxoRpc.AnyUtxoData] where |
120 | 140 | toList policyAssets <&> \(assetName, Quantity qty) -> do |
121 | 141 | defMessage |
122 | 142 | & #name .~ serialiseToRawBytes assetName |
123 | | - -- we don't have access to info it the coin was minted in the transaction, |
| 143 | + -- we don't have access to info if the coin was minted in the transaction, |
124 | 144 | -- maybe we should add it later |
125 | 145 | & #maybe'mintCoin .~ Nothing |
126 | 146 | & #outputCoin .~ fromIntegral qty |
|
0 commit comments