Skip to content

Commit 7c187b3

Browse files
committed
cardano-rpc | Add UTxO RPC: Update cardano.proto & query.proto with definitions for readUtxos
1 parent f1f208a commit 7c187b3

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

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

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,131 @@ syntax = "proto3";
22

33
package utxorpc.v1alpha.cardano;
44

5+
// Purpose of the redeemer in a transaction.
6+
enum RedeemerPurpose {
7+
REDEEMER_PURPOSE_UNSPECIFIED = 0;
8+
REDEEMER_PURPOSE_SPEND = 1;
9+
REDEEMER_PURPOSE_MINT = 2;
10+
REDEEMER_PURPOSE_CERT = 3;
11+
REDEEMER_PURPOSE_REWARD = 4;
12+
REDEEMER_PURPOSE_VOTE = 5;
13+
REDEEMER_PURPOSE_PROPOSE = 6;
14+
}
15+
16+
// Redeemer information for a Plutus script.
17+
message Redeemer {
18+
RedeemerPurpose purpose = 1; // Purpose of the redeemer.
19+
PlutusData payload = 2; // Plutus data associated with the redeemer.
20+
uint32 index = 3; // Index of the redeemer.
21+
ExUnits ex_units = 4; // Execution units consumed by the redeemer.
22+
bytes original_cbor = 5; // Original cbor-encoded data as seen on-chain
23+
}
24+
25+
// Represents a transaction output in the Cardano blockchain.
26+
message TxOutput {
27+
bytes address = 1; // Address receiving the output.
28+
uint64 coin = 2; // Amount of ADA in the output.
29+
repeated MultiAsset assets = 3; // Additional native (non-ADA) assets in the output.
30+
Datum datum = 4; // Plutus data associated with the output.
31+
Script script = 5; // Script associated with the output.
32+
}
33+
34+
message Datum {
35+
bytes hash = 1; // Hash of this datum as seen on-chain
36+
PlutusData payload = 2; // Parsed Plutus data payload
37+
bytes original_cbor = 3; // Original cbor-encoded data as seen on-chain
38+
}
39+
40+
// Represents a custom asset in the Cardano blockchain.
41+
message Asset {
42+
bytes name = 1; // Name of the custom asset.
43+
uint64 output_coin = 2; // Quantity of the custom asset in case of an output.
44+
int64 mint_coin = 3; // Quantity of the custom asset in case of a mint.
45+
}
46+
47+
// Represents a multi-asset group in the Cardano blockchain.
48+
message MultiAsset {
49+
bytes policy_id = 1; // Policy ID governing the custom assets.
50+
repeated Asset assets = 2; // List of custom assets.
51+
Redeemer redeemer = 3; // Redeemer for the Plutus script.
52+
}
53+
54+
// Represents a native script in Cardano.
55+
message NativeScript {
56+
oneof native_script {
57+
bytes script_pubkey = 1; // Script based on an address key hash.
58+
NativeScriptList script_all = 2; // Script that requires all nested scripts to be satisfied.
59+
NativeScriptList script_any = 3; // Script that requires any of the nested scripts to be satisfied.
60+
ScriptNOfK script_n_of_k = 4; // Script that requires k out of n nested scripts to be satisfied.
61+
uint64 invalid_before = 5; // Slot number before which the script is invalid.
62+
uint64 invalid_hereafter = 6; // Slot number after which the script is invalid.
63+
}
64+
}
65+
66+
// Represents a list of native scripts.
67+
message NativeScriptList {
68+
repeated NativeScript items = 1; // List of native scripts.
69+
}
70+
71+
// Represents a "k out of n" native script.
72+
message ScriptNOfK {
73+
uint32 k = 1; // The number of required satisfied scripts.
74+
repeated NativeScript scripts = 2; // List of native scripts.
75+
}
76+
77+
// Represents a constructor for Plutus data in Cardano.
78+
message Constr {
79+
uint32 tag = 1;
80+
uint64 any_constructor = 2;
81+
repeated PlutusData fields = 3;
82+
}
83+
84+
// Represents a big integer for Plutus data in Cardano.
85+
message BigInt {
86+
oneof big_int {
87+
int64 int = 1;
88+
bytes big_u_int = 2;
89+
bytes big_n_int = 3;
90+
}
91+
}
92+
93+
// Represents a key-value pair for Plutus data in Cardano.
94+
message PlutusDataPair {
95+
PlutusData key = 1; // Key of the pair.
96+
PlutusData value = 2; // Value of the pair.
97+
}
98+
99+
// Represents a Plutus data item in Cardano.
100+
message PlutusData {
101+
oneof plutus_data {
102+
Constr constr = 2; // Constructor.
103+
PlutusDataMap map = 3; // Map of Plutus data.
104+
BigInt big_int = 4; // Big integer.
105+
bytes bounded_bytes = 5; // Bounded bytes.
106+
PlutusDataArray array = 6; // Array of Plutus data.
107+
}
108+
}
109+
110+
// Represents a map of Plutus data in Cardano.
111+
message PlutusDataMap {
112+
repeated PlutusDataPair pairs = 1; // List of key-value pairs.
113+
}
114+
115+
// Represents an array of Plutus data in Cardano.
116+
message PlutusDataArray {
117+
repeated PlutusData items = 1; // List of Plutus data items.
118+
}
119+
120+
// Represents a script in Cardano.
121+
message Script {
122+
oneof script {
123+
NativeScript native = 1; // Native script.
124+
bytes plutus_v1 = 2; // Plutus V1 script.
125+
bytes plutus_v2 = 3; // Plutus V2 script.
126+
bytes plutus_v3 = 4; // Plutus V3 script.
127+
}
128+
}
129+
5130
// Represents a rational number as a fraction.
6131
message RationalNumber {
7132
int32 numerator = 1;
@@ -73,3 +198,4 @@ message PParams {
73198
uint64 drep_deposit = 30; // The drep deposit.
74199
uint64 drep_inactivity_period = 31; // The drep inactivity period.
75200
}
201+

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ message ChainPoint {
1515
uint64 timestamp = 4; // Block ms timestamp
1616
}
1717

18+
// Represents a reference to a transaction output
19+
message TxoRef {
20+
bytes hash = 1; // Tx hash.
21+
uint32 index = 2; // Output index.
22+
}
23+
1824
// Request to get the chain parameters
1925
message ReadParamsRequest {
2026
google.protobuf.FieldMask field_mask = 1; // Field mask to selectively return fields in the parsed response.
@@ -33,7 +39,29 @@ message ReadParamsResponse {
3339
ChainPoint ledger_tip = 2; // The chain point that represent the ledger current position.
3440
}
3541

42+
// An evenlope that holds an UTxO from any of compatible chains
43+
message AnyUtxoData {
44+
bytes native_bytes = 1; // Original bytes as defined by the chain
45+
TxoRef txo_ref = 2; // Hash of the previous transaction.
46+
oneof parsed_state {
47+
utxorpc.v1alpha.cardano.TxOutput cardano = 3; // A cardano UTxO
48+
}
49+
}
50+
51+
// Request to get specific UTxOs
52+
message ReadUtxosRequest {
53+
repeated TxoRef keys = 1; // List of keys UTxOs.
54+
google.protobuf.FieldMask field_mask = 2; // Field mask to selectively return fields.
55+
}
56+
57+
// Response containing the UTxOs associated with the requested addresses.
58+
message ReadUtxosResponse {
59+
repeated AnyUtxoData items = 1; // List of UTxOs.
60+
ChainPoint ledger_tip = 2; // The chain point that represent the ledger current position.
61+
}
62+
3663
// Service definition for querying the state of the chain.
3764
service QueryService {
3865
rpc ReadParams(ReadParamsRequest) returns (ReadParamsResponse); // Get overall chain state.
66+
rpc ReadUtxos(ReadUtxosRequest) returns (ReadUtxosResponse); // Read specific UTxOs by reference.
3967
}

0 commit comments

Comments
 (0)