Skip to content

Commit 34084d4

Browse files
committed
init
0 parents  commit 34084d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6762
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.git
4+
*.log

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT=8080 # The port your server will listen on

.github/workflows/qa.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: QA
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
name: Lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: the-ton-tech/toolchain/lint@v1.2.0
17+
18+
build:
19+
name: Test & Build
20+
needs: lint
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: the-ton-tech/toolchain/build@v1.2.0

.github/workflows/reward.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Reward
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
reward:
10+
name: Reward
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
steps:
16+
- uses: the-ton-tech/toolchain/reward@v1.3.0
17+
with:
18+
activity_id: tl-b-tool
19+
on_reward_label: rewarded
20+
github_token: ${{ secrets.GITHUB_TOKEN }}
21+
society_api_key: ${{ secrets.X_API_KEY }}
22+
society_partner_id: ${{ secrets.X_PARTNER_ID }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
node_modules
3+
.vscode
4+
dist
5+
.env
6+
coverage

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:22.15.1-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
COPY package.json yarn.lock ./
6+
7+
RUN yarn install --frozen-lockfile
8+
9+
COPY . .
10+
11+
RUN yarn build
12+
13+
FROM node:22.15.1-alpine AS runner
14+
15+
WORKDIR /app
16+
17+
COPY package.json yarn.lock ./
18+
19+
RUN yarn install --production --frozen-lockfile
20+
21+
COPY --from=builder /app/dist ./dist
22+
23+
CMD [ "node", "dist/server.js" ]

README.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# TLB Rest Server
2+
3+
**TLB Rest Server** is an HTTP API service for parsing serialized TVM cells using a given TL-B schema.
4+
5+
## API
6+
7+
### POST `/parse`
8+
9+
Parses a base64-encoded cell using the provided TL-B schema.
10+
11+
#### Request Body
12+
13+
| Field | Type | Required | Description |
14+
|--------|----------|----------|-----------------------------|
15+
| schema | `string` | Yes | A TL-B serialization schema |
16+
| cell | `string` | Yes | A base64-encoded cell |
17+
18+
##### Example:
19+
20+
```json
21+
{
22+
"schema": "foo$01 v:uint32 = Foo;bar$10 v:uint128 = Bar;",
23+
"cell": "te6cckEBAQEABwAACUAAAAqgsDZXlg=="
24+
}
25+
```
26+
27+
#### Responses
28+
29+
* **200 OK** — successful parse:
30+
31+
```json
32+
{
33+
"success": true,
34+
"result": {
35+
"parsedCell": {
36+
"kind": "Foo_foo",
37+
"v": 42
38+
}
39+
}
40+
}
41+
42+
```
43+
44+
* **400 Bad Request** — parsing failed (e.g., invalid TL-B schema or cell)
45+
* **422 Unprocessable Entity** — request body validation failed
46+
* **500 Internal Server Error** — unexpected internal error
47+
48+
##### Example `curl` request:
49+
50+
```bash
51+
curl -X POST http://localhost:3000/parse \
52+
-H "Content-Type: application/json" \
53+
-d '{"cell":"te6cckEBAQEABwAACUAAAAqgsDZXlg=="}'
54+
```
55+
56+
### POST `/try-parse`
57+
58+
Attempts to parse a base64-encoded cell **without requiring a TL-B schema**. This endpoint is useful for parsing unknown cells.
59+
60+
#### Request Body
61+
62+
| Field | Type | Required | Description |
63+
|-------|----------|----------|-----------------------|
64+
| cell | `string` | Yes | A base64-encoded cell |
65+
66+
##### Example:
67+
68+
```json
69+
{
70+
"cell": "te6cckEBAgEAywABsA+KfqUADpIH1lB9/kBfXhAIAO87mQKicbKgHIk4pSPP4k5xhHqutqYgAB7USnesDnCdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYiA7msoEBANslk4VhgAIqFqMWTE1aoxM/MRD/EEluAMqKyKvv/FAn4CTTNIDD6gjOY1bdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYsAJXpnI3GpDhSbfSWGTb/USCfMHoow3xseDEM4UCreKtluqcoI0="
71+
}
72+
```
73+
74+
#### Responses
75+
76+
* **200 OK** — successful parse:
77+
78+
```json
79+
{
80+
"success": true,
81+
"result": {
82+
"parsedCell": {
83+
"opCode": 260734629,
84+
"schema": "jettons",
85+
"internal": "jetton_transfer",
86+
"data": {
87+
"kind": "JettonTransfer",
88+
"query_id": "4101212031974910",
89+
"amount": "100000000",
90+
"destination": "EQB3ncyBUTjZUA5EnFKR5_EnOMI9V1tTEAAPaiU71gc4TiUt",
91+
"response_destination": "EQBSzBN6cnxDwDjn_IQXqgU8OJXUMcol9pxyL-yLkpKzYs9U",
92+
"custom_payload": { "kind": "Maybe_nothing" },
93+
"forward_ton_amount": "125000000",
94+
"forward_payload": {
95+
"kind": "Either_right",
96+
"value": { "parsed": {...} }
97+
}
98+
}
99+
}
100+
}
101+
}
102+
```
103+
104+
* **400 Bad Request** — parsing failed (e.g., invalid TL-B schema or cell)
105+
* **422 Unprocessable Entity** — request body validation failed
106+
* **500 Internal Server Error** — unexpected internal error
107+
108+
##### Example `curl` request:
109+
110+
```bash
111+
curl -X POST http://localhost:3000/try-parse \
112+
-H "Content-Type: application/json" \
113+
-d '{"cell":"te6cckEBAgEAywABsA+KfqUADpIH1lB9/kBfXhAIAO87mQKicbKgHIk4pSPP4k5xhHqutqYgAB7USnesDnCdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYiA7msoEBANslk4VhgAIqFqMWTE1aoxM/MRD/EEluAMqKyKvv/FAn4CTTNIDD6gjOY1bdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYsAJXpnI3GpDhSbfSWGTb/USCfMHoow3xseDEM4UCreKtluqcoI0="}'
114+
```
115+
116+
## Prometheus Metrics
117+
118+
The service exposes metrics compatible with Prometheus.
119+
120+
### GET `/metrics`
121+
122+
* Exposes uptime, HTTP method/path/status metrics, and default process metrics.
123+
124+
## Healthcheck
125+
126+
The service exposes healthcheck endpoint.
127+
128+
### GET `/health`
129+
130+
* Exposes uptime and current timestamp.
131+
132+
##### Example:
133+
134+
```bash
135+
curl http://localhost:3000/metrics
136+
```
137+
138+
## Running the Service
139+
140+
### Run with Docker
141+
142+
To build the Docker image:
143+
144+
```bash
145+
docker build -t app .
146+
```
147+
148+
To run the container:
149+
150+
```bash
151+
docker run -e PORT=3000 -p 3000:3000 app:latest
152+
```
153+
154+
The app will be available at [http://localhost:3000](http://localhost:3000)
155+
156+
### Run with Docker Compose
157+
158+
For local development:
159+
160+
```bash
161+
docker-compose -f docker-compose.develop.yml up
162+
```
163+
164+
The app will be available at [http://localhost:3000](http://localhost:3000)
165+
166+
## Environment Variables
167+
168+
| Variable | Description | Default |
169+
| -------- | --------------------------------- | ------- |
170+
| `PORT` | Port on which the app will listen | `3000` |
171+
172+
## Testing
173+
174+
### Run Tests
175+
176+
```bash
177+
yarn test
178+
```

docker-compose.develop.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3.9"
2+
services:
3+
api:
4+
build:
5+
context: .
6+
environment:
7+
- PORT=3000 # if not set 3000 is used
8+
ports:
9+
- "3000:3000"

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@ton/toolchain');

0 commit comments

Comments
 (0)