|
3 | 3 | </a>
|
4 | 4 |
|
5 | 5 | # About
|
| 6 | + |
6 | 7 | This project provides written in Java API for interaction with a Polkadot or Substrate based network.
|
7 | 8 |
|
8 | 9 | ## Key features
|
9 |
| -- ### Java 8 or higher. |
| 10 | + |
| 11 | +### Java 8 or higher. |
| 12 | + |
10 | 13 | The main idea is to make this library available and usable for as many projects as possible.
|
11 | 14 |
|
12 |
| -- ### Non-blocking API. |
| 15 | +### Non-blocking API. |
13 | 16 |
|
14 | 17 | The API is designed to be non-blocking in order to not engage resources for waiting responses from a node, especially when working with web sockets.
|
15 | 18 | Each method returns `CompletableFuture<>`.
|
16 | 19 |
|
17 |
| -- ### Declarative approach. |
| 20 | +### Declarative approach. |
| 21 | + |
18 | 22 | Some of our goals are:
|
| 23 | + |
19 | 24 | - make API simpler for usage;
|
20 | 25 | - let users organize their code similar to the one in the pallet they are interacting with;
|
21 | 26 | - hide difficulties of low level and infrastructure code;
|
22 | 27 | - facilitate the future maintenance.
|
23 | 28 |
|
24 | 29 | The best approach to reach project’s goals is to use annotations and code generation techniques. Below are listed some annotations that this API shall provide:
|
| 30 | + |
25 | 31 | - [x] Scale
|
26 |
| - - [x] `@ScaleWriter`; |
27 |
| - - [x] `@ScaleReader`; |
28 |
| - - [x] `@Scale`; |
29 |
| - - [x] `@ScaleGeneric`; |
30 |
| - - [x] `@Ignore`; |
| 32 | + |
| 33 | + - [x] `@ScaleWriter`; |
| 34 | + - [x] `@ScaleReader`; |
| 35 | + - [x] `@Scale`; |
| 36 | + - [x] `@ScaleGeneric`; |
| 37 | + - [x] `@Ignore`; |
31 | 38 |
|
32 | 39 | - [x] Rpc
|
33 |
| - - [x] `@RpcInterface`; |
34 |
| - - [x] `@RpcCall`; |
35 |
| - - [x] `@RpcSubscription`; |
36 |
| - - [x] `@RpcEncoder`; |
37 |
| - - [x] `@RpcDecoder`; |
| 40 | + |
| 41 | + - [x] `@RpcInterface`; |
| 42 | + - [x] `@RpcCall`; |
| 43 | + - [x] `@RpcSubscription`; |
| 44 | + - [x] `@RpcEncoder`; |
| 45 | + - [x] `@RpcDecoder`; |
38 | 46 |
|
39 | 47 | - [ ] Pallet
|
40 |
| - - [x] `@Pallet`; |
41 |
| - - [ ] `@Transaction`; |
42 |
| - - [x] `@Storage`; |
43 |
| - - [x] `@Event`. |
| 48 | + - [x] `@Pallet`; |
| 49 | + - [ ] `@Transaction`; |
| 50 | + - [x] `@Storage`; |
| 51 | + - [x] `@Event`. |
44 | 52 |
|
45 | 53 | These allow the generation of scale serializers, deserializers, RPC methods, code for interaction with pallet, etc.
|
46 | 54 | More examples you can find below.
|
47 | 55 |
|
48 |
| -- ### Deferred parametrization of codecs |
| 56 | +### Deferred parametrization of codecs |
| 57 | + |
49 | 58 | Annotations for codecs allow deferring parameters of a generic until it's used at an RPC method. E.g.:
|
50 |
| - ```java |
| 59 | + |
| 60 | +```java |
51 | 61 | @RequiredArgsConstructor
|
52 | 62 | @Getter
|
53 | 63 | @ScaleWriter
|
54 | 64 | public class Some<A> {
|
55 |
| - private final int number; |
56 |
| - private final A some; |
| 65 | + private final int number; |
| 66 | + private final A some; |
57 | 67 | }
|
58 | 68 |
|
59 | 69 | @RpcInterface(section = "test")
|
60 | 70 | public interface TestSection {
|
61 |
| - @RpcCall(method = "sendSome") |
62 |
| - CompletableFuture<Boolean> doNothing(@Scale Some<Parameter> value); |
| 71 | + @RpcCall(method = "sendSome") |
| 72 | + CompletableFuture<Boolean> doNothing(@Scale Some<Parameter> value); |
63 | 73 | }
|
64 | 74 | ```
|
| 75 | + |
65 | 76 | Annotation processors will generate scale writer for the class `Some` which expects another writer as a dependency.
|
66 | 77 | When a processor faces a parameter like `Some<String> value`, it injects the `Strings`'s writer into the writer of `Some`.
|
67 | 78 |
|
68 |
| -- ### GC Manageable requests. |
| 79 | +### GC Manageable requests. |
| 80 | + |
69 | 81 | We take care of either lost responses or canceled futures by not holding handlers that are needed to match an RPC request with a response.
|
70 | 82 |
|
71 |
| -- ### Tests run with substrate node. |
| 83 | +### Tests run with substrate node. |
| 84 | + |
72 | 85 | All API methods related to the substrate node will be tested for operability and compatibility.
|
73 | 86 | Currently, we use [test containers](https://www.testcontainers.org/) and docker image [parity/substrate:v3.0.0](https://hub.docker.com/layers/parity/substrate/v3.0.0/images/sha256-1aef07509d757c584320773c476dcb6077578bbf2f5e468ceb413dcf908897f1?context=explore).
|
74 | 87 |
|
75 | 88 | ## Building Locally
|
76 | 89 |
|
77 | 90 | You will need to install
|
78 | 91 |
|
79 |
| -- [asdf](https://asdf-vm.com/guide/getting-started.html) |
80 |
| - - Install the [Rust plugin](https://github.com/asdf-community/asdf-rust) |
81 |
| - - Install the [Java plugin](https://github.com/halcyon/asdf-java) |
82 |
| - - Make sure to follow instructions in the **MacOS** section. |
83 |
| - - Then, run `asdf install` at the root of the repo. |
| 92 | +### Install Prerequisites: |
84 | 93 |
|
85 |
| - _If you prefer to not use `asdf`, you can install [Rust directly](https://www.rust-lang.org/tools/install) and install Java via [`sdkman`](https://sdkman.io/install). Reference `.tool-versions` to ensure you are installing the correct versions._ |
| 94 | +1. Install [asdf](https://asdf-vm.com/guide/getting-started.html) tools version manager. Make sure to follow instructions for your shell (e.g. ZSH, Fish, etc.) and package manager (e.g. Homebrew) |
86 | 95 |
|
87 |
| -- [Docker](https://www.docker.com/products/docker-desktop/) |
| 96 | + - Install the [Rust plugin](https://github.com/asdf-community/asdf-rust) |
| 97 | + - Install the [Java plugin](https://github.com/halcyon/asdf-java) |
| 98 | + - Then, run `asdf install` at the root of the repo to install tools listed in `/.tool-versions`. |
88 | 99 |
|
89 |
| -build |
| 100 | +1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/), an application for managing Docker containers and images along with docker CLI tools. |
| 101 | + |
| 102 | + _Note: If using fish shell you'd need to update the $PATH manually with this command, so `docker` executables can be found:_ |
| 103 | + |
| 104 | + ```sh |
| 105 | + set -U fish_user_paths /Applications/Docker.app/Contents/Resources/bin $fish_user_paths |
| 106 | + ``` |
| 107 | + |
| 108 | +### Build and Publish |
| 109 | + |
| 110 | +1. Build project. |
| 111 | + |
| 112 | + ```sh |
| 113 | + ./gradlew build |
| 114 | + ``` |
| 115 | + |
| 116 | +1. Publish compile artifacts to the local Maven cache, so other apps (e.g. Custodial Wallet) can consume it. |
| 117 | + ```sh |
| 118 | + ./gradlew publishToMavenLocal |
| 119 | + ``` |
| 120 | + |
| 121 | +### Clean up Built Artifacts |
| 122 | + |
| 123 | +To delete compiled artifacts in local `build` directories: |
| 124 | + |
| 125 | +```sh |
| 126 | +./gradlew clean |
| 127 | +``` |
| 128 | + |
| 129 | +To verify all compiled artifacts have been deleted run this command in the repo root: |
| 130 | + |
| 131 | +```sh |
| 132 | +find . -type d -name "build" |
| 133 | +--- |
| 134 | +(should be empty output) |
| 135 | +``` |
0 commit comments