77import httpx
88
99CAPITALIZATION_EXCEPTIONS = {
10- "NFTOKEN" : "NFToken" ,
11- "URITOKEN" : "URIToken" ,
12- "URI" : "URI" ,
13- "UNL" : "UNL" ,
1410 "XCHAIN" : "XChain" ,
15- "DID" : "DID" ,
16- "ID" : "ID" ,
17- "AMM" : "AMM" ,
1811}
1912
2013if len (sys .argv ) != 2 and len (sys .argv ) != 3 :
@@ -66,22 +59,21 @@ def _translate(inp: str) -> str:
6659 return inp .replace ("UINT" , "Hash" )
6760 else :
6861 return inp .replace ("UINT" , "UInt" )
69- if inp == "OBJECT" or inp == "ARRAY" :
70- return "ST" + inp [0 :1 ].upper () + inp [1 :].lower ()
71- if inp == "ACCOUNT" :
72- return "AccountID"
73- if inp == "LEDGERENTRY" :
74- return "LedgerEntry"
75- if inp == "NOTPRESENT" :
76- return "NotPresent"
77- if inp == "PATHSET" :
78- return "PathSet"
79- if inp == "VL" :
80- return "Blob"
81- if inp == "DIR_NODE" :
82- return "DirectoryNode"
83- if inp == "PAYCHAN" :
84- return "PayChannel"
62+
63+ non_standard_renames = {
64+ "OBJECT" : "STObject" ,
65+ "ARRAY" : "STArray" ,
66+ "AMM" : "AMM" ,
67+ "ACCOUNT" : "AccountID" ,
68+ "LEDGERENTRY" : "LedgerEntry" ,
69+ "NOTPRESENT" : "NotPresent" ,
70+ "PATHSET" : "PathSet" ,
71+ "VL" : "Blob" ,
72+ "DIR_NODE" : "DirectoryNode" ,
73+ "PAYCHAN" : "PayChannel" ,
74+ }
75+ if inp in non_standard_renames :
76+ return non_standard_renames [inp ]
8577
8678 parts = inp .split ("_" )
8779 result = ""
@@ -96,6 +88,7 @@ def _translate(inp: str) -> str:
9688output = ""
9789
9890
91+ # add a new line of content to the output
9992def _add_line (line : str ) -> None :
10093 global output
10194 output += line + "\n "
@@ -173,13 +166,17 @@ def _add_line(line: str) -> None:
173166 ],"""
174167)
175168
169+ # Parse STypes
170+ # Example line:
171+ # STYPE(STI_UINT32, 2) \
176172type_hits = re .findall (
177173 r"^ *STYPE\(STI_([^ ]*?) *, *([0-9-]+) *\) *\\?$" , sfield_h , re .MULTILINE
178174)
179175if len (type_hits ) == 0 :
180176 type_hits = re .findall (
181177 r"^ *STI_([^ ]*?) *= *([0-9-]+) *,?$" , sfield_h , re .MULTILINE
182178 )
179+ # name-to-value map - needed for SField processing
183180type_map = {x [0 ]: x [1 ] for x in type_hits }
184181
185182
@@ -206,6 +203,9 @@ def _is_signing_field(t: str, not_signing_field: str) -> str:
206203
207204
208205# Parse SField.cpp for all the SFields and their serialization info
206+ # Example lines:
207+ # TYPED_SFIELD(sfFee, AMOUNT, 8)
208+ # UNTYPED_SFIELD(sfSigners, ARRAY, 3, SField::sMD_Default, SField::notSigning)
209209sfield_hits = re .findall (
210210 r"^ *[A-Z]*TYPED_SFIELD *\( *sf([^,\n]*),[ \n]*([^, \n]+)[ \n]*,[ \n]*"
211211 r"([0-9]+)(,.*?(notSigning))?" ,
@@ -251,6 +251,9 @@ def _unhex(x: str) -> str:
251251 return x
252252
253253
254+ # Parse ledger entries
255+ # Example line:
256+ # LEDGER_ENTRY(ltNFTOKEN_OFFER, 0x0037, NFTokenOffer, nft_offer, ({
254257lt_hits = re .findall (
255258 r"^ *LEDGER_ENTRY[A-Z_]*\(lt[A-Z_]+ *, *([x0-9a-f]+) *, *([^,]+), *([^,]+), \({$" ,
256259 ledger_entries_file ,
@@ -274,6 +277,7 @@ def _unhex(x: str) -> str:
274277_add_line (' "TRANSACTION_RESULTS": {' )
275278ter_h = str (ter_h ).replace ("[[maybe_unused]]" , "" )
276279
280+ # Parse TER codes
277281ter_code_hits = re .findall (
278282 r"^ *((tel|tem|tef|ter|tes|tec)[A-Z_]+)( *= *([0-9-]+))? *,? *(\/\/[^\n]*)?$" ,
279283 ter_h ,
@@ -282,16 +286,18 @@ def _unhex(x: str) -> str:
282286ter_codes = []
283287upto = - 1
284288
289+ # Get the exact values of the TER codes and sort them
285290for x in range (len (ter_code_hits )):
286291 if ter_code_hits [x ][3 ] != "" :
287292 upto = int (ter_code_hits [x ][3 ])
288293 ter_codes .append ((ter_code_hits [x ][0 ], upto ))
289294
290295 upto += 1
291-
292296ter_codes .sort (key = lambda x : x [0 ])
297+
293298current_type = ""
294299for x in range (len (ter_codes )):
300+ # print newline between the different code types
295301 if current_type == "" :
296302 current_type = ter_codes [x ][0 ][:3 ]
297303 elif current_type != ter_codes [x ][0 ][:3 ]:
@@ -313,13 +319,17 @@ def _unhex(x: str) -> str:
313319########################################################################
314320_add_line (' "TRANSACTION_TYPES": {' )
315321
322+ # Parse transaction types
323+ # Example line:
324+ # TRANSACTION(ttCHECK_CREATE, 16, CheckCreate, ({
316325tx_hits = re .findall (
317326 r"^ *TRANSACTION\(tt[A-Z_]+ *,* ([0-9]+) *, *([A-Za-z]+).*$" ,
318327 transactions_file ,
319328 re .MULTILINE ,
320329)
321330tx_hits .append (("-1" , "Invalid" ))
322331tx_hits .sort (key = lambda x : x [1 ])
332+
323333for x in range (len (tx_hits )):
324334 _add_line (
325335 ' "'
0 commit comments