-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2253 from ManfredKarrer/http-api
Http api
- Loading branch information
Showing
36 changed files
with
1,193 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.git | ||
.gitignore | ||
.gitmodules | ||
.dockerignore | ||
.travis.yml | ||
docker-compose.yml | ||
docker-compose-base.yml | ||
Dockerfile | ||
.idea | ||
*.iml | ||
target | ||
support | ||
.gradle | ||
build | ||
out | ||
doc | ||
|
||
api/docker/dev/Dockerfile | ||
api/docker/prod/Dockerfile | ||
api/.dockerignore | ||
api/.editorconfig | ||
api/.git | ||
api/.gitignore | ||
api/.travis.yml | ||
api/support |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
language: java | ||
jdk: openjdk10 | ||
before_install: | ||
grep -v '^#' assets/src/main/resources/META-INF/services/bisq.asset.Asset | sort --check --dictionary-order --ignore-case | ||
sudo: required | ||
services: | ||
- docker | ||
jobs: | ||
include: | ||
- stage: asset ordering | ||
install: echo No installation needed | ||
script: grep -v '^#' assets/src/main/resources/META-INF/services/bisq.asset.Asset | sort --check --dictionary-order --ignore-case | ||
- stage: build | ||
- stage: integration | ||
env: | ||
- CUBE_LOGGER_ENABLE=true | ||
install: cd api; docker-compose build; | ||
script: ../gradlew testIntegration; | ||
before_cache: | ||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock | ||
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/ | ||
cache: | ||
directories: | ||
- $HOME/.gradle/caches/ | ||
- $HOME/.gradle/wrapper/ | ||
notifications: | ||
slack: | ||
on_success: change | ||
on_failure: always | ||
rooms: | ||
- secure: EzlqWTBuhb3FCfApjUXaShWgsWOVDwMXI7ISMiVBkcl2VFISYs/lc/7Qjr7rdy4iqQOQXMcUPHdwMUp0diX+GxiSjLARjUpKIvNOPswZWBL+3Z1h28jyOwtHRviZbM1EU0BZROrr+ODyTNz2lf+L1iXTkpSvk50o5JAnAkumsPw= | ||
slack: | ||
on_success: change | ||
on_failure: always | ||
rooms: | ||
- secure: EzlqWTBuhb3FCfApjUXaShWgsWOVDwMXI7ISMiVBkcl2VFISYs/lc/7Qjr7rdy4iqQOQXMcUPHdwMUp0diX+GxiSjLARjUpKIvNOPswZWBL+3Z1h28jyOwtHRviZbM1EU0BZROrr+ODyTNz2lf+L1iXTkpSvk50o5JAnAkumsPw= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.git | ||
.gitignore | ||
.dockerignore | ||
docker-compose.yml | ||
docker-compose-base.yml | ||
Dockerfile | ||
docker/dev/Dockerfile | ||
docker/prod/Dockerfile | ||
|
||
.idea | ||
*.iml | ||
|
||
target | ||
support | ||
|
||
build | ||
out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Bisq HTTP API | ||
|
||
**The API branch is under development! | ||
Do not use it in production environment at the current state!** | ||
|
||
Enabling the API exposes some of Bisq's functionality for access over a http API. | ||
You can run it either as the desktop application or as a headless application. | ||
|
||
On that branch we start to implement feature by feature starting with the most simple one - `version`. | ||
|
||
|
||
_**Known issues**: Wallet password protection is not supported at the moment for the headless version. So if you have set | ||
a wallet password when running the Desktop version and afterwards run the headless version it will get stuck at startup | ||
expecting the wallet password. This feature will be implemented soon._ | ||
|
||
_**Note**: | ||
If you have a Bisq application with BTC already set up it is recommended to use the optional `appName` argument to | ||
provide a different name and data directory so that the default Bisq application is not exposed via the API. That way | ||
your data and wallet from your default Bisq application are completely isolated from the API application. In the below | ||
commands we use the argument `--appName=bisq-API` to ensure you are not mixing up your default Bisq setup when | ||
experimenting with the API branch. You cannot run the desktop and the headless version in parallel as they would access | ||
the same data. | ||
|
||
## Run the API as Desktop application | ||
|
||
cd desktop | ||
../gradlew run --args="--desktopWithHttpApi=true --appName=bisq-API" | ||
|
||
If the application has started up you should see following line in the logs: | ||
|
||
HTTP API started on localhost/127.0.0.1:8080 | ||
|
||
If you prefer another port or host use the arguments `--httpApiHost` and `--httpApiPort`. | ||
|
||
### API Documentation | ||
|
||
Documentation is available at http://localhost:8080/docs/ | ||
|
||
Sample call: | ||
|
||
curl http://localhost:8080/api/v1/version | ||
|
||
## Run the API as headless application | ||
|
||
cd api | ||
../gradlew run --args="--appName=bisq-API" | ||
|
||
## Docker integration | ||
|
||
First you need to build the docker image for the API: | ||
|
||
cd api | ||
docker-compose build | ||
|
||
Start container with the API: | ||
|
||
docker-compose up alice | ||
|
||
It will automatically start `bisq-api` (alice), `bitcoind` and `seednode` in regtest mode. | ||
|
||
curl localhost:8080/api/v1/version | ||
|
||
## Host and port configuration | ||
|
||
../gradlew run --args="--httpApiHost=127.0.0.1 --httpApiPort=8080" | ||
|
||
**CAUTION! Please do not expose the API over a public interface** | ||
|
||
## Experimental features | ||
|
||
Some features will be not sufficiently tested and will only be enabled if you add the | ||
`enableHttpApiExperimentalFeatures` argument: | ||
|
||
../gradlew run --args="--enableHttpApiExperimentalFeatures" | ||
|
||
## Regtest mode | ||
|
||
../gradlew run --args="--appName=bisq-BTC_REGTEST-alice --nodePort=8003 --useLocalhostForP2P=true | ||
--seedNodes=localhost:8000 --btcNodes=localhost:18445 --baseCurrencyNetwork=BTC_REGTEST --logLevel=info | ||
--useDevPrivilegeKeys=true --bitcoinRegtestHost=NONE --myAddress=172.17.0.1:8003 | ||
--enableHttpApiExperimentalFeatures" | ||
|
||
## Integration tests | ||
|
||
Integration tests leverage Docker and run in headless mode. First you need to build docker images for the api: | ||
|
||
cd api | ||
docker-compose build | ||
../gradlew testIntegration | ||
|
||
IntelliJ Idea has awesome integration so just right click on `api/src/testIntegration` directory and select | ||
`Debug All Tests`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
version: '2.1' | ||
|
||
services: | ||
api: | ||
build: | ||
context: .. | ||
dockerfile: api/docker/dev/Dockerfile | ||
image: bisq/api | ||
environment: | ||
- LOG_LEVEL=debug | ||
- USE_LOCALHOST_FOR_P2P=true | ||
- USE_DEV_PRIVILEGE_KEYS=true | ||
- SEED_NODES=seed:8000 | ||
- BTC_NODES=bitcoin:18444 | ||
- BASE_CURRENCY_NETWORK=BTC_REGTEST | ||
- BITCOIN_REGTEST_HOST=NONE | ||
- HTTP_API_HOST=0.0.0.0 | ||
- ENABLE_HTTP_API_EXPERIMENTAL_FEATURES=true | ||
seed: | ||
image: bisq/seednode | ||
environment: | ||
- MY_ADDRESS=seed:8000 | ||
- SEED_NODES=seed:8000 | ||
- BTC_NODES=bitcoin:18444 | ||
- USE_LOCALHOST_FOR_P2P=true | ||
- BASE_CURRENCY_NETWORK=BTC_REGTEST | ||
- BITCOIN_REGTEST_HOST=NONE | ||
bitcoin: | ||
image: kylemanna/bitcoind:latest | ||
command: -logips -rpcallowip=::/0 -regtest -printtoconsole | ||
environment: | ||
- DISABLEWALLET=0 | ||
- RPCUSER=user | ||
- RPCPASSWORD=password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
version: '2.1' | ||
|
||
services: | ||
alice: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: api | ||
ports: | ||
- 8080:8080 | ||
environment: | ||
- NODE_PORT=8003 | ||
links: | ||
- seed | ||
- bitcoin | ||
bob: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: api | ||
ports: | ||
- 8081:8080 | ||
environment: | ||
- NODE_PORT=8004 | ||
links: | ||
- seed | ||
- bitcoin | ||
arbitrator: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: api | ||
ports: | ||
- 8082:8080 | ||
environment: | ||
- NODE_PORT=8005 | ||
links: | ||
- seed | ||
- bitcoin | ||
seed: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: seed | ||
ports: | ||
- 8000:8000 | ||
links: | ||
- bitcoin | ||
bitcoin: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: bitcoin | ||
ports: | ||
# If it is default regtest port (18444) then bisq ignores btcNodes param and uses localhost | ||
- 18445:18444 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM openjdk:10-jdk | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
openjfx && rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /bisq/api | ||
|
||
#ENV HTTP_API_HOST= | ||
#ENV HTTP_API_PORT= | ||
ENV LANG=en_US | ||
|
||
CMD ./docker/startApi.sh | ||
|
||
#Fetch gradle and dependencies | ||
COPY gradle /bisq/gradle/ | ||
COPY gradlew build.gradle gradle.properties settings.gradle /bisq/ | ||
RUN ../gradlew --no-daemon -v | ||
|
||
COPY assets /bisq/assets/ | ||
COPY common /bisq/common/ | ||
COPY core /bisq/core/ | ||
COPY p2p /bisq/p2p/ | ||
COPY pricenode /bisq/pricenode/ | ||
RUN ../gradlew --no-daemon build -x test | ||
|
||
COPY api /bisq/api | ||
|
||
#Compile sources to speed up startup | ||
RUN ../gradlew --no-daemon --offline compileJava -x test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
IP=`ip -4 -o addr show eth0 | sed 's/.*inet \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/'` | ||
ARGS="--myAddress $IP:${NODE_PORT:-9999}" | ||
if [ ! -z "$APP_NAME" ]; then | ||
ARGS="$ARGS --appName=$APP_NAME" | ||
fi | ||
if [ ! -z "$NODE_PORT" ]; then | ||
ARGS="$ARGS --nodePort=$NODE_PORT" | ||
fi | ||
if [ ! -z "$USE_LOCALHOST_FOR_P2P" ]; then | ||
ARGS="$ARGS --useLocalhostForP2P=$USE_LOCALHOST_FOR_P2P" | ||
fi | ||
if [ ! -z "$SEED_NODES" ]; then | ||
ARGS="$ARGS --seedNodes=$SEED_NODES" | ||
fi | ||
if [ ! -z "$BTC_NODES" ]; then | ||
ARGS="$ARGS --btcNodes=$BTC_NODES" | ||
fi | ||
if [ ! -z "$BITCOIN_REGTEST_HOST" ]; then | ||
ARGS="$ARGS --bitcoinRegtestHost=$BITCOIN_REGTEST_HOST" | ||
fi | ||
if [ ! -z "$BASE_CURRENCY_NETWORK" ]; then | ||
ARGS="$ARGS --baseCurrencyNetwork=$BASE_CURRENCY_NETWORK" | ||
fi | ||
if [ ! -z "$LOG_LEVEL" ]; then | ||
ARGS="$ARGS --logLevel=$LOG_LEVEL" | ||
fi | ||
if [ ! -z "$USE_DEV_PRIVILEGE_KEYS" ]; then | ||
ARGS="$ARGS --useDevPrivilegeKeys=$USE_DEV_PRIVILEGE_KEYS" | ||
fi | ||
if [ "$ENABLE_HTTP_API_EXPERIMENTAL_FEATURES" == "true" ]; then | ||
ARGS="$ARGS --enableHttpApiExperimentalFeatures" | ||
fi | ||
if [ ! -z "$HTTP_API_PORT" ]; then | ||
ARGS="$ARGS --httpApiPort=$HTTP_API_PORT" | ||
fi | ||
if [ ! -z "$HTTP_API_HOST" ]; then | ||
ARGS="$ARGS --httpApiHost=$HTTP_API_HOST" | ||
fi | ||
|
||
echo ../gradlew run --no-daemon --args "foo $ARGS" | ||
../gradlew run --no-daemon --args "foo $ARGS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* This file is part of Bitsquare. | ||
* | ||
* Bitsquare is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.api.http; | ||
|
||
import bisq.api.http.service.HttpApiServer; | ||
import bisq.api.http.service.endpoint.VersionEndpoint; | ||
|
||
import bisq.core.app.AppOptionKeys; | ||
|
||
import bisq.common.app.AppModule; | ||
|
||
import org.springframework.core.env.Environment; | ||
|
||
import com.google.inject.Singleton; | ||
import com.google.inject.name.Names; | ||
|
||
public class HttpApiModule extends AppModule { | ||
|
||
public HttpApiModule(Environment environment) { | ||
super(environment); | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
bind(HttpApiServer.class).in(Singleton.class); | ||
bind(VersionEndpoint.class).in(Singleton.class); | ||
|
||
String httpApiHost = environment.getProperty(AppOptionKeys.HTTP_API_HOST, String.class, "127.0.0.1"); | ||
bind(String.class).annotatedWith(Names.named(AppOptionKeys.HTTP_API_HOST)).toInstance(httpApiHost); | ||
|
||
Integer httpApiPort = Integer.valueOf(environment.getProperty(AppOptionKeys.HTTP_API_PORT, String.class, "8080")); | ||
bind(Integer.class).annotatedWith(Names.named(AppOptionKeys.HTTP_API_PORT)).toInstance(httpApiPort); | ||
} | ||
} |
Oops, something went wrong.