Skip to content

Commit d598fe0

Browse files
authored
Add contract events to spec (#1818)
1 parent b75239b commit d598fe0

File tree

4 files changed

+154
-97
lines changed

4 files changed

+154
-97
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@monaco-editor/react": "^4.7.0",
3232
"@next/third-parties": "^15.5.7",
3333
"@sentry/nextjs": "^10.29.0",
34-
"@stellar-expert/contract-wasm-interface-parser": "^3.2.0",
34+
"@stellar-expert/contract-wasm-interface-parser": "^4.0.0",
3535
"@stellar/design-system": "^3.2.7",
3636
"@stellar/stellar-sdk": "^14.3.3",
3737
"@stellar/stellar-xdr-json": "^23.0.0",

pnpm-lock.yaml

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

src/constants/networkLimits.ts

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -78,36 +78,36 @@ export const MAINNET_LIMITS: NetworkLimits = {
7878
"persistent_rent_rate_denominator": "1215",
7979
"temp_rent_rate_denominator": "2430",
8080
"live_soroban_state_size_window": [
81-
"739002948",
82-
"739904520",
83-
"740719020",
84-
"741626100",
85-
"742179684",
86-
"743255320",
87-
"744351820",
88-
"745031696",
89-
"745729172",
90-
"746406280",
91-
"747289380",
92-
"747751068",
93-
"748268676",
94-
"749029564",
95-
"749613280",
96-
"749733384",
97-
"749705612",
98-
"749645476",
99-
"749630656",
100-
"749613812",
101-
"749624628",
102-
"749636004",
103-
"749646520",
104-
"749654220",
105-
"749666512",
106-
"749681760",
107-
"749695644",
108-
"749717500",
109-
"749716784",
110-
"749734072"
81+
"749789052",
82+
"749769188",
83+
"749723808",
84+
"749692100",
85+
"749640968",
86+
"749601580",
87+
"749598364",
88+
"749605912",
89+
"749622672",
90+
"749631516",
91+
"749648176",
92+
"749662364",
93+
"749672192",
94+
"749698628",
95+
"749694628",
96+
"749723996",
97+
"749741584",
98+
"749754972",
99+
"749779296",
100+
"749808480",
101+
"749827556",
102+
"749844492",
103+
"749864220",
104+
"749888696",
105+
"749904340",
106+
"749926128",
107+
"749943884",
108+
"749944148",
109+
"749959260",
110+
"749976756"
111111
],
112112
"state_target_size_bytes": "3000000000",
113113
"rent_fee_1kb_state_size_low": "-17000",
@@ -146,36 +146,36 @@ export const TESTNET_LIMITS: NetworkLimits = {
146146
"persistent_rent_rate_denominator": "1215",
147147
"temp_rent_rate_denominator": "2430",
148148
"live_soroban_state_size_window": [
149-
"298261778",
150-
"298936974",
151-
"298941102",
152-
"298945038",
153-
"298928150",
154-
"299644892",
155-
"299648908",
156-
"300304696",
157-
"300313808",
158-
"300329296",
159-
"300310280",
160-
"300329684",
161-
"300337304",
162-
"300518280",
163-
"303565556",
164-
"303579996",
165-
"303571692",
166-
"304069557",
167-
"304498393",
168-
"304740057",
169-
"305015235",
170-
"305020419",
171-
"304998943",
172-
"305007847",
173-
"305012559",
174-
"305016495",
175-
"305036151",
176-
"305171919",
177-
"304759932",
178-
"304763868"
149+
"302780638",
150+
"303382070",
151+
"304146257",
152+
"303539379",
153+
"303554591",
154+
"303563147",
155+
"303581103",
156+
"303592483",
157+
"303121843",
158+
"303016633",
159+
"303021101",
160+
"303026077",
161+
"303533991",
162+
"303776435",
163+
"303722527",
164+
"302908282",
165+
"302996345",
166+
"303000857",
167+
"304042171",
168+
"304255132",
169+
"304655525",
170+
"305207623",
171+
"307262287",
172+
"307291359",
173+
"308367975",
174+
"308946183",
175+
"308908971",
176+
"308656982",
177+
"308840066",
178+
"309372788"
179179
],
180180
"state_target_size_bytes": "3000000000",
181181
"rent_fee_1kb_state_size_low": "-17000",
@@ -214,36 +214,36 @@ export const FUTURENET_LIMITS: NetworkLimits = {
214214
"persistent_rent_rate_denominator": "1215",
215215
"temp_rent_rate_denominator": "2430",
216216
"live_soroban_state_size_window": [
217-
"50248220",
218-
"50248220",
219-
"50248220",
220-
"50248220",
221-
"50248220",
222-
"50248220",
223-
"50248220",
224-
"50248220",
225-
"50248220",
226-
"50248220",
227-
"50248220",
228-
"50248220",
229-
"50248220",
230-
"50248220",
231-
"50248220",
232-
"50248220",
233-
"50248220",
234-
"50248220",
235-
"50248220",
236-
"50248220",
237-
"50248220",
238-
"50248220",
239-
"50248220",
240-
"50248220",
241-
"50248220",
242-
"50248220",
243-
"50248220",
244-
"50248220",
245-
"50248220",
246-
"50248220"
217+
"50247016",
218+
"50247016",
219+
"50247016",
220+
"50247016",
221+
"50247016",
222+
"50247016",
223+
"50247016",
224+
"50247016",
225+
"50247016",
226+
"50247016",
227+
"50247016",
228+
"50247016",
229+
"50247016",
230+
"50247016",
231+
"50247016",
232+
"50247016",
233+
"50247016",
234+
"50247016",
235+
"50247016",
236+
"50247016",
237+
"50247016",
238+
"50247016",
239+
"50247016",
240+
"50247016",
241+
"50247016",
242+
"50247016",
243+
"50247016",
244+
"50247016",
245+
"50247016",
246+
"50247016"
247247
],
248248
"state_target_size_bytes": "3000000000",
249249
"rent_fee_1kb_state_size_low": "-17000",

src/helpers/formatContractInterface.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export const formatContractInterface = (
1616
output += `/// ${contractInterface.doc}\n`;
1717
}
1818

19+
// Events
20+
output += eventsOutput(contractInterface.events);
21+
1922
// Functions
2023
output += functionsOutput(contractInterface.functions);
2124

@@ -177,3 +180,57 @@ const formatFnOutputs = (outputs: any) => {
177180

178181
return outputType ? `-> ${outputType}` : "";
179182
};
183+
184+
const eventsOutput = (events: any) => {
185+
let eventsString = "";
186+
187+
if (events && typeof events === "object" && Object.keys(events).length) {
188+
eventsString += `// ==========================================\n`;
189+
eventsString += `// Events\n`;
190+
eventsString += `// ==========================================\n\n`;
191+
192+
Object.entries(events).forEach((eventItem) => {
193+
const key = eventItem[0];
194+
const value = eventItem[1] as any;
195+
196+
if (value.doc) {
197+
value.doc.split("\n").forEach((line: string) => {
198+
eventsString += `/// ${line}\n`;
199+
});
200+
}
201+
202+
// Format the decorator with topics and data_format
203+
const topics = value.prefixTopics || [];
204+
const topicsStr = topics.map((t: string) => `"${t}"`).join(", ");
205+
206+
// Convert dataFormat from scSpecEventDataFormatSingleValue to single-value
207+
let dataFormat = "single-value";
208+
if (value.dataFormat) {
209+
if (value.dataFormat.includes("SingleValue")) {
210+
dataFormat = "single-value";
211+
} else if (value.dataFormat.includes("MultiValue")) {
212+
dataFormat = "multi-value";
213+
}
214+
}
215+
216+
eventsString += `#[contractevent(topics = [${topicsStr}], data_format = "${dataFormat}")]\n`;
217+
eventsString += `struct ${value.name || key} {\n`;
218+
219+
if (value.params && Array.isArray(value.params) && value.params.length) {
220+
value.params.forEach((param: any) => {
221+
if (param.doc) {
222+
param.doc.split("\n").forEach((line: string) => {
223+
eventsString += `${TAB}/// ${line}\n`;
224+
});
225+
}
226+
227+
eventsString += `${TAB}${param.name}: ${param.type || param.type_},\n`;
228+
});
229+
}
230+
231+
eventsString += "}\n\n";
232+
});
233+
}
234+
235+
return eventsString;
236+
};

0 commit comments

Comments
 (0)