Skip to content

Commit fe7afe3

Browse files
committed
cardano-rpc | Add decoded PlutusData to Datum in proto definition
1 parent f857964 commit fe7afe3

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ message AddressArray {
1616
repeated bytes items = 1;
1717
}
1818

19-
// TODO u5c: replaced plutus_data with just bytes
2019
message Datum {
2120
bytes hash = 1; // Hash of this datum as seen on-chain
21+
PlutusData payload = 2; // Parsed Plutus data payload
2222
bytes original_cbor = 3; // Original cbor-encoded data as seen on-chain
2323
}
2424

@@ -37,6 +37,51 @@ message MultiAsset {
3737
repeated Asset assets = 2; // List of custom assets.
3838
}
3939

40+
// Represents a constructor for Plutus data in Cardano.
41+
message Constr {
42+
uint32 tag = 1;
43+
uint64 any_constructor = 2;
44+
repeated PlutusData fields = 3;
45+
}
46+
47+
// Represents a big integer for Plutus data in Cardano.
48+
message BigInt {
49+
oneof big_int {
50+
int64 int = 1;
51+
bytes big_u_int = 2;
52+
bytes big_n_int = 3;
53+
}
54+
}
55+
56+
57+
// Represents a key-value pair for Plutus data in Cardano.
58+
message PlutusDataPair {
59+
PlutusData key = 1; // Key of the pair.
60+
PlutusData value = 2; // Value of the pair.
61+
}
62+
63+
// Represents a Plutus data item in Cardano.
64+
message PlutusData {
65+
oneof plutus_data {
66+
Constr constr = 2; // Constructor.
67+
PlutusDataMap map = 3; // Map of Plutus data.
68+
BigInt big_int = 4; // Big integer.
69+
bytes bounded_bytes = 5; // Bounded bytes.
70+
PlutusDataArray array = 6; // Array of Plutus data.
71+
}
72+
}
73+
74+
// Represents a map of Plutus data in Cardano.
75+
message PlutusDataMap {
76+
repeated PlutusDataPair pairs = 1; // List of key-value pairs.
77+
}
78+
79+
// Represents an array of Plutus data in Cardano.
80+
message PlutusDataArray {
81+
repeated PlutusData items = 1; // List of Plutus data items.
82+
}
83+
84+
4085
// Represents a script in Cardano.
4186
// TODO u5c: removed native script representation
4287
message Script {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE FlexibleInstances #-}
22
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE MultiParamTypeClasses #-}
45
{-# LANGUAGE OverloadedLabels #-}
56
{-# LANGUAGE OverloadedLists #-}
@@ -87,6 +88,28 @@ instance Inject (ReferenceScript era) (Proto UtxoRpc.Script) where
8788
PlutusScript PlutusScriptV3 ps ->
8889
defMessage & #plutusV3 .~ serialiseToRawBytes ps
8990

91+
instance Inject ScriptData (Proto UtxoRpc.PlutusData) where
92+
inject = \case
93+
ScriptDataBytes bs ->
94+
defMessage & #boundedBytes .~ bs
95+
ScriptDataNumber int ->
96+
defMessage & #bigInt . #int .~ fromIntegral int
97+
ScriptDataList sds ->
98+
defMessage & #array . #items .~ map inject sds
99+
ScriptDataMap elements -> do
100+
let pairs =
101+
elements <&> \(k, v) ->
102+
defMessage
103+
& #key .~ inject k
104+
& #value .~ inject v
105+
defMessage & #map . #pairs .~ pairs
106+
ScriptDataConstructor tag args -> do
107+
let constr =
108+
defMessage
109+
& #tag .~ fromIntegral tag
110+
& #fields .~ map inject args
111+
defMessage & #constr .~ constr
112+
90113
instance IsCardanoEra era => Inject (UTxO era) [Proto UtxoRpc.AnyUtxoData] where
91114
inject utxo =
92115
toList utxo <&> \(txIn, TxOut addressInEra txOutValue datum script) -> do
@@ -110,10 +133,12 @@ instance IsCardanoEra era => Inject (UTxO era) [Proto UtxoRpc.AnyUtxoData] where
110133
TxOutDatumHash _ scriptDataHash ->
111134
defMessage
112135
& #hash .~ serialiseToRawBytes scriptDataHash
136+
& #maybe'payload .~ Nothing -- we don't have it
113137
& #originalCbor .~ mempty -- we don't have it
114138
TxOutDatumInline _ hashableScriptData ->
115139
defMessage
116140
& #hash .~ serialiseToRawBytes (hashScriptDataBytes hashableScriptData)
141+
& #payload .~ inject (getScriptData hashableScriptData)
117142
& #originalCbor .~ getOriginalScriptDataBytes hashableScriptData
118143

119144
protoTxOut =

0 commit comments

Comments
 (0)