Skip to content

Commit 2ddb2c7

Browse files
authored
refactor!: use chainhook to listen for chain events instead of a direct stacks api connection (#200)
* chore: add chainhook client * chore: single predicate draft * fix: remove old code * fix: test builds * test: get contract abi * test: first sip-019 notif * test: print event chainhook observer * feat: consume deployments * test: chain tip * fix: unify chainhook events processors * feat: rollback contract deployments * feat: rollback sft mint * chore: draft for sip-019 storage * feat: keep sip-019 notifs * fix: notifications table inserts * fix: update code * fix: some tests * fix: admin rpc * fix: rollback contracts and sip-013 mints * test: divide into suites * ci: codecov * chore: progress * chore: update deps * fix: remove abi * fix: block cache * chore: migrations * fix: upgrade chainhook client * chore: upgrade api toolkit * chore: divide test files * test: ft, nft * test: sft * fix: notification tests * fix: dynamic refresh * fix: token queue tests * fix: admin rpc tests * fix: api tests * chore: remove contract import admin rpc * feat: start validating with chainhook * fix: eslint * fix: admin rpc tests * ci: run matrix tests properly * fix: skip ingested blocks * feat: return asset_identifier in FT responses (#229) * test: zero token nft * fix: refactor GCS image cache upload script to typescript (#232) * fix: image cache ts * test: more * fix: code * build: use v2 docker compose * fix: admin tests * fix: try finally * test: debug logs * test: only 1 * test: one more * fix: not the timeout * fix: different ports * fix: improve test servers * fix: add cause to error message * fix: try 127.0.0.1 * fix: try timeout sleep * fix: standard close * test: more * fix: improve message * fix: echo status * fix: detect * fix: finally * fix: x * fix: timeouts * fix: revert debug stuff * chore: remove old test * fix: store chainhook predicate in local file for reuse after restart (#233) fix: add tests * fix: process image cache in stages for memory optimization (#234) * fix: try to use native sharp pipeline * fix: job queue controls, profiler * fix: tests * fix: upgrade toolkit * fix: improve error propagation * fix: listen to stream errors * fix: process cached image step by step * fix: report errors retried immediately * fix: image stream * fix: wait for sharp stream correctly * chore: upgrade to node 20 (#235) * feat: provide detailed error responses for tokens with user/contract errors (#236) * chore: demote httperror to usererror * fix: add errors * fix: custom messages * feat: add testnet support
1 parent 33cbd36 commit 2ddb2c7

File tree

78 files changed

+4454
-16110
lines changed

Some content is hidden

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

78 files changed

+4454
-16110
lines changed

.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ module.exports = {
99
ecmaVersion: 2020,
1010
sourceType: 'module',
1111
},
12-
ignorePatterns: ['*.config.js', 'config/*', '*.mjs', 'tests/*.js', 'client/*'],
12+
ignorePatterns: [
13+
'*.config.js',
14+
'config/*',
15+
'*.mjs',
16+
'tests/**/*.js',
17+
'client/*',
18+
'coverage/*',
19+
'dist/*',
20+
],
1321
plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc', 'prettier'],
1422
rules: {
1523
'prettier/prettier': 'error',

.github/workflows/ci.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ jobs:
1818
lint:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222

2323
- name: Use Node.js
2424
uses: actions/setup-node@v4
2525
with:
2626
node-version-file: '.nvmrc'
2727

2828
- name: Cache node modules
29-
uses: actions/cache@v3
29+
uses: actions/cache@v4
3030
env:
3131
cache-name: cache-node-modules
3232
with:
@@ -49,6 +49,10 @@ jobs:
4949
run: npm run lint:prettier
5050

5151
test:
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
suite: [admin, api, chainhook, token-queue]
5256
runs-on: ubuntu-latest
5357
env:
5458
API_HOST: 127.0.0.1
@@ -67,7 +71,7 @@ jobs:
6771
STACKS_NODE_RPC_HOST: 127.0.0.1
6872
STACKS_NODE_RPC_PORT: 24440
6973
steps:
70-
- uses: actions/checkout@v3
74+
- uses: actions/checkout@v4
7175
with:
7276
fetch-depth: 0
7377

@@ -77,7 +81,7 @@ jobs:
7781
node-version-file: '.nvmrc'
7882

7983
- name: Cache node modules
80-
uses: actions/cache@v3
84+
uses: actions/cache@v4
8185
env:
8286
cache-name: cache-node-modules
8387
with:
@@ -100,10 +104,12 @@ jobs:
100104
npm run testenv:logs -- --no-color &> docker-compose-logs.txt &
101105
102106
- name: Run tests
103-
run: npm run test -- --coverage
107+
run: npm run test:${{ matrix.suite }} -- --coverage
104108

105109
- name: Upload coverage to Codecov
106-
uses: codecov/codecov-action@v3
110+
uses: codecov/codecov-action@v4
111+
with:
112+
token: ${{ secrets.CODECOV_TOKEN }}
107113

108114
- name: Print integration environment logs
109115
run: cat docker-compose-logs.txt
@@ -119,14 +125,14 @@ jobs:
119125
- lint
120126
- test
121127
steps:
122-
- uses: actions/checkout@v3
128+
- uses: actions/checkout@v4
123129
with:
124130
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
125131
fetch-depth: 0
126132
persist-credentials: false
127133

128134
- name: Semantic Release
129-
uses: cycjimmy/semantic-release-action@v3
135+
uses: cycjimmy/semantic-release-action@v4
130136
id: semantic
131137
# Only run on non-PR events or only PRs that aren't from forks
132138
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
20

.vscode/launch.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,69 @@
7575
"preLaunchTask": "npm: testenv:run",
7676
"postDebugTask": "npm: testenv:stop",
7777
},
78+
{
79+
"type": "node",
80+
"request": "launch",
81+
"name": "Jest: Admin",
82+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
83+
"args": [
84+
"--testTimeout=3600000",
85+
"--runInBand",
86+
"--no-cache",
87+
"${workspaceFolder}/tests/admin/"
88+
],
89+
"outputCapture": "std",
90+
"console": "integratedTerminal",
91+
"preLaunchTask": "npm: testenv:run",
92+
"postDebugTask": "npm: testenv:stop",
93+
},
94+
{
95+
"type": "node",
96+
"request": "launch",
97+
"name": "Jest: API",
98+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
99+
"args": [
100+
"--testTimeout=3600000",
101+
"--runInBand",
102+
"--no-cache",
103+
"${workspaceFolder}/tests/api/"
104+
],
105+
"outputCapture": "std",
106+
"console": "integratedTerminal",
107+
"preLaunchTask": "npm: testenv:run",
108+
"postDebugTask": "npm: testenv:stop",
109+
},
110+
{
111+
"type": "node",
112+
"request": "launch",
113+
"name": "Jest: Chainhook",
114+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
115+
"args": [
116+
"--testTimeout=3600000",
117+
"--runInBand",
118+
"--no-cache",
119+
"${workspaceFolder}/tests/chainhook/",
120+
],
121+
"outputCapture": "std",
122+
"console": "integratedTerminal",
123+
"preLaunchTask": "npm: testenv:run",
124+
"postDebugTask": "npm: testenv:stop",
125+
},
126+
{
127+
"type": "node",
128+
"request": "launch",
129+
"name": "Jest: Token Queue",
130+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
131+
"args": [
132+
"--testTimeout=3600000",
133+
"--runInBand",
134+
"--no-cache",
135+
"${workspaceFolder}/tests/token-queue/"
136+
],
137+
"outputCapture": "std",
138+
"console": "integratedTerminal",
139+
"preLaunchTask": "npm: testenv:run",
140+
"postDebugTask": "npm: testenv:stop",
141+
},
78142
]
79143
}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:18-alpine
1+
FROM node:20-alpine
22

