feat: added a new endpoint fee_rate #729

This commit is contained in:
Asim Mehmood
2021-09-08 13:57:25 +05:00
committed by GitHub
parent 10b1c67d20
commit 7c09ac53a9
9 changed files with 113 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
{
"transaction": "0x5e9f3933e358df6a73fec0d47ce3e1062c20812c129f5294e6f37a8d27c051d9"
}

View File

@@ -0,0 +1,15 @@
{
"type": "object",
"title": "FeeRateRequest",
"description": "Request to fetch fee for a transaction",
"additionalProperties": false,
"required": [
"transaction"
],
"properties": {
"transaction": {
"type": "string",
"description": "A serialized transaction"
}
}
}

View File

@@ -0,0 +1,3 @@
{
"fee_rate": 360
}

View File

@@ -0,0 +1,14 @@
{
"title": "FeeRate",
"description": "Get fee rate information.",
"type": "object",
"additionalProperties": false,
"required": [
"fee_rate"
],
"properties": {
"fee_rate": {
"type": "integer"
}
}
}

17
docs/generated.d.ts vendored
View File

@@ -37,6 +37,8 @@ export type SchemaMergeRootStub =
| CoreNodeInfoResponse
| CoreNodePoxResponse
| RunFaucetResponse
| FeeRateRequest
| FeeRate
| NetworkBlockTimeResponse
| NetworkBlockTimesResponse
| ServerStatusResponse
@@ -1562,6 +1564,21 @@ export interface RunFaucetResponse {
*/
txRaw?: string;
}
/**
* Request to fetch fee for a transaction
*/
export interface FeeRateRequest {
/**
* A serialized transaction
*/
transaction: string;
}
/**
* Get fee rate information.
*/
export interface FeeRate {
fee_rate: number;
}
/**
* GET request that target block time for a given network
*/

View File

@@ -1083,7 +1083,7 @@ paths:
in: path
description: Stacks address or a contract identifier
required: true
schema:
schema:
type: string
- name: tx_id
in: path
@@ -1556,7 +1556,7 @@ paths:
content:
application/json:
schema:
$ref: ./api/search/search.schema.json
$ref: ./api/search/search.schema.json
example:
$ref: ./api/search/search-contract.example.json
404:
@@ -2659,3 +2659,28 @@ paths:
$ref: ./entities/tokens/fungible-token.schema.json
example:
$ref: ./entities/tokens/fungible-token.schema.example.json
/extended/v1/fee_rate:
post:
operationId: fetch_fee_rate
summary: fetch fee rate
description: Fetch fee rate information.
tags:
- fee_rate
responses:
200:
description: Transaction fee rate
content:
application/json:
schema:
$ref: ./api/info/get-fee-rate-response.schema.json
example:
$ref: ./api/info/get-fee-rate-response.example.json
requestBody:
required: true
content:
application/json:
schema:
$ref: ./api/info/get-fee-rate-request.schema.json
example:
$ref: ./api/info/get-fee-rate-request.example.json

View File

@@ -42,6 +42,7 @@ import { createMiddleware as createPrometheusMiddleware } from '@promster/expres
import { createMicroblockRouter } from './routes/microblock';
import { createStatusRouter } from './routes/status';
import { createTokenRouter } from './routes/tokens/tokens';
import { createFeeRateRouter } from './routes/fee-rate';
export interface ApiServer {
expressApp: ExpressWithAsync;
@@ -152,6 +153,7 @@ export async function startApiServer(opts: {
router.use('/stx_supply', createStxSupplyRouter(datastore));
router.use('/debug', createDebugRouter(datastore));
router.use('/status', createStatusRouter(datastore));
router.use('/fee_rate', createFeeRateRouter(datastore));
router.use('/faucets', createFaucetRouter(datastore));
router.use('/tokens', createTokenRouter(datastore));
return router;

View File

@@ -0,0 +1,20 @@
import * as express from 'express';
import { addAsync, RouterWithAsync } from '@awaitjs/express';
import { DataStore } from '../../datastore/common';
import { FeeRate } from '@stacks/stacks-blockchain-api-types';
export const FEE_RATE = 400;
export function createFeeRateRouter(_: DataStore): RouterWithAsync {
const router = addAsync(express.Router());
router.post('/', (req, res) => {
//validate and use req.body.transaction when we want to use it
const response: FeeRate = {
fee_rate: FEE_RATE,
};
res.json(response);
});
return router;
}

View File

@@ -42,6 +42,8 @@ import { startApiServer, ApiServer } from '../api/init';
import { PgDataStore, cycleMigrations, runMigrations } from '../datastore/postgres-store';
import { PoolClient } from 'pg';
import { bufferToHexPrefixString, I32_MAX, microStxToStx, STACKS_DECIMAL_PLACES } from '../helpers';
import { FEE_RATE } from './../api/routes/fee-rate';
import { FeeRateRequest } from 'docs/generated';
describe('api tests', () => {
let db: PgDataStore;
@@ -4998,6 +5000,16 @@ describe('api tests', () => {
expect(result4.body.results.length).toBe(0);
});
test('Get fee rate', async () => {
const request: FeeRateRequest = {
transaction: '0x5e9f3933e358df6a73fec0d47ce3e1062c20812c129f5294e6f37a8d27c051d9',
};
const result = await supertest(api.server).post('/extended/v1/fee_rate').send(request);
expect(result.status).toBe(200);
expect(result.type).toBe('application/json');
expect(result.body.fee_rate).toBe(FEE_RATE);
});
afterEach(async () => {
await api.terminate();
client.release();