@bsv/overlay-express 0.8.2-rc1 → 0.8.2-rc2
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/dist/cjs/package.json +13 -13
- package/dist/cjs/src/JanitorService.js +215 -0
- package/dist/cjs/src/JanitorService.js.map +1 -0
- package/dist/cjs/src/OverlayExpress.js +130 -30
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/generalGuide.md.js +77 -0
- package/dist/cjs/src/generalGuide.md.js.map +1 -0
- package/dist/cjs/src/makeUserInterface.js +290 -93
- package/dist/cjs/src/makeUserInterface.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/JanitorService.js +211 -0
- package/dist/esm/src/JanitorService.js.map +1 -0
- package/dist/esm/src/OverlayExpress.js +125 -25
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/generalGuide.md.js +75 -0
- package/dist/esm/src/generalGuide.md.js.map +1 -0
- package/dist/esm/src/makeUserInterface.js +287 -93
- package/dist/esm/src/makeUserInterface.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/JanitorService.d.ts +59 -0
- package/dist/types/src/JanitorService.d.ts.map +1 -0
- package/dist/types/src/OverlayExpress.d.ts +15 -3
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/generalGuide.md.d.ts +3 -0
- package/dist/types/src/generalGuide.md.d.ts.map +1 -0
- package/dist/types/src/makeUserInterface.d.ts +7 -2
- package/dist/types/src/makeUserInterface.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/OverlayExpress.ts +55 -4
package/src/OverlayExpress.ts
CHANGED
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
HTTPSOverlayBroadcastFacilitator,
|
|
14
14
|
DEFAULT_TESTNET_SLAP_TRACKERS,
|
|
15
15
|
DEFAULT_SLAP_TRACKERS,
|
|
16
|
-
Utils
|
|
16
|
+
Utils,
|
|
17
|
+
Beef,
|
|
18
|
+
Transaction
|
|
17
19
|
} from '@bsv/sdk'
|
|
18
20
|
import Knex from 'knex'
|
|
19
21
|
import { MongoClient, Db } from 'mongodb'
|
|
@@ -757,10 +759,59 @@ export default class OverlayExpress {
|
|
|
757
759
|
this.app.post('/lookup', (req, res) => {
|
|
758
760
|
; (async () => {
|
|
759
761
|
try {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
+
// Check for aggregation header to determine response format
|
|
763
|
+
const aggregationHeader = req.headers['x-aggregation']
|
|
764
|
+
const shouldReturnBinary = aggregationHeader === 'yes'
|
|
765
|
+
|
|
766
|
+
// Validate request body structure
|
|
767
|
+
const lookupRequest = req.body as { service: string, query: unknown }
|
|
768
|
+
if (typeof lookupRequest.service !== 'string' || lookupRequest.query === undefined) {
|
|
769
|
+
return res.status(400).json({
|
|
770
|
+
status: 'error',
|
|
771
|
+
message: 'Invalid request: body must contain "service" (string) and "query" fields'
|
|
772
|
+
})
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const result = await engine.lookup(lookupRequest)
|
|
776
|
+
|
|
777
|
+
if (!shouldReturnBinary) {
|
|
778
|
+
// Return JSON response (default behavior)
|
|
779
|
+
return res.status(200).json(result)
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const beef = new Beef()
|
|
783
|
+
const outputs = result.outputs
|
|
784
|
+
|
|
785
|
+
// Serialize in the format expected by LookupResolver
|
|
786
|
+
const writer = new Utils.Writer()
|
|
787
|
+
|
|
788
|
+
// Write number of outpoints
|
|
789
|
+
writer.writeVarIntNum(outputs.length)
|
|
790
|
+
|
|
791
|
+
// Write each outpoint data
|
|
792
|
+
for (const output of outputs) {
|
|
793
|
+
const tx = Transaction.fromBEEF(output.beef)
|
|
794
|
+
// Write txid (32 bytes)
|
|
795
|
+
writer.write(tx.id())
|
|
796
|
+
// Write outputIndex
|
|
797
|
+
writer.writeVarIntNum(output.outputIndex)
|
|
798
|
+
// Write context length and data
|
|
799
|
+
if ((output.context != null) && output.context.length > 0) {
|
|
800
|
+
writer.writeVarIntNum(output.context.length)
|
|
801
|
+
writer.write(output.context)
|
|
802
|
+
} else {
|
|
803
|
+
writer.writeVarIntNum(0)
|
|
804
|
+
}
|
|
805
|
+
beef.mergeTransaction(tx)
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// Write the beef data
|
|
809
|
+
writer.write(beef.toBinary())
|
|
810
|
+
|
|
811
|
+
res.setHeader('Content-Type', 'application/octet-stream')
|
|
812
|
+
return res.status(200).send(Buffer.from(writer.toArray()))
|
|
762
813
|
} catch (error) {
|
|
763
|
-
console.error(chalk.red('
|
|
814
|
+
console.error(chalk.red('Error in /lookup:'), error)
|
|
764
815
|
return res.status(400).json({
|
|
765
816
|
status: 'error',
|
|
766
817
|
message: error instanceof Error ? error.message : 'An unknown error occurred'
|