This project provides written in Java API for interaction with a Polkadot or Substrate based network.
The main idea is to make this library available and usable for as many projects as possible.
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.
Each method returns CompletableFuture<>.
Some of our goals are:
- make API simpler for usage;
- let users organize their code similar to the one in the pallet they are interacting with;
- hide difficulties of low level and infrastructure code;
- facilitate the future maintenance.
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:
-
Scale
-
@ScaleWriter; -
@ScaleReader; -
@Scale; -
@ScaleGeneric; -
@Ignore;
-
-
Rpc
-
@RpcInterface; -
@RpcCall; -
@RpcSubscription; -
@RpcEncoder; -
@RpcDecoder;
-
-
Pallet
-
@Pallet; -
@Transaction; -
@Storage; -
@Event.
-
These allow the generation of scale serializers, deserializers, RPC methods, code for interaction with pallet, etc. More examples you can find below.
Annotations for codecs allow deferring parameters of a generic until it's used at an RPC method. E.g.:
@RequiredArgsConstructor
@Getter
@ScaleWriter
public class Some<A> {
private final int number;
private final A some;
}
@RpcInterface(section = "test")
public interface TestSection {
@RpcCall(method = "sendSome")
CompletableFuture<Boolean> doNothing(@Scale Some<Parameter> value);
}Annotation processors will generate scale writer for the class Some which expects another writer as a dependency.
When a processor faces a parameter like Some<String> value, it injects the Strings's writer into the writer of Some.
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.
All API methods related to the substrate node will be tested for operability and compatibility. Currently, we use test containers and docker image parity/substrate:v3.0.0.
-
Install asdf tools version manager. Make sure to follow instructions for your shell (e.g. ZSH, Fish, etc.) and package manager (e.g. Homebrew)
- Install the Rust plugin.
- Install the Java plugin.
- Then, run
asdf installat the root of the repo to install tools listed in/.tool-versions. - Verify your local Java version matches what's in /.tool-versions. If they don't match check the
$PATHenv var to ensure~/.asdf/shimsdirectory has precedence over others.java -version cat .tool-versions
-
Install Docker Desktop, an application for managing Docker containers and images along with docker CLI tools.
Note: If using fish shell you'd need to update the $PATH manually with this command, so
dockerexecutables can be found and restart the shell:set -U fish_user_paths /Applications/Docker.app/Contents/Resources/bin $fish_user_paths
-
Build project.
./gradlew clean build
-
Publish compile artifacts to the local Maven cache, so other apps (e.g. saas-frequency-client, Custodial Wallet) can consume it.
./gradlew publishToMavenLocal
To delete compiled artifacts in local build directories:
./gradlew cleanTo verify all compiled artifacts have been deleted run this command in the repo root:
find . -type d -name "build"
---
(should be empty output)build