psf-bch-api 7.3.4 → 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) {
|
|
@@ -106,13 +106,24 @@ class FulcrumUseCases {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
async getTransactions ({ address, allTxs }) {
|
|
109
|
+
async getTransactions ({ address, allTxs, bearerToken = null }) {
|
|
110
110
|
try {
|
|
111
111
|
const response = await this.fulcrum.get(`electrumx/transactions/${address}`)
|
|
112
112
|
|
|
113
113
|
// Sort transactions in descending order, so that newest transactions are first.
|
|
114
114
|
if (response.transactions && Array.isArray(response.transactions)) {
|
|
115
|
-
|
|
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')
|
|
116
127
|
|
|
117
128
|
if (!allTxs) {
|
|
118
129
|
// Return only the first 100 transactions of the history.
|
|
@@ -127,16 +138,27 @@ class FulcrumUseCases {
|
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
140
|
|
|
130
|
-
async getTransactionsBulk ({ addresses, allTxs }) {
|
|
141
|
+
async getTransactionsBulk ({ addresses, allTxs, bearerToken = null }) {
|
|
131
142
|
try {
|
|
132
143
|
const response = await this.fulcrum.post('electrumx/transactions/', { addresses })
|
|
133
144
|
|
|
134
145
|
// Sort transactions in descending order for each address entry.
|
|
135
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
|
+
|
|
136
158
|
for (let i = 0; i < response.transactions.length; i++) {
|
|
137
159
|
const thisEntry = response.transactions[i]
|
|
138
160
|
if (thisEntry.transactions && Array.isArray(thisEntry.transactions)) {
|
|
139
|
-
thisEntry.transactions = await
|
|
161
|
+
thisEntry.transactions = await bchjsInstance.Electrumx.sortAllTxs(thisEntry.transactions, 'DESCENDING')
|
|
140
162
|
|
|
141
163
|
if (!allTxs && thisEntry.transactions.length > 100) {
|
|
142
164
|
// Extract only the first 100 transactions.
|