Skip to content

Commit

Permalink
fix(api-http): evm transaction type fixes (#682)
Browse files Browse the repository at this point in the history
* update queries

* update test fixtures

* style: resolve style guide violations

---------

Co-authored-by: oXtxNt9U <[email protected]>
  • Loading branch information
oXtxNt9U and oXtxNt9U authored Aug 27, 2024
1 parent a7c6a97 commit 82dbbc0
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export const makeTransactionRepository = (dataSource: RepositoryDataSource): Tra

return this.createQueryBuilder()
.select(['type_group AS "typeGroup"', "type"])
.addSelect("COALESCE(AVG(fee), 0)::int8", "avg")
.addSelect("COALESCE(MIN(fee), 0)::int8", "min")
.addSelect("COALESCE(MAX(fee), 0)::int8", "max")
.addSelect("COALESCE(SUM(fee), 0)::int8", "sum")
.addSelect("TRUNC(COALESCE(AVG(fee), 0)::numeri)c", "avg")
.addSelect("TRUNC(COALESCE(MIN(fee), 0)::numeri)c", "min")
.addSelect("TRUNC(COALESCE(MAX(fee), 0)::numeri)c", "max")
.addSelect("TRUNC(COALESCE(SUM(fee), 0)::numeri)c", "sum")
.where("timestamp > :age AND fee >= :minFee", { age, minFee })
.groupBy("type_group")
.addGroupBy("type")
Expand All @@ -47,10 +47,10 @@ export const makeTransactionRepository = (dataSource: RepositoryDataSource): Tra
return this.manager.query<FeeStatistics[]>(
`
select t_outer.type_group as "typeGroup", t_outer.type as "type",
COALESCE(AVG(fee), 0)::int8 AS "avg",
COALESCE(MIN(fee), 0)::int8 AS "min",
COALESCE(MIN(fee), 0)::int8 AS "max",
COALESCE(MAX(fee), 0)::int8 AS "sum"
TRUNC(COALESCE(AVG(fee), 0)::numeric) AS "avg",
TRUNC(COALESCE(MIN(fee), 0)::numeric) AS "min",
TRUNC(COALESCE(MIN(fee), 0)::numeric) AS "max",
TRUNC(COALESCE(MAX(fee), 0)::numeric) AS "sum"
from transactions t_outer
join lateral (
select 1 from transactions t_inner
Expand Down
1 change: 1 addition & 0 deletions packages/api-http/integration/routes/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe<{
ValidatorResignation: 7,
UsernameRegistration: 8,
UsernameResignation: 9,
EvmCall: 10,
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/api-http/source/controllers/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class TransactionsController extends Controller {
typeGroups[typeGroup] = {};
}

typeGroups[typeGroup][key] = staticFees[key].toFixed() ?? "0";
typeGroups[typeGroup][key] = staticFees[key]?.toFixed() ?? "0";
}

return { data: typeGroups };
Expand Down
6 changes: 6 additions & 0 deletions packages/api-http/test/fixtures/node_fees.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"max": "0",
"min": "0",
"sum": "0"
},
"evmCall": {
"avg": "0",
"max": "0",
"min": "0",
"sum": "0"
}
}
}
3 changes: 2 additions & 1 deletion packages/api-http/test/fixtures/transactions_fees.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"multiPayment": "10000000",
"validatorResignation": "2500000000",
"usernameRegistration": "2500000000",
"usernameResignation": "2500000000"
"usernameResignation": "2500000000",
"evmCall": "0"
}
}
91 changes: 90 additions & 1 deletion packages/api-http/test/fixtures/transactions_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"$ref": "publicKey"
},
"maxItems": 16,
"minItems": 1,
"minItems": 2,
"uniqueItems": true
}
},
Expand Down Expand Up @@ -662,6 +662,95 @@
"senderPublicKey": {
"$ref": "publicKey"
}
},
"10": {
"id": {
"anyOf": [
{
"$ref": "transactionId"
},
{
"type": "null"
}
]
},
"fee": {
"bignumber": {
"maximum": 1000,
"minimum": 5
}
},
"type": {
"transactionType": 10
},
"asset": {
"type": "object",
"required": ["evmCall"],
"properties": {
"evmCall": {
"type": "object",
"required": ["gasLimit", "payload"],
"properties": {
"payload": {
"bytecode": {}
},
"gasLimit": {
"transactionGasLimit": {}
}
},
"unevaluatedProperties": false
}
},
"unevaluatedProperties": false
},
"nonce": {
"bignumber": {
"minimum": 0
}
},
"amount": {
"bignumber": {
"maximum": 0,
"minimum": 0
}
},
"network": {
"$ref": "networkByte"
},
"version": {
"enum": [1]
},
"signature": {
"$ref": "alphanumeric"
},
"typeGroup": {
"type": "integer",
"minimum": 0
},
"signatures": {
"type": "array",
"items": {
"type": "string",
"allOf": [
{
"maxLength": 130,
"minLength": 130
},
{
"$ref": "alphanumeric"
}
]
},
"maxItems": 16,
"minItems": 1,
"uniqueItems": true
},
"recipientId": {
"$ref": "address"
},
"senderPublicKey": {
"$ref": "publicKey"
}
}
}
}
97 changes: 96 additions & 1 deletion packages/api-http/test/fixtures/transactions_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
"$ref": "publicKey"
},
"maxItems": 16,
"minItems": 1,
"minItems": 2,
"uniqueItems": true
}
},
Expand Down Expand Up @@ -709,5 +709,100 @@
"$ref": "publicKey"
}
}
},
{
"type": 10,
"typeGroup": 1,
"version": 1,
"key": "evmCall",
"schema": {
"id": {
"anyOf": [
{
"$ref": "transactionId"
},
{
"type": "null"
}
]
},
"fee": {
"bignumber": {
"maximum": 1000,
"minimum": 5
}
},
"type": {
"transactionType": 10
},
"asset": {
"type": "object",
"required": ["evmCall"],
"properties": {
"evmCall": {
"type": "object",
"required": ["gasLimit", "payload"],
"properties": {
"payload": {
"bytecode": {}
},
"gasLimit": {
"transactionGasLimit": {}
}
},
"unevaluatedProperties": false
}
},
"unevaluatedProperties": false
},
"nonce": {
"bignumber": {
"minimum": 0
}
},
"amount": {
"bignumber": {
"maximum": 0,
"minimum": 0
}
},
"network": {
"$ref": "networkByte"
},
"version": {
"enum": [1]
},
"signature": {
"$ref": "alphanumeric"
},
"typeGroup": {
"type": "integer",
"minimum": 0
},
"signatures": {
"type": "array",
"items": {
"type": "string",
"allOf": [
{
"maxLength": 130,
"minLength": 130
},
{
"$ref": "alphanumeric"
}
]
},
"maxItems": 16,
"minItems": 1,
"uniqueItems": true
},
"recipientId": {
"$ref": "address"
},
"senderPublicKey": {
"$ref": "publicKey"
}
}
}
]

0 comments on commit 82dbbc0

Please sign in to comment.