Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
037f8fb
Merge pull request #16 from strategyobject/release/v0.1.0
kalaninja May 15, 2022
48a0432
added Unit type support
kalaninja May 20, 2022
338ebdc
Merge pull request #18 from strategyobject/feature/types
kalaninja May 20, 2022
e8a7c79
Restructure project
kalaninja Jun 1, 2022
a678ba8
Merge pull request #19 from strategyobject/feature/cleanup
kalaninja Jun 10, 2022
2907b3b
updated build
kalaninja Jun 10, 2022
438f0ea
revise rpc api types
kalaninja Jun 11, 2022
76e90ad
fix parsing of long numbers in RpcObject
kalaninja Jun 14, 2022
751668d
Merge pull request #21 from strategyobject/bugfix/long-num
kalaninja Jun 14, 2022
7d3b515
Merge pull request #20 from strategyobject/feature/abstract-hash
kalaninja Jun 14, 2022
43fa079
Implement DI with Guice (Close #22)
kalaninja Jun 29, 2022
74ce9e8
Merge pull request #23 from strategyobject/feature/di
kalaninja Jul 4, 2022
7cbafd8
Merge branch 'master' into develop
kalaninja Jul 4, 2022
6a2d6e7
Merge branch 'master' into develop
kalaninja Jul 5, 2022
a2ef953
add MetadataProvider
kalaninja Jul 8, 2022
020f0e3
Merge pull request #24 from strategyobject/feature/meta
kalaninja Jul 12, 2022
2713c4f
There is fixed the issue of reconnection. `autoConnectMs` was changed…
vnabiev Jul 15, 2022
01002ce
Merge pull request #25 from strategyobject/fix/reconnection
vnabiev Jul 18, 2022
d337038
add java enums support
kalaninja Jul 19, 2022
43d9f6b
Merge pull request #26 from strategyobject/feature/enums
kalaninja Jul 19, 2022
7922673
events support
kalaninja Jul 18, 2022
3c169b2
Merge pull request #27 from strategyobject/feature/events
kalaninja Aug 3, 2022
6daaf8f
Update version
kalaninja Aug 3, 2022
9f2a106
switch to java-library plugin
kalaninja Aug 7, 2022
e1df62e
switch to java-library plugin
kalaninja Aug 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ on:
jobs:
build:

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
distribution: 'temurin'

- name: Build with Gradle
run: gradle build
8 changes: 4 additions & 4 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ on:
jobs:
publish:

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
distribution: 'temurin'

- name: Build with Gradle
run: gradle build
Expand Down
21 changes: 13 additions & 8 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
dependencies {
implementation project(':common')
implementation project(':crypto')
implementation project(':pallet')
implementation project(':rpc')
implementation project(':rpc:rpc-core')
implementation project(':rpc:rpc-sections')
implementation project(':rpc:rpc-types')
implementation project(':rpc:rpc-api')
implementation project(':scale')
implementation project(':storage')
implementation project(':transport')
implementation project(':types')

api 'com.google.inject:guice:5.1.0'

annotationProcessor project(':pallet:pallet-codegen')
annotationProcessor project(':rpc:rpc-codegen')

testImplementation project(':tests')

testImplementation 'org.testcontainers:testcontainers:1.17.1'
testImplementation 'org.testcontainers:junit-jupiter:1.17.1'
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
testImplementation 'org.testcontainers:testcontainers:1.17.3'
testImplementation 'org.testcontainers:junit-jupiter:1.17.3'
testImplementation 'org.awaitility:awaitility:4.2.0'
testImplementation 'org.hamcrest:hamcrest:2.2'

testAnnotationProcessor project(':pallet:pallet-codegen')
}
}
68 changes: 54 additions & 14 deletions api/src/main/java/com/strategyobject/substrateclient/api/Api.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,73 @@
package com.strategyobject.substrateclient.api;

import com.strategyobject.substrateclient.pallet.GeneratedPalletResolver;
import com.strategyobject.substrateclient.rpc.Rpc;
import com.strategyobject.substrateclient.rpc.RpcImpl;
import com.google.inject.Module;
import com.strategyobject.substrateclient.pallet.PalletFactory;
import com.strategyobject.substrateclient.rpc.RpcSectionFactory;
import com.strategyobject.substrateclient.rpc.metadata.MetadataProvider;
import com.strategyobject.substrateclient.transport.ProviderInterface;
import lombok.val;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

/**
* Provides the ability to query a node and interact with the Polkadot or Substrate chains.
* It allows interacting with blockchain in various ways: using RPC's queries directly or
* accessing Pallets and its APIs, such as storages, transactions, etc.
*/
public interface Api {
static DefaultApi with(ProviderInterface provider) {
val rpc = RpcImpl.with(provider);
@RequiredArgsConstructor
public class Api implements AutoCloseable {
private final @NonNull RpcSectionFactory rpcSectionFactory;
private final @NonNull PalletFactory palletFactory;
private final @NonNull MetadataProvider metadataProvider;
private final Map<Class<?>, Object> resolvedCache = new ConcurrentHashMap<>();

return DefaultApi.with(rpc, GeneratedPalletResolver.with(rpc));
}

/**
* @return the instance that provides a proper API for querying the RPC's methods.
* Resolves the instance of a rpc by its definition.
*
* @param clazz the class of the rpc
* @param <T> the type of the rpc
* @return appropriate instance of the rpc
*/
Rpc rpc();
public <T> T rpc(@NonNull Class<T> clazz) {
return clazz.cast(resolvedCache.computeIfAbsent(clazz, rpcSectionFactory::create));
}

/**
* Resolves the instance of a pallet by its definition.
*
* @param clazz the class of the pallet
* @param <T> the type of the pallet
* @param <T> the type of the pallet
* @return appropriate instance of the pallet
*/
<T> T pallet(Class<T> clazz);
}
public <T> T pallet(@NonNull Class<T> clazz) {
return clazz.cast(resolvedCache.computeIfAbsent(clazz, palletFactory::create));
}

/**
* Provides access to current version of metadata in use.
*
* @return MetadataProvider instance
*/
public MetadataProvider metadata() {
return metadataProvider;
}

@Override
public void close() throws Exception {
if (rpcSectionFactory instanceof AutoCloseable) {
((AutoCloseable) rpcSectionFactory).close();
}
}

public static ApiBuilder<DefaultModule> with(@NonNull Supplier<ProviderInterface> providerInterface) {
return with(new DefaultModule(providerInterface.get()));
}

public static <M extends Module> ApiBuilder<M> with(@NonNull M module) {
return new ApiBuilder<>(module);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.strategyobject.substrateclient.api;

import com.google.inject.Guice;
import com.google.inject.Module;
import com.strategyobject.substrateclient.transport.ProviderInterface;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.val;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;

@RequiredArgsConstructor
public class ApiBuilder<M extends Module> {
private final @NonNull M module;

public ApiBuilder<M> configure(@NonNull Consumer<M> configuration) {
configuration.accept(module);
return this;
}

public <N extends Module> ApiBuilder<N> reconfigure(@NonNull Function<M, N> configuration) {
return new ApiBuilder<>(configuration.apply(this.module));
}

public CompletableFuture<Api> build() {
val injector = Guice.createInjector(new RequireModule(), module);
val provider = injector.getInstance(ProviderInterface.class);
val result = provider.isConnected() ?
CompletableFuture.<Void>completedFuture(null) :
provider.connect();

return result.thenApply(ignored -> injector.getInstance(Api.class));
}
}

This file was deleted.

Loading