Skip to content

Commit 0a4ccdd

Browse files
committed
feat(macros): Add description field on subjects
1 parent 90e9866 commit 0a4ccdd

File tree

15 files changed

+480
-44
lines changed

15 files changed

+480
-44
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dotenvy = "0.15"
3939
futures = "0.3"
4040
futures-util = "0.3"
4141
hex = "0.4"
42+
indexmap = { version = "2.7.1", features = ["serde"] }
4243
moka = { version = "0.12.9", features = ["sync"] }
4344
num_cpus = "1.16"
4445
pretty_assertions = "1.4"

crates/domains/src/blocks/subjects.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ use super::types::*;
1212
#[subject(query_all = "blocks.>")]
1313
#[subject(format = "blocks.{producer}.{height}")]
1414
pub struct BlocksSubject {
15-
#[subject(sql_column = "producer_address")]
15+
#[subject(
16+
sql_column = "producer_address",
17+
description = "The address of the producer that created the block"
18+
)]
1619
pub producer: Option<Address>,
17-
#[subject(sql_column = "block_height")]
20+
#[subject(
21+
sql_column = "block_height",
22+
description = "The height of the block as unsigned 64 bit integer"
23+
)]
1824
pub height: Option<BlockHeight>,
1925
}
2026

crates/domains/src/inputs/subjects.rs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,27 @@ use super::InputType;
1313
format = "inputs.coin.{block_height}.{tx_id}.{tx_index}.{input_index}.{owner}.{asset}"
1414
)]
1515
pub struct InputsCoinSubject {
16+
#[subject(
17+
description = "The height of the block containing this coin input"
18+
)]
1619
pub block_height: Option<BlockHeight>,
20+
#[subject(
21+
description = "The ID of the transaction containing this coin input (32 byte string prefixed by 0x)"
22+
)]
1723
pub tx_id: Option<TxId>,
24+
#[subject(description = "The index of the transaction within the block")]
1825
pub tx_index: Option<u32>,
26+
#[subject(description = "The index of this input within the transaction")]
1927
pub input_index: Option<u32>,
20-
#[subject(sql_column = "owner_id")]
28+
#[subject(
29+
sql_column = "owner_id",
30+
description = "The address of the coin owner (32 byte string prefixed by 0x)"
31+
)]
2132
pub owner: Option<Address>,
22-
#[subject(sql_column = "asset_id")]
33+
#[subject(
34+
sql_column = "asset_id",
35+
description = "The asset ID of the coin (32 byte string prefixed by 0x)"
36+
)]
2337
pub asset: Option<AssetId>,
2438
}
2539

@@ -32,11 +46,22 @@ pub struct InputsCoinSubject {
3246
format = "inputs.contract.{block_height}.{tx_id}.{tx_index}.{input_index}.{contract}"
3347
)]
3448
pub struct InputsContractSubject {
49+
#[subject(
50+
description = "The height of the block containing this contract input"
51+
)]
3552
pub block_height: Option<BlockHeight>,
53+
#[subject(
54+
description = "The ID of the transaction containing this contract input (32 byte string prefixed by 0x)"
55+
)]
3656
pub tx_id: Option<TxId>,
57+
#[subject(description = "The index of the transaction within the block")]
3758
pub tx_index: Option<u32>,
59+
#[subject(description = "The index of this input within the transaction")]
3860
pub input_index: Option<u32>,
39-
#[subject(sql_column = "contract_id")]
61+
#[subject(
62+
sql_column = "contract_id",
63+
description = "The ID of the contract being called (32 byte string prefixed by 0x)"
64+
)]
4065
pub contract: Option<ContractId>,
4166
}
4267

