Skip to content

Commit

Permalink
feature: ada supply query
Browse files Browse the repository at this point in the history
Adds a top-level query to return the principle currency supply information,
including circulating, max supply
(read from protocol params), and total supply (max - reserve balance).
cardano-cli query ledger-state is used to access the reserve balance,
with the result piped through jq in a sub-process. API requests are served
using the cache. This query can be safely to exposed to public consumers
  • Loading branch information
rhyslbw committed Jan 8, 2021
1 parent 9fdbfb1 commit e716d51
Show file tree
Hide file tree
Showing 180 changed files with 1,742 additions and 266 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
bin
node_modules
state
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ lerna-debug.log
*node_modules/
result*
*yarn-error.log
bin
state
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cardano-node"]
path = cardano-node
url = https://github.com/input-output-hk/cardano-node.git
179 changes: 138 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,158 @@
FROM node:14.15.0-alpine as node_alpine
FROM node_alpine as builder
RUN apk add --update python make g++ yarn
RUN mkdir /application
COPY package.json yarn.lock .yarnrc /application/
COPY packages-cache /application/packages-cache
WORKDIR /application
RUN mkdir /application/packages
COPY tsconfig.json /application/
COPY packages/api-cardano-db-hasura /application/packages/api-cardano-db-hasura
COPY packages/server /application/packages/server
COPY packages/util /application/packages/util
COPY packages/util-dev /application/packages/util-dev
RUN yarn --offline --frozen-lockfile --non-interactive
RUN yarn build
ARG UBUNTU_VERSION=20.04
FROM ubuntu:${UBUNTU_VERSION} as haskell-builder
ARG CABAL_VERSION=3.2.0.0
ARG GHC_VERSION=8.10.2
ARG IOHK_LIBSODIUM_GIT_REV=66f017f16633f2060db25e17c170c2afa0f2a8a1
ENV DEBIAN_FRONTEND=nonintercative
RUN mkdir -p /app/src
WORKDIR /app
RUN apt-get update -y && apt-get install -y \
automake=1:1.16.* \
build-essential=12.* \
g++=4:9.3.* \
git=1:2.25.* \
jq \
libffi-dev=3.* \
libghc-postgresql-libpq-dev=0.9.4.* \
libgmp-dev=2:6.2.* \
libncursesw5=6.* \
libpq-dev=12.* \
libssl-dev=1.1.* \
libsystemd-dev=245.* \
libtinfo-dev=6.* \
libtool=2.4.* \
make=4.2.* \
pkg-config=0.29.* \
tmux=3.* \
wget=1.20.* \
zlib1g-dev=1:1.2.*
RUN wget --secure-protocol=TLSv1_2 \
https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-x86_64-unknown-linux.tar.xz &&\
tar -xf cabal-install-${CABAL_VERSION}-x86_64-unknown-linux.tar.xz &&\
rm cabal-install-${CABAL_VERSION}-x86_64-unknown-linux.tar.xz cabal.sig &&\
mv cabal /usr/local/bin/
RUN cabal update
WORKDIR /app/ghc
RUN wget --secure-protocol=TLSv1_2 \
https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-x86_64-deb9-linux.tar.xz &&\
tar -xf ghc-${GHC_VERSION}-x86_64-deb9-linux.tar.xz &&\
rm ghc-${GHC_VERSION}-x86_64-deb9-linux.tar.xz
WORKDIR /app/ghc/ghc-${GHC_VERSION}
RUN ./configure && make install
WORKDIR /app/src
RUN git clone https://github.com/input-output-hk/libsodium.git &&\
cd libsodium &&\
git fetch --all --tags &&\
git checkout ${IOHK_LIBSODIUM_GIT_REV}
WORKDIR /app/src/libsodium
RUN ./autogen.sh && ./configure && make && make install
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
WORKDIR /app/src
COPY /cardano-node /app/src/cardano-node
WORKDIR /app/src/cardano-node
RUN cabal install cardano-cli \
--install-method=copy \
--installdir=/usr/local/bin \
-f -systemd
# Cleanup for server copy of /usr/local/lib
RUN rm -rf /usr/local/lib/ghc-${GHC_VERSION} /usr/local/lib/pkgconfig

FROM node_alpine as production_deps
RUN mkdir -p application/packages
COPY package.json yarn.lock .yarnrc /application/
COPY --from=builder /application/packages-cache /application/packages-cache
WORKDIR /application/packages
RUN mkdir api-cardano-db-hasura util server
COPY packages/api-cardano-db-hasura/package.json api-cardano-db-hasura/
COPY packages/server/package.json server/
COPY packages/util/package.json util/
WORKDIR /application
RUN yarn --production --offline --frozen-lockfile --non-interactive
FROM ubuntu:${UBUNTU_VERSION} as ubuntu-nodejs
ARG NODEJS_MAJOR_VERSION=14
ENV DEBIAN_FRONTEND=nonintercative
RUN apt-get update && apt-get install curl -y &&\
curl --proto '=https' --tlsv1.2 -sSf -L https://deb.nodesource.com/setup_${NODEJS_MAJOR_VERSION}.x | bash - &&\
apt-get install nodejs -y

