Commit 709e1c3
authored
feat(api): support int64_as_string parameter for GET requests (#6699)
* feat(api): support int64_as_string parameter for GET requests (#6568)
Add an opt-in `int64_as_string` query parameter on TRON HTTP GET endpoints.
When set, int64/uint64 protobuf fields in the response are serialized as
quoted JSON strings to avoid precision loss in clients whose native number
type cannot safely represent integers above 2^53 - 1 (e.g. JavaScript).
Scope: GET only. POST is intentionally unsupported because reading the
request body in a centralized location (RateLimiterServlet.service or a
Filter) would consume request.getReader() and break downstream servlets
that read the body themselves. Most TRON query endpoints support both
GET and POST, so clients that need precision can use the GET form. POST-
only write endpoints return Transaction proto whose int64 fields would
break round-trip JsonFormat.merge if quoted, so they should not enable
this flag in the first place.
- JsonFormat: add INT64_AS_STRING ThreadLocal + setInt64AsString /
clearInt64AsString / isInt64AsString helpers; split printFieldValue
INT64/SINT64/SFIXED64 and UINT64/FIXED64 branches so they emit quoted
strings only when the flag is set.
- Util: add INT64_AS_STRING constant + getInt64AsString (URL query,
mirrors getVisible).
- RateLimiterServlet.service: set ThreadLocal from URL query on GET only;
clear in finally so reused Tomcat threads do not leak state across
requests.
- GetBurnTrx / GetPendingSize / GetTransactionCountByBlockNum: emit
quoted int64 in their hand-built JSON responses when isInt64AsString
is true.
- JsonFormatInt64AsStringTest: covers default behavior, int64 / uint64
quoting, non-int64 fields unaffected, nested / map / boundary values
(2^53 +/- 1, Long.MAX/MIN, -1), state cleanup (normal close, after
exception, explicit clear), thread isolation, thread-reuse anti-pollution.
Backward compatibility: requests without int64_as_string=true produce
byte-identical responses to develop -- the new code paths are gated
entirely on the new flag.
Closes #6568.
* refactor(api): address review feedback on int64_as_string PR
Three small adjustments per review on PR #6699:
- GetTransactionCountByBlockNumServlet: add trailing newline at end of
file to satisfy checkstyle.
- Util.getInt64AsString: align control flow with the existing
Util.getVisible (single-return via local boolean, Boolean.valueOf
instead of Boolean.parseBoolean). Functionally identical -- both
return true only when the parameter value is "true" (case-insensitive).
- Util.INT64_AS_STRING -> Util.INT64_AS_STRING_PARAM: rename the public
parameter-name constant to avoid potential confusion with the unrelated
private ThreadLocal field of the same simple name in JsonFormat.
The user-facing query parameter remains "int64_as_string" -- only the
Java identifier changes.1 parent 03bd4af commit 709e1c3
9 files changed
Lines changed: 525 additions & 9 deletions
File tree
- framework/src
- main/java/org/tron/core/services/http
- test/java/org/tron/core/services/http
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | | - | |
| 48 | + | |
Lines changed: 54 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
93 | 128 | | |
94 | 129 | | |
95 | 130 | | |
| |||
340 | 375 | | |
341 | 376 | | |
342 | 377 | | |
343 | | - | |
344 | 378 | | |
345 | | - | |
346 | 379 | | |
347 | | - | |
348 | 380 | | |
349 | 381 | | |
350 | 382 | | |
351 | 383 | | |
352 | 384 | | |
353 | 385 | | |
354 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
355 | 399 | | |
356 | 400 | | |
357 | 401 | | |
358 | 402 | | |
359 | 403 | | |
360 | 404 | | |
361 | 405 | | |
362 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
363 | 413 | | |
364 | 414 | | |
365 | 415 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
| |||
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
136 | 146 | | |
137 | 147 | | |
138 | 148 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
348 | 349 | | |
349 | 350 | | |
350 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
351 | 367 | | |
352 | 368 | | |
353 | 369 | | |
| |||
0 commit comments