Skip to content

Commit

Permalink
Merge pull request #60 from Permissionless-Software-Foundation/ct-uns…
Browse files Browse the repository at this point in the history
…table

v3.0 - remove Mongo, update README
  • Loading branch information
christroutner committed Oct 6, 2023
2 parents e3caff8 + 3bfe2fd commit 12d3833
Show file tree
Hide file tree
Showing 54 changed files with 38 additions and 6,532 deletions.
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,50 @@

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

This application crawls the Bitcoin Cash (BCH) blockchain and indexes all the SLP token transactions. This code base is intended to be a replacement for [SLPDB](https://github.com/Permissionless-Software-Foundation/docker-slpdb). The work is based on [this report](https://gist.github.com/christroutner/77c46f1fa9adaf593074d41a508a6401) and the work was funded by [this Flipstarter](https://flipstarter.fullstack.cash/).
This application crawls the Bitcoin Cash (BCH) blockchain and indexes SLP token transactions. This code base is intended to be a replacement for [SLPDB](https://github.com/Permissionless-Software-Foundation/docker-slpdb). The work is based on [this report](https://gist.github.com/christroutner/77c46f1fa9adaf593074d41a508a6401) and the work was funded by [this Flipstarter](https://flipstarter.fullstack.cash/).

This indexer is one part of a collection of blockchain infrastructure. To understand how all the pieces fit together, read the [Cash Stack Documentation](https://permissionless-software-foundation.github.io/cashstack.info/).
This indexer is one part of a collection of blockchain infrastructure. To understand how all the pieces fit together, read the [Cash Stack Documentation](https://cashstack.info).

## Development Status
If you have question or need help, ask in the [community support Telegram channel](https://t.me/psf_slp).

Current status: **Beta**
## Videos

This project is using conventional development milestones:
- Alpha = Under active development. Bugs are expected, things are expected to break.
- Beta = Some bugs still exist, but code is mature enough for careful roll-out into production.
- Production = Code has been heavily tested and code commits have slowed in frequency. App is ready for normal operators.
- [Installing the psf-slp-indexer](https://youtu.be/5gF4ON9lRHI)
- [Additional Infrastructure Videos](https://psfoundation.cash/video/) in the 'Dev Ops & Infrastructure' section.

Regular status updates will be reported at the [bi-weekly PSF Technical Steering Committee meetings](https://github.com/Permissionless-Software-Foundation/TSC/issues). Updates will also be reported in [this Telegram channel](https://t.me/psf_slp).
## Installation and Usage

**See the [developer documentation](./dev-docs) for more information.**
This software is intended to be run inside a Docker container, controlled with Docker Compose, on a Ubuntu 20 OS.

### Videos

- [Installing the psf-slp-indexer](https://youtu.be/5gF4ON9lRHI)
- [Additional Infrastructure Videos](https://psfoundation.cash/video/) in the 'Dev Ops & Infrastructure' section.
- Enter the `production/docker` directory.
- Build the image with `docker-compose build --no-cache`
- Ensure you have a BCHN full node running and fully synced. [docker-bchn](https://github.com/Permissionless-Software-Foundation/docker-bchn) is recommended for running a full node.
- Start the indexer with `docker-compose up -d`


## Features

- Written in [standard JavaScript](https://www.npmjs.com/package/standard), using the [Clean Architecture](https://troutsblog.com/blog/clean-architecture) design pattern.
- Written in [standard JavaScript](https://www.npmjs.com/package/standard), using the [Clean Architecture](https://christroutner.github.io/trouts-blog/blog/clean-architecture) design pattern.
- 100% unit test coverage. This allows for operational reliability and easy code collaboration.
- [GPLv2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) Licensed to encourage wide adoption and free use throughout the BCH ecosystem.
- [GPLv2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) Licensed to encourage wide adoption and free use throughout the crypto ecosystem.
- [LevelDB](https://github.com/google/leveldb) used for fast, efficient indexing and querying.
- Drastically reduced memory usage, compared to SLPDB.
- Fast indexing using transaction maps.
- Docker container for easy deployment and horizontal scaling.

## Requirements
## Development Environment

**See the [developer documentation](./dev-docs) for more information.**

### Requirements

- Ubuntu Linux OS v20.4+
- node **^14.17.0**
- npm **^7.13.0**
- node **^16.17.0**
- npm **^8.15.0**

## Installation
### Dev Environment Installation

Customize the [slp-indexer.sh](./slp-indexer.sh) bash shell script to point to the a BCH full node with the standard JSON RPC. [docker-bchn](https://github.com/Permissionless-Software-Foundation/docker-bchn) is recommended.
Customize the [slp-indexer.sh](./slp-indexer.sh) bash shell script to point to the a BCH full node with the standard JSON RPC. [docker-bchn](https://github.com/Permissionless-Software-Foundation/docker-bchn) is recommended for running a full node.

```
git clone https://github.com/Permissionless-Software-Foundation/psf-slp-indexer
Expand Down
30 changes: 0 additions & 30 deletions bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,20 @@ import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import convert from 'koa-convert'
import logger from 'koa-logger'
import mongoose from 'mongoose'
import session from 'koa-generic-session'
import passport from 'koa-passport'
import mount from 'koa-mount'
import serve from 'koa-static'
import cors from 'kcors'

// Local libraries
import config from '../config/index.js' // this first.

import AdminLib from '../src/adapters/admin.js'
import errorMiddleware from '../src/controllers/rest-api/middleware/error.js'
import wlogger from '../src/adapters/wlogger.js'
import Controllers from '../src/controllers/index.js'
import { applyPassportMods } from '../config/passport.js'

class Server {
constructor () {
// Encapsulate dependencies
this.adminLib = new AdminLib()
this.controllers = new Controllers()
this.mongoose = mongoose
this.config = config
this.process = process
}
Expand All @@ -45,17 +37,6 @@ class Server {
const app = new Koa()
app.keys = [this.config.session]

// Connect to the Mongo Database.
this.mongoose.Promise = global.Promise
this.mongoose.set('useCreateIndex', true) // Stop deprecation warning.
console.log(
`Connecting to MongoDB with this connection string: ${this.config.database}`
)
await this.mongoose.connect(this.config.database, {
useUnifiedTopology: true,
useNewUrlParser: true
})

console.log(`Starting environment: ${this.config.env}`)
console.log(`Debug level: ${this.config.debugLevel}`)

Expand All @@ -64,20 +45,13 @@ class Server {
app.use(convert(logger()))
app.use(bodyParser())
app.use(session())
app.use(errorMiddleware())

// Used to generate the docs.
app.use(mount('/', serve(`${process.cwd()}/docs`)))

// Mount the page for displaying logs.
app.use(mount('/logs', serve(`${process.cwd()}/config/logs`)))

// User Authentication
// require('../config/passport')
applyPassportMods(passport)
app.use(passport.initialize())
app.use(passport.session())

// Enable CORS for testing
// THIS IS A SECURITY RISK. COMMENT OUT FOR PRODUCTION
// Dev Note: This line must come BEFORE controllers.attachRESTControllers()
Expand All @@ -102,10 +76,6 @@ class Server {
this.server = await app.listen(this.config.port)
console.log(`Server started on ${this.config.port}`)

// Create the system admin user.
const success = await this.adminLib.createSystemUser()
if (success) console.log('System admin user created.')

// Attach the other IPFS controllers.
// Skip if this is a test environment.
if (this.config.env !== 'test') {
Expand Down
59 changes: 0 additions & 59 deletions config/passport.js

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "psf-slp-indexer",
"version": "1.0.0",
"version": "3.0.0",
"description": "Indexer for validating SLP transactions. Uses LevelDB.",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node --max_old_space_size=16000 index.js",
"test": "npm run test:all",
"test:all": "export SVC_ENV=test && c8 --reporter=text mocha --exit --timeout 15000 --recursive test/unit test/e2e/automated/",
"test:all": "export SVC_ENV=test && c8 --reporter=text mocha --exit --timeout 15000 --recursive test/unit/",
"test:unit": "export SVC_ENV=test && c8 --reporter=text mocha --exit --timeout 15000 --recursive test/unit/",
"test:e2e:auto": "export SVC_ENV=test && mocha --exit --timeout 15000 test/e2e/automated/",
"test:temp": "export SVC_ENV=test && mocha --exit --timeout 15000 -g '#rate-limit' test/unit/json-rpc/",
"lint": "standard --env mocha --fix",
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
Expand Down
1 change: 1 addition & 0 deletions production/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ EXPOSE 5010

# Start the application.
#COPY start-production.sh start-production.sh
VOLUME start-production.sh
CMD ["./start-production.sh"]

#CMD ["npm", "start"]
15 changes: 3 additions & 12 deletions production/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
version: '3.9'

services:
mongo-slp-indexer:
image: mongo:4.2.0
container_name: mongo-slp-indexer
ports:
- '5555:27017' # <host port>:<container port>
volumes:
- ../data/database:/data/db
command: mongod --logpath=/dev/null # -- quiet
restart: always

slp-indexer:
build: .
container_name: slp-indexer
Expand All @@ -22,11 +12,12 @@ services:
max-size: '10m'
max-file: '10'
#mem_limit: 500mb
links:
- mongo-slp-indexer
#links:
# - mongo-slp-indexer
ports:
- '5010:5010' # <host port>:<container port>
volumes:
- ../data/ipfsdata:/home/safeuser/psf-slp-indexer/.ipfsdata
- ../data/leveldb:/home/safeuser/psf-slp-indexer/leveldb
- ./start-production.sh:/home/safeuser/psf-slp-indexer/start-production.sh
restart: always
Loading

0 comments on commit 12d3833

Please sign in to comment.