@@ -49,13 +74,27 @@ pub struct InputsContractSubject {
4974
format = "inputs.message.{block_height}.{tx_id}.{tx_index}.{input_index}.{sender}.{recipient}"
5075
)]
5176
pub struct InputsMessageSubject {
77+
#[subject(
78+
description = "The height of the block containing this message input"
79+
)]
5280
pub block_height: Option<BlockHeight>,
81+
#[subject(
82+
description = "The ID of the transaction containing this message input (32 byte string prefixed by 0x)"
83+
)]
5384
pub tx_id: Option<TxId>,
85+
#[subject(description = "The index of the transaction within the block")]
5486
pub tx_index: Option<u32>,
87+
#[subject(description = "The index of this input within the transaction")]
5588
pub input_index: Option<u32>,
56-
#[subject(sql_column = "sender_address")]
89+
#[subject(
90+
sql_column = "sender_address",
91+
description = "The address that sent the message (32 byte string prefixed by 0x)"
92+
)]
5793
pub sender: Option<Address>,
58-
#[subject(sql_column = "recipient_address")]
94+
#[subject(
95+
sql_column = "recipient_address",
96+
description = "The address that will receive the message (32 byte string prefixed by 0x)"
97+
)]
5998
pub recipient: Option<Address>,
6099
}
61100

@@ -68,9 +107,16 @@ pub struct InputsMessageSubject {
68107
format = "inputs.{input_type}.{block_height}.{tx_id}.{tx_index}.{input_index}"
69108
)]
70109
pub struct InputsSubject {
110+
#[subject(description = "The type of input (coin, contract, or message)")]
71111
pub input_type: Option<InputType>,
112+
#[subject(description = "The height of the block containing this input")]
72113
pub block_height: Option<BlockHeight>,
114+
#[subject(
115+
description = "The ID of the transaction containing this input (32 byte string prefixed by 0x)"
116+
)]
73117
pub tx_id: Option<TxId>,
118+
#[subject(description = "The index of the transaction within the block")]
74119
pub tx_index: Option<u32>,
120+
#[subject(description = "The index of this input within the transaction")]
75121
pub input_index: Option<u32>,
76122
}

crates/domains/src/outputs/subjects.rs

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,27 @@ use super::OutputType;
1313
format = "outputs.coin.{block_height}.{tx_id}.{tx_index}.{output_index}.{to}.{asset}"
1414
)]
1515
pub struct OutputsCoinSubject {
16+
#[subject(
17+
description = "The height of the block containing this coin output"
18+
)]
1619
pub block_height: Option<BlockHeight>,
20+
#[subject(
21+
description = "The ID of the transaction containing this coin output (32 byte string prefixed by 0x)"
22+
)]
1723
pub tx_id: Option<TxId>,
24+
#[subject(description = "The index of the transaction within the block")]
1825
pub tx_index: Option<u32>,
26+
#[subject(description = "The index of this output within the transaction")]
1927
pub output_index: Option<u32>,
20-
#[subject(sql_column = "to_address")]
28+
#[subject(
29+
sql_column = "to_address",
30+
description = "The recipient address of the coin output (32 byte string prefixed by 0x)"
31+
)]
2132
pub to: Option<Address>,
22-
#[subject(sql_column = "asset_id")]
33+
#[subject(
34+
sql_column = "asset_id",
35+
description = "The asset ID of the coin (32 byte string prefixed by 0x)"
36+
)]
2337
pub asset: Option<AssetId>,
2438
}
2539

@@ -32,11 +46,22 @@ pub struct OutputsCoinSubject {
3246
format = "outputs.contract.{block_height}.{tx_id}.{tx_index}.{output_index}.{contract}"
3347
)]
3448
pub struct OutputsContractSubject {
49+
#[subject(
50+
description = "The height of the block containing this contract output"
51+
)]
3552
pub block_height: Option<BlockHeight>,
53+
#[subject(
54+
description = "The ID of the transaction containing this contract output (32 byte string prefixed by 0x)"
55+
)]
3656
pub tx_id: Option<TxId>,
57+
#[subject(description = "The index of the transaction within the block")]
3758
pub tx_index: Option<u32>,
59+
#[subject(description = "The index of this output within the transaction")]
3860
pub output_index: Option<u32>,
39-
#[subject(sql_column = "contract_id")]
61+
#[subject(
62+
sql_column = "contract_id",
63+
description = "The ID of the contract (32 byte string prefixed by 0x)"
64+
)]
4065
pub contract: Option<ContractId>,
4166
}
4267

