mirror of
https://github.com/alexgo-io/stacks-blockchain-api.git
synced 2026-01-12 16:53:19 +08:00
Merge branch 'master' into develop
# Conflicts: # .vscode/tasks.json
This commit is contained in:
28
.vscode/launch.json
vendored
28
.vscode/launch.json
vendored
@@ -109,6 +109,34 @@
|
||||
},
|
||||
"killBehavior": "polite",
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch: mocknet offline-mode",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"runtimeArgs": [
|
||||
"-r",
|
||||
"ts-node/register/transpile-only",
|
||||
"-r",
|
||||
"tsconfig-paths/register"
|
||||
],
|
||||
"args": [
|
||||
"${workspaceFolder}/src/index.ts"
|
||||
],
|
||||
"outputCapture": "std",
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"preLaunchTask": "stacks-node:start-mocknet",
|
||||
"postDebugTask": "stacks-node:stop-mocknet",
|
||||
"env": {
|
||||
"STACKS_CHAIN_ID": "0x80000000",
|
||||
"NODE_ENV": "development",
|
||||
"STACKS_API_MODE": "offline",
|
||||
"TS_NODE_SKIP_IGNORE": "true"
|
||||
},
|
||||
"killBehavior": "polite",
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
|
||||
22
.vscode/tasks.json
vendored
22
.vscode/tasks.json
vendored
@@ -22,6 +22,28 @@
|
||||
},
|
||||
"presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "dedicated", "clear": false }
|
||||
},
|
||||
{
|
||||
"label": "stacks-node:start-mocknet",
|
||||
"type": "shell",
|
||||
"command": "docker compose -f docker/docker-compose.dev.stacks-blockchain.yml up --force-recreate -V",
|
||||
"isBackground": true,
|
||||
"problemMatcher": {
|
||||
"pattern": { "regexp": ".", "file": 1, "location": 2, "message": 3, },
|
||||
"background": { "activeOnStart": true, "beginsPattern": ".", "endsPattern": "." }
|
||||
},
|
||||
"presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "dedicated", "clear": false }
|
||||
},
|
||||
{
|
||||
"label": "stacks-node:stop-mocknet",
|
||||
"type": "shell",
|
||||
"command": "docker compose -f docker/docker-compose.dev.stacks-blockchain.yml down -v -t 0",
|
||||
"isBackground": true,
|
||||
"problemMatcher": {
|
||||
"pattern": { "regexp": ".", "file": 1, "location": 2, "message": 3, },
|
||||
"background": { "activeOnStart": true, "beginsPattern": ".", "endsPattern": "." }
|
||||
},
|
||||
"presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "dedicated", "clear": false }
|
||||
},
|
||||
{
|
||||
"label": "deploy:subnets",
|
||||
"type": "shell",
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
## [7.1.3](https://github.com/hirosystems/stacks-blockchain-api/compare/v7.1.2...v7.1.3) (2023-03-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* domain migration ([#1596](https://github.com/hirosystems/stacks-blockchain-api/issues/1596)) ([#1597](https://github.com/hirosystems/stacks-blockchain-api/issues/1597)) ([e348ac0](https://github.com/hirosystems/stacks-blockchain-api/commit/e348ac05b325272e0317b3af314469b3e94c0adc))
|
||||
* postgres should not be required in STACKS_API_MODE=offline mode [#1391](https://github.com/hirosystems/stacks-blockchain-api/issues/1391) ([#1599](https://github.com/hirosystems/stacks-blockchain-api/issues/1599)) ([299705f](https://github.com/hirosystems/stacks-blockchain-api/commit/299705f270981b226fdeae2c7c37c00ce16fe4ce))
|
||||
|
||||
## [7.1.2](https://github.com/hirosystems/stacks-blockchain-api/compare/v7.1.1...v7.1.2) (2023-03-22)
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { PgStoreEventEmitter } from './pg-store-event-emitter';
|
||||
import { PgStore } from './pg-store';
|
||||
import { PgWriteStore } from './pg-write-store';
|
||||
|
||||
export const OfflineDummyStore: PgStore = new Proxy(new EventEmitter() as PgStoreEventEmitter, {
|
||||
get(target: any, propKey) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
if (propKey === 'eventEmitter') return target;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
if (propKey in target) return target[propKey];
|
||||
return function () {
|
||||
throw new Error(
|
||||
`Cannot call function on the Dummy datastore. Check if the application is running in offline mode.`
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
export const OfflineDummyStore: PgWriteStore = new Proxy(
|
||||
new EventEmitter() as PgStoreEventEmitter,
|
||||
{
|
||||
get(target: any, propKey) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
if (propKey === 'eventEmitter') return target;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
if (propKey in target) return target[propKey];
|
||||
return function () {
|
||||
throw new Error(
|
||||
`Cannot call function on the Dummy datastore. Check if the application is running in offline mode.`
|
||||
);
|
||||
};
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
51
src/index.ts
51
src/index.ts
@@ -111,18 +111,21 @@ async function init(): Promise<void> {
|
||||
);
|
||||
}
|
||||
const apiMode = getApiMode();
|
||||
const dbStore =
|
||||
apiMode === StacksApiMode.offline
|
||||
? OfflineDummyStore
|
||||
: await PgStore.connect({
|
||||
usageName: `datastore-${apiMode}`,
|
||||
});
|
||||
const dbWriteStore = await PgWriteStore.connect({
|
||||
usageName: `write-datastore-${apiMode}`,
|
||||
skipMigrations: apiMode === StacksApiMode.readOnly,
|
||||
});
|
||||
|
||||
registerMempoolPromStats(dbWriteStore.eventEmitter);
|
||||
let dbStore: PgStore;
|
||||
let dbWriteStore: PgWriteStore;
|
||||
if (apiMode === StacksApiMode.offline) {
|
||||
dbStore = OfflineDummyStore;
|
||||
dbWriteStore = OfflineDummyStore;
|
||||
} else {
|
||||
dbStore = await PgStore.connect({
|
||||
usageName: `datastore-${apiMode}`,
|
||||
});
|
||||
dbWriteStore = await PgWriteStore.connect({
|
||||
usageName: `write-datastore-${apiMode}`,
|
||||
skipMigrations: apiMode === StacksApiMode.readOnly,
|
||||
});
|
||||
registerMempoolPromStats(dbWriteStore.eventEmitter);
|
||||
}
|
||||
|
||||
if (apiMode === StacksApiMode.default || apiMode === StacksApiMode.writeOnly) {
|
||||
const configuredChainID = getApiConfiguredChainID();
|
||||
@@ -168,7 +171,11 @@ async function init(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
if (apiMode === StacksApiMode.default || apiMode === StacksApiMode.readOnly) {
|
||||
if (
|
||||
apiMode === StacksApiMode.default ||
|
||||
apiMode === StacksApiMode.readOnly ||
|
||||
apiMode === StacksApiMode.offline
|
||||
) {
|
||||
const apiServer = await startApiServer({
|
||||
datastore: dbStore,
|
||||
writeDatastore: dbWriteStore,
|
||||
@@ -193,14 +200,16 @@ async function init(): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
registerShutdownConfig({
|
||||
name: 'DB',
|
||||
handler: async () => {
|
||||
await dbStore.close();
|
||||
await dbWriteStore.close();
|
||||
},
|
||||
forceKillable: false,
|
||||
});
|
||||
if (apiMode !== StacksApiMode.offline) {
|
||||
registerShutdownConfig({
|
||||
name: 'DB',
|
||||
handler: async () => {
|
||||
await dbStore.close();
|
||||
await dbWriteStore.close();
|
||||
},
|
||||
forceKillable: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (isProdEnv) {
|
||||
const prometheusServer = await createPrometheusServer({ port: 9153 });
|
||||
|
||||
Reference in New Issue
Block a user