Skip to content

Commit

Permalink
feat(api-transaction-pool): add configuration route and remove transa…
Browse files Browse the repository at this point in the history
…ctionPool on `node/configuration` from public api (#750)

* Remove dynamic fees

* Add configuration endpoint

* Remove transaction pool from node/configuration

* Add version

* Add height

* Fix integration tests
  • Loading branch information
sebastijankuzner authored Nov 4, 2024
1 parent ce343c5 commit c1d539a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
11 changes: 0 additions & 11 deletions packages/api-http/source/controllers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export class NodeController extends Controller {
public async configuration(request: Hapi.Request) {
const configuration = await this.getConfiguration();
const plugins = await this.getPlugins();
const transactionPoolConfiguration = plugins["@mainsail/transaction-pool"]?.configuration ?? {};

const cryptoConfiguration = configuration.cryptoConfiguration as Contracts.Crypto.NetworkConfig;
const network = cryptoConfiguration.network;
Expand All @@ -101,16 +100,6 @@ export class NodeController extends Controller {
slip44: network.slip44,
symbol: network.client.symbol,
token: network.client.token,
transactionPool: {
dynamicFees: transactionPoolConfiguration.dynamicFees?.enabled
? transactionPoolConfiguration.dynamicFees
: { enabled: false },
maxTransactionAge: transactionPoolConfiguration.maxTransactionAge,
maxTransactionBytes: transactionPoolConfiguration.maxTransactionBytes,
maxTransactionsInPool: transactionPoolConfiguration.maxTransactionsInPool,
maxTransactionsPerRequest: transactionPoolConfiguration.maxTransactionsPerRequest,
maxTransactionsPerSender: transactionPoolConfiguration.maxTransactionsPerSender,
},
version: network.pubKeyHash,
wif: network.wif,
},
Expand Down
5 changes: 0 additions & 5 deletions packages/api-http/test/fixtures/node_configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
"slip44": 1,
"symbol": "",
"token": "ARK",
"transactionPool": {
"dynamicFees": {
"enabled": false
}
},
"version": 30,
"wif": 186
}
33 changes: 33 additions & 0 deletions packages/api-transaction-pool/source/controllers/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Hapi from "@hapi/hapi";
import { AbstractController } from "@mainsail/api-common";
import { inject, injectable, tagged } from "@mainsail/container";
import { Contracts, Identifiers } from "@mainsail/contracts";
import { Providers } from "@mainsail/kernel";

@injectable()
export class ConfigurationController extends AbstractController {
@inject(Identifiers.ServiceProvider.Configuration)
@tagged("plugin", "transaction-pool-service")
private readonly pluginConfiguration!: Providers.PluginConfiguration;

@inject(Identifiers.State.Store)
private readonly stateStore!: Contracts.State.Store;

public async configuration(request: Hapi.Request) {
return {
data: {
core: {
version: this.app.version(),
},
height: this.stateStore.getHeight(),
transactionPool: {
maxTransactionAge: this.pluginConfiguration.get("maxTransactionAge"),
maxTransactionBytes: this.pluginConfiguration.get("maxTransactionBytes"),
maxTransactionsInPool: this.pluginConfiguration.get("maxTransactionsInPool"),
maxTransactionsPerRequest: this.pluginConfiguration.get("maxTransactionsPerRequest"),
maxTransactionsPerSender: this.pluginConfiguration.get("maxTransactionsPerSender"),
},
},
};
}
}
3 changes: 2 additions & 1 deletion packages/api-transaction-pool/source/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Contracts } from "@mainsail/contracts";

import * as Configuration from "./routes/configuration.js";
import * as Transactions from "./routes/transactions.js";

const config = {
name: "Transaction Pool API",
async register(server: Contracts.Api.ApiServer): Promise<void> {
const handlers = [Transactions];
const handlers = [Transactions, Configuration];

for (const handler of handlers) {
handler.register(server);
Expand Down
15 changes: 15 additions & 0 deletions packages/api-transaction-pool/source/routes/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Hapi from "@hapi/hapi";
import { Contracts } from "@mainsail/contracts";

import { ConfigurationController } from "../controllers/configuration.js";

export const register = (server: Contracts.Api.ApiServer): void => {
const controller = server.app.app.resolve(ConfigurationController);
server.bind(controller);

server.route({
handler: (request: Hapi.Request) => controller.configuration(request),
method: "GET",
path: "/configuration",
});
};

0 comments on commit c1d539a

Please sign in to comment.