diff --git a/java-example/README.md b/java-example/README.md index 44d7785..f615dee 100644 --- a/java-example/README.md +++ b/java-example/README.md @@ -70,6 +70,9 @@ Below is a list of all Java code examples currently supported in this repo: [Get collections by ID.](src/main/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnector.java) +- Get collection by id +- Get full collection by id (returns all transactions in collection response) + #### Get Execution Data [Get execution data by block ID.](src/main/java/org/onflow/examples/java/getExecutionData/GetExecutionDataAccessAPIConnector.java) diff --git a/java-example/src/main/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnector.java b/java-example/src/main/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnector.java index 318d76b..5c29ebb 100644 --- a/java-example/src/main/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnector.java +++ b/java-example/src/main/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnector.java @@ -4,6 +4,9 @@ import org.onflow.flow.sdk.FlowAccessApi.AccessApiCallResponse; import org.onflow.flow.sdk.FlowCollection; import org.onflow.flow.sdk.FlowId; +import org.onflow.flow.sdk.FlowTransaction; + +import java.util.List; public class GetCollectionAccessAPIConnector { private final FlowAccessApi accessAPI; @@ -21,4 +24,14 @@ public FlowCollection getCollectionById(FlowId collectionId) { throw new RuntimeException(errorResponse.getMessage(), errorResponse.getThrowable()); } } + + public List getFullCollectionById(FlowId collectionId) { + AccessApiCallResponse> response = accessAPI.getFullCollectionById(collectionId); + if (response instanceof AccessApiCallResponse.Success) { + return ((AccessApiCallResponse.Success>) response).getData(); + } else { + AccessApiCallResponse.Error errorResponse = (AccessApiCallResponse.Error) response; + throw new RuntimeException(errorResponse.getMessage(), errorResponse.getThrowable()); + } + } } diff --git a/java-example/src/test/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnectorTest.java b/java-example/src/test/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnectorTest.java index e844ba8..170eb9a 100644 --- a/java-example/src/test/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnectorTest.java +++ b/java-example/src/test/java/org/onflow/examples/java/getCollection/GetCollectionAccessAPIConnectorTest.java @@ -11,6 +11,8 @@ import org.onflow.flow.sdk.crypto.Crypto; import org.onflow.flow.sdk.crypto.PublicKey; +import java.util.List; + import static org.junit.jupiter.api.Assertions.*; @FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json") @@ -51,4 +53,16 @@ public void canFetchCollectionById() { assertNotNull(collection, "Collection should not be null"); assertEquals(collectionId, collection.getId(), "Collection ID should match the fetched collection ID"); } + + @Test + public void canFetchFullCollectionById() { + List fullCollectionResponse = connector.getFullCollectionById(collectionId); + + assertNotNull(fullCollectionResponse, "Collection transactions should not be null"); + assertFalse(fullCollectionResponse.isEmpty(), "Collection transactions should not be empty"); + + FlowTransaction firstTransaction = fullCollectionResponse.get(0); + assertNotNull(firstTransaction.getId(), "Transaction ID should not be null"); + assertNotNull(firstTransaction.getScript(), "Transaction script should not be null"); + } } diff --git a/kotlin-example/README.md b/kotlin-example/README.md index ed1a977..a7d5436 100644 --- a/kotlin-example/README.md +++ b/kotlin-example/README.md @@ -71,6 +71,9 @@ Below is a list of all Kotlin code examples currently supported in this repo: [Get collections by ID.](src/main/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnector.kt) +- Get collection by id +- Get full collection by id (returns all transactions in collection response) + #### Get Execution Data [Get execution data by block ID.](src/main/kotlin/org/onflow/examples/kotlin/getExecutionData/GetExecutionDataAccessAPIConnector.kt) diff --git a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnector.kt b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnector.kt index 030c82e..fc86d18 100644 --- a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnector.kt +++ b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getCollection/GetCollectionAccessAPIConnector.kt @@ -11,4 +11,10 @@ class GetCollectionAccessAPIConnector( is AccessApiCallResponse.Success -> response.data is AccessApiCallResponse.Error -> throw Exception(response.message, response.throwable) } + + fun getFullCollectionById(collectionId: FlowId): List = + when (val response = accessAPI.getFullCollectionById(collectionId)) { + is AccessApiCallResponse.Success -> response.data + is 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 36a1e0b..53545f9 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 @@ -8,10 +8,7 @@ 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 -import org.onflow.flow.sdk.SignatureAlgorithm +import org.onflow.flow.sdk.* import org.onflow.flow.sdk.crypto.Crypto @FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json") @@ -53,4 +50,16 @@ class GetCollectionAccessAPIConnectorTest { assertNotNull(collection, "Collection should not be null") assertEquals(collectionId, collection.id, "Collection ID should match the fetched collection ID") } + + @Test + fun `Can fetch full collection by ID`() { + val collectionTransactions: List = connector.getFullCollectionById(collectionId) + + assertNotNull(collectionTransactions, "Collection transactions should not be null") + assertTrue(collectionTransactions.isNotEmpty(), "Collection transactions should not be empty") + + val firstTransaction = collectionTransactions.first() + assertNotNull(firstTransaction.id, "Transaction ID should not be null") + assertNotNull(firstTransaction.script, "Transaction script should not be null") + } }