Skip to content

chore(dapi)!: disable unnecessary for v1 endpoints #1857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions packages/dapi/doc/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@

## Layer 1 endpoints

### generate

Note: regtest only

Generates blocks on demand for regression tests.

##### Params

| name | type | description |
|---------|--------|----------------------------------------|
| args.amount | number | Amount of blocks to generate |

##### Response

| name | type | description |
|--------------|------------------------|------------------------------------------------------------|
| blockHashes | promise (string array) | Returns a promise containing strings of block hashes |

---

### getBestBlockHash

Returns best block hash (hash of the chaintip)
Expand Down
73 changes: 37 additions & 36 deletions packages/dapi/lib/grpcServer/handlers/core/coreHandlersFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ const {
BroadcastTransactionRequest,
GetTransactionRequest,
GetBlockchainStatusRequest,
GetMasternodeStatusRequest,
GetBlockRequest,
// GetMasternodeStatusRequest,
// GetBlockRequest,
pbjs: {
BroadcastTransactionRequest: PBJSBroadcastTransactionRequest,
BroadcastTransactionResponse: PBJSBroadcastTransactionResponse,
GetTransactionRequest: PBJSGetTransactionRequest,
GetTransactionResponse: PBJSGetTransactionResponse,
GetBlockchainStatusRequest: PBJSGetBlockchainStatusRequest,
GetBlockchainStatusResponse: PBJSGetBlockchainStatusResponse,
GetMasternodeStatusRequest: PBJSGetMasternodeStatusRequest,
GetMasternodeStatusResponse: PBJSGetMasternodeStatusResponse,
GetBlockRequest: PBJSGetBlockRequest,
GetBlockResponse: PBJSGetBlockResponse,
// GetMasternodeStatusRequest: PBJSGetMasternodeStatusRequest,
// GetMasternodeStatusResponse: PBJSGetMasternodeStatusResponse,
// GetBlockRequest: PBJSGetBlockRequest,
// GetBlockResponse: PBJSGetBlockResponse,
},
},
} = require('@dashevo/dapi-grpc');

const logger = require('../../../logger');

