Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
FIX - change kinesis to sparkswap (#71)
Browse files Browse the repository at this point in the history
* change kinesis to sparkswap and remove unused code for public release

* change circleci badge

* change engine name
  • Loading branch information
dannypaz committed Jul 25, 2018
1 parent 4afe474 commit 5c9e419
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 151 deletions.
5 changes: 2 additions & 3 deletions .circleci/config.yml
@@ -1,12 +1,11 @@
# Kinesis CircleCI Config
#
# Sparkswap CircleCI Config
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
- image: node:8
- image: node:8.11
working_directory: ~/relayer

steps:
Expand Down
128 changes: 86 additions & 42 deletions README.md
@@ -1,70 +1,114 @@
# Kinesis LND Engine
# SparkSwap LND Engine

<img src="https://kines.is/logo.png" alt="Kinesis Exchange" width="550">
<img src="https://kines.is/logo.png" alt="SparkSwap" width="550">

[![CircleCI](https://circleci.com/gh/kinesis-exchange/lnd-engine.svg?style=svg&circle-token=47c81b3a717f062885f159dfded078e134413db1)](https://circleci.com/gh/kinesis-exchange/lnd-engine)
[![CircleCI](https://circleci.com/gh/sparkswap/lnd-engine.svg?style=svg&circle-token=47c81b3a717f062885f159dfded078e134413db1)](https://circleci.com/gh/sparkswap/lnd-engine)

The following repo contains 2 modules that make up a `Kinesis Engine`:
The following repo contains 2 modules that make up a SparkSwap Payment Channel Network Engine:

1. NPM module w/ LND abstraction layer (located in `src`)
2. Dockerfiles for all containers needed for the LND Engine
2. Dockerfiles for all containers needed for the LND Engine to run on a broker daemon

A current docker setup for the Kinesis exchange may look like:
A current docker setup a functional BTC/LTC LND Engine:
1. BTCD node
2. LND BTCD node (kinesis-exchange fork)
2. LND BTCD node (SparkSwap fork)
3. LTCD node
4. LND LTCD node (kinesis-exchange fork)
4. LND LTCD node (SparkSwap fork)

#### Installation (lnd-engine only)

The following commands will install dependencies, import proto files and run tests on the
lnd-engine codebase. These steps do not build the docker images associated with the lnd-engine.
The following commands will install dependencies and import associated proto files for
the lnd-engine codebase.

```
npm i
npm run build
npm test
```

You can then use `npm run build-images` to build all docker containers.

To run tests, use `npm run test`

#### Installation w/ Docker

The lnd-engine docker files make use of Docker's image storage. Run the `npm run build-images` command to
The lnd-engine docker files make use of Docker's internal image storage (to replicate the functionality of docker hub locally). Run the `npm run build-images` command to
update all docker images on your local docker installation.

#### Using the docker files in your personal project

After you have built all images on your local system, you can then use the provided `docker-compose.btc.example.yml` or
`docker-compose.ltc.example.yml` files in your project.
After you have built all images on your local system, you can use the provided `docker-compose.btc.example.yml` or
`docker-compose.ltc.example.yml` files as a reference for docker setup in your own project.

#### Library Usage

```
const LndEngine = require('lnd-engine')
const engine = new LndEngine(LND_HOST, engineOptions)
engine.getTotalBalance.... etc...
```

# JS API

```
getTotalBalance()
getUnconfirmedBalance()
getConfirmedBalanace()
getUncommittedBalance()
getCommittedBalance()
getPublicKey()
getInvoiceValue(requestHash)
getTotalChannelBalance())
createNewAddress()
createSwapHash(orderId, amountInSatoshis)
createInvoice()
createChannel(host, publicKey, fundingAmount)
isAvailable()
isInvoicePaid()
isBalanceSufficient()
payInvoice(invoiceRequest)
prepareSwap(swapHash, inbound, outbound)
executeSwap(counterpartyPubKey, swapHash, inbound, outbound)
createRefundInvoice(paymentRequest)
const engineOptions = {
logger: ...,
tlsCertPath: /absolute/path/to/tls/cert, // required
macaroonPath: /absolute/path/to/macaroon, // required
}
const engine = new LndEngine('0.0.0.0:10009', 'BTC', engineOptions)
engine.getTotalBalance.... etc
```

# API

Documentation is up-to-date as of 119fcabe94d286c88a144d9c3de1f78e85fc64ed

**NOTE:** Please see detailed documentation at [sparkswap.com/docs/engines/lnd](https://sparkswap.com/docs/engines/lnd)

### Healthcheck

```
isAvailable
validateNodeConfig
```

### Addresses

```
createNewAddress
getPaymentChannelNetworkAddress
getPublicKey
```

### Invoices

```
createInvoice
createRefundInvoice
getInvoiceValue
getInvoices
isInvoicePaid
payInvoice
```

### Cross-Chain Atomic Swaps

```
createSwapHash
executeSwap
getSettledSwapPreimage
prepareSwap
translateSwap
```

### Balances

```
getConfirmedBalance
getTotalBalance
getTotalChannelBalance
getUnconfirmedBalance
isBalanceSufficient
```

### Channels

```
createChannel
numChannelsForAddress
```
4 changes: 2 additions & 2 deletions docker-compose.btc.example.yml
Expand Up @@ -20,7 +20,7 @@ version: '2.4'

services:
btcd:
image: kinesis_btcd:latest
image: sparkswap_btcd:latest
volumes:
- shared:/shared
- bitcoin:/data
Expand Down Expand Up @@ -48,7 +48,7 @@ services:
entrypoint: ["./start-btcd.sh"]

lnd_btc:
image: kinesis_lnd_btc:latest
image: sparkswap_lnd_btc:latest
environment:
# PLEASE modify the user/pass on your BTCD node to more secure information
# as these credentials can be used to directly access your btcd instance
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.ltc.example.yml
Expand Up @@ -20,7 +20,7 @@ version: '2.4'

services:
ltcd:
image: kinesis_ltcd:latest
image: sparkswap_ltcd:latest
ports:
- '18556:18556'
volumes:
Expand All @@ -46,7 +46,7 @@ services:
entrypoint: ["./start-ltcd.sh"]

lnd_ltc:
image: kinesis_lnd_ltc:latest
image: sparkswap_lnd_ltc:latest
depends_on:
- ltcd
volumes:
Expand All @@ -66,7 +66,7 @@ services:
- TLS_KEY_PATH=/secure/lnd-engine-tls-ltc.key
- NETWORK=simnet
# The original lnd implementation does not support litecoin simnet (yet as of 7/10/2018),
# however the kinesis-network lnd fork has enabled litecoin/ltcd simnet
# however the sparkswap/lnd fork has enabled litecoin/ltcd simnet
- CHAIN=litecoin
- NODE=ltcd
- DEBUG=info
Expand Down
16 changes: 1 addition & 15 deletions docker/README.md
@@ -1,17 +1,3 @@
## LND ENGINE DOCKER FILES

This directory contains all files needed to setup LND Engine w/ the kinesis exchange

#### Before you begin

You must have docker installed. For all applications in Kinesis, it is possible to run these applications standalone
on MacOS or Ubuntu, but it is not recommeneded.

### Getting Started

Provided below is a quick-n-dirty guide on how to get started with BTC/LND so we can use the Kinesis Broker. In order for the Kinesis CLI and Kinesis Daemon to be fully functional, the following containers must be running:

- rousabeef/BTCD - Headless daemon to interact with blockchain (no wallet in this package)
- LND - Lightning Network Daemon + Wallet

These containers are what make up the `LND-Engine` which is what the Kinesis Broker AND Kinesis Relayer rely on for LND communication.`
This directory contains all files needed to setup the LND Engine with a SparkSwap Broker
2 changes: 1 addition & 1 deletion docker/btcd/Dockerfile
@@ -1,6 +1,6 @@
FROM golang:1.10-alpine as builder

LABEL maintainer="Kinesis Network <kinesis.network>"
LABEL maintainer="SparkSwap <dev@sparkswap.com>"

# Install build dependencies such as git and glide.
RUN apk add --no-cache \
Expand Down
4 changes: 2 additions & 2 deletions docker/lnd/Dockerfile
@@ -1,6 +1,6 @@
FROM golang:1.10-alpine as builder

LABEL maintainer="Kinesis Network <kinesis.network>"
LABEL maintainer="SparkSwap <dev@sparkswap.com>"

# Set the chain that is used for the current image
ARG NETWORK
Expand Down Expand Up @@ -44,7 +44,7 @@ WORKDIR $GOPATH/src/github.com/lightningnetwork/lnd
ARG COMMIT_SHA=blank
RUN : "${COMMIT_SHA:?COMMIT_SHA Build argument needs to be set.}"

RUN git clone https://github.com/kinesis-exchange/lnd . \
RUN git clone https://github.com/sparkswap/lnd . \
&& git checkout ${COMMIT_SHA} \
&& make \
&& make install
Expand Down
4 changes: 2 additions & 2 deletions docker/ltcd/Dockerfile
@@ -1,6 +1,6 @@
FROM golang:1.10-alpine as builder

LABEL maintainer="Kinesis Network <kinesis.network>"
LABEL maintainer="SparkSwap <dev@sparkswap.com>"

# Install build deps
RUN apk add --no-cache git \
Expand All @@ -26,7 +26,7 @@ RUN git clone https://github.com/ltcsuite/ltcd ./ \
&& git remote add dev git://github.com/cfromknecht/btcd \
&& git fetch dev \
# We must set git configuration to use `git merge`
&& git config --global user.email "dev@kinesis.network" \
&& git config --global user.email "dev@sparkswap.com" \
&& git config --global user.name "dev" \
# Merges the fix/single change into ltcd
&& git merge dev/rpc-witness-serialization-fix \
Expand Down
16 changes: 8 additions & 8 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "lnd-engine",
"version": "0.1.0-alpha-preview",
"description": "Kinesis engine for LND",
"description": "A SparkSwap Engine for LND lightning implementation",
"main": "src/index.js",
"standard": {
"env": [
Expand All @@ -28,23 +28,23 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/kinesis-exchange/lnd-engine.git"
"url": "git+https://github.com/sparkswap/lnd-engine.git"
},
"keywords": [
"sparkswap",
"lnd",
"kinesis",
"exchange",
"bitcoin",
"lightning",
"btc",
"bitcoin",
"ltc",
"litecoin"
],
"author": "Kinesis Network <kinesis.network>",
"author": "SparkSwap <dev@sparkswap.com>",
"license": "ISC",
"bugs": {
"url": "https://github.com/kinesis-exchange/lnd-engine/issues"
"url": "https://github.com/sparkswap/lnd-engine/issues"
},
"homepage": "https://github.com/kinesis-exchange/lnd-engine#readme",
"homepage": "https://github.com/sparkswap/lnd-engine#readme",
"devDependencies": {
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
Expand Down
14 changes: 7 additions & 7 deletions scripts/build-images.sh
Expand Up @@ -2,7 +2,7 @@

set -e -u

# Default certhost needed to build images. For production, this will change to *.kinesis.network
# Default certhost needed to build images. For production, this will change to *.sparkswap.com
LTCD_CERT_HOST=${LTCD_CERT_HOST:-docker.for.mac.host.internal}
BTCD_CERT_HOST=${BTCD_CERT_HOST:-docker.for.mac.host.internal}

Expand All @@ -17,10 +17,10 @@ LTCD_VERSION='master'
BTCD_VERSION='master'

# We add a COMMIT_SHA argument to the lnd dockerfile to trigger cache-invalidation
# when get git clone the kinesis-exchange/lnd repo. Without it, docker would continue
# when get git clone the sparkswap/lnd repo. Without it, docker would continue
# to cache old code and we would never receive updates from the fork.
#
COMMIT_SHA=`git ls-remote git://github.com/kinesis-exchange/lnd | grep "refs/heads/$LND_VERSION$" | cut -f 1`
COMMIT_SHA=`git ls-remote git://github.com/sparkswap/lnd | grep "refs/heads/$LND_VERSION$" | cut -f 1`
LTCD_COMMIT_SHA=`git ls-remote git://github.com/ltcsuite/ltcd | grep "refs/heads/$LTCD_VERSION$" | cut -f 1`
BTCD_COMMIT_SHA=`git ls-remote git://github.com/btcsuite/btcd | grep "refs/heads/$BTCD_VERSION$" | cut -f 1`

Expand All @@ -35,7 +35,7 @@ LTCD_COMMIT_SHA='cdab10132e8c6e4a3ffd112dba54791946d28906'

# NOTE: The names specified with `-t` directly map to the service names in
# the applicable services docker-compose file
docker build -t kinesis_lnd_btc ./docker/lnd --build-arg NETWORK=btc --build-arg COMMIT_SHA=$COMMIT_SHA
docker build -t kinesis_lnd_ltc ./docker/lnd --build-arg NETWORK=ltc --build-arg COMMIT_SHA=$COMMIT_SHA
docker build -t kinesis_ltcd ./docker/ltcd --build-arg COMMIT_SHA=$LTCD_COMMIT_SHA --build-arg CERT_HOST=$LTCD_CERT_HOST
docker build -t kinesis_btcd ./docker/btcd --build-arg COMMIT_SHA=$BTCD_COMMIT_SHA --build-arg CERT_HOST=$BTCD_CERT_HOST
docker build -t sparkswap_lnd_btc ./docker/lnd --build-arg NETWORK=btc --build-arg COMMIT_SHA=$COMMIT_SHA
docker build -t sparkswap_lnd_ltc ./docker/lnd --build-arg NETWORK=ltc --build-arg COMMIT_SHA=$COMMIT_SHA
docker build -t sparkswap_ltcd ./docker/ltcd --build-arg COMMIT_SHA=$LTCD_COMMIT_SHA --build-arg CERT_HOST=$LTCD_CERT_HOST
docker build -t sparkswap_btcd ./docker/btcd --build-arg COMMIT_SHA=$BTCD_COMMIT_SHA --build-arg CERT_HOST=$BTCD_CERT_HOST
6 changes: 3 additions & 3 deletions scripts/build.sh
@@ -1,15 +1,15 @@
#!/usr/bin/env bash

set -e
set -e -u

echo ""
echo "It's time to BUILD! All resistance is futile."
echo ""

npm i

# Downloads the LND proto file
LND_PROTO_URL=${LND_PROTO_URL:-https://raw.githubusercontent.com/kinesis-exchange/lnd/k%23epic/cross-chain-preimage/lnrpc/rpc.proto}
# Downloads an LND proto file from the sparkswap/lnd fork
LND_PROTO_URL=${LND_PROTO_URL:-https://raw.githubusercontent.com/sparkswap/lnd/k%23epic/cross-chain-preimage/lnrpc/rpc.proto}
curl -o ./proto/lnd-rpc.proto $LND_PROTO_URL

# Prepares the downloaded lnd-rpc proto file (installation steps tell you to remove this line)
Expand Down
20 changes: 10 additions & 10 deletions scripts/prebuild.sh
@@ -1,13 +1,13 @@
#!/bin/bash

echo ""
echo " ██ ▄█▀ ██▓ ███▄ █ ▓█████ ██████ ██▓ ██████ "
echo " ██▄█▒ ▓██▒ ██ ▀█ █ ▓█ ▀ ▒██ ▒ ▓██▒▒██ ▒ "
echo "▓███▄░ ▒██▒▓██ ▀█ ██▒▒███ ░ ▓██▄ ▒██▒░ ▓██▄ "
echo "▓██ █▄ ░██░▓██▒ ▐▌██▒▒▓█ ▄ ▒ ██▒░██░ ▒ ██▒"
echo "▒██▒ █▄░██░▒██░ ▓██░░▒████▒▒██████▒▒░██░▒██████▒▒"
echo "▒ ▒▒ ▓▒░▓ ░ ▒░ ▒ ▒ ░░ ▒░ ░▒ ▒▓▒ ▒ ░░▓ ▒ ▒▓▒ ▒ ░"
echo "░ ░▒ ▒░ ▒ ░░ ░░ ░ ▒░ ░ ░ ░░ ░▒ ░ ░ ▒ ░░ ░▒ ░ ░"
echo "░ ░░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ "
echo "░ ░ ░ ░ ░ ░ ░ ░ ░ "
echo " "
echo " ██████ ██▓███ ▄▄▄ ██▀███ ██ ▄█▀ ██████ █ █░ ▄▄▄ ██▓███ ";
echo "▒██ ▒ ▓██░ ██▒▒████▄ ▓██ ▒ ██▒ ██▄█▒ ▒██ ▒ ▓█░ █ ░█░▒████▄ ▓██░ ██▒";
echo "░ ▓██▄ ▓██░ ██▓▒▒██ ▀█▄ ▓██ ░▄█ ▒▓███▄░ ░ ▓██▄ ▒█░ █ ░█ ▒██ ▀█▄ ▓██░ ██▓▒";
echo " ▒ ██▒▒██▄█▓▒ ▒░██▄▄▄▄██ ▒██▀▀█▄ ▓██ █▄ ▒ ██▒░█░ █ ░█ ░██▄▄▄▄██ ▒██▄█▓▒ ▒";
echo "▒██████▒▒▒██▒ ░ ░ ▓█ ▓██▒░██▓ ▒██▒▒██▒ █▄▒██████▒▒░░██▒██▓ ▓█ ▓██▒▒██▒ ░ ░";
echo "▒ ▒▓▒ ▒ ░▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ▒▓ ░▒▓░▒ ▒▒ ▓▒▒ ▒▓▒ ▒ ░░ ▓░▒ ▒ ▒▒ ▓▒█░▒▓▒░ ░ ░";
echo "░ ░▒ ░ ░░▒ ░ ▒ ▒▒ ░ ░▒ ░ ▒░░ ░▒ ▒░░ ░▒ ░ ░ ▒ ░ ░ ▒ ▒▒ ░░▒ ░ ";
echo "░ ░ ░ ░░ ░ ▒ ░░ ░ ░ ░░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ";
echo " ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ";
echo " ";

0 comments on commit 5c9e419

Please sign in to comment.