Skip to content

Commit

Permalink
Merge pull request #1 from DeFiCh/defi-node
Browse files Browse the repository at this point in the history
DeFiChain integration
  • Loading branch information
DeFiDev authored Mar 17, 2021
2 parents 1b4c984 + c4def63 commit 7e43a0e
Show file tree
Hide file tree
Showing 55 changed files with 1,177 additions and 765 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ executors:
docker:
- image: circleci/golang:1.15
user: root # go directory is owned by root
working_directory: /go/src/github.com/coinbase/rosetta-bitcoin
working_directory: /go/src/github.com/coinbase/rosetta-defichain
environment:
- GO111MODULE: "on"

Expand Down
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rosetta-bitcoin
bitcoin-data
cli-data
rosetta-defichain
data
cli-data
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rosetta-bitcoin
bitcoin-data
cli-data
rosetta-defichain
data
cli-data
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to rosetta-bitcoin
# Contributing to rosetta-defichain

## Code of Conduct

Expand Down
38 changes: 19 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Build bitcoind
FROM ubuntu:18.04 as bitcoind-builder
# Build defid
FROM ubuntu:18.04 as defid-builder

RUN mkdir -p /app \
&& chown -R nobody:nogroup /app
Expand All @@ -23,18 +23,18 @@ WORKDIR /app
RUN apt-get update && apt-get install -y make gcc g++ autoconf autotools-dev bsdmainutils build-essential git libboost-all-dev \
libcurl4-openssl-dev libdb++-dev libevent-dev libssl-dev libtool pkg-config python python-pip libzmq3-dev wget

# VERSION: Bitcoin Core 0.20.1
RUN git clone https://github.com/bitcoin/bitcoin \
&& cd bitcoin \
&& git checkout 7ff64311bee570874c4f0dfa18f518552188df08
# VERSION: DeFiChain 1.5.1
RUN git clone https://github.com/DeFiCh/ain \
&& cd ain \
&& git checkout 5bb08f5f750eed8ff3927c44889ed3031ae96d60

RUN cd bitcoin \
RUN cd ain \
&& ./autogen.sh \
&& ./configure --disable-tests --without-miniupnpc --without-gui --with-incompatible-bdb --disable-hardening --disable-zmq --disable-bench --disable-wallet \
&& ./configure --disable-tests --without-miniupnpc --without-gui --with-incompatible-bdb --disable-hardening --disable-zmq --disable-bench \
&& make

RUN mv bitcoin/src/bitcoind /app/bitcoind \
&& rm -rf bitcoin
RUN mv ain/src/defid /app/defid \
&& rm -rf ain

# Build Rosetta Server Components
FROM ubuntu:18.04 as rosetta-builder
Expand All @@ -43,7 +43,7 @@ RUN mkdir -p /app \
&& chown -R nobody:nogroup /app
WORKDIR /app

RUN apt-get update && apt-get install -y curl make gcc g++
RUN apt-get update && apt-get install -y curl make gcc g++ git
ENV GOLANG_VERSION 1.15.5
ENV GOLANG_DOWNLOAD_SHA256 9a58494e8da722c3aef248c9227b0e9c528c7318309827780f16220998180a0d
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
Expand All @@ -58,19 +58,19 @@ ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

