psf-bch-api 7.3.3 → 7.3.5
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/package.json
CHANGED
|
@@ -424,7 +424,20 @@ class FulcrumRESTController {
|
|
|
424
424
|
|
|
425
425
|
const cashAddr = this._validateAndConvertAddress(address)
|
|
426
426
|
|
|
427
|
-
|
|
427
|
+
// Extract bearer token from request header if present
|
|
428
|
+
let bearerToken = null
|
|
429
|
+
if (req.headers && req.headers.authorization) {
|
|
430
|
+
const parts = req.headers.authorization.split(' ')
|
|
431
|
+
if (parts.length === 2 && parts[0] === 'Bearer') {
|
|
432
|
+
bearerToken = parts[1]
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const result = await this.fulcrumUseCases.getTransactions({
|
|
437
|
+
address: cashAddr,
|
|
438
|
+
allTxs,
|
|
439
|
+
bearerToken
|
|
440
|
+
})
|
|
428
441
|
return res.status(200).json(result)
|
|
429
442
|
} catch (err) {
|
|
430
443
|
return this.handleError(err, res)
|
|
@@ -470,9 +483,19 @@ class FulcrumRESTController {
|
|
|
470
483
|
}
|
|
471
484
|
}
|
|
472
485
|
|
|
486
|
+
// Extract bearer token from request header if present
|
|
487
|
+
let bearerToken = null
|
|
488
|
+
if (req.headers && req.headers.authorization) {
|
|
489
|
+
const parts = req.headers.authorization.split(' ')
|
|
490
|
+
if (parts.length === 2 && parts[0] === 'Bearer') {
|
|
491
|
+
bearerToken = parts[1]
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
473
495
|
const result = await this.fulcrumUseCases.getTransactionsBulk({
|
|
474
496
|
addresses: validatedAddresses,
|
|
475
|
-
allTxs
|
|
497
|
+
allTxs,
|
|
498
|
+
bearerToken
|
|
476
499
|
})
|
|
477
500
|
return res.status(200).json(result)
|
|
478
501
|
} catch (err) {
|
|
@@ -6,9 +6,14 @@ import wlogger from '../adapters/wlogger.js'
|
|
|
6
6
|
import BCHJS from '@psf/bch-js'
|
|
7
7
|
import config from '../config/index.js'
|
|
8
8
|
|
|
9
|
+
// Use RESTURL (from test) or REST_URL (from psf-bch-api config) or fallback to config
|
|
10
|
+
const restURL = process.env.RESTURL || process.env.REST_URL || process.env.LOCAL_RESTURL || config.restURL
|
|
11
|
+
// Use BCHJSBEARERTOKEN (from test) or BASIC_AUTH_TOKEN (from psf-bch-api config) or fallback to config
|
|
12
|
+
const bearerToken = process.env.BCHJSBEARERTOKEN || process.env.BASIC_AUTH_TOKEN || config.basicAuth.token
|
|
13
|
+
|
|
9
14
|
const bchjs = new BCHJS({
|
|
10
|
-
restURL
|
|
11
|
-
bearerToken
|
|
15
|
+
restURL,
|
|
16
|
+
bearerToken
|
|
12
17
|
})
|
|
13
18
|
|
|
14
19
|
class FulcrumUseCases {
|
|
@@ -101,13 +106,24 @@ class FulcrumUseCases {
|
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
|
|
104
|
-
async getTransactions ({ address, allTxs }) {
|
|
109
|
+
async getTransactions ({ address, allTxs, bearerToken = null }) {
|
|
105
110
|
try {
|
|
106
111
|
const response = await this.fulcrum.get(`electrumx/transactions/${address}`)
|
|
107
112
|
|
|
108
113
|
// Sort transactions in descending order, so that newest transactions are first.
|
|
109
114
|
if (response.transactions && Array.isArray(response.transactions)) {
|
|
110
|
-
|
|
115
|
+
// Use bearer token from request if provided, otherwise use the default bchjs instance
|
|
116
|
+
let bchjsInstance = this.bchjs
|
|
117
|
+
if (bearerToken) {
|
|
118
|
+
// Create a temporary bchjs instance with the bearer token from the request
|
|
119
|
+
const restURL = process.env.RESTURL || process.env.REST_URL || process.env.LOCAL_RESTURL || config.restURL
|
|
120
|
+
bchjsInstance = new BCHJS({
|
|
121
|
+
restURL,
|
|
122
|
+
bearerToken
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
response.transactions = await bchjsInstance.Electrumx.sortAllTxs(response.transactions, 'DESCENDING')
|
|
111
127
|
|
|
112
128
|
if (!allTxs) {
|
|
113
129
|
// Return only the first 100 transactions of the history.
|
|
@@ -122,16 +138,27 @@ class FulcrumUseCases {
|
|
|
122
138
|
}
|
|
123
139
|
}
|
|
124
140
|
|
|
125
|
-
async getTransactionsBulk ({ addresses, allTxs }) {
|
|
141
|
+
async getTransactionsBulk ({ addresses, allTxs, bearerToken = null }) {
|
|
126
142
|
try {
|
|
127
143
|
const response = await this.fulcrum.post('electrumx/transactions/', { addresses })
|
|
128
144
|
|
|
129
145
|
// Sort transactions in descending order for each address entry.
|
|
130
146
|
if (response.transactions && Array.isArray(response.transactions)) {
|
|
147
|
+
// Use bearer token from request if provided, otherwise use the default bchjs instance
|
|
148
|
+
let bchjsInstance = this.bchjs
|
|
149
|
+
if (bearerToken) {
|
|
150
|
+
// Create a temporary bchjs instance with the bearer token from the request
|
|
151
|
+
const restURL = process.env.RESTURL || process.env.REST_URL || process.env.LOCAL_RESTURL || config.restURL
|
|
152
|
+
bchjsInstance = new BCHJS({
|
|
153
|
+
restURL,
|
|
154
|
+
bearerToken
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
131
158
|
for (let i = 0; i < response.transactions.length; i++) {
|
|
132
159
|
const thisEntry = response.transactions[i]
|
|
133
160
|
if (thisEntry.transactions && Array.isArray(thisEntry.transactions)) {
|
|
134
|
-
thisEntry.transactions = await
|
|
161
|
+
thisEntry.transactions = await bchjsInstance.Electrumx.sortAllTxs(thisEntry.transactions, 'DESCENDING')
|
|
135
162
|
|
|
136
163
|
if (!allTxs && thisEntry.transactions.length > 100) {
|
|
137
164
|
// Extract only the first 100 transactions.
|