Skip to content

Commit a7b06fd

Browse files
committed
Merge branch 'develop'
2 parents 0472abb + d4c95fa commit a7b06fd

58 files changed

Lines changed: 4966 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/publish.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish to Maven
2+
3+
env:
4+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5+
SONA_USER: ${{ secrets.SONA_USER }}
6+
SONA_PASS: ${{ secrets.SONA_PASS }}
7+
8+
on:
9+
push:
10+
tags:
11+
- 'v*'
12+
13+
jobs:
14+
package:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Configure GPG Key
18+
run: |
19+
mkdir -p ~/.gnupg/
20+
printf "$GPG_SIGNING_KEY" | base64 --decode > ~/.gnupg/private.key
21+
gpg --import --no-tty --batch --yes ~/.gnupg/private.key
22+
env:
23+
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
24+
- uses: actions/checkout@v2
25+
- name: Package
26+
uses: actions/setup-java@v1.4.2
27+
with:
28+
java-version: '11.0.8'
29+
- run: sbt publishSigned sonatypeRelease
30+
- name: Package Command Line Jar
31+
uses: actions/setup-java@v1.4.2
32+
with:
33+
java-version: '11.0.8'
34+
- run: sbt assembly
35+
- name: Upload Command Line Jar
36+
uses: actions/upload-artifact@v2
37+
with:
38+
name: psg-cardano-wallet-api-assembly
39+
path: target/scala-2.13/psg-cardano-wallet-api-assembly*.jar
40+

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Clean, build, test, coverage
2+
3+
env:
4+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
- develop
11+
pull_request:
12+
branches:
13+
- master
14+
- develop
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Run tests
22+
uses: actions/setup-java@v1.4.2
23+
with:
24+
java-version: '11.0.8'
25+
- run: sbt coverage test it:test coverageReport
26+
env:
27+
BASE_URL: ${{ secrets.BASE_URL }}
28+
CARDANO_API_WALLET_1_PASSPHRASE: ${{ secrets.CARDANO_API_WALLET_1_PASSPHRASE }}
29+
CARDANO_API_WALLET_1_MNEMONIC: ${{ secrets.CARDANO_API_WALLET_1_MNEMONIC }}
30+
CARDANO_API_WALLET_2_MNEMONIC: ${{ secrets.CARDANO_API_WALLET_2_MNEMONIC }}
31+
CARDANO_API_WALLET_3_MNEMONIC: ${{ secrets.CARDANO_API_WALLET_3_MNEMONIC }}
32+
CARDANO_API_WALLET_3_MNEMONIC_SECONDARY: ${{ secrets.CARDANO_API_WALLET_3_MNEMONIC_SECONDARY }}
33+
CARDANO_API_WALLET_3_PASSPHRASE: ${{ secrets.CARDANO_API_WALLET_3_PASSPHRASE }}
34+
35+
- name: Archive code coverage results
36+
uses: actions/upload-artifact@v2
37+
with:
38+
name: code-coverage-report
39+
path: target/scala-2.13/scoverage-report
40+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
target

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2020 iog-psg
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,145 @@
1-
# psg-cardano-wallet-api
2-
Scala client to the Cardano wallet REST API
1+
# PSG Cardano Wallet API
2+
3+
_For consultancy services email [enterprise.solutions@iohk.io](mailto:enterprise.solutions@iohk.io)_
4+
### Scala and Java client for the Cardano Wallet API
5+
6+
The Cardano node exposes a [REST like API](https://github.com/input-output-hk/cardano-wallet)
7+
allowing clients to perform a variety of tasks including
8+
- creating or restoring a wallet
9+
- submitting a transaction with or without [metadata](https://github.com/input-output-hk/cardano-wallet/wiki/TxMetadata)
10+
- checking on the status of the node
11+
- listing transactions
12+
- listing wallets
13+
14+
The full list of capabilities can be found [here](https://input-output-hk.github.io/cardano-wallet/api/edge/).
15+
16+
This artefact wraps calls to that API to make them easily accessible to Java or Scala developers.
17+
18+
It also provides an executable jar to provide rudimentary command line access.
19+
20+
21+
- [Building](#building)
22+
- [Usage](#usage)
23+
- [scala](#usagescala)
24+
- [java](#usagejava)
25+
- [Command line executable jar](#cmdline)
26+
- [Examples](#examples)
27+
- [Issues](#issues)
28+
29+
30+
### <a name="building"></a> Building
31+
32+
This is an `sbt` project, so the usual `sbt` commands apply.
33+
34+
Clone the [repository](https://github.com/input-output-hk/psg-cardano-wallet-api)
35+
36+
To build and publish the project to your local repository use
37+
38+
`sbt publish`
39+
40+
To build the command line executable jar use
41+
42+
`sbt assembly`
43+
44+
To build the command line executable jar skipping tests, use
45+
46+
`sbt 'set test in assembly := {}' assembly`
47+
48+
This will create a jar in the `target/scala-2.13` folder.
49+
50+
#### Implementation
51+
52+
The jar is part of an Akka streaming ecosystem and unsurprisingly uses [Akka Http](https://doc.akka.io/docs/akka-http/current/introduction.html) to make the http requests,
53+
it also uses [circe](https://circe.github.io/circe/) to marshal and unmarshal the json.
54+
55+
### <a name="usage"></a>Usage
56+
57+
The jar is published in Maven Central, the command line executable jar can be downloaded from the releases section
58+
of the [github repository](https://github.com/input-output-hk/psg-cardano-wallet-api)
59+
60+
61+
Before you can use this API you need a cardano wallet backend to contact, you can set one up following the instructions
62+
[here](https://github.com/input-output-hk/cardano-wallet). The docker setup is recommended.
63+
64+
Alternatively, for 'tire kicking' purposes you may try `http://cardano-wallet-testnet.iog.solutions:8090/v2/`
65+
66+
#### <a name="usagescala"></a>Scala
67+
68+
Add the library to your dependencies
69+
70+
`libraryDependencies += "iog.psg" %% "psg-cardano-wallet-api" % "0.2.0"`
71+
72+
The api calls return a HttpRequest set up to the correct url and a mapper to take the entity result and
73+
map it from Json to the corresponding case classes. Using `networkInfo` as an example...
74+
75+
```
76+
import iog.psg.cardano.CardanoApi.CardanoApiOps._
77+
import iog.psg.cardano.CardanoApi._
78+
79+
implicit val as = ActorSystem("MyActorSystem")
80+
val baseUri = "http://localhost:8090/v2/"
81+
import as.dispatcher
82+
83+
val api = new CardanoApi(baseUri)
84+
85+
val networkInfoF: Future[CardanoApiResponse[NetworkInfo]] =
86+
api.networkInfo.toFuture.execute
87+
88+
val networkInfo: CardanoApiResponse[NetworkInfo] =
89+
api.networkInfo.toFuture.executeBlocking
90+
91+
networkInfo match {
92+
case Left(ErrorMessage(message, code)) => //do something
93+
case Right(netInfo: NetworkInfo) => // good!
94+
}
95+
```
96+
97+
#### <a name="usagejava"></a>Java
98+
99+
First, add the library to your dependencies,
100+
```
101+
<dependency>
102+
<groupId>iog.psg</groupId>
103+
<artifactId>psg-cardano-wallet-api_2.13</artifactId>
104+
<version>0.2.0</version>
105+
</dependency>
106+
```
107+
108+
Then, using `getWallet` as an example...
109+
110+
```
111+
import iog.psg.cardano.jpi.*;
112+
113+
ActorSystem as = ActorSystem.create();
114+
ExecutorService es = Executors.newFixedThreadPool(10);
115+
CardanoApiBuilder builder =
116+
CardanoApiBuilder.create("http://localhost:8090/v2/")
117+
.withActorSystem(as)
118+
.withExecutorService(es);
119+
120+
CardanoApi api = builder.build();
121+
122+
String walletId = "<PUT WALLET ID HERE>";
123+
CardanoApiCodec.Wallet wallet =
124+
api.getWallet(walletId).toCompletableFuture().get();
125+
126+
```
127+
128+
#### <a name="cmdline"></a>Command Line
129+
130+
To see the usage instructions, use
131+
132+
`java -jar psg-cardano-wallet-api-assembly-x.x.x-SNAPSHOT.jar`
133+
134+
For example, to see the [network information](https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Network) use
135+
136+
`java -jar psg-cardano-wallet-api-assembly-x.x.x-SNAPSHOT.jar -baseUrl http://localhost:8090/v2/ -netInfo`
137+
138+
#### <a name="examples"></a> Examples
139+
140+
The best place to find working examples is in the [test](https://github.com/input-output-hk/psg-cardano-wallet-api/tree/develop/src/test) folder
141+
142+
#### <a name="issues"></a> Issues
143+
144+
This release does *not* cover the entire cardano-wallet API, it focuses on getting the shelley core functionality into the hands of developers, if you need another call covered please log
145+
an [issue (or make a PR!)](https://github.com/input-output-hk/psg-cardano-wallet-api/issues)

build.sbt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
val akkaVersion = "2.6.8"
2+
val akkaHttpVersion = "10.2.0"
3+
val akkaHttpCirce = "1.31.0"
4+
val circeVersion = "0.13.0"
5+
val scalaTestVersion = "3.1.2"
6+
val commonsCodecVersion = "1.15"
7+
8+
lazy val rootProject = (project in file("."))
9+
.configs(IntegrationTest)
10+
.settings(
11+
Defaults.itSettings,
12+
IntegrationTest / dependencyClasspath := (IntegrationTest / dependencyClasspath).value ++ (Test / exportedProducts).value,
13+
name:= "psg-cardano-wallet-api",
14+
scalaVersion := "2.13.3",
15+
organization := "solutions.iog",
16+
homepage := Some(url("https://github.com/input-output-hk/psg-cardano-wallet-api")),
17+
scmInfo := Some(ScmInfo(url("https://github.com/input-output-hk/psg-cardano-wallet-api"), "scm:git@github.com:input-output-hk/psg-cardano-wallet-api.git")),
18+
developers := List(
19+
Developer("mcsherrylabs", "Alan McSherry", "alan.mcsherry@iohk.io", url("https://github.com/mcsherrylabs")),
20+
Developer("maciejbak85", "Maciej Bak", "maciej.bak@iohk.io", url("https://github.com/maciejbak85"))
21+
),
22+
publishMavenStyle := true,
23+
licenses := Seq("APL2" -> url("https://www.apache.org/licenses/LICENSE-2.0.txt")),
24+
description := "A java/scala wrapper for the cardano wallet backend API",
25+
usePgpKeyHex("75E12F006A3F08C757EE8343927AE95EEEF4A02F"),
26+
publishTo := Some {
27+
// publish to the sonatype repository
28+
val sonaUrl = "https://oss.sonatype.org/"
29+
if (isSnapshot.value)
30+
"snapshots" at sonaUrl + "content/repositories/snapshots"
31+
else
32+
"releases" at sonaUrl + "service/local/staging/deploy/maven2"
33+
},
34+
credentials += Credentials("Sonatype Nexus Repository Manager",
35+
"oss.sonatype.org",
36+
sys.env.getOrElse("SONA_USER", ""),
37+
sys.env.getOrElse("SONA_PASS", "")),
38+
dynverSonatypeSnapshots in ThisBuild := true,
39+
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
40+
scalacOptions ++= Seq("-unchecked", "-deprecation", "-Ymacro-annotations"),
41+
parallelExecution in Test := true,
42+
parallelExecution in IntegrationTest := false,
43+
libraryDependencies ++= Seq(
44+
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
45+
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
46+
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
47+
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
48+
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
49+
"io.circe" %% "circe-generic-extras" % circeVersion,
50+
"de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirce,
51+
"commons-codec" % "commons-codec" % commonsCodecVersion,
52+
"org.scalatest" %% "scalatest" % scalaTestVersion % "it, test",
53+
)
54+
)

cmdline.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
VER=0.1.3-SNAPSHOT
4+
#BASE_URL="http://cardano-wallet-testnet.iog.solutions:8090/v2/"
5+
#BASE_URL="http://localhost:8090/v2/"
6+
7+
#run sbt assembly to create this jar
8+
exec java -jar target/scala-2.13/psg-cardano-wallet-api-assembly-${VER}.jar -baseUrl ${BASE_URL} "$@"

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.3.13

project/plugins.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
2+
3+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
4+
5+
// sbt-sonatype plugin used to publish artifact to maven central via sonatype nexus
6+
// sbt-pgp plugin used to sign the artifcat with pgp keys
7+
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.4")
8+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")
9+
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package iog.psg.cardano;
2+
3+
import akka.actor.ActorSystem;
4+
import iog.psg.cardano.jpi.CardanoApi;
5+
import iog.psg.cardano.jpi.*;
6+
import scala.Enumeration;
7+
8+
import java.util.*;
9+
import java.util.concurrent.ExecutionException;
10+
import java.util.concurrent.ExecutorService;
11+
import java.util.concurrent.Executors;
12+
13+
public class TestMain {
14+
15+
public static void main(String[] args) throws CardanoApiException, ExecutionException, InterruptedException {
16+
17+
try {
18+
ActorSystem as = ActorSystem.create();
19+
ExecutorService es = Executors.newFixedThreadPool(10);
20+
CardanoApiBuilder builder =
21+
CardanoApiBuilder.create("http://localhost:8090/v2/")
22+
.withActorSystem(as)
23+
.withExecutorService(es);
24+
25+
CardanoApi api = builder.build();
26+
String passphrase = "password10";
27+
String menmString = "receive post siren monkey mistake morning teach section mention rural idea say offer number ribbon toward rigid pluck begin ticket auto";
28+
List<String> menmLst = Arrays.asList(menmString.split(" "));
29+
String walletId = "b63eacb4c89bd942cacfe0d3ed47459bbf0ce5c9";
30+
31+
32+
CardanoApiCodec.Wallet wallet = null;
33+
try {
34+
wallet =
35+
api.getWallet(walletId).toCompletableFuture().get();
36+
} catch(Exception e) {
37+
wallet = api.createRestore("cardanoapimainspec", passphrase, menmLst, 10).toCompletableFuture().get();
38+
}
39+
40+
CardanoApiCodec.WalletAddressId unusedAddr = api.listAddresses(wallet.id(), AddressFilter.UNUSED).toCompletableFuture().get().get(0);
41+
42+
Enumeration.Value lovelace = CardanoApiCodec.Units$.MODULE$.lovelace();
43+
Map<Long, String> meta = new HashMap();
44+
String l = Long.toString(Long.MAX_VALUE);
45+
meta.put(Long.MAX_VALUE, "hello world");
46+
47+
//9223372036854775807
48+
//meta.put(l, "0123456789012345678901234567890123456789012345678901234567890123");
49+
50+
List<CardanoApiCodec.Payment> pays =
51+
Arrays.asList(
52+
new CardanoApiCodec.Payment(unusedAddr.id(),
53+
new CardanoApiCodec.QuantityUnit(1000000, lovelace)
54+
)
55+
);
56+
CardanoApiCodec.CreateTransactionResponse resp =
57+
api.createTransaction(
58+
wallet.id(),
59+
passphrase,
60+
pays,
61+
MetadataBuilder.withMap(meta),
62+
"self").toCompletableFuture().get();
63+
System.out.println(resp.status().toString());
64+
System.out.println(resp.id());
65+
System.out.println(resp.metadata());
66+
67+
//executeHelper.execute(req);
68+
} catch (Exception e) {
69+
System.out.println(e.toString());
70+
} finally {
71+
System.exit(9);
72+
}
73+
74+
}
75+
}

0 commit comments

Comments
 (0)