Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import com.strategyobject.substrateclient.rpc.Rpc;

public interface Api {
Rpc getRpc();
Rpc rpc();
}
1 change: 0 additions & 1 deletion rpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ dependencies {
implementation project(':transport')
implementation project(':rpc:rpc-sections')
implementation project(':rpc:rpc-core')
implementation project(':rpc:rpc-codegen')
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.strategyobject.substrateclient.rpc.codegen.sections;

import com.strategyobject.substrateclient.rpc.codegen.substitutes.TestSection;
import com.strategyobject.substrateclient.rpc.core.RpcGeneratedSectionFactory;
import com.strategyobject.substrateclient.rpc.core.RpcInterfaceInitializationException;
import com.strategyobject.substrateclient.transport.ProviderInterface;
import com.strategyobject.substrateclient.transport.RpcBoolean;
import com.strategyobject.substrateclient.transport.RpcObject;
Expand All @@ -26,8 +28,7 @@ void createsRpcSectionAndCallsMethod() throws ExecutionException, InterruptedExc
when(provider.send(anyString(), anyList()))
.thenReturn(sendFuture);

val factory = new RpcGeneratedSectionFactory();
val rpcSection = factory.create(TestSection.class, provider);
val rpcSection = RpcGeneratedSectionFactory.create(TestSection.class, provider);

val actual = rpcSection.doNothing("some").get();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.strategyobject.substrateclient.rpc.codegen.sections;
package com.strategyobject.substrateclient.rpc.core;

import com.strategyobject.substrateclient.rpc.core.annotations.RpcInterface;
import com.strategyobject.substrateclient.transport.ProviderInterface;
Expand All @@ -7,11 +7,14 @@

import java.lang.reflect.InvocationTargetException;

import static com.strategyobject.substrateclient.rpc.codegen.sections.Constants.CLASS_NAME_TEMPLATE;

public class RpcGeneratedSectionFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class doesn't seem to be anyhow involved in code generation. What do you think about moving it to rpc-sections or rpc-core?

public <T> T create(@NonNull Class<T> interfaceClass,
@NonNull ProviderInterface provider) throws RpcInterfaceInitializationException {
private static final String CLASS_NAME_TEMPLATE = "%sImpl";

private RpcGeneratedSectionFactory() {
}

public static <T> T create(@NonNull Class<T> interfaceClass,
@NonNull ProviderInterface provider) throws RpcInterfaceInitializationException {
if (interfaceClass.getDeclaredAnnotationsByType(RpcInterface.class).length == 0) {
throw new IllegalArgumentException(
String.format("`%s` can't be constructed because isn't annotated with `@%s`.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.strategyobject.substrateclient.rpc.codegen.sections;
package com.strategyobject.substrateclient.rpc.core;

public class RpcInterfaceInitializationException extends Exception {
public RpcInterfaceInitializationException(Throwable ex) {
Expand Down
1 change: 0 additions & 1 deletion rpc/rpc-sections/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ dependencies {
implementation project(':rpc:rpc-types')
implementation project(':scale')

testImplementation project(':rpc:rpc-codegen')
testImplementation project(':tests')
testCompileOnly project(':rpc:rpc-core')
testCompileOnly project(':common')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.strategyobject.substrateclient.rpc.core.annotations.RpcCall;
import com.strategyobject.substrateclient.rpc.core.annotations.RpcInterface;
import com.strategyobject.substrateclient.rpc.core.annotations.RpcSubscription;
import com.strategyobject.substrateclient.rpc.types.*;
import com.strategyobject.substrateclient.scale.annotations.Scale;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

@RpcInterface(section = "state")
public interface State {
Expand All @@ -20,9 +23,56 @@ public interface State {
@RpcCall(method = "getKeys")
CompletableFuture<List<StorageKey>> getKeys(StorageKey key);

@RpcCall(method = "getKeys")
CompletableFuture<List<StorageKey>> getKeys(StorageKey key, @Scale BlockHash at);

@RpcCall(method = "getKeysPaged")
CompletableFuture<List<StorageKey>> getKeysPaged(StorageKey key, int count);

@RpcCall(method = "getKeysPaged")
CompletableFuture<List<StorageKey>> getKeysPaged(StorageKey key, int count, StorageKey startKey);

@RpcCall(method = "getKeysPaged")
CompletableFuture<List<StorageKey>> getKeysPaged(StorageKey key,
int count,
StorageKey startKey,
@Scale BlockHash at);

@RpcCall(method = "getStorage")
CompletableFuture<StorageData> getStorage(StorageKey key);

@RpcCall(method = "getStorage")
CompletableFuture<StorageData> getStorage(StorageKey key, @Scale BlockHash at);

@RpcCall(method = "getStorageHash")
@Scale
CompletableFuture<Hash> getStorageHash(StorageKey key);

@RpcCall(method = "getStorageHash")
@Scale
CompletableFuture<Hash> getStorageHash(StorageKey key, @Scale BlockHash at);

@RpcCall(method = "getStorageSize")
CompletableFuture<Long> getStorageSize(StorageKey key);

@RpcCall(method = "getStorageSize")
CompletableFuture<Long> getStorageSize(StorageKey key, @Scale BlockHash at);

@RpcCall(method = "queryStorage")
CompletableFuture<List<StorageChangeSet>> queryStorage(List<StorageKey> keys, @Scale BlockHash fromBlock);

@RpcCall(method = "queryStorage")
CompletableFuture<List<StorageChangeSet>> queryStorage(List<StorageKey> keys,
@Scale BlockHash fromBlock,
@Scale BlockHash toBlock);

@RpcCall(method = "queryStorageAt")
CompletableFuture<List<StorageChangeSet>> queryStorageAt(List<StorageKey> keys);

@RpcCall(method = "queryStorageAt")
CompletableFuture<List<StorageChangeSet>> queryStorageAt(List<StorageKey> keys, @Scale BlockHash at);

@RpcSubscription(type = "storage", subscribeMethod = "subscribeStorage", unsubscribeMethod = "unsubscribeStorage")
CompletableFuture<Supplier<CompletableFuture<Boolean>>> subscribeStorage(List<StorageKey> keys,
BiConsumer<Exception, StorageChangeSet> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.strategyobject.substrateclient.common.utils.HexConverter;
import com.strategyobject.substrateclient.crypto.KeyRing;
import com.strategyobject.substrateclient.rpc.codegen.sections.RpcGeneratedSectionFactory;
import com.strategyobject.substrateclient.rpc.codegen.sections.RpcInterfaceInitializationException;
import com.strategyobject.substrateclient.rpc.core.RpcGeneratedSectionFactory;
import com.strategyobject.substrateclient.rpc.core.RpcInterfaceInitializationException;
import com.strategyobject.substrateclient.rpc.sections.substitutes.BalanceTransfer;
import com.strategyobject.substrateclient.rpc.types.*;
import com.strategyobject.substrateclient.tests.containers.SubstrateVersion;
Expand Down Expand Up @@ -58,8 +58,7 @@ void hasKey() throws ExecutionException, InterruptedException, TimeoutException,
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
Author rpcSection = sectionFactory.create(Author.class, wsProvider);
Author rpcSection = RpcGeneratedSectionFactory.create(Author.class, wsProvider);

val publicKey = PublicKey.fromBytes(
HexConverter.toBytes("0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"));
Expand All @@ -83,8 +82,7 @@ void insertKey() throws ExecutionException, InterruptedException, TimeoutExcepti
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
Author rpcSection = sectionFactory.create(Author.class, wsProvider);
Author rpcSection = RpcGeneratedSectionFactory.create(Author.class, wsProvider);

assertDoesNotThrow(() -> rpcSection.insertKey("aura",
"alice",
Expand All @@ -102,11 +100,10 @@ void submitExtrinsic() throws ExecutionException, InterruptedException, TimeoutE
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
Chain chainSection = sectionFactory.create(Chain.class, wsProvider);
Chain chainSection = RpcGeneratedSectionFactory.create(Chain.class, wsProvider);

val genesis = chainSection.getBlockHash(0).get(WAIT_TIMEOUT, TimeUnit.SECONDS);
Author authorSection = sectionFactory.create(Author.class, wsProvider);
Author authorSection = RpcGeneratedSectionFactory.create(Author.class, wsProvider);

assertDoesNotThrow(() -> authorSection.submitExtrinsic(createBalanceTransferExtrinsic(genesis, NONCE.getAndIncrement()))
.get(WAIT_TIMEOUT, TimeUnit.SECONDS));
Expand All @@ -121,11 +118,10 @@ void submitAndWatchExtrinsic() throws ExecutionException, InterruptedException,
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
Chain chainSection = sectionFactory.create(Chain.class, wsProvider);
Chain chainSection = RpcGeneratedSectionFactory.create(Chain.class, wsProvider);

val genesis = chainSection.getBlockHash(0).get(WAIT_TIMEOUT, TimeUnit.SECONDS);
Author authorSection = sectionFactory.create(Author.class, wsProvider);
Author authorSection = RpcGeneratedSectionFactory.create(Author.class, wsProvider);

val updateCount = new AtomicInteger(0);
val status = new AtomicReference<ExtrinsicStatus>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.strategyobject.substrateclient.rpc.sections;

import com.strategyobject.substrateclient.rpc.codegen.sections.RpcGeneratedSectionFactory;
import com.strategyobject.substrateclient.rpc.codegen.sections.RpcInterfaceInitializationException;
import com.strategyobject.substrateclient.rpc.core.RpcGeneratedSectionFactory;
import com.strategyobject.substrateclient.rpc.core.RpcInterfaceInitializationException;
import com.strategyobject.substrateclient.rpc.types.BlockHash;
import com.strategyobject.substrateclient.tests.containers.SubstrateVersion;
import com.strategyobject.substrateclient.tests.containers.TestSubstrateContainer;
Expand Down Expand Up @@ -40,8 +40,7 @@ void getFinalizedHead() throws ExecutionException, InterruptedException, Timeout
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
val rpcSection = sectionFactory.create(Chain.class, wsProvider);
val rpcSection = RpcGeneratedSectionFactory.create(Chain.class, wsProvider);

val result = rpcSection.getFinalizedHead().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

Expand All @@ -57,8 +56,7 @@ void subscribeNewHeads() throws ExecutionException, InterruptedException, Timeou
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
val rpcSection = sectionFactory.create(Chain.class, wsProvider);
val rpcSection = RpcGeneratedSectionFactory.create(Chain.class, wsProvider);

val blockCount = new AtomicInteger(0);
val blockHash = new AtomicReference<BlockHash>(null);
Expand Down Expand Up @@ -91,8 +89,7 @@ void getBlockHash() throws ExecutionException, InterruptedException, TimeoutExce
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
val rpcSection = sectionFactory.create(Chain.class, wsProvider);
val rpcSection = RpcGeneratedSectionFactory.create(Chain.class, wsProvider);

val result = rpcSection.getBlockHash(0).get(WAIT_TIMEOUT, TimeUnit.SECONDS);

Expand All @@ -108,8 +105,7 @@ void getBlock() throws ExecutionException, InterruptedException, TimeoutExceptio
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
Chain rpcSection = sectionFactory.create(Chain.class, wsProvider);
Chain rpcSection = RpcGeneratedSectionFactory.create(Chain.class, wsProvider);

val height = new AtomicInteger(0);
rpcSection.subscribeNewHeads((e, header) -> {
Expand Down
Loading