FROM ubuntu-nodejs as nodejs-builder
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&\
apt-get update && apt-get install gcc g++ make gnupg2 yarn -y
RUN mkdir -p /app/packages
WORKDIR /app
COPY packages-cache packages-cache
COPY packages/api-cardano-db-hasura packages/api-cardano-db-hasura
COPY packages/server packages/server
COPY packages/util packages/util
COPY packages/util-dev packages/util-dev
COPY \
.yarnrc \
package.json \
yarn.lock \
tsconfig.json \
/app/

FROM nodejs-builder as cardano-graphql-builder
RUN yarn --offline --frozen-lockfile --non-interactive &&\
yarn build

FROM nodejs-builder as cardano-graphql-production-deps
RUN yarn --offline --frozen-lockfile --non-interactive --production

FROM frolvlad/alpine-glibc:alpine-3.11_glibc-2.30 as downloader
RUN apk add curl
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | sh
RUN hasura --skip-update-check update-cli --version v1.3.3

FROM frolvlad/alpine-glibc:alpine-3.11_glibc-2.30 as server
ARG NETWORK=mainnet
FROM nodejs-builder as dev
RUN apt-get update && apt-get install yarn -y
RUN mkdir src
RUN mkdir /node-ipc
COPY --from=haskell-builder /usr/local/lib /usr/local/lib
COPY --from=haskell-builder /usr/local/bin/cardano-cli /usr/local/bin/
COPY --from=downloader /usr/local/bin/hasura /usr/local/bin/hasura
ENV \
CARDANO_CLI_PATH=/usr/local/bin/cardano-cli \
CARDANO_NODE_SOCKET_PATH=/node-ipc/node.socket \
GENESIS_FILE_BYRON=/config/genesis/byron.json \
GENESIS_FILE_SHELLEY=/config/genesis/shelley.json \
HASURA_CLI_PATH=/usr/local/bin/hasura \
HASURA_URI="http://hasura:8080" \
LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" \
POSTGRES_DB_FILE=/run/secrets/postgres_db \
POSTGRES_HOST=postgres \
POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password \
POSTGRES_PORT=5432 \
POSTGRES_USER_FILE=/run/secrets/postgres_user
RUN apk add nodejs
RUN mkdir /application
COPY --from=builder /application/packages/api-cardano-db-hasura/dist /application/packages/api-cardano-db-hasura/dist
COPY --from=builder /application/packages/api-cardano-db-hasura/hasura/project /application/packages/api-cardano-db-hasura/hasura/project
COPY --from=builder /application/packages/api-cardano-db-hasura/package.json /application/packages/api-cardano-db-hasura/package.json
COPY --from=builder /application/packages/api-cardano-db-hasura/schema.graphql /application/packages/api-cardano-db-hasura/schema.graphql
COPY --from=builder /application/packages/server/dist /application/packages/server/dist
COPY --from=builder /application/packages/server/package.json /application/packages/server/package.json
COPY --from=builder /application/packages/util/dist /application/packages/util/dist
COPY --from=builder /application/packages/util/package.json /application/packages/util/package.json
COPY --from=production_deps /application/node_modules /application/node_modules
POSTGRES_USER_FILE=/run/secrets/postgres_user
WORKDIR /src
FROM ubuntu-nodejs as server
ARG NETWORK=mainnet
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - &&\
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list &&\
apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
jq
COPY --from=haskell-builder /usr/local/lib /usr/local/lib
COPY --from=haskell-builder /usr/local/bin/cardano-cli /usr/local/bin/
COPY --from=downloader /usr/local/bin/hasura /usr/local/bin/hasura
ENV \
CARDANO_CLI_PATH=/usr/local/bin/cardano-cli \
CARDANO_NODE_SOCKET_PATH=/node-ipc/node.socket \
GENESIS_FILE_BYRON=/config/genesis/byron.json \
GENESIS_FILE_SHELLEY=/config/genesis/shelley.json \
HASURA_CLI_PATH=/usr/local/bin/hasura \
HASURA_URI="http://hasura:8080" \
JQ_PATH=/usr/bin/jq \
LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" \
POSTGRES_DB_FILE=/run/secrets/postgres_db \
POSTGRES_HOST=postgres \
POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password \
POSTGRES_PORT=5432 \
POSTGRES_USER_FILE=/run/secrets/postgres_user
COPY --from=cardano-graphql-builder /app/packages/api-cardano-db-hasura/dist /app/packages/api-cardano-db-hasura/dist
COPY --from=cardano-graphql-builder /app/packages/api-cardano-db-hasura/hasura/project /app/packages/api-cardano-db-hasura/hasura/project
COPY --from=cardano-graphql-builder /app/packages/api-cardano-db-hasura/package.json /app/packages/api-cardano-db-hasura/package.json
COPY --from=cardano-graphql-builder /app/packages/api-cardano-db-hasura/schema.graphql /app/packages/api-cardano-db-hasura/schema.graphql
COPY --from=cardano-graphql-builder /app/packages/server/dist /app/packages/server/dist
COPY --from=cardano-graphql-builder /app/packages/server/package.json /app/packages/server/package.json
COPY --from=cardano-graphql-builder /app/packages/util/dist /app/packages/util/dist
COPY --from=cardano-graphql-builder /app/packages/util/package.json /app/packages/util/package.json
COPY --from=cardano-graphql-production-deps /app/node_modules /app/node_modules
COPY --from=cardano-graphql-production-deps /app/packages/api-cardano-db-hasura/node_modules /app/packages/api-cardano-db-hasura/node_modules
COPY config/network/${NETWORK}/genesis /config/genesis/
WORKDIR /application/packages/server/dist
RUN mkdir /node-ipc
WORKDIR /app/packages/server/dist
EXPOSE 3100
CMD ["node", "index.js"]
1 change: 1 addition & 0 deletions cardano-node
Submodule cardano-node added at 400d18
37 changes: 37 additions & 0 deletions config/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path')

