Skip to content

Commit

Permalink
docs: Add java docs for new classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zurcusa committed Aug 30, 2024
1 parent 76f2b45 commit 0d2e821
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/limechain/rpc/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import org.teavm.jso.JSObject;

/**
* A functional interface used to export rpc functionalities to the user. A function which conforms with "sendRequest"
* signature can be exported via {@link com.limechain.Main}{@code .exportAPI(Function, JSString)}
*/
@FunctionalInterface
public interface Function extends JSObject {

String sendRequest(String method, String[] params);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/limechain/rpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
* A simple load balancer that switches between provided endpoints. Each consecutive call takes the latter endpoint
* in the provided list.
*/
public class LoadBalancer {

private final List<String> endpoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.limechain.network.protocol.warp.scale.reader.HeaderDigestReader;
import com.limechain.polkaj.Hash256;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.rpc.BlockRpcClient;
import com.limechain.rpc.ChainRpcClient;
import com.limechain.rpc.GrandpaRpcClient;
import com.limechain.rpc.dto.ChainGetHeaderResult;
import com.limechain.rpc.dto.GrandpaRoundStateResult;
import com.limechain.rpc.server.AppBean;
Expand All @@ -18,6 +19,11 @@
import java.util.List;
import java.util.logging.Level;

/**
* A fallback state of the {@link WarpSyncMachine}. If the machine fails to start or fails during execution without
* the possibility to retry it reaches this action. The {@link SyncState} of the node gets populated with the latest
* finalized block data via the use of RPC calls to other active nodes.
*/
@Log
public class RpcFallbackAction implements WarpSyncAction {
private final SyncState syncState;
Expand All @@ -30,7 +36,7 @@ public RpcFallbackAction() {
@Override
public void next(WarpSyncMachine sync) {
if (this.error != null) {
sync.setWarpSyncAction(new RequestFragmentsAction(syncState.getLastFinalizedBlockHash()));
sync.setWarpSyncAction(new FinishedAction());
return;
}

Expand All @@ -45,9 +51,9 @@ public void next(WarpSyncMachine sync) {
@Override
public void handle(WarpSyncMachine sync) {
try {
Hash256 latestFinalizedHashResult = BlockRpcClient.getLastFinalizedBlockHash();
ChainGetHeaderResult headerResult = BlockRpcClient.getHeader(latestFinalizedHashResult.toString());
GrandpaRoundStateResult roundStateResult = BlockRpcClient.getGrandpaRoundState();
Hash256 latestFinalizedHashResult = ChainRpcClient.getLastFinalizedBlockHash();
ChainGetHeaderResult headerResult = ChainRpcClient.getHeader(latestFinalizedHashResult.toString());
GrandpaRoundStateResult roundStateResult = GrandpaRpcClient.getGrandpaRoundState();

BlockHeader latestFinalizedHeader = new BlockHeader();
latestFinalizedHeader.setBlockNumber(new BigInteger(
Expand Down

0 comments on commit 0d2e821

Please sign in to comment.