Skip to content

Commit 64796e9

Browse files
committed
refactor: removed unecessary global server
1 parent bee1aae commit 64796e9

File tree

16 files changed

+11
-115
lines changed

16 files changed

+11
-115
lines changed

.gitpod.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ ENV STACKS_CORE_EVENT_PORT 3700
1515
ENV STACKS_CORE_EVENT_HOST http://0.0.0.0
1616
ENV STACKS_BLOCKCHAIN_API_PORT 3999
1717
ENV STACKS_BLOCKCHAIN_API_HOST 0.0.0.0
18-
ENV STACKS_BLOCKCHAIN_API_DB pg
1918
ENV STACKS_CORE_RPC_HOST 127.0.0.1
2019
ENV STACKS_CORE_RPC_PORT 20443
2120
ENV NODE_ENV development

.vscode/launch.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"preLaunchTask": "stacks-node:deploy-dev",
4343
"postDebugTask": "stacks-node:stop-dev",
4444
"env": {
45-
"STACKS_BLOCKCHAIN_API_DB": "pg",
4645
"STACKS_CHAIN_ID": "0x80000000",
4746
"NODE_ENV": "development",
4847
"TS_NODE_SKIP_IGNORE": "true"
@@ -64,7 +63,6 @@
6463
"postDebugTask": "stacks-node:stop-dev",
6564
"env": {
6665
"STACKS_API_MODE": "writeonly",
67-
"STACKS_BLOCKCHAIN_API_DB": "pg",
6866
"STACKS_CHAIN_ID": "0x80000000",
6967
"NODE_ENV": "development",
7068
"TS_NODE_SKIP_IGNORE": "true"
@@ -92,7 +90,6 @@
9290
"env": {
9391
"STACKS_BLOCKCHAIN_API_PORT": "3998",
9492
"STACKS_API_MODE": "readonly",
95-
"STACKS_BLOCKCHAIN_API_DB": "pg",
9693
"STACKS_CHAIN_ID": "0x80000000",
9794
"NODE_ENV": "development",
9895
"TS_NODE_SKIP_IGNORE": "true"
@@ -110,7 +107,6 @@
110107
"preLaunchTask": "stacks-node:deploy-follower",
111108
"postDebugTask": "stacks-node:stop-dev",
112109
"env": {
113-
"STACKS_BLOCKCHAIN_API_DB": "pg",
114110
"STACKS_CHAIN_ID": "0x00000001",
115111
"NODE_ENV": "development",
116112
"TS_NODE_SKIP_IGNORE": "true"

docker/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ services:
4242
STACKS_CORE_EVENT_HOST: http://0.0.0.0
4343
STACKS_BLOCKCHAIN_API_PORT: 3999
4444
STACKS_BLOCKCHAIN_API_HOST: 0.0.0.0
45-
STACKS_BLOCKCHAIN_API_DB: pg
4645
STACKS_CORE_RPC_HOST: stacks-blockchain
4746
STACKS_CORE_RPC_PORT: 20443
4847
NODE_ENV: development

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6-
"dev": "cross-env NODE_ENV=development STACKS_BLOCKCHAIN_API_DB=pg STACKS_CHAIN_ID=0x80000000 ts-node-transpile-only src/index.ts",
7-
"dev:watch": "cross-env NODE_ENV=development STACKS_BLOCKCHAIN_API_DB=pg nodemon -e ts -x 'ts-node-transpile-only src/index.ts'",
6+
"dev": "cross-env NODE_ENV=development STACKS_CHAIN_ID=0x80000000 ts-node-transpile-only src/index.ts",
7+
"dev:watch": "cross-env NODE_ENV=development nodemon -e ts -x 'ts-node-transpile-only src/index.ts'",
88
"dev:integrated": "npm run devenv:build && concurrently npm:dev npm:devenv:deploy",
99
"dev:follower": "npm run devenv:build && concurrently npm:dev npm:devenv:follower",
1010
"test": "cross-env NODE_ENV=development jest --config ./jest.config.js --coverage --runInBand",

running_an_api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ STACKS_CORE_EVENT_PORT=3700
159159
STACKS_CORE_EVENT_HOST=0.0.0.0
160160
STACKS_BLOCKCHAIN_API_PORT=3999
161161
STACKS_BLOCKCHAIN_API_HOST=0.0.0.0
162-
STACKS_BLOCKCHAIN_API_DB=pg
163162
STACKS_CORE_RPC_HOST=stacks-blockchain
164163
STACKS_CORE_RPC_PORT=20443
165164
BNS_IMPORT_DIR=/bns-data

running_api_from_source.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ STACKS_CORE_EVENT_PORT=3700
146146
STACKS_CORE_EVENT_HOST=0.0.0.0
147147
STACKS_BLOCKCHAIN_API_PORT=3999
148148
STACKS_BLOCKCHAIN_API_HOST=0.0.0.0
149-
STACKS_BLOCKCHAIN_API_DB=pg
150149
STACKS_CORE_RPC_HOST=localhost
151150
STACKS_CORE_RPC_PORT=20443
152151
#BNS_IMPORT_DIR=/stacks-node/bns

src/datastore/postgres-store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,6 @@ export class PgDataStore
29862986
`,
29872987
[limit, offset]
29882988
);
2989-
console.log('printing results here: ', results);
29902989
const parsed = results.rows.map(r => this.parseBlockQueryResult(r));
29912990
return { results: parsed, total: total.rows[0].count } as const;
29922991
});

src/index.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,11 @@ async function init(): Promise<void> {
139139
if (apiMode === StacksApiMode.offline) {
140140
db = OfflineDummyStore;
141141
} else {
142-
switch (process.env['STACKS_BLOCKCHAIN_API_DB']) {
143-
case 'pg':
144-
case undefined: {
145-
const skipMigrations = apiMode === StacksApiMode.readOnly;
146-
db = await PgDataStore.connect({
147-
usageName: `datastore-${apiMode}`,
148-
skipMigrations: skipMigrations,
149-
});
150-
break;
151-
}
152-
default: {
153-
throw new Error(
154-
`Invalid STACKS_BLOCKCHAIN_API_DB option: "${process.env['STACKS_BLOCKCHAIN_API_DB']}"`
155-
);
156-
}
157-
}
142+
const skipMigrations = apiMode === StacksApiMode.readOnly;
143+
db = await PgDataStore.connect({
144+
usageName: `datastore-${apiMode}`,
145+
skipMigrations: skipMigrations,
146+
});
158147

159148
if (apiMode !== StacksApiMode.readOnly) {
160149
if (db instanceof PgDataStore) {

src/tests-bns/setup.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
import { loadDotEnv } from '../helpers';
22
import { StacksCoreRpcClient } from '../core-rpc/client';
3-
import { PgDataStore } from '../datastore/postgres-store';
4-
5-
export interface GlobalServices {
6-
db: PgDataStore;
7-
}
83

94
// ts-unused-exports:disable-next-line
105
export default async (): Promise<void> => {
116
console.log('Jest - setup..');
12-
if (!process.env.NODE_ENV) {
13-
process.env.NODE_ENV = 'test';
14-
}
157
loadDotEnv();
16-
const db = await PgDataStore.connect({ skipMigrations: true, usageName: 'tests' });
178
console.log('Waiting for RPC connection to core node..');
189
await new StacksCoreRpcClient().waitForConnection(60000);
19-
const globalServices: GlobalServices = {
20-
db: db,
21-
};
22-
Object.assign(global, globalServices);
2310
console.log('Jest - setup done');
2411
};

src/tests-bns/teardown.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import type { GlobalServices } from './setup';
2-
31
// ts-unused-exports:disable-next-line
42
export default async (): Promise<void> => {
53
console.log('Jest - teardown..');
6-
const globalServices = (global as unknown) as GlobalServices;
7-
await globalServices.db.close();
84
console.log('Jest - teardown done');
95
};

src/tests-rosetta/setup.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
import { loadDotEnv } from '../helpers';
22
import { StacksCoreRpcClient } from '../core-rpc/client';
3-
import { PgDataStore } from '../datastore/postgres-store';
4-
5-
export interface GlobalServices {
6-
db: PgDataStore;
7-
}
83

94
// ts-unused-exports:disable-next-line
105
export default async (): Promise<void> => {
116
console.log('Jest - setup..');
12-
if (!process.env.NODE_ENV) {
13-
process.env.NODE_ENV = 'test';
14-
}
157
loadDotEnv();
16-
const db = await PgDataStore.connect({skipMigrations: true, usageName: 'tests' });
178
console.log('Waiting for RPC connection to core node..');
189
await new StacksCoreRpcClient().waitForConnection(60000);
19-
const globalServices: GlobalServices = {
20-
db: db,
21-
};
22-
Object.assign(global, globalServices);
2310
console.log('Jest - setup done');
2411
};

src/tests-rosetta/teardown.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import type { GlobalServices } from './setup';
2-
31
// ts-unused-exports:disable-next-line
42
export default async (): Promise<void> => {
53
console.log('Jest - teardown..');
6-
const globalServices = (global as unknown) as GlobalServices;
7-
await globalServices.db.close();
84
console.log('Jest - teardown done');
95
};

src/tests-tokens/setup.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
import { loadDotEnv } from '../helpers';
2-
import { StacksCoreRpcClient } from '../core-rpc/client';
3-
import { PgDataStore } from '../datastore/postgres-store';
4-
5-
export interface GlobalServices {
6-
db: PgDataStore;
7-
}
8-
92
// ts-unused-exports:disable-next-line
10-
export default async (): Promise<void> => {
3+
export default (): void => {
114
console.log('Jest - setup..');
12-
if (!process.env.NODE_ENV) {
13-
process.env.NODE_ENV = 'test';
14-
}
155
loadDotEnv();
16-
const db = await PgDataStore.connect({ skipMigrations: true, usageName: 'tests' });
17-
console.log('Waiting for RPC connection to core node..');
18-
await new StacksCoreRpcClient().waitForConnection(60000);
19-
const globalServices: GlobalServices = {
20-
db: db,
21-
};
22-
Object.assign(global, globalServices);
236
console.log('Jest - setup done');
247
};

src/tests-tokens/teardown.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import type { GlobalServices } from './setup';
2-
31
// ts-unused-exports:disable-next-line
4-
export default async (): Promise<void> => {
2+
export default (): void => {
53
console.log('Jest - teardown..');
6-
const globalServices = (global as unknown) as GlobalServices;
7-
await globalServices.db.close();
84
console.log('Jest - teardown done');
95
};

src/tests/setup.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import * as WebSocket from 'ws';
21
import { loadDotEnv } from '../helpers';
3-
import { startEventServer } from '../event-stream/event-server';
42
import { StacksCoreRpcClient } from '../core-rpc/client';
5-
import { ChainID } from '@stacks/transactions';
6-
import { PgDataStore } from '../datastore/postgres-store';
73

84
// ts-unused-exports:disable-next-line
95
export default async (): Promise<void> => {
@@ -13,22 +9,6 @@ export default async (): Promise<void> => {
139
}
1410
loadDotEnv();
1511
process.env.PG_DATABASE = 'postgres';
16-
const db = await PgDataStore.connect({ skipMigrations: true, usageName: 'setup' });
17-
const server = await startEventServer({
18-
chainId: ChainID.Testnet,
19-
datastore: db,
20-
messageHandler: {
21-
handleBlockMessage: () => {},
22-
handleBurnBlock: () => {},
23-
handleMempoolTxs: () => {},
24-
handleDroppedMempoolTxs: () => {},
25-
handleNewAttachment: () => {},
26-
handleRawEventRequest: () => {},
27-
handleMicroblockMessage: () => {},
28-
},
29-
httpLogLevel: 'silly',
30-
});
31-
Object.assign(global, { server: server, db: db });
3212
console.log('Waiting for RPC connection to core node..');
3313
await new StacksCoreRpcClient().waitForConnection(60000);
3414
console.log('Jest - setup done');

src/tests/teardown.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
import * as isCI from 'is-ci';
2-
import { PgDataStore } from '../datastore/postgres-store';
32

43
// ts-unused-exports:disable-next-line
5-
export default async (): Promise<void> => {
6-
console.log('Jest - teardown..');
7-
const eventSocketServer: import('net').Server = (global as any).server;
8-
const database: PgDataStore = (global as any).db;
9-
await new Promise<void>(async resolve => {
10-
eventSocketServer.close();
11-
await database.close();
12-
console.log('Jest - teardown done');
13-
resolve();
14-
});
4+
export default (): void => {
5+
console.log('Jest - teardown');
156

167
// If running in CI setup the "why am I still running?" log to detect stuck Jest tests
178
if (isCI) {

0 commit comments

Comments
 (0)