Skip to content

Commit

Permalink
feat: Introduce new cardano-node api package
Browse files Browse the repository at this point in the history
Using cardano-cli as the cardano-node interface, it's now possible
to submit a signed transaction query the tip directly from the node.

Closes #10
  • Loading branch information
rhyslbw committed Jul 26, 2020
1 parent 929467e commit b558b68
Show file tree
Hide file tree
Showing 58 changed files with 1,106 additions and 36 deletions.
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
./node-ipc
app/
77 changes: 59 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:10.15.3-alpine as builder
FROM node:10.15.3-alpine as nodejs_builder
RUN apk add --update python make g++ yarn
RUN mkdir /application
COPY package.json yarn.lock .yarnrc /application/
Expand All @@ -7,46 +7,87 @@ WORKDIR /application
RUN mkdir /application/packages
COPY tsconfig.json /application/
COPY packages/api-cardano-db-hasura /application/packages/api-cardano-db-hasura
COPY packages/api-cardano-node /application/packages/api-cardano-node
COPY packages/api-genesis /application/packages/api-genesis
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

FROM node:10.15.3-alpine as production_deps
FROM node:10.15.3-alpine as nodejs_production_deps
RUN mkdir -p application/packages
COPY package.json yarn.lock .yarnrc /application/
COPY --from=builder /application/packages-cache /application/packages-cache
COPY --from=nodejs_builder /application/packages-cache /application/packages-cache
WORKDIR /application/packages
RUN mkdir api-cardano-db-hasura api-genesis util server
RUN mkdir api-cardano-db-hasura api-cardano-node api-genesis util server
COPY packages/api-cardano-db-hasura/package.json api-cardano-db-hasura/
COPY packages/api-cardano-node/package.json api-cardano-node/
COPY packages/api-genesis/package.json api-genesis/
COPY packages/server/package.json server/
COPY packages/util/package.json util/
WORKDIR /application
RUN yarn --production --offline --frozen-lockfile --non-interactive

FROM debian:buster-slim as cardano_haskell_builder
ARG CARDANO_NODE_TAG=1.15.1
WORKDIR /build
RUN apt -yq update && apt -yq upgrade

RUN apt install build-essential pkg-config libffi-dev libgmp-dev libssl-dev libtinfo-dev libsodium-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libncursesw5 \
-y
RUN wget https://downloads.haskell.org/~cabal/cabal-install-3.2.0.0/cabal-install-3.2.0.0-x86_64-unknown-linux.tar.xz && \
tar -xf cabal-install-3.2.0.0-x86_64-unknown-linux.tar.xz && \
rm cabal-install-3.2.0.0-x86_64-unknown-linux.tar.xz cabal.sig && \
mv cabal /usr/local/bin/
RUN cabal update
WORKDIR /app/ghc
RUN wget https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-deb9-linux.tar.xz && \
tar -xf ghc-8.6.5-x86_64-deb9-linux.tar.xz && \
rm ghc-8.6.5-x86_64-deb9-linux.tar.xz
WORKDIR /app/ghc/ghc-8.6.5
RUN ./configure
RUN make install
WORKDIR /app
RUN mkdir build
RUN git clone https://github.com/input-output-hk/cardano-node.git && \
cd cardano-node && \
git fetch --all --tags && \
git checkout ${CARDANO_NODE_TAG}
WORKDIR /app/cardano-node
COPY config/cabal.project.local .
RUN cabal build cardano-cli && \
mv ./dist-newstyle/build/x86_64-linux/ghc-8.6.5/cardano-cli-${CARDANO_NODE_TAG}/x/cardano-cli/build/cardano-cli/cardano-cli /usr/local/bin/

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.2.1

FROM frolvlad/alpine-glibc:alpine-3.11_glibc-2.30 as server
RUN apk add nodejs
#FROM frolvlad/alpine-glibc:alpine-3.11_glibc-2.30 as server
#RUN apt add nodejs
FROM debian:buster-slim as server
RUN apt -yq update && apt -yq upgrade
RUN apt install nodejs -y
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/api-genesis/dist /application/packages/api-genesis/dist
COPY --from=builder /application/packages/api-genesis/package.json /application/packages/api-genesis/package.json
COPY --from=builder /application/packages/api-genesis/schema.graphql /application/packages/api-genesis/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
COPY --from=cardano_haskell_builder /usr/lib /usr/lib
COPY --from=cardano_haskell_builder /etc /etc
COPY --from=cardano_haskell_builder /usr/local/bin/cardano-cli /usr/local/bin/cardano-cli
COPY --from=nodejs_builder /application/packages/api-cardano-db-hasura/dist /application/packages/api-cardano-db-hasura/dist
COPY --from=nodejs_builder /application/packages/api-cardano-db-hasura/hasura/project /application/packages/api-cardano-db-hasura/hasura/project
COPY --from=nodejs_builder /application/packages/api-cardano-db-hasura/package.json /application/packages/api-cardano-db-hasura/package.json
COPY --from=nodejs_builder /application/packages/api-cardano-db-hasura/schema.graphql /application/packages/api-cardano-db-hasura/schema.graphql
COPY --from=nodejs_builder /application/packages/api-cardano-node/dist /application/packages/api-cardano-node/dist
COPY --from=nodejs_builder /application/packages/api-cardano-node/package.json /application/packages/api-cardano-node/package.json
COPY --from=nodejs_builder /application/packages/api-cardano-node/schema.graphql /application/packages/api-cardano-node/schema.graphql
COPY --from=nodejs_builder /application/packages/api-genesis/dist /application/packages/api-genesis/dist
COPY --from=nodejs_builder /application/packages/api-genesis/package.json /application/packages/api-genesis/package.json
COPY --from=nodejs_builder /application/packages/api-genesis/schema.graphql /application/packages/api-genesis/schema.graphql
COPY --from=nodejs_builder /application/packages/server/dist /application/packages/server/dist
COPY --from=nodejs_builder /application/packages/server/package.json /application/packages/server/package.json
COPY --from=nodejs_builder /application/packages/util/dist /application/packages/util/dist
COPY --from=nodejs_builder /application/packages/util/package.json /application/packages/util/package.json
COPY --from=nodejs_production_deps /application/node_modules /application/node_modules
COPY --from=downloader /usr/local/bin/hasura /usr/local/bin/hasura
WORKDIR /application
WORKDIR /application/packages/server/dist
Expand Down
2 changes: 2 additions & 0 deletions config/cabal.project.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package cardano-crypto-praos
flags: -external-libsodium-vrf
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ services:
- CACHE_ENABLED=true
- GENESIS_FILE_SHELLEY=/configuration/genesis_shelley.json
- HASURA_URI=http://hasura:8080
- CARDANO_NODE_SOCKET_PATH=/node-ipc/node.socket
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB_FILE=/run/secrets/postgres_db
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
- POSTGRES_USER_FILE=/run/secrets/postgres_user
- CARDANO_MAGIC=42
expose:
- 3100
ports:
Expand All @@ -108,6 +110,7 @@ services:
max-size: "200k"
max-file: "10"
volumes:
- node-ipc:/node-ipc
- ./config/network/${NETWORK:-mainnet}:/configuration
secrets:
postgres_db:
Expand Down
47 changes: 47 additions & 0 deletions mk-addresses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -ex