# Use native remote build context to build in any directory
COPY . src
COPY . src
RUN cd src \
&& go build \
&& cd .. \
&& mv src/rosetta-bitcoin /app/rosetta-bitcoin \
&& mv src/rosetta-defichain /app/rosetta-defichain \
&& mv src/assets/* /app \
&& rm -rf src
&& rm -rf src

## Build Final Image
FROM ubuntu:18.04

RUN apt-get update && \
apt-get install --no-install-recommends -y libevent-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev && \
apt-get install --no-install-recommends -y libevent-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev libdb++-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir -p /app \
Expand All @@ -80,13 +80,13 @@ RUN mkdir -p /app \

WORKDIR /app

# Copy binary from bitcoind-builder
COPY --from=bitcoind-builder /app/bitcoind /app/bitcoind
# Copy binary from defid-builder
COPY --from=defid-builder /app/defid /app/defid

# Copy binary from rosetta-builder
# Copy binary and configuration files from rosetta-builder
COPY --from=rosetta-builder /app/* /app/

# Set permissions for everything added to /app
RUN chmod -R 755 /app/*

CMD ["/app/rosetta-bitcoin"]
CMD ["/app/rosetta-defichain"]
66 changes: 54 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: deps build run lint mocks run-mainnet-online run-mainnet-offline run-testnet-online \
run-testnet-offline check-comments add-license check-license shorten-lines test \
coverage spellcheck salus build-local coverage-local format check-format
coverage spellcheck salus build-local coverage-local format check-format check-data-api \
check-construction-api check-testnet-rosetta-cli-configuration

ADDLICENSE_CMD=go run github.com/google/addlicense
ADDLICENCE_SCRIPT=${ADDLICENSE_CMD} -c "Coinbase, Inc." -l "apache" -v
Expand All @@ -9,38 +10,40 @@ GOLINES_CMD=go run github.com/segmentio/golines
GOLINT_CMD=go run golang.org/x/lint/golint
GOVERALLS_CMD=go run github.com/mattn/goveralls
GOIMPORTS_CMD=go run golang.org/x/tools/cmd/goimports
GO_PACKAGES=./services/... ./indexer/... ./bitcoin/... ./configuration/...
GO_PACKAGES=./services/... ./indexer/... ./defichain/... ./configuration/...
GO_FOLDERS=$(shell echo ${GO_PACKAGES} | sed -e "s/\.\///g" | sed -e "s/\/\.\.\.//g")
TEST_SCRIPT=go test ${GO_PACKAGES}
LINT_SETTINGS=golint,misspell,gocyclo,gocritic,whitespace,goconst,gocognit,bodyclose,unconvert,lll,unparam
LINT_SETTINGS=golint,misspell,gocyclo,gocritic,whitespace,goconst,gocognit,bodyclose,unconvert,lll,unparam,unused,gosec,deadcode
PWD=$(shell pwd)
NOFILE=100000
CONTAINER_NAME = rosetta-defichain


deps:
go get ./...

build:
docker build -t rosetta-bitcoin:latest https://github.com/coinbase/rosetta-bitcoin.git
docker build -t rosetta-defichain:latest https://github.com/DeFiCh/rosetta-defichain.git

build-local:
docker build -t rosetta-bitcoin:latest .
docker build -t rosetta-defichain:latest .

build-release:
# make sure to always set version with vX.X.X
docker build -t rosetta-bitcoin:$(version) .;
docker save rosetta-bitcoin:$(version) | gzip > rosetta-bitcoin-$(version).tar.gz;
docker build -t rosetta-defichain:$(version) .;
docker save rosetta-defichain:$(version) | gzip > rosetta-defichain-$(version).tar.gz;

run-mainnet-online:
docker run -d --rm --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 8333:8333 rosetta-bitcoin:latest
docker run -d --ulimit --name ${CONTAINER_NAME} "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 rosetta-defichain:latest

run-mainnet-offline:
docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest
docker run -d --rm --name ${CONTAINER_NAME} -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 rosetta-defichain:latest

run-testnet-online:
docker run -d --rm --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 18333:18333 rosetta-bitcoin:latest
docker run -d --rm --name ${CONTAINER_NAME} --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 rosetta-defichain:latest

run-testnet-offline:
docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest
docker run -d --rm --name ${CONTAINER_NAME} -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 rosetta-defichain:latest

train:
./zstd-train.sh $(network) transaction $(data-directory)
Expand Down Expand Up @@ -71,7 +74,7 @@ check-format:
test:
${TEST_SCRIPT}

coverage:
coverage:
if [ "${COVERALLS_TOKEN}" ]; then ${TEST_SCRIPT} -coverprofile=c.out -covermode=count; ${GOVERALLS_CMD} -coverprofile=c.out -repotoken ${COVERALLS_TOKEN}; fi

coverage-local:
Expand All @@ -88,3 +91,42 @@ mocks:
mockery --dir indexer --all --case underscore --outpkg indexer --output mocks/indexer;
mockery --dir services --all --case underscore --outpkg services --output mocks/services;
${ADDLICENCE_SCRIPT} .;

# Possible configuration parameters:
# ----------------------------------
# GENERAL:
# - https://pkg.go.dev/github.com/coinbase/rosetta-cli/configuration#Configuration
#
# DATA:
# - https://pkg.go.dev/github.com/coinbase/rosetta-cli/configuration#DataConfiguration
#
# CONSTRUCTION:
# - https://pkg.go.dev/github.com/coinbase/rosetta-cli/configuration#ConstructionConfiguration
#
# NOTE: in order to perform all checks correctly rosetta-cli should be installed from
# the following source:
# - https://github.com/DeFiDev/rosetta-cli/tree/v0.6.7-1
#
# This is a fork of original rosetta-cli implementation, but with some fix applied.
# Detailed fix description may be found here:
# - https://github.com/coinbase/rosetta-cli/issues/222
#
check-mainnet-data-api: check-mainnet-rosetta-cli-configuration
rosetta-cli check:data --configuration-file ${CLI_MAINNET_CONFIG_PATH}

check-testnet-data-api: check-testnet-rosetta-cli-configuration
rosetta-cli check:data --configuration-file ${CLI_TESTNET_CONFIG_PATH}

check-testnet-construction-api: check-testnet-rosetta-cli-configuration
rosetta-cli check:construction --configuration-file ${CLI_TESTNET_CONFIG_PATH}

# NOTE: may be provided as an environment variable
CLI_TESTNET_CONFIG_PATH = `pwd`/rosetta-cli-conf/testnet/config.json
CLI_MAINNET_CONFIG_PATH = `pwd`/rosetta-cli-conf/mainnet/config.json

check-testnet-rosetta-cli-configuration:
rosetta-cli configuration:validate ${CLI_TESTNET_CONFIG_PATH}

check-mainnet-rosetta-cli-configuration:
rosetta-cli configuration:validate ${CLI_MAINNET_CONFIG_PATH}

Loading

0 comments on commit 7e43a0e

Please sign in to comment.