]> git.ardis.lu - event-hashes/commitdiff
Add strict mode
authorArdis Lu <ardisglu@gmail.com>
Tue, 9 Jan 2024 06:33:28 +0000 (22:33 -0800)
committerArdis Lu <ardisglu@gmail.com>
Tue, 9 Jan 2024 06:33:28 +0000 (22:33 -0800)
index.html

index b19ca4589521162d41e8af4da9e1975a5cfff180..c9e14af5ab07587453f5f0770770e832d1646773 100644 (file)
     // From noble-hashes v1.3.3
     import { keccak256 } from '/keccak256.js';
 
-    function normalizeEvent(event) {
+    function normalizeEvent(event, strict = false) {
       // Clean all characters that definitely do not affect the signature
       const commentIndex = event.indexOf('//');
       event = commentIndex === -1 ? event : event.substring(0, commentIndex);
       event = event.trim();
 
       // Split the event name and the event topics
-      const eventRegex = /^(event )?(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<topics>.*?)(?!.+\))/;
+      const eventRegex = strict ?
+        /^(event )(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<topics>.*?)(?!.+\))/ :
+        /^(event )?(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<topics>.*?)(?!.+\))/;
       const { name, topics } = eventRegex.exec(event).groups;
 
       // Drop parameter names and extraneous whitespace, if there are any. Preserves tuple parentheses.
 
     function getEvents(code) {
       const events = new Set();
+      let strict = false;
       for (let line of code.split('\n')) {
         line = line.trim();
         if (line === '') {
           continue;
         }
+        if (line.substring(0, 8) === 'contract' || line.substring(0, 17) === 'abstract contract') {
+          strict = true;
+          continue;
+        }
         try {
-          const normalizedEvent = normalizeEvent(line);
+          const normalizedEvent = normalizeEvent(line, strict);
           events.add(normalizedEvent);
         }
         catch {
This page took 0.0434 seconds and 4 git commands to generate.