Skip to content

Commit 2152b87

Browse files
committedApr 3, 2024··
Merge branch 'main' of https://github.com/vsc-eco/vsc-node into main
2 parents c8a898b + 818a1ad commit 2152b87

20 files changed

+778
-179
lines changed
 

‎docker-compose.dev.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
version: "3.3"
2+
3+
services:
4+
vsc-node: # name of the service
5+
build: .
6+
image: vsc-node # the image to use
7+
container_name: vsc-node_dev # what to label the container for docker ps
8+
restart: always # restart if failed, until we stop it ourselves
9+
#external_links:
10+
#- mongo
11+
depends_on:
12+
- ipfs
13+
- mongo
14+
networks:
15+
- vsc-node
16+
env_file:
17+
- .env
18+
ports:
19+
- 1338:1337
20+
environment:
21+
DEV: true
22+
IPFS_HOST: http://ipfs:5201
23+
MONGO_HOST: mongo:27017
24+
volumes:
25+
- node-modules-store:/home/github/app/node_modules
26+
- ./data/vsc-node:/root/.vsc-node
27+
- ./seed-backup.json:/root/.vsc-seed-backup.json
28+
- ./.git/refs/heads/main:/root/git_commit
29+
- ./src:/home/github/app/src
30+
31+
mongo:
32+
container_name: mongo_vsc_dev
33+
image: mongo:4.4.18
34+
restart: always
35+
ports:
36+
- 127.0.0.1:27022:27017
37+
networks:
38+
- vsc-node
39+
volumes:
40+
- ./data/vsc-db:/data/db
41+
42+
ipfs:
43+
container_name: ipfs-vsc_dev
44+
image: ipfs/kubo:v0.18.1
45+
restart: always
46+
command:
47+
- daemon
48+
- --enable-pubsub-experiment
49+
- --init-profile
50+
- server
51+
networks:
52+
- vsc-node
53+
ports:
54+
- "4002:4002"
55+
- "127.0.0.1:5201:5201"
56+
environment:
57+
IPFS_PATH: /etc/ipfs
58+
volumes:
59+
- ./data/ipfs:/etc/ipfs
60+
61+
volumes:
62+
node-modules-store: {}
63+
mongodb: {}
64+
65+
networks:
66+
vsc-node:
67+
driver: bridge

‎package-lock.json

+57-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@nestjs/platform-express": "^8.4.7",
1717
"@summa-tx/bitcoin-spv-js": "^4.0.2",
1818
"@transmute/did-key-bls12381": "^0.3.0-unstable.10",
19+
"@types/node": "^20.12.2",
1920
"@vsc.eco/client": "^0.0.4",
2021
"@vsc.eco/sdk": "^0.1.3",
2122
"ajv": "^6.12.6",

‎src/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ async function startup(): Promise<void> {
1515

1616
const api = new ApiModule(1337, core)
1717
await api.listen()
18+
19+
20+
const cleanup = async (code: number) => {
21+
await core.stop()
22+
await coreNew.stop()
23+
await api.stop()
24+
};
25+
26+
process.on("SIGINT", () => cleanup(0));
27+
process.on("SIGTERM", () => cleanup(0));
28+
process.on("beforeExit", cleanup);
1829
}
1930

2031
void startup()

‎src/modules/api/graphql/resolvers.ts

-95
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,6 @@ export const DebugResolvers = {
3838
}
3939
}
4040

