diff --git a/java-example/src/main/java/org/onflow/examples/java/getExecutionData/GetExecutionDataAccessAPIConnector.java b/java-example/src/main/java/org/onflow/examples/java/getExecutionData/GetExecutionDataAccessAPIConnector.java new file mode 100644 index 0000000..99e288c --- /dev/null +++ b/java-example/src/main/java/org/onflow/examples/java/getExecutionData/GetExecutionDataAccessAPIConnector.java @@ -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 response = accessAPI.getExecutionResultByBlockId(blockId); + if (response instanceof FlowAccessApi.AccessApiCallResponse.Success) { + return ((FlowAccessApi.AccessApiCallResponse.Success) response).getData(); + } else { + FlowAccessApi.AccessApiCallResponse.Error errorResponse = (FlowAccessApi.AccessApiCallResponse.Error) response; + throw new RuntimeException(errorResponse.getMessage(), errorResponse.getThrowable()); + } + } +} + diff --git a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getExecutionData/GetExecutionDataAccessAPIConnector.kt b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getExecutionData/GetExecutionDataAccessAPIConnector.kt new file mode 100644 index 0000000..1f72511 --- /dev/null +++ b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getExecutionData/GetExecutionDataAccessAPIConnector.kt @@ -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) + } + } +} diff --git a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnectorTest.kt b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnectorTest.kt index 4df50d4..36a1e0b 100644 --- a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnectorTest.kt +++ b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnectorTest.kt @@ -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