33
WORKDIR /app
44
COPY . .

config/image-cache.js

Lines changed: 0 additions & 147 deletions
This file was deleted.

docker/docker-compose.dev.postgres.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.7'
22
services:
33
postgres:
4-
image: "postgres:14"
4+
image: "postgres:15"
55
ports:
66
- "5432:5432"
77
environment:

migrations/1670264425574_smart-contracts.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,37 @@ export function up(pgm: MigrationBuilder): void {
1313
principal: {
1414
type: 'text',
1515
notNull: true,
16+
unique: true,
1617
},
1718
sip: {
1819
type: 'sip_number',
1920
notNull: true,
2021
},
21-
abi: {
22-
type: 'jsonb',
22+
token_count: {
23+
type: 'numeric',
24+
},
25+
fungible_token_name: {
26+
type: 'text',
27+
},
28+
non_fungible_token_name: {
29+
type: 'text',
30+
},
31+
block_height: {
32+
type: 'int',
33+
notNull: true,
34+
},
35+
index_block_hash: {
36+
type: 'text',
2337
notNull: true,
2438
},
2539
tx_id: {
2640
type: 'text',
2741
notNull: true,
2842
},
29-
block_height: {
43+
tx_index: {
3044
type: 'int',
3145
notNull: true,
3246
},
33-
token_count: {
34-
type: 'numeric',
35-
},
3647
created_at: {
3748
type: 'timestamptz',
3849
default: pgm.func('(NOW())'),
@@ -42,7 +53,5 @@ export function up(pgm: MigrationBuilder): void {
4253
type: 'timestamptz',
4354
},
4455
});
45-
pgm.createConstraint('smart_contracts', 'smart_contracts_principal_unique', 'UNIQUE(principal)');
4656
pgm.createIndex('smart_contracts', [{ name: 'block_height', sort: 'DESC' }]);
47-
pgm.createIndex('smart_contracts', ['principal']);
4857
}

0 commit comments

Comments
 (0)