Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.stratumn.sdk;
import com.stratumn.sdk.model.account.*;
import com.stratumn.sdk.model.trace.*;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.stratumn.chainscript.*;
public class Sdk implements ISdk {
private ISerializer serializer;
public void setSerializer(ISerializer s) {
this.serializer = s;
}
private SdkOptions opts;
private SdkConfig config;
// This is temporary until we plug the SDK to the APIs.
private TState getMockState() {
return this.serializer.deserialize(null);
}
public Sdk(SdkOptions opts) {
this.opts = opts;
this.pingTrace();
}
private void pingTrace() {
HttpResponse response;
try {
// ping trace to test network connectivity.
HttpClient client = HttpClient.newHttpClient();
String url = String.format("%s/healthz", this.opts.endpoints.trace);
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).build();
response = client.send(request, BodyHandlers.ofString());
} catch (Exception e) {
System.err.print("Could not call Trace");
e.printStackTrace();
return;
}
if (response.statusCode() != 200) {
System.out.printf("Could not call Trace (%d)\n", response.statusCode());
}
System.out.println("================================================================================");
System.out.println(" Connection to trace established ");
System.out.println("================================================================================");
}
@Override
public TraceState newTrace(NewTraceInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceState appendLink(AppendLinkInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceState pushTrace(PushTransferInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceState pullTrace(PullTransferInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceState acceptTransfer(TransferResponseInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceState rejectTransfer(TransferResponseInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceState cancelTransfer(TransferResponseInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceState getTraceState(GetTraceStateInput input) {
return new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(),
this.getMockState());
}
@Override
public TraceDetails getTraceDetails(GetTraceDetailsInput input) {
throw new UnsupportedOperationException("Not implemented yet");
}
@Override
public TracesState getIncomingTraces(PaginationInfo paginationInfo) {
List> res = new ArrayList>();
res.add(
new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(), this.getMockState()));
return new TracesState(res);
}
@Override
public TracesState getOutgoingTraces(PaginationInfo paginationInfo) {
List> res = new ArrayList>();
res.add(
new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(), this.getMockState()));
return new TracesState(res);
}
@Override
public TracesState getBacklogTraces(PaginationInfo paginationInfo) {
List> res = new ArrayList>();
res.add(
new TraceState("trace ID", new TraceLink(new Link()), new Date(), new Account(), this.getMockState()));
return new TracesState(res);
}
}