41-
// called recursively, as the object might consist of a nested JWS structure
42-
const getDagCborIpfsHashContent = async (cid: CID) => {
43-
let content = await appContainer.self.ipfs.dag.get(cid) as any;
44-
45-
if (typeof content === 'object' && content) {
46-
// check if ipfs object is in JWS format, if so we need to go one layer below
47-
const data = content.value;
48-
if ('payload' in data && 'signatures' in data) {
49-
const nestedCid: CID = (data as any).link as CID;
50-
if (nestedCid.toString() === cid.toString()) {
51-
return 'the ipfs object is in JWS format, but the link points to itself, this is not allowed!';
52-
}
53-
54-
content = await getDagCborIpfsHashContent(nestedCid);
55-
if (typeof content === 'object') {
56-
content.link = data.link.toString()
57-
content.payload = data.payload
58-
content.signatures = data.signatures
59-
} else {
60-
content = {
61-
data: content,
62-
link: data.link.toString(),
63-
payload: data.payload,
64-
signatures: data.signatures
65-
}
66-
}
67-
}
68-
}
69-
70-
return content;
71-
}
72-
7341
export const Resolvers = {
7442
contractState: async (_, args) => {
7543
// const data = await appContainer.self.contractEngine.contractDb.findOne({
@@ -349,69 +317,6 @@ export const Resolvers = {
349317
})
350318
return nextSlot;
351319
},
352-
353-
// finds and tags vsc-tx/ vsc-blocks via ipfs CID's, unidentifiable CID's are tagged with the type 'null'
354-
findCID: async (_, args) => {
355-
if (appContainer.self.config.get('ipfs.pinEverything')) {
356-
const ipfsHash = args.id;
357-
358-
let cid = null;
359-
try {
360-
cid = CID.parse(ipfsHash)
361-
} catch {
362-
throw new GraphQLError('Invalid CID format!')
363-
}
364-
365-
// get ipfs content for cid
366-
let content = null;
367-
if (cid.code === 0x70) {
368-
// dag-pd
369-
const stream = appContainer.self.ipfs.cat(cid);
370-
const chunks = [];
371-
372-
for await (const chunk of stream) {
373-
chunks.push(chunk);
374-
}
375-
376-
const buffer = Buffer.concat(chunks);
377-
let dataRaw = buffer.toString();
378-
379-
try {
380-
content = JSON.parse(dataRaw);
381-
} catch (e) {
382-
content = dataRaw;
383-
}
384-
} else if (cid.code === 0x71) {
385-
// dag-cbor
386-
content = await getDagCborIpfsHashContent(cid);
387-
}
388-
389-
// determine the type of vsc data structure that was found e.g.: vsc-tx/ blocks
390-
let type = null;
391-
if (content && typeof content.value === 'object' && content.value.__t && ['vsc-tx', 'vsc-block'].includes(content.value.__t)) {
392-
type = content.value.__t
393-
}
394-
395-
let result: {
396-
type: string,
397-
data: any,
398-
link?: string,
399-
payload?: string,
400-
signatures?: {
401-
protected: string,
402-
signature: string
403-
}[]
404-
} = { type: type, data: content.value }
405-
if (content.payload && content.signatures && content.link) {
406-
result.payload = content.payload
407-
result.signatures = content.signatures
408-
result.link = content.link
409-
}
410-
return result
411-
} else {
412-
throw new GraphQLError("Current node configuration does not allow for this endpoint to be used.")
413-
}
414-
},
415320
submitTransactionV1: async (_, args) => {
416321
const {id} = await appContainer.self.newService.transactionPool.ingestTx({
417322
tx: args.tx,

‎src/modules/api/graphql/schema.ts

-8
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ export const schema = `
7676
enabled_at: Int
7777
trusted: Boolean
7878
}
79-
type findCIDResult {
80-
type: String
81-
data: JSON
82-
link: String
83-
payload: String
84-
signatures: JSON
85-
}
8679
interface BalanceController {
8780
type: BalanceControllerType
8881
authority: String
@@ -161,7 +154,6 @@ export const schema = `
161154
# Need Revision
162155
163156
findContract(id: String): FindContractResult
164-
findCID(id: String): findCIDResult
165157
166158
# End Need Revision
167159

‎src/modules/api/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { Module } from '@nestjs/common'
2+
import { INestApplication, Module } from '@nestjs/common'
33
import { NestFactory } from '@nestjs/core'
44
import { createSchema, createYoga } from 'graphql-yoga'
55
import { IPFSHTTPClient } from 'kubo-rpc-client'
@@ -24,6 +24,7 @@ class ControllerModule {}
2424
* see api requirements here https://github.com/3speaknetwork/research/discussions/3
2525
*/
2626
export class ApiModule {
27+
app: INestApplication
2728
constructor(
2829
private readonly listenPort: number,
2930
private readonly self: CoreService
@@ -32,7 +33,8 @@ export class ApiModule {
3233
}
3334

3435
public async listen() {
35-
const app = await NestFactory.create(ControllerModule)
36+
this.app = await NestFactory.create(ControllerModule)
37+
const app = this.app
3638

3739
// Bring back API docs when needed. Mostly use already documented graphql
3840
// const swaggerconfig = new DocumentBuilder().setTitle('VSC API').build()
@@ -78,4 +80,8 @@ export class ApiModule {
7880

7981
await app.listen(this.listenPort)
8082
}
83+
84+
async stop() {
85+
await this.app.close()
86+
}
8187
}

0 commit comments

Comments
 (0)
Please sign in to comment.