Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6007cfc
add deploy action
gclaramunt Mar 13, 2025
a446ec7
use postgres and prisma for dag, metagraph, and actions endpoints
gclaramunt Mar 12, 2025
13f6045
temporarily change stage
gclaramunt Mar 13, 2025
3508b34
add prisma binary targets
gclaramunt Mar 13, 2025
b5e725c
add new endpoints
gclaramunt Mar 27, 2025
b7ab6ad
update db structure
gclaramunt Apr 1, 2025
ced0dc8
Added endpoint tests using local postgres db
AlexBrandes Apr 2, 2025
1f82e89
fix typo
gclaramunt Apr 3, 2025
4617dab
update db structure
gclaramunt Apr 3, 2025
0760ad3
fix typo
gclaramunt Apr 3, 2025
1e94422
Adjust fields optionality
gclaramunt Apr 3, 2025
daea3d9
use ordinal from query parameters
gclaramunt Apr 3, 2025
a9a0a55
update db structure
gclaramunt Apr 3, 2025
e4c3d4b
Adjust fields optionality
gclaramunt Apr 3, 2025
8972569
use ordinal from query parameters
gclaramunt Apr 3, 2025
1012360
Merge branch 'release/testnet' of github.com:Constellation-Labs/block…
gclaramunt Apr 4, 2025
916edc2
add ordinal and unlock ordinal
gclaramunt Apr 3, 2025
005ab87
fix: PROT-1112 add fee, staking address, owner addres, and size to me…
gclaramunt Apr 7, 2025
3133281
fix: await globalSnapshotWhere and metagraphSnapshotWhere
gclaramunt Apr 8, 2025
0858163
PROT-1119 add detail endpoints
gclaramunt Apr 8, 2025
645f3d0
shorter names
gclaramunt Apr 9, 2025
a2d13d7
Fix metagraph filters for findUnique
gclaramunt Apr 9, 2025
1965f87
Merge branch 'develop' into release/integrationnet
gclaramunt Apr 9, 2025
6b57bdf
use proper latest for querying metagraph snapshot
gclaramunt Apr 10, 2025
fc77e21
fix: use metagraph_id for query
gclaramunt Apr 10, 2025
2bce9b1
add active token locks query param
gclaramunt Apr 14, 2025
75fe2c9
remove error details
gclaramunt Apr 21, 2025
d97aa2f
fix transaction ordering and add tests
gclaramunt Apr 22, 2025
f5dc433
update tests
gclaramunt Apr 24, 2025
85257a8
Add delegated staking endpoints
gclaramunt Apr 21, 2025
b9ec7ee
docs: added openapi spec covering current endpoints
AlexBrandes Apr 24, 2025
091b5ea
token lock tests
gclaramunt Apr 29, 2025
91e7243
add active filter to address endpoint
gclaramunt Apr 29, 2025
ded8f1f
token locks tests
gclaramunt Apr 29, 2025
d475b02
add active filter to allow spends
gclaramunt Apr 30, 2025
1b6721f
add metagraph count to response
gclaramunt May 4, 2025
6b96d57
Update docs/schemas/dag.yml
gclaramunt May 5, 2025
f3bde87
PROT-1163 increase page size limit
gclaramunt May 7, 2025
47c43d5
add snapshot ordinal to actions
gclaramunt May 4, 2025
7b846b0
add fee transactions endpoint and tests
gclaramunt May 13, 2025
434d48f
add new fee tx endpoint docs
gclaramunt May 13, 2025
9460cf7
add position endponts
gclaramunt May 9, 2025
a563703
query tx by snapshot directly
gclaramunt May 18, 2025
221e3ae
rename sizeInKB
gclaramunt May 21, 2025
36c35fc
fix: delegated staking pagination
gclaramunt May 29, 2025
730c121
add nodeId filter
gclaramunt Jun 2, 2025
5c2b2a1
return transaction original
gclaramunt Jun 2, 2025
e7527b3
add delegated staking to actions
gclaramunt Jun 3, 2025
22f763a
fix ordinal number
gclaramunt Jun 6, 2025
04b693e
fallback to opensearch for balance changes
gclaramunt May 20, 2025
4c2cd76
fix not found
gclaramunt May 21, 2025
12e66d2
remove opensearch fallback
gclaramunt May 26, 2025
9a20105
optomize total rewards
gclaramunt Jun 6, 2025
06c8061
Merge branch 'release/integrationnet' into release/testnet
gclaramunt Jun 11, 2025
b1dc9f0
fix snapshot count typo
gclaramunt Jun 12, 2025
f90f02f
fix dag/mg pagination
gclaramunt Jun 12, 2025
fc66cb9
PROT 1236 remove transferred stakes from active and include transferr…
gclaramunt Jun 13, 2025
5e62e2e
feat: PROT 1237 add global snapshot to txs (#184)
gclaramunt Jun 13, 2025
eb1b913
Merge branch 'PROT-1266-add-before-after' into release/testnet
gclaramunt Jun 18, 2025
1433bb9
PROT-1257 add currencyId to locks and spends (#189)
gclaramunt Jun 18, 2025
0805ff0
add desc indexes
gclaramunt Jun 19, 2025
014db4d
fix view create script for test
gclaramunt Jun 19, 2025
78bc1a1
fix: global snapshot transactions pagination (#191)
gclaramunt Jun 19, 2025
8fb6d7f
support multiple rewards per address (#192)
gclaramunt Jul 28, 2025
5e88322
Support many rewards per address (#193)
gclaramunt Jul 28, 2025
28dc8c9
Improve spend pagination and add more comprehensive pagination test (…
gclaramunt Jul 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Test DB connection
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/be_api_test_db?schema=public
39 changes: 39 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy OpenAPI Docs

on:
push:
branches:
- release/mainnet
- release/integrationnet
- release/testnet

jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: ${{ (github.ref_name == 'release/testnet' && 'testnet') || (github.ref_name == 'release/integrationnet' && 'integrationnet') || (github.ref_name == 'release/mainnet' && 'mainnet') }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install Redocly CLI
run: npm install -g @redocly/cli@1.34.2

- name: Build OpenAPI Docs
run: redocly build-docs docs/openapi.yaml -o docs/index.html

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-1

- name: Sync to S3
run: |
aws s3 sync docs/ s3://${{ secrets.S3_BUCKET_NAME }}/ --delete
4 changes: 2 additions & 2 deletions .github/workflows/deploy-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name: Deploy postgress app
jobs:
deploy:
name: Deploy ${{ github.ref_name }} to ${{ inputs.environment }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
environment: ${{ inputs.environment }}
steps:
- name: Checkout code
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Serverless deploy
uses: serverless/github-action@v3
with:
args: deploy --stage ${{ inputs.environment }}20 --region us-west-1
args: deploy --stage ${{ inputs.environment }} --region us-west-1
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23 changes: 20 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ jobs:
strategy:
matrix:
node-version: [19.x]

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: be_api_test_db
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -25,4 +42,4 @@ jobs:
run: npm run test:tsc

- name: Test
run: npm test -- --coverage --ci
run: npm run test
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,72 @@
# Changelog

All notable changes to this project will be documented in this file.

## [Unreleased]

## [v3.1.0] 2023-06-15

- Fix currency snapshot rewards

## [v3.0.6] 2023-06-15

- Currency Framework support

## [v3.0.5] 2023-03-30

- Revert "Fix false non-zero balances"

## [v3.0.4] 2023-02-24

- Fix deploy workflow

## [v3.0.3] 2023-02-24

- Fix false non-zero balances

## [v3.0.2] 2022-11-17

- Fix 'next' reference for pagination

## [v3.0.1] 2022-10-05

- Fix returned type of balances endpoint

## [v3.0.0] 2022-09-22

Mainnet 2.0 - upgraded block explorer

## [v2.0.4] 2021-10-15

### Fixed

- Fetch by address using keyword field

## [v2.0.3] 2021-06-25

### Changed

- Fetch checkpoint block by soe hash by default and fallback to search by base hash

## [v2.0.2] 2020-10-19

### Changed

- Query parameters search_after and limit can be provided independently

## [v2.0.1] 2020-10-16

### Added

- Pagination support

### Changed

- Get by hash triggers document API
- Max size limit when no pagination used

## [v2.0.0] 2020-10-13

### Added

- Changelog introduced
100 changes: 79 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,99 @@
Block Explorer
===========
# Block Explorer

![build](https://img.shields.io/github/actions/workflow/status/Constellation-Labs/block_explorer/release.yml?label=build)
![version](https://img.shields.io/github/v/release/Constellation-Labs/block_explorer?sort=semver)

Block Explorer exposes API functions to retrieve on-chain data from a tessellation opensearch database cluster.
The Block Explorer provides API functions to retrieve on-chain data from a Constellation Network indexer. The service uses PostgreSQL for data storage and retrieval and the Serverless framework for API deployment.

## Build and Run
## Table of Contents

### Prerequisites
- [Block Explorer](#block-explorer)
- [Table of Contents](#table-of-contents)
- [Prerequisites](#prerequisites)
- [Quick Start](#quick-start)
- [Development](#development)
- [Database Setup](#database-setup)
- [API Development](#api-development)
- [Testing](#testing)
- [API Documentation](#api-documentation)

1. [TypeScript](https://www.typescriptlang.org/id/download)
2. [Serverless Framework](https://www.serverless.com/framework/docs/getting-started/)
3. [Docker Desktop](https://www.docker.com/get-started/) with [Kubernetes](https://docs.docker.com/desktop/kubernetes/) enabled
## Prerequisites

### Setup local development cluster
An [opensearch](https://aws.amazon.com/what-is/opensearch/) instance is used to store and query the on-chain data.
- [Node.js](https://nodejs.org/) (v18 or higher recommended)
- [TypeScript](https://www.typescriptlang.org/download)
- [Docker](https://www.docker.com/get-started/)
- [Serverless Framework](https://www.serverless.com/framework/docs/getting-started/)

Follow the instructions from the [snapshot streaming](https://github.com/Constellation-Labs/snapshot-streaming) repository which sets up your local tessellation development cluster along with an opensearch instance (hosted on port `4510`).
## Quick Start

### Run
Install the npm packages from the project directory:
```
npm install
```
1. Clone the repository
```bash
git clone https://github.com/Constellation-Labs/block_explorer.git
cd block_explorer
```

2. Install dependencies
```bash
npm install
```

3. Start the PostgreSQL database
```bash
npm run db:start
```

4. Run the API locally
```bash
serverless offline
```

Start the serverless offline host to test the APIs locally:
## Development

### Database Setup

The project uses PostgreSQL for data storage. A Docker Compose configuration is provided for easy setup:

```bash
# Start the PostgreSQL container
npm run db:start

# To stop the container when finished
npm run db:stop
```

The database configuration is stored in `.env` and can be customized as needed.

### API Development

Start the serverless offline host to test API endpoints locally:

```bash
serverless offline
```

The output of this command shows an overview of the function URL's that can be called locally.
This will display a list of available endpoints that can be called locally.

## Unit Tests
## Testing

Run tests with the following commands:

Run the unit tests locally:
```
```bash
# Start the database if not already running
npm run db:start

# Run tests (this will reset and seed the database automatically)
npm run test
```

The test suite uses Jest and automatically resets the database schema before each test run.

## API Documentation

API endpoints are defined in the `routes/` directory with their handlers in `src/handlers/`.

Available endpoints include:
- DAG operations
- Metagraph information
- Token locks
- Actions
- Allow spends
22 changes: 11 additions & 11 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-typescript',
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current",
},
},
],
};
"@babel/preset-typescript",
],
};
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.8'

services:
postgres:
image: postgres:15
restart: unless-stopped
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: be_api_test_db
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 2s
timeout: 5s
retries: 10

volumes:
postgres_data:
Loading