const getBlockHandlerFactory = require(
'./getBlockHandlerFactory',
);
// const getBlockHandlerFactory = require(
// './getBlockHandlerFactory',
// );
const getBlockchainStatusHandlerFactory = require(
'./getBlockchainStatusHandlerFactory',
);
const getMasternodeStatusHandlerFactory = require(
'./getMasternodeStatusHandlerFactory',
);
// const getMasternodeStatusHandlerFactory = require(
// './getMasternodeStatusHandlerFactory',
// );
const getTransactionHandlerFactory = require(
'./getTransactionHandlerFactory',
);
Expand All @@ -62,17 +62,17 @@ function coreHandlersFactory(coreRPCClient, isProductionEnvironment) {
const wrapInErrorHandler = wrapInErrorHandlerFactory(logger, isProductionEnvironment);

// getBlock
const getBlockHandler = getBlockHandlerFactory(coreRPCClient);
const wrappedGetBlock = jsonToProtobufHandlerWrapper(
jsonToProtobufFactory(
GetBlockRequest,
PBJSGetBlockRequest,
),
protobufToJsonFactory(
PBJSGetBlockResponse,
),
wrapInErrorHandler(getBlockHandler),
);
// const getBlockHandler = getBlockHandlerFactory(coreRPCClient);
// const wrappedGetBlock = jsonToProtobufHandlerWrapper(
// jsonToProtobufFactory(
// GetBlockRequest,
// PBJSGetBlockRequest,
// ),
// protobufToJsonFactory(
// PBJSGetBlockResponse,
// ),
// wrapInErrorHandler(getBlockHandler),
// );

// getBlockchainStatus
const getBlockchainStatusHandler = getBlockchainStatusHandlerFactory(coreRPCClient);
Expand All @@ -88,17 +88,17 @@ function coreHandlersFactory(coreRPCClient, isProductionEnvironment) {
);

// getMasternodeStatus
const getMasternodeStatusHandler = getMasternodeStatusHandlerFactory(coreRPCClient);
const wrappedGetMasternodeStatus = jsonToProtobufHandlerWrapper(
jsonToProtobufFactory(
GetMasternodeStatusRequest,
PBJSGetMasternodeStatusRequest,
),
protobufToJsonFactory(
PBJSGetMasternodeStatusResponse,
),
wrapInErrorHandler(getMasternodeStatusHandler),
);
// const getMasternodeStatusHandler = getMasternodeStatusHandlerFactory(coreRPCClient);
// const wrappedGetMasternodeStatus = jsonToProtobufHandlerWrapper(
// jsonToProtobufFactory(
// GetMasternodeStatusRequest,
// PBJSGetMasternodeStatusRequest,
// ),
// protobufToJsonFactory(
// PBJSGetMasternodeStatusResponse,
// ),
// wrapInErrorHandler(getMasternodeStatusHandler),
// );

// getTransaction
const getTransactionHandler = getTransactionHandlerFactory(coreRPCClient);
Expand Down Expand Up @@ -127,9 +127,10 @@ function coreHandlersFactory(coreRPCClient, isProductionEnvironment) {
);

return {
getBlock: wrappedGetBlock,
// TODO: Enable when an attack resistance is proved
// getBlock: wrappedGetBlock,
getBlockchainStatus: wrappedGetBlockchainStatus,
getMasternodeStatus: wrappedGetMasternodeStatus,
// getMasternodeStatus: wrappedGetMasternodeStatus,
getTransaction: wrappedGetTransaction,
broadcastTransaction: wrappedBroadcastTransaction,
};
Expand Down
87 changes: 0 additions & 87 deletions packages/dapi/lib/rpcServer/commands/generateToAddress.js

This file was deleted.

20 changes: 3 additions & 17 deletions packages/dapi/lib/rpcServer/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const jayson = require('jayson/promise');
const { isRegtest, isDevnet } = require('../utils');
const errorHandlerDecorator = require('./errorHandlerDecorator');

const getBestBlockHash = require('./commands/getBestBlockHash');
const getBlockHash = require('./commands/getBlockHash');
const getMnListDiff = require('./commands/getMnListDiff');
const generateToAddress = require('./commands/generateToAddress');

// Following commands are not implemented yet:
// const getVersion = require('./commands/getVersion');
Expand All @@ -16,10 +14,6 @@ const createCommands = (dashcoreAPI) => ({
getMnListDiff: getMnListDiff(dashcoreAPI),
});

const createRegtestCommands = (dashcoreAPI) => ({
generateToAddress: generateToAddress(dashcoreAPI),
});

/**
* Starts RPC server
* @param options
Expand All @@ -33,29 +27,21 @@ const createRegtestCommands = (dashcoreAPI) => ({
*/
const start = ({
port,
networkType,
dashcoreAPI,
logger,
}) => {
const commands = createCommands(
dashcoreAPI,
);

const areRegtestCommandsEnabled = isRegtest(networkType) || isDevnet(networkType);

const allCommands = areRegtestCommandsEnabled
? Object.assign(commands, createRegtestCommands(dashcoreAPI))
: commands;

/*
Decorate all commands with decorator that will intercept errors and format
them before passing to user.
*/
Object.keys(allCommands).forEach((commandName) => {
allCommands[commandName] = errorHandlerDecorator(allCommands[commandName], logger);
Object.keys(commands).forEach((commandName) => {
commands[commandName] = errorHandlerDecorator(commands[commandName], logger);
});

const server = jayson.server(allCommands);
const server = jayson.server(commands);
server.http().listen(port);
};

Expand Down
1 change: 0 additions & 1 deletion packages/dapi/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ async function main() {
logger.info('Starting JSON RPC server');
rpcServer.start({
port: config.rpcServer.port,
networkType: config.network,
dashcoreAPI: dashCoreRpcClient,
logger,
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const createClientWithoutWallet = require('../../../lib/test/createClientWithout

const { Core: { Block }, Essentials: { Buffer } } = Dash;

describe('Core', () => {
describe.skip('Core', () => {
describe('getBlock', () => {
let client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { Essentials: { Buffer } } = require('dash');

const createClientWithoutWallet = require('../../../lib/test/createClientWithoutWallet');

describe('Core', () => {
describe.skip('Core', () => {
describe('getMasternodeStatus', function main() {
let client;

Expand Down
Loading
Loading