#
# In order to run the graphql tests you need some addresses set up on the testnet with funds
# Copy this file into the ./app directory and then run it from inside the graphql docker container. e.g. docker exec -t ./app/mk-addresses.sh
# You will then need to add some ada to the payment.addr using https://testnets.cardano.org/en/shelley/tools/faucet/
#

# All taken from https://github.com/input-output-hk/cardano-tutorials/blob/master/node-setup/020_keys_and_addresses.md


# build the stake address
cardano-cli shelley stake-address key-gen \
--verification-key-file stake.vkey \
--signing-key-file stake.skey

cardano-cli shelley stake-address build \
--stake-verification-key-file stake.vkey \
--out-file stake.addr \
--testnet-magic 42

# build the first payment address, this is the address that you will send payments from in the tests, it needs funds to be added
cardano-cli shelley address key-gen \
--verification-key-file payment.vkey \
--signing-key-file payment.skey

cardano-cli shelley address build \
--payment-verification-key-file payment.vkey \
--stake-verification-key-file stake.vkey \
--out-file payment.addr \
--testnet-magic 42

# build the second payment address, this is the address that you will send payments to in the tests and it needs no funds
cardano-cli shelley address key-gen \
--verification-key-file payment2.vkey \
--signing-key-file payment2.skey

cardano-cli shelley address build \
--payment-verification-key-file payment2.vkey \
--stake-verification-key-file stake.vkey \
--out-file payment2.addr \
--testnet-magic 42

# This is the address you need to add funds to using https://testnets.cardano.org/en/shelley/tools/faucet/
cat payment.addr
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"homepage": "https://github.com/input-output-hk/cardano-graphql#README.md",
"devDependencies": {
"@graphql-codegen/add": "^1.16.3",
"@graphql-codegen/cli": "^1.15.2",
"@graphql-codegen/typescript": "^1.15.2",
"@graphql-codegen/typescript-graphql-files-modules": "^1.15.2",
Expand All @@ -60,6 +61,7 @@
"apollo-link-http": "^1.5.17",
"apollo-server-core": "^2.15.0",
"apollo-server-testing": "^2.15.0",
"axios": "^0.19.2",
"bignumber.js": "^9.0.0",
"cross-fetch": "^3.0.4",
"env-paths": "^2.2.0",
Expand Down
Binary file added packages-cache/@babel-runtime-7.10.5.tgz
Binary file not shown.
Binary file added packages-cache/@graphql-codegen-add-1.16.3.tgz
Binary file not shown.
Binary file not shown.
Binary file added packages-cache/@graphql-tools-links-6.0.12.tgz
Binary file not shown.
Binary file not shown.
Binary file added packages-cache/@graphql-tools-mock-6.0.12.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added packages-cache/@graphql-tools-stitch-6.0.12.tgz
Binary file not shown.
Binary file added packages-cache/apollo-upload-client-13.0.0.tgz
Binary file not shown.
Binary file added packages-cache/axios-0.19.2.tgz
Binary file not shown.
Binary file added packages-cache/cbor-5.0.2.tgz
Binary file not shown.
Binary file added packages-cache/cbor-body-parser-1.0.2.tgz
Binary file not shown.
Binary file added packages-cache/extract-files-8.1.0.tgz
Binary file not shown.
Binary file added packages-cache/follow-redirects-1.5.10.tgz
Binary file not shown.
Binary file added packages-cache/fs-capacitor-6.2.0.tgz
Binary file not shown.
Binary file added packages-cache/graphql-iso-date-3.6.1.tgz
Binary file not shown.
Binary file added packages-cache/graphql-tools-6.0.12.tgz
Binary file not shown.
Binary file added packages-cache/graphql-upload-11.0.0.tgz
Binary file not shown.
Binary file added packages-cache/isobject-4.0.0.tgz
Binary file not shown.
Binary file added packages-cache/lodash-4.17.15.tgz
Binary file not shown.
Binary file added packages-cache/nofilter-1.0.3.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions packages/api-cardano-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/graphql_types.ts
Loading

0 comments on commit b558b68

Please sign in to comment.