Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #22 from hyahatiph-labs/dev
Browse files Browse the repository at this point in the history
Sync main
  • Loading branch information
Nigel Christian authored Jul 27, 2021
2 parents 7904b5c + 07b79c6 commit 39adf27
Show file tree
Hide file tree
Showing 27 changed files with 1,022 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Build the .jar
# Build the .jar without running test suite
- name: Build
run: mvn clean && mvn install -DskipTests=true
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest

Expand All @@ -24,6 +24,6 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs the test suite [WIP]
- name: Build
run: mvn test
# Runs the test suite
- name: Test
run: mvn clean install
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ build/

### VS Code ###
.vscode/

### db
data.mv.db
61 changes: 51 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If successfully settled the equivalent amount in Monero is sent
3. Run bitcoind on [regtest](https://developer.bitcoin.org/examples/testing.html)
4. Setup LND nodes for invoice generation and settling. *[Polar](https://lightningpolar.com/) is a cool tool!
5. Run Monero on [stagenet](https://monerodocs.org/infrastructure/networks/)
6. H2 db runs at host/h2-console. Execute the `src/main/resources/schema.sql` first
6. H2 db runs at host/h2-console.
7. Currently working on Bitcoin core 0.21, LND 0.12.x, Debian 10, Java 11, Maven 3.6 and Monero 0.17.2

NOTE: currently have an issue with Monero digest authentication rpc calls, so use `--disable-rpc-login`
Expand All @@ -38,7 +38,7 @@ request:

```json
{
"amount": 0.0123,
"amount": 0.123,
"address": "54gqcJZAtgzBFnQWEQHec3RoWfmoHqL4H8sASqdQMGshfqdpG1fzT5ddCpz9y4C2MwQkB5GE2o6vUVCGKbokJJa6S6NSatn"
}
```
Expand All @@ -47,12 +47,18 @@ response:

```json
{
"quoteId": "e8754cd5189125b46490b30cb958792e88ae34e76b954d32ad70ced27ac21c2a",
"quoteId": "63eb4534535a4c4afa9455f7dacde8cecbbac91e2bcd390407e1b88704a9a758",
"address": "54gqcJZAtgzBFnQWEQHec3RoWfmoHqL4H8sASqdQMGshfqdpG1fzT5ddCpz9y4C2MwQkB5GE2o6vUVCGKbokJJa6S6NSatn",
"isValidAddress": true,
"amount": 0.0123,
"rate": 0.006363,
"invoice": "lnbcrt78260n1psw3ax6pp5ap65e4gcjyjmgeyskvxtjkre96y2ud88dw256v4dwr8dy7kzrs4qdq8d4shxuccqzpgxqzjcsp5wyywgyzhek48wdpwq3jl04jn203d07s9huwpl7dyducstjh2eqcs9qyyssq6j27kf9vzydqqhqaal2cdryzn7u4xgm3vnltvj4qsd9aqhavpwcre5q4sy0megg005gj0zycs3j3l3nvleqqxklppknjgug30sauq8cpe2sm74"
"reserveProof": {
"signature": "ReserveProofV21AhtWZDjV1SG7AcQFSxfSVWZvQB9QG99kgr2havWLjWgewkBnnKYBt3UqQycx7A9sTaNYfiCo8PLGi28kjP7f9SvN16QNUMNaLKH7kuqySYJ4kYtnPT8qPnHK72weEpQXZhmAm3ebXEjZiH9wskFnVEfVjeCBegqcAVNsXjBZHfv95NZBoE4MgKZvfDT2ank1cqLj7VLUyC4pGVR2Y8bNdv8R1gjjQEQFo6r4YFcPKUz59k6yQ1iokWr6ZJwEauMviEk5CNEK8XYUr47TWJTzM5S3whFW5NhDZFeQ1fdsHTHbV332kwcHoDjGf3ZKaeGa5hNMHbb1XjjM5MURdHR6N59vHXPkN3xTnmZd2k1d6Dg8btwutBZujBBzWT5QNswm1V4ewutYTBBcg1cT8XsZh5MtG7cpobgaHGYYxEtGSfpD9R3agCJBpF5EZ9vsm5",
"proofAddress": "56fK1PpmCjz5CEiAb8dbpyQZtpJ8s4B2WaXPqyFD2FU9DUobuSDJZztEPeppvAqT2DPWcdp7qtW6KasCbYoWJC7qBcwWrSH"
},
"minSwapAmt": 10000,
"maxSwapAmt": 10000000,
"amount": 0.123,
"rate": 0.00629129,
"invoice": "lnbcrt773820n1ps0xdf8pp5v0452dzntfxy47552hma4n0gem9m4jg790xnjpq8uxugwp9f5avqdq8d4shxuccqzpgxqzjcsp5a75z3kfuwvas78t2a8rmm7j04su4e7t2dwh02x3e0dvwpc6w4urs9qyyssqqqryuthw0sgmtpwymmqjue89ltsre8vnh9uzrey9fs46tynqfk4rxnq5jwyjwvq3vksndfklxa578540zhuu9dprjweyezqjhcg9n8qp068g75"
}
```

Expand All @@ -66,19 +72,54 @@ request:

```json
{
"hash": "e8754cd5189125b46490b30cb958792e88ae34e76b954d32ad70ced27ac21c2a"
"hash": "63eb4534535a4c4afa9455f7dacde8cecbbac91e2bcd390407e1b88704a9a758"
}
```

response:

lncli

```bash
user@server:~$ lncli -n regtest payinvoice $PAY_REQ
Payment hash: 63eb4534535a4c4afa9455f7dacde8cecbbac91e2bcd390407e1b88704a9a758
Description: mass
Amount (in satoshis): 77382
Fee limit (in satoshis): 77382
Destination: 03e420f400087f0640ee6dfd5b0b589908133c8cf36a737e2d0c3c908661477597
Confirm payment (yes/no): yes
+------------+--------------+--------------+--------------+-----+----------+-----------------+----------------------+
| HTLC_STATE | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE | TIMELOCK | CHAN_OUT | ROUTE |
+------------+--------------+--------------+--------------+-----+----------+-----------------+----------------------+
| SUCCEEDED | 0.041 | 33.868 | 77382 | 0 | 792 | 713583046557696 | 03e420f400087f0640ee |
+------------+--------------+--------------+--------------+-----+----------+-----------------+----------------------+
Amount + fee: 77382 + 0 sat
Payment hash: 63eb4534535a4c4afa9455f7dacde8cecbbac91e2bcd390407e1b88704a9a758
Payment status: SUCCEEDED, preimage: cb4605aa339a21d70e20db617a2853214759999cac90c35e5a65fd2462bc0447
```

```json

{
"hash": "e8754cd5189125b46490b30cb958792e88ae34e76b954d32ad70ced27ac21c2a",
"txId": "fc30f5dceccc9a5514af8ec6d01e2bd8405282382a973ed8185d8d2ac8a03934"
"hash": "63eb4534535a4c4afa9455f7dacde8cecbbac91e2bcd390407e1b88704a9a758",
"metadata": "02000102000b8e8ee801a5a31b..."
}

```

relay the transaction with [relay_tx](https://web.getmonero.org/resources/developer-guides/wallet-rpc.html#relay_tx)

## Tests

MASS uses JUnit5 - [junit-jupiter](https://junit.org/junit5/) framework

Run `mvn clean install` from the root directory

View test coverage with web browser `./target/site/jacoco/index.htm`

![image](https://user-images.githubusercontent.com/13033037/126047819-09fe351a-be62-4bf9-bd5f-cb3580862c6e.png)


## TODOs

Refund / Cancel logic, Tests, etc
See [milestones](https://github.com/hyahatiph-labs/mass/milestones)
4 changes: 2 additions & 2 deletions api.http
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Content-Type: application/json

{
"amount": 0.123,
"address": "54gqcJZAtgzBFnQWEQHec3RoWfmoHqL4H8sASqdQMGshfqdpG1fzT5ddCpz9y4C2MwQkB5GE2o6vUVCGKbokJJa6S6NSatn"
"address": "56fK1PpmCjz5CEiAb8dbpyQZtpJ8s4B2WaXPqyFD2FU9DUobuSDJZztEPeppvAqT2DPWcdp7qtW6KasCbYoWJC7qBcwWrSH"
}

### Validate Monero address
Expand Down Expand Up @@ -57,7 +57,7 @@ POST http://localhost:6789/swap/xmr
Content-Type: application/json

{
"hash": "fbbdbe08b60d66514dfa295f9f192413bb549f217479fabf5ae3887f1ccdc1a2"
"hash": "2161997ea4adcaa2806c0a0e66f30b3ac48ed9f969108742a6b163148f5c7b6c"
}

### get balances of xmr wallet
Expand Down
125 changes: 124 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
</parent>
<groupId>org.hiahatf</groupId>
<artifactId>mass</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- release version -->
<version>0.1.0-beta</version>
<name>mass</name>
<description>lightning powered xmr swaps</description>

Expand Down Expand Up @@ -39,6 +40,65 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- testing dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.11.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
<version>3.2.3.RELEASE</version>
</dependency>
<!-- lombok is dope -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down Expand Up @@ -80,6 +140,7 @@
<version>30.1.1-jre</version>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -89,6 +150,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.7.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -106,6 +174,61 @@
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<!-- build restrict the application, not individual packages -->
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
<excludes>
<!-- no need to test entry point -->
<exclude>**/MassApplication.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SwapController extends BaseController {

/**
* Swap Controller constructor dependency injection
* @param quoteService
* @param service
*/
@Autowired
public SwapController(SwapService service) {
Expand All @@ -40,7 +40,7 @@ public SwapController(SwapService service) {
*/
@PostMapping(Constants.XMR_SWAP_PATH)
@ResponseStatus(HttpStatus.CREATED)
public Mono<SwapResponse> fetchMoneroQuote(@RequestBody SwapRequest request) {
public Mono<SwapResponse> fetchMoneroSwap(@RequestBody SwapRequest request) {
return swapService.processMoneroSwap(request);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/hiahatf/mass/models/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public final class Constants {
public static final String PARSE_RATE_MSG = "parsed rate: {} => real rate: {}";

// quote service values

public static final String SHA_256 = "SHA-256";
public static final Long COIN = 100000000L;
public static final String RP_ADDRESS = "${rp-address}";

// swap service values
public static final String MIN_PAY = "${min-pay}";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/hiahatf/mass/models/monero/Quote.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Quote {
// proof of address validity
private Boolean isValidAddress;
// reserve proof
private String reserveProof;
private ReserveProof reserveProof;
// minimum swap amount in satoshis
private Long minSwapAmt;
// maximum swap amount in satoshis
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/hiahatf/mass/models/monero/ReserveProof.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.hiahatf.mass.models.monero;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* POJO for the quote proof
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReserveProof {
// proof signature
private String signature;
// proof address
// configure in application.yml
// TODO: dynamic configuration
private String proofAddress;
}
Loading

0 comments on commit 39adf27

Please sign in to comment.