Skip to content

Commit b2c9cea

Browse files
committed
cardano-rpc | Revert: Remove PlutusData and NativeScript from UTxO RPC proto files and haskell conversion code
1 parent 26346ce commit b2c9cea

File tree

3 files changed

+11
-120
lines changed

3 files changed

+11
-120
lines changed

cardano-rpc/proto/utxorpc/v1alpha/cardano/cardano.proto

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ message TxOutput {
1111
Script script = 5; // Script associated with the output.
1212
}
1313

14+
// TODO u5c: replaced plutus_data with just bytes
1415
message Datum {
1516
bytes hash = 1; // Hash of this datum as seen on-chain
16-
PlutusData payload = 2; // Parsed Plutus data payload
1717
bytes original_cbor = 3; // Original cbor-encoded data as seen on-chain
1818
}
1919

20-
// TODO u5c: mint_coin removed
20+
// TODO u5c: mint_coin made optional
2121
// Represents a custom asset in the Cardano blockchain.
2222
message Asset {
2323
bytes name = 1; // Name of the custom asset.
2424
uint64 output_coin = 2; // Quantity of the custom asset in case of an output.
25+
optional int64 mint_coin = 3; // Quantity of the custom asset in case of a mint.
2526
}
2627

2728
// TODO u5c: redeemer was removed
@@ -31,76 +32,11 @@ message MultiAsset {
3132
repeated Asset assets = 2; // List of custom assets.
3233
}
3334

