Skip to content

Commit

Permalink
Merge pull request #89 from onflow/get-execution-data
Browse files Browse the repository at this point in the history
Examples use-cases - get execution data
  • Loading branch information
lealobanov authored Oct 3, 2024
2 parents e146c6b + b5fdec1 commit bdebe65
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.onflow.examples.java.getExecutionData;

import org.onflow.flow.sdk.FlowAccessApi;
import org.onflow.flow.sdk.FlowExecutionResult;
import org.onflow.flow.sdk.FlowId;

public class GetExecutionDataAccessAPIConnector {
private final FlowAccessApi accessAPI;

public GetExecutionDataAccessAPIConnector(FlowAccessApi accessAPI) {
this.accessAPI = accessAPI;
}

public FlowExecutionResult getExecutionDataByBlockId(FlowId blockId) {
FlowAccessApi.AccessApiCallResponse<FlowExecutionResult> response = accessAPI.getExecutionResultByBlockId(blockId);
if (response instanceof FlowAccessApi.AccessApiCallResponse.Success) {
return ((FlowAccessApi.AccessApiCallResponse.Success<FlowExecutionResult>) response).getData();
} else {
FlowAccessApi.AccessApiCallResponse.Error errorResponse = (FlowAccessApi.AccessApiCallResponse.Error) response;
throw new RuntimeException(errorResponse.getMessage(), errorResponse.getThrowable());
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.onflow.examples.kotlin.getExecutionData

import org.onflow.flow.sdk.*

internal class GetExecutionDataAccessAPIConnector(private val accessAPI: FlowAccessApi) {
fun getExecutionDataByBlockId(blockId: FlowId): FlowExecutionResult {
return when (val response = accessAPI.getExecutionResultByBlockId(blockId)) {
is FlowAccessApi.AccessApiCallResponse.Success -> response.data
is FlowAccessApi.AccessApiCallResponse.Error -> throw Exception(response.message, response.throwable)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.onflow.examples.kotlin.AccessAPIConnector
import org.onflow.flow.common.test.*
import org.onflow.flow.common.test.FlowEmulatorProjectTest
import org.onflow.flow.common.test.FlowServiceAccountCredentials
import org.onflow.flow.common.test.FlowTestClient
import org.onflow.flow.common.test.TestAccount
import org.onflow.flow.sdk.FlowAccessApi
import org.onflow.flow.sdk.FlowCollection
import org.onflow.flow.sdk.FlowId
Expand Down

0 comments on commit bdebe65

Please sign in to comment.