module.exports = {
apps: [
{
name: 'cardano-node',
script: `${process.env.BIN_DIR}/cardano-node`,
args: [
'run',
'--config', `${process.env.CONFIG_DIR}/cardano-node/config.json`,
'--database-path', `${process.env.STATE_DIR}/node-db`,
'--socket-path', process.env.CARDANO_NODE_SOCKET_PATH,
'--topology', `${process.env.CONFIG_DIR}/cardano-node/topology.json`
],
autorestart: true,
exec_mode: 'fork_mode',
kill_timeout: 30000
},
{
name: 'docker-service-dependencies',
env: {
API_PORT: process.env.API_PORT,
HASURA_PORT: process.env.HASURA_PORT,
NETWORK: process.env.NETWORK
},
script: 'docker-compose',
args: [
'-f', `${path.resolve(__dirname, '..')}/docker-compose.dev.yml`,
'-p', `dev-${process.env.NETWORK}`,
'up', '--build'
],
autorestart: false,
exec_mode: 'fork_mode',
kill_timeout: 30000
}
]
}
3 changes: 3 additions & 0 deletions config/network/testnet/cardano-node/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
"kind": "UserDefinedBK",
"name": "LiveViewBackend"
}
],
"cardano.node.resources": [
"EKGViewBK"
]
},
"mapSubtrace": {
Expand Down
82 changes: 82 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
version: "3.5"

services:
postgres:
image: postgres:${POSTGRES_VERSION:-11.5-alpine}
environment:
- POSTGRES_LOGGING=true
- POSTGRES_DB_FILE=/run/secrets/postgres_db
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
- POSTGRES_USER_FILE=/run/secrets/postgres_user
ports:
- ${POSTGRES_PORT:-5442}:5432
secrets:
- postgres_db
- postgres_password
- postgres_user
shm_size: '2gb'
volumes:
- postgres-data:/var/lib/postgresql/data
restart: on-failure
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
cardano-db-sync-extended:
image: inputoutput/cardano-db-sync:${CARDANO_DB_SYNC_VERSION:-7.1.0}
command: [
"--config", "/config/cardano-db-sync/config.json",
"--socket-path", "/node-ipc/node.socket",
"--state-dir", "/data"
]
environment:
- EXTENDED=true
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
depends_on:
- postgres
secrets:
- postgres_password
- postgres_user
- postgres_db
volumes:
- ./config/network/${NETWORK:-mainnet}:/config
- db-sync-data:/data
- ./state/network/${NETWORK:-mainnet}/node-ipc:/node-ipc
restart: on-failure
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
hasura:
build:
context: ./packages/api-cardano-db-hasura/hasura
image: inputoutput/cardano-graphql-hasura:${CARDANO_GRAPHQL_VERSION:-3.0.1}
depends_on:
- "postgres"
restart: on-failure
environment:
- HASURA_GRAPHQL_ENABLE_CONSOLE=true
ports:
- ${HASURA_PORT:-8090}:8080
secrets:
- postgres_db
- postgres_password
- postgres_user
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
secrets:
postgres_db:
file: ./config/secrets/postgres_db
postgres_password:
file: ./config/secrets/postgres_password
postgres_user:
file: ./config/secrets/postgres_user
volumes:
db-sync-data:
postgres-data:
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ services:
environment:
- ALLOW_INTROSPECTION=true
- CACHE_ENABLED=true
- CURRENT_ERA_FIRST_SLOT=${CURRENT_ERA_FIRST_SLOT:-16588800}
- ERA_NAME=${ERA_NAME:-allegra}
expose:
- ${API_PORT:-3100}
ports:
Expand All @@ -115,6 +117,8 @@ services:
options:
max-size: "200k"
max-file: "10"
volumes:
- node-ipc:/node-ipc
secrets:
postgres_db:
file: ./config/secrets/postgres_db
Expand Down
Loading

0 comments on commit e716d51

Please sign in to comment.