34-
// Represents a native script in Cardano.
35-
message NativeScript {
36-
oneof native_script {
37-
bytes script_pubkey = 1; // Script based on an address key hash.
38-
NativeScriptList script_all = 2; // Script that requires all nested scripts to be satisfied.
39-
NativeScriptList script_any = 3; // Script that requires any of the nested scripts to be satisfied.
40-
ScriptNOfK script_n_of_k = 4; // Script that requires k out of n nested scripts to be satisfied.
41-
uint64 invalid_before = 5; // Slot number before which the script is invalid.
42-
uint64 invalid_hereafter = 6; // Slot number after which the script is invalid.
43-
}
44-
}
45-
46-
// Represents a list of native scripts.
47-
message NativeScriptList {
48-
repeated NativeScript items = 1; // List of native scripts.
49-
}
50-
51-
// Represents a "k out of n" native script.
52-
message ScriptNOfK {
53-
uint32 k = 1; // The number of required satisfied scripts.
54-
repeated NativeScript scripts = 2; // List of native scripts.
55-
}
56-
57-
// Represents a constructor for Plutus data in Cardano.
58-
message Constr {
59-
uint32 tag = 1;
60-
uint64 any_constructor = 2;
61-
repeated PlutusData fields = 3;
62-
}
63-
64-
// Represents a big integer for Plutus data in Cardano.
65-
message BigInt {
66-
oneof big_int {
67-
int64 int = 1;
68-
bytes big_u_int = 2;
69-
bytes big_n_int = 3;
70-
}
71-
}
72-
73-
// Represents a key-value pair for Plutus data in Cardano.
74-
message PlutusDataPair {
75-
PlutusData key = 1; // Key of the pair.
76-
PlutusData value = 2; // Value of the pair.
77-
}
78-
79-
// Represents a Plutus data item in Cardano.
80-
message PlutusData {
81-
oneof plutus_data {
82-
Constr constr = 2; // Constructor.
83-
PlutusDataMap map = 3; // Map of Plutus data.
84-
BigInt big_int = 4; // Big integer.
85-
bytes bounded_bytes = 5; // Bounded bytes.
86-
PlutusDataArray array = 6; // Array of Plutus data.
87-
}
88-
}
89-
90-
// Represents a map of Plutus data in Cardano.
91-
message PlutusDataMap {
92-
repeated PlutusDataPair pairs = 1; // List of key-value pairs.
93-
}
94-
95-
// Represents an array of Plutus data in Cardano.
96-
message PlutusDataArray {
97-
repeated PlutusData items = 1; // List of Plutus data items.
98-
}
99-
10035
// Represents a script in Cardano.
36+
// TODO u5c: removed native script representation
10137
message Script {
10238
oneof script {
103-
NativeScript native = 1; // Native script.
39+
bytes native = 1; // Native script.
10440
bytes plutus_v1 = 2; // Plutus V1 script.
10541
bytes plutus_v2 = 3; // Plutus V2 script.
10642
bytes plutus_v3 = 4; // Plutus V3 script.

cardano-rpc/src/Cardano/Rpc/Proto/Api/UtxoRpc/Query.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ import Network.GRPC.Common.Protobuf
1515
import Proto.Utxorpc.V1alpha.Cardano.Cardano
1616
import Proto.Utxorpc.V1alpha.Cardano.Cardano_Fields hiding
1717
( hash
18-
, index
19-
, items
20-
, key
2118
, values
22-
, vec'items
2319
, vec'values
2420
)
2521
import Proto.Utxorpc.V1alpha.Query.Query

cardano-rpc/src/Cardano/Rpc/Server/Internal/Orphans.hs

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE FlexibleInstances #-}
22
{-# LANGUAGE GADTs #-}
3-
{-# LANGUAGE LambdaCase #-}
43
{-# LANGUAGE MultiParamTypeClasses #-}
54
{-# LANGUAGE OverloadedLabels #-}
65
{-# LANGUAGE ScopedTypeVariables #-}
@@ -10,12 +9,12 @@
109
module Cardano.Rpc.Server.Internal.Orphans () where
1110

1211
import Cardano.Api.Address
13-
import Cardano.Api.Block
1412
import Cardano.Api.Era
1513
import Cardano.Api.Error
1614
import Cardano.Api.Ledger qualified as L
1715
import Cardano.Api.Plutus
1816
import Cardano.Api.Pretty
17+
import Cardano.Api.Serialise.Cbor
1918
import Cardano.Api.Serialise.Raw
2019
import Cardano.Api.Tx
2120
import Cardano.Api.Value
@@ -66,60 +65,19 @@ instance Inject TxIn (Proto UtxoRpc.TxoRef) where
6665
& #hash .~ serialiseToRawBytes txId'
6766
& #index .~ fromIntegral txIx
6867

69-
instance Inject ScriptData (Proto UtxoRpc.PlutusData) where
70-
inject = \case
71-
ScriptDataBytes bs ->
72-
defMessage & #boundedBytes .~ bs
73-
ScriptDataNumber int ->
74-
defMessage & #bigInt . #int .~ fromIntegral int
75-
ScriptDataList sds ->
76-
defMessage & #array . #items .~ map inject sds
77-
ScriptDataMap elements -> do
78-
let pairs =
79-
elements <&> \(k, v) ->
80-
defMessage
81-
& #key .~ inject k
82-
& #value .~ inject v
83-
defMessage & #map . #pairs .~ pairs
84-
ScriptDataConstructor tag args -> do
85-
let constr =
86-
defMessage
87-
& #tag .~ fromIntegral tag
88-
& #fields .~ map inject args
89-
defMessage & #constr .~ constr
90-
9168
instance Inject (ReferenceScript era) (Proto UtxoRpc.Script) where
9269
inject ReferenceScriptNone = defMessage
9370
inject (ReferenceScript _ (ScriptInAnyLang _ script)) =
9471
case script of
95-
SimpleScript ss ->
96-
defMessage & #native .~ inject ss
72+
SimpleScript _ ->
73+
defMessage & #native .~ serialiseToCBOR script
9774
PlutusScript PlutusScriptV1 ps ->
9875
defMessage & #plutusV1 .~ serialiseToRawBytes ps
9976
PlutusScript PlutusScriptV2 ps ->
10077
defMessage & #plutusV2 .~ serialiseToRawBytes ps
10178
PlutusScript PlutusScriptV3 ps ->
10279
defMessage & #plutusV3 .~ serialiseToRawBytes ps
10380

104-
instance Inject SimpleScript (Proto UtxoRpc.NativeScript) where
105-
inject = \case
106-
RequireSignature paymentKeyHash ->
107-
defMessage & #scriptPubkey .~ serialiseToRawBytes paymentKeyHash
108-
RequireTimeBefore (SlotNo slotNo) ->
109-
defMessage & #invalidHereafter .~ slotNo
110-
RequireTimeAfter (SlotNo slotNo) ->
111-
defMessage & #invalidBefore .~ slotNo
112-
RequireAllOf scripts ->
113-
defMessage & #scriptAll . #items .~ map inject scripts
114-
RequireAnyOf scripts ->
115-
defMessage & #scriptAny . #items .~ map inject scripts
116-
RequireMOf k scripts -> do
117-
let nScriptsOf =
118-
defMessage
119-
& #k .~ fromIntegral k
120-
& #scripts .~ map inject scripts
121-
defMessage & #scriptNOfK .~ nScriptsOf
122-
12381
instance IsCardanoEra era => Inject (UTxO era) [Proto UtxoRpc.AnyUtxoData] where
12482
inject utxo =
12583
toList utxo <&> \(txIn, TxOut addressInEra txOutValue datum script) -> do
@@ -130,6 +88,9 @@ instance IsCardanoEra era => Inject (UTxO era) [Proto UtxoRpc.AnyUtxoData] where
13088
toList policyAssets <&> \(assetName, Quantity qty) -> do
13189
defMessage
13290
& #name .~ serialiseToRawBytes assetName
91+
-- we don't have access to info it the coin was minted in the transaction,
92+
-- maybe we should add it later
93+
& #maybe'mintCoin .~ Nothing
13394
& #outputCoin .~ fromIntegral qty
13495
defMessage
13596
& #policyId .~ serialiseToRawBytes pId
@@ -140,12 +101,10 @@ instance IsCardanoEra era => Inject (UTxO era) [Proto UtxoRpc.AnyUtxoData] where
140101
TxOutDatumHash _ scriptDataHash ->
141102
defMessage
142103
& #hash .~ serialiseToRawBytes scriptDataHash
143-
& #maybe'payload .~ Nothing -- we don't have it
144104
& #originalCbor .~ mempty -- we don't have it
145105
TxOutDatumInline _ hashableScriptData ->
146106
defMessage
147107
& #hash .~ serialiseToRawBytes (hashScriptDataBytes hashableScriptData)
148-
& #payload .~ inject (getScriptData hashableScriptData)
149108
& #originalCbor .~ getOriginalScriptDataBytes hashableScriptData
150109

151110
protoTxOut =

0 commit comments

Comments
 (0)