psf-bch-api 7.3.9 → 7.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/server.js CHANGED
@@ -59,6 +59,7 @@ class Server {
59
59
  try {
60
60
  // Create an Express instance.
61
61
  const app = express()
62
+ app.set('trust proxy', true)
62
63
 
63
64
  const x402Settings = getX402Settings()
64
65
  const basicAuthSettings = getBasicAuthSettings()
@@ -183,7 +184,10 @@ class Server {
183
184
 
184
185
  // Request logging middleware
185
186
  app.use((req, res, next) => {
186
- wlogger.info(`${req.method} ${req.path}`)
187
+ wlogger.info(`${req.method} ${req.path}`, {
188
+ client_ip: req.ip,
189
+ remote_address: req.socket?.remoteAddress || null
190
+ })
187
191
  next()
188
192
  })
189
193
 
@@ -0,0 +1,21 @@
1
+ # 2026-03-16 Update Log
2
+
3
+ ## Summary
4
+
5
+ Reduced noisy error logging for common SLP transaction misses in the `/v6/slp/txid` path.
6
+
7
+ ## Changes Made
8
+
9
+ - Updated `src/use-cases/slp-use-cases.js` in `getTxid()`:
10
+ - Added a guard for expected missing-record errors (`404` + `Key not found in database`).
11
+ - Skips `wlogger.error()` for that specific, common case.
12
+ - Still rethrows the error so API response behavior is unchanged.
13
+ - Updated `src/controllers/rest-api/slp/controller.js` in `handleError()`:
14
+ - Added the same guard to suppress duplicate error-level logs for the same expected case.
15
+ - Keeps normal error logging for all other errors.
16
+
17
+ ## Outcome
18
+
19
+ - The common "Key not found in database" case no longer pollutes error logs.
20
+ - Unexpected failures continue to be logged at error level.
21
+ - Client-facing status and error message behavior remains unchanged.
@@ -0,0 +1,60 @@
1
+ # 2026-03-17 Update Log
2
+
3
+ ## Summary
4
+
5
+ Enhanced REST request logging to capture client network identity in Winston logs and enabled proxy-aware IP resolution.
6
+
7
+ ## Changes Made
8
+
9
+ - Updated `bin/server.js`:
10
+ - Set Express proxy handling with `app.set('trust proxy', true)`.
11
+ - Kept the current Winston request message format (`"${req.method} ${req.path}"`).
12
+ - Added structured Winston metadata fields to request logs:
13
+ - `client_ip` from `req.ip`
14
+ - `remote_address` from `req.socket.remoteAddress`
15
+
16
+ ## Useful Fields Available for REST Request Logging
17
+
18
+ - Routing and request basics:
19
+ - `method` (`req.method`)
20
+ - `path` (`req.path`)
21
+ - `original_url` (`req.originalUrl`)
22
+ - `query` (`req.query`)
23
+ - Client network identity:
24
+ - `client_ip` (`req.ip`)
25
+ - `forwarded_ips` (`req.ips`, when behind one or more proxies)
26
+ - `remote_address` (`req.socket.remoteAddress`)
27
+ - HTTP and transport:
28
+ - `protocol` (`req.protocol`)
29
+ - `secure` (`req.secure`)
30
+ - `http_version` (`req.httpVersion`)
31
+ - `host` (`req.get('host')`)
32
+ - `origin` (`req.get('origin')`)
33
+ - `referer` (`req.get('referer')`)
34
+ - `user_agent` (`req.get('user-agent')`)
35
+ - Request/response performance and size:
36
+ - `status_code` (`res.statusCode`, from `res.on('finish')`)
37
+ - `duration_ms` (elapsed time between request start and response finish)
38
+ - `request_size_bytes` (`req.get('content-length')`)
39
+ - `response_size_bytes` (`res.getHeader('content-length')`)
40
+ - App-specific request context in this codebase:
41
+ - `basic_auth_valid` (`req.locals.basicAuthValid`)
42
+ - x402 decision/bypass status (derived from middleware path and config)
43
+
44
+ ## Already Logging
45
+
46
+ - In Winston request logs:
47
+ - `message` with method + path (for example `GET /v6/full-node/blockchain/getBlockCount`)
48
+ - `client_ip`
49
+ - `remote_address`
50
+ - `timestamp` (from Winston timestamp formatter)
51
+ - `level`
52
+ - In console endpoint logs:
53
+ - Request line with method, path, and `req.ip`
54
+ - Response line with method, path, and final `res.statusCode`
55
+
56
+ ## Outcome
57
+
58
+ - Request logs now preserve existing behavior while adding IP attribution fields.
59
+ - `trust proxy` ensures `req.ip` is proxy-aware when the server is deployed behind a reverse proxy.
60
+ - The project now has a documented list of high-value request fields for future logging expansion.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "psf-bch-api",
3
- "version": "7.3.9",
3
+ "version": "7.3.11",
4
4
  "main": "psf-bch-api.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -208,7 +208,14 @@ class SlpRESTController {
208
208
  }
209
209
 
210
210
  handleError (err, res) {
211
- wlogger.error('Error in SlpRESTController:', err)
211
+ const isCommonMissingTxError =
212
+ err?.status === 404 &&
213
+ typeof err?.message === 'string' &&
214
+ err.message.includes('Key not found in database')
215
+
216
+ if (!isCommonMissingTxError) {
217
+ wlogger.error('Error in SlpRESTController:', err)
218
+ }
212
219
 
213
220
  const status = err.status || 500
214
221
  const message = err.message || 'Internal server error'
@@ -98,7 +98,14 @@ class SlpUseCases {
98
98
  try {
99
99
  return await this.slpIndexer.post('slp/tx/', { txid })
100
100
  } catch (err) {
101
- wlogger.error('Error in SlpUseCases.getTxid()', err)
101
+ const isCommonMissingTxError =
102
+ err?.status === 404 &&
103
+ typeof err?.message === 'string' &&
104
+ err.message.includes('Key not found in database')
105
+
106
+ if (!isCommonMissingTxError) {
107
+ wlogger.error('Error in SlpUseCases.getTxid()', err)
108
+ }
102
109
  throw err
103
110
  }
104
111
  }