Skip to content

Commit 31936db

Browse files
authored
fix serialized types causing overflow (#181)
### TL;DR Updated numeric field types to strings for better precision and updated openapi schema ### What changed? - Generated openapi for a new API endpoint `/{chainId}/transfers` for retrieving token transfers with various filtering options - Added a new `TransferModel` definition to support the token transfers endpoint - Changed several numeric field types from `integer` to `string` in API models to better handle large numbers: - In `BlockModel`: `gas_limit` and `gas_used` - In `TransactionModel`: `value`, `gas_price`, `max_fee_per_gas`, `max_priority_fee_per_gas`, `effective_gas_price`, and `blob_gas_price` ### How to test? 1. Make a GET request to the new endpoint `/{chainId}/transfers` with appropriate filters 2. Verify the response contains token transfer data in the expected format 3. Check that numeric values are properly returned as strings without precision loss 4. Test various filter combinations (token type, address, block range, etc.) ### Why make this change? - The new transfers endpoint provides a dedicated way to query token transfer events, making it easier for clients to track token movements - Converting numeric fields to strings prevents precision loss when dealing with large numbers (like gas prices and token values) that can exceed JavaScript's safe integer limits GitHub Copilot: I'll help you create a pull request description for this change.
2 parents 057ba67 + 3f8d1bb commit 31936db

File tree

5 files changed

+536
-60
lines changed

5 files changed

+536
-60
lines changed

docs/docs.go

Lines changed: 194 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,151 @@ const docTemplate = `{
13051305
}
13061306
}
13071307
}
1308+
},
1309+
"/{chainId}/transfers": {
1310+
"get": {
1311+
"security": [
1312+
{
1313+
"BasicAuth": []
1314+
}
1315+
],
1316+
"description": "Retrieve token transfers by various filters",
1317+
"consumes": [
1318+
"application/json"
1319+
],
1320+
"produces": [
1321+
"application/json"
1322+
],
1323+
"tags": [
1324+
"transfers"
1325+
],
1326+
"summary": "Get token transfers",
1327+
"parameters": [
1328+
{
1329+
"type": "string",
1330+
"description": "Chain ID",
1331+
"name": "chainId",
1332+
"in": "path",
1333+
"required": true
1334+
},
1335+
{
1336+
"type": "array",
1337+
"items": {
1338+
"type": "string"
1339+
},
1340+
"collectionFormat": "csv",
1341+
"description": "Token types (erc721, erc1155, erc20)",
1342+
"name": "token_type",
1343+
"in": "query"
1344+
},
1345+
{
1346+
"type": "string",
1347+
"description": "Token contract address",
1348+
"name": "token_address",
1349+
"in": "query"
1350+
},
1351+
{
1352+
"type": "string",
1353+
"description": "Wallet address",
1354+
"name": "wallet",
1355+
"in": "query"
1356+
},
1357+
{
1358+
"type": "string",
1359+
"description": "Start block number",
1360+
"name": "start_block",
1361+
"in": "query"
1362+
},
1363+
{
1364+
"type": "string",
1365+
"description": "End block number",
1366+
"name": "end_block",
1367+
"in": "query"
1368+
},
1369+
{
1370+
"type": "string",
1371+
"description": "Start timestamp (RFC3339 format)",
1372+
"name": "start_timestamp",
1373+
"in": "query"
1374+
},
1375+
{
1376+
"type": "string",
1377+
"description": "End timestamp (RFC3339 format)",
1378+
"name": "end_timestamp",
1379+
"in": "query"
1380+
},
1381+
{
1382+
"type": "array",
1383+
"items": {
1384+
"type": "string"
1385+
},
1386+
"collectionFormat": "csv",
1387+
"description": "Token IDs",
1388+
"name": "token_id",
1389+
"in": "query"
1390+
},
1391+
{
1392+
"type": "string",
1393+
"description": "Transaction hash",
1394+
"name": "transaction_hash",
1395+
"in": "query"
1396+
},
1397+
{
1398+
"type": "integer",
1399+
"description": "Page number for pagination",
1400+
"name": "page",
1401+
"in": "query"
1402+
},
1403+
{
1404+
"type": "integer",
1405+
"default": 20,
1406+
"description": "Number of items per page",
1407+
"name": "limit",
1408+
"in": "query"
1409+
}
1410+
],
1411+
"responses": {
1412+
"200": {
1413+
"description": "OK",
1414+
"schema": {
1415+
"allOf": [
1416+
{
1417+
"$ref": "#/definitions/api.QueryResponse"
1418+
},
1419+
{
1420+
"type": "object",
1421+
"properties": {
1422+
"data": {
1423+
"type": "array",
1424+
"items": {
1425+
"$ref": "#/definitions/handlers.TransferModel"
1426+
}
1427+
}
1428+
}
1429+
}
1430+
]
1431+
}
1432+
},
1433+
"400": {
1434+
"description": "Bad Request",
1435+
"schema": {
1436+
"$ref": "#/definitions/api.Error"
1437+
}
1438+
},
1439+
"401": {
1440+
"description": "Unauthorized",
1441+
"schema": {
1442+
"$ref": "#/definitions/api.Error"
1443+
}
1444+
},
1445+
"500": {
1446+
"description": "Internal Server Error",
1447+
"schema": {
1448+
"$ref": "#/definitions/api.Error"
1449+
}
1450+
}
1451+
}
1452+
}
13081453
}
13091454
},
13101455
"definitions": {
@@ -1410,10 +1555,10 @@ const docTemplate = `{
14101555
"type": "string"
14111556
},
14121557
"gas_limit": {
1413-
"type": "integer"
1558+
"type": "string"
14141559
},
14151560
"gas_used": {
1416-
"type": "integer"
1561+
"type": "string"
14171562
},
14181563
"logs_bloom": {
14191564
"type": "string"
@@ -1550,7 +1695,7 @@ const docTemplate = `{
15501695
"type": "string"
15511696
},
15521697
"blob_gas_price": {
1553-
"type": "integer"
1698+
"type": "string"
15541699
},
15551700
"blob_gas_used": {
15561701
"type": "integer"
@@ -1588,7 +1733,7 @@ const docTemplate = `{
15881733
]
15891734
},
15901735
"effective_gas_price": {
1591-
"type": "integer"
1736+
"type": "string"
15921737
},
15931738
"from_address": {
15941739
"type": "string"
@@ -1600,7 +1745,7 @@ const docTemplate = `{
16001745
"type": "integer"
16011746
},
16021747
"gas_price": {
1603-
"type": "integer"
1748+
"type": "string"
16041749
},
16051750
"gas_used": {
16061751
"type": "integer"
@@ -1612,10 +1757,10 @@ const docTemplate = `{
16121757
"type": "string"
16131758
},
16141759
"max_fee_per_gas": {
1615-
"type": "integer"
1760+
"type": "string"
16161761
},
16171762
"max_priority_fee_per_gas": {
1618-
"type": "integer"
1763+
"type": "string"
16191764
},
16201765
"nonce": {
16211766
"type": "integer"
@@ -1642,7 +1787,7 @@ const docTemplate = `{
16421787
"type": "string"
16431788
},
16441789
"value": {
1645-
"type": "integer"
1790+
"type": "string"
16461791
}
16471792
}
16481793
},
@@ -1691,7 +1836,7 @@ const docTemplate = `{
16911836
"type": "string"
16921837
},
16931838
"blob_gas_price": {
1694-
"type": "integer"
1839+
"type": "string"
16951840
},
16961841
"blob_gas_used": {
16971842
"type": "integer"
@@ -1718,7 +1863,7 @@ const docTemplate = `{
17181863
"type": "string"
17191864
},
17201865
"effective_gas_price": {
1721-
"type": "integer"
1866+
"type": "string"
17221867
},
17231868
"from_address": {
17241869
"type": "string"
@@ -1730,7 +1875,7 @@ const docTemplate = `{
17301875
"type": "integer"
17311876
},
17321877
"gas_price": {
1733-
"type": "integer"
1878+
"type": "string"
17341879
},
17351880
"gas_used": {
17361881
"type": "integer"
@@ -1742,10 +1887,10 @@ const docTemplate = `{
17421887
"type": "string"
17431888
},
17441889
"max_fee_per_gas": {
1745-
"type": "integer"
1890+
"type": "string"
17461891
},
17471892
"max_priority_fee_per_gas": {
1748-
"type": "integer"
1893+
"type": "string"
17491894
},
17501895
"nonce": {
17511896
"type": "integer"
@@ -1772,7 +1917,7 @@ const docTemplate = `{
17721917
"type": "string"
17731918
},
17741919
"value": {
1775-
"type": "integer"
1920+
"type": "string"
17761921
}
17771922
}
17781923
},
@@ -1865,6 +2010,41 @@ const docTemplate = `{
18652010
"type": "string"
18662011
}
18672012
}
2013+
},
2014+
"handlers.TransferModel": {
2015+
"type": "object",
2016+
"properties": {
2017+
"amount": {
2018+
"type": "string"
2019+
},
2020+
"block_number": {
2021+
"type": "string"
2022+
},
2023+
"block_timestamp": {
2024+
"type": "string"
2025+
},
2026+
"from_address": {
2027+
"type": "string"
2028+
},
2029+
"log_index": {
2030+
"type": "integer"
2031+
},
2032+
"to_address": {
2033+
"type": "string"
2034+
},
2035+
"token_address": {
2036+
"type": "string"
2037+
},
2038+
"token_id": {
2039+
"type": "string"
2040+
},
2041+
"token_type": {
2042+
"type": "string"
2043+
},
2044+
"transaction_hash": {
2045+
"type": "string"
2046+
}
2047+
}
18682048
}
18692049
},
18702050
"securityDefinitions": {

0 commit comments

Comments
 (0)