@@ -49,13 +74,27 @@ pub struct OutputsContractSubject {
4974
format = "outputs.change.{block_height}.{tx_id}.{tx_index}.{output_index}.{to}.{asset}"
5075
)]
5176
pub struct OutputsChangeSubject {
77+
#[subject(
78+
description = "The height of the block containing this change output"
79+
)]
5280
pub block_height: Option<BlockHeight>,
81+
#[subject(
82+
description = "The ID of the transaction containing this change output (32 byte string prefixed by 0x)"
83+
)]
5384
pub tx_id: Option<TxId>,
85+
#[subject(description = "The index of the transaction within the block")]
5486
pub tx_index: Option<u32>,
87+
#[subject(description = "The index of this output within the transaction")]
5588
pub output_index: Option<u32>,
56-
#[subject(sql_column = "to_address")]
89+
#[subject(
90+
sql_column = "to_address",
91+
description = "The recipient address of the change output (32 byte string prefixed by 0x)"
92+
)]
5793
pub to: Option<Address>,
58-
#[subject(sql_column = "asset_id")]
94+
#[subject(
95+
sql_column = "asset_id",
96+
description = "The asset ID of the change output (32 byte string prefixed by 0x)"
97+
)]
5998
pub asset: Option<AssetId>,
6099
}
61100

@@ -68,13 +107,27 @@ pub struct OutputsChangeSubject {
68107
format = "outputs.variable.{block_height}.{tx_id}.{tx_index}.{output_index}.{to}.{asset}"
69108
)]
70109
pub struct OutputsVariableSubject {
110+
#[subject(
111+
description = "The height of the block containing this variable output"
112+
)]
71113
pub block_height: Option<BlockHeight>,
114+
#[subject(
115+
description = "The ID of the transaction containing this variable output (32 byte string prefixed by 0x)"
116+
)]
72117
pub tx_id: Option<TxId>,
118+
#[subject(description = "The index of the transaction within the block")]
73119
pub tx_index: Option<u32>,
120+
#[subject(description = "The index of this output within the transaction")]
74121
pub output_index: Option<u32>,
75-
#[subject(sql_column = "to_address")]
122+
#[subject(
123+
sql_column = "to_address",
124+
description = "The recipient address of the variable output (32 byte string prefixed by 0x)"
125+
)]
76126
pub to: Option<Address>,
77-
#[subject(sql_column = "asset_id")]
127+
#[subject(
128+
sql_column = "asset_id",
129+
description = "The asset ID of the variable output (32 byte string prefixed by 0x)"
130+
)]
78131
pub asset: Option<AssetId>,
79132
}
80133

@@ -87,11 +140,22 @@ pub struct OutputsVariableSubject {
87140
format = "outputs.contract_created.{block_height}.{tx_id}.{tx_index}.{output_index}.{contract}"
88141
)]
89142
pub struct OutputsContractCreatedSubject {
143+
#[subject(
144+
description = "The height of the block containing this contract creation output"
145+
)]
90146
pub block_height: Option<BlockHeight>,
147+
#[subject(
148+
description = "The ID of the transaction containing this contract creation output (32 byte string prefixed by 0x)"
149+
)]
91150
pub tx_id: Option<TxId>,
151+
#[subject(description = "The index of the transaction within the block")]
92152
pub tx_index: Option<u32>,
153+
#[subject(description = "The index of this output within the transaction")]
93154
pub output_index: Option<u32>,
94-
#[subject(sql_column = "contract_id")]
155+
#[subject(
156+
sql_column = "contract_id",
157+
description = "The ID of the created contract (32 byte string prefixed by 0x)"
158+
)]
95159
pub contract: Option<ContractId>,
96160
}
97161

@@ -104,9 +168,18 @@ pub struct OutputsContractCreatedSubject {
104168
format = "outputs.{output_type}.{block_height}.{tx_id}.{tx_index}.{output_index}"
105169
)]
106170
pub struct OutputsSubject {
171+
#[subject(
172+
description = "The type of output (coin, contract, change, variable, or contract_created)"
173+
)]
107174
pub output_type: Option<OutputType>,
175+
#[subject(description = "The height of the block containing this output")]
108176
pub block_height: Option<BlockHeight>,
177+
#[subject(
178+
description = "The ID of the transaction containing this output (32 byte string prefixed by 0x)"
179+
)]
109180
pub tx_id: Option<TxId>,
181+
#[subject(description = "The index of the transaction within the block")]
110182
pub tx_index: Option<u32>,
183+
#[subject(description = "The index of this output within the transaction")]
111184
pub output_index: Option<u32>,
112185
}

0 commit comments

Comments
 (0)