-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
/extended/v2/mempool/fees
endpoint (#1795)
* docs: endpoints * feat: fees endpoint * test: strict eq
- Loading branch information
Showing
10 changed files
with
403 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"all": { | ||
"no_priority": 3000, | ||
"low_priority": 3000, | ||
"medium_priority": 6000, | ||
"high_priority": 401199 | ||
}, | ||
"token_transfer": { | ||
"no_priority": 3000, | ||
"low_priority": 3000, | ||
"medium_priority": 6000, | ||
"high_priority": 401199 | ||
}, | ||
"smart_contract": { | ||
"no_priority": 837500, | ||
"low_priority": 925000, | ||
"medium_priority": 1012500, | ||
"high_priority": 1082500 | ||
}, | ||
"contract_call": { | ||
"no_priority": 3000, | ||
"low_priority": 10368, | ||
"medium_priority": 100000, | ||
"high_priority": 1000000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"description": "GET request that returns fee priorities from mempool transactions", | ||
"title": "MempoolFeePriorities", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": [ | ||
"all" | ||
], | ||
"properties": { | ||
"all": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": [ | ||
"no_priority", | ||
"low_priority", | ||
"medium_priority", | ||
"high_priority" | ||
], | ||
"properties": { | ||
"no_priority": { | ||
"type": "integer" | ||
}, | ||
"low_priority": { | ||
"type": "integer" | ||
}, | ||
"medium_priority": { | ||
"type": "integer" | ||
}, | ||
"high_priority": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"token_transfer": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": [ | ||
"no_priority", | ||
"low_priority", | ||
"medium_priority", | ||
"high_priority" | ||
], | ||
"properties": { | ||
"no_priority": { | ||
"type": "integer" | ||
}, | ||
"low_priority": { | ||
"type": "integer" | ||
}, | ||
"medium_priority": { | ||
"type": "integer" | ||
}, | ||
"high_priority": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"smart_contract": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": [ | ||
"no_priority", | ||
"low_priority", | ||
"medium_priority", | ||
"high_priority" | ||
], | ||
"properties": { | ||
"no_priority": { | ||
"type": "integer" | ||
}, | ||
"low_priority": { | ||
"type": "integer" | ||
}, | ||
"medium_priority": { | ||
"type": "integer" | ||
}, | ||
"high_priority": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"contract_call": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": [ | ||
"no_priority", | ||
"low_priority", | ||
"medium_priority", | ||
"high_priority" | ||
], | ||
"properties": { | ||
"no_priority": { | ||
"type": "integer" | ||
}, | ||
"low_priority": { | ||
"type": "integer" | ||
}, | ||
"medium_priority": { | ||
"type": "integer" | ||
}, | ||
"high_priority": { | ||
"type": "integer" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as express from 'express'; | ||
import { asyncHandler } from '../async-handler'; | ||
import { | ||
ETagType, | ||
getETagCacheHandler, | ||
setETagCacheHeaders, | ||
} from '../controllers/cache-controller'; | ||
import { PgStore } from '../../datastore/pg-store'; | ||
import { DbMempoolFeePriority, DbTxTypeId } from '../../datastore/common'; | ||
import { MempoolFeePriorities } from '../../../docs/generated'; | ||
|
||
function parseMempoolFeePriority(fees: DbMempoolFeePriority[]): MempoolFeePriorities { | ||
const out: MempoolFeePriorities = { | ||
all: { no_priority: 0, low_priority: 0, medium_priority: 0, high_priority: 0 }, | ||
}; | ||
for (const fee of fees) { | ||
const value = { | ||
no_priority: fee.no_priority, | ||
low_priority: fee.low_priority, | ||
medium_priority: fee.medium_priority, | ||
high_priority: fee.high_priority, | ||
}; | ||
if (fee.type_id == null) out.all = value; | ||
else | ||
switch (fee.type_id) { | ||
case DbTxTypeId.TokenTransfer: | ||
out.token_transfer = value; | ||
break; | ||
case DbTxTypeId.ContractCall: | ||
out.contract_call = value; | ||
break; | ||
case DbTxTypeId.SmartContract: | ||
case DbTxTypeId.VersionedSmartContract: | ||
out.smart_contract = value; | ||
break; | ||
} | ||
} | ||
return out; | ||
} | ||
|
||
export function createMempoolRouter(db: PgStore): express.Router { | ||
const router = express.Router(); | ||
const mempoolCacheHandler = getETagCacheHandler(db, ETagType.mempool); | ||
|
||
router.get( | ||
'/fees', | ||
mempoolCacheHandler, | ||
asyncHandler(async (req, res, next) => { | ||
setETagCacheHeaders(res); | ||
res.status(200).json(parseMempoolFeePriority(await db.getMempoolFeePriority())); | ||
}) | ||
); | ||
|
||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.