Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#107/ Update GetNodeVersionInfo response object #117

Merged
merged 33 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0f3aa62
Add new data classes
lealobanov Oct 5, 2024
cda949e
Add new data classes
lealobanov Oct 5, 2024
6a4cd5b
Add missing Access API methods
lealobanov Oct 5, 2024
7adaa02
Add missing Access API methods
lealobanov Oct 5, 2024
97ed1d5
Setup unit tests
lealobanov Oct 5, 2024
db6a989
Bump protobuf release
lealobanov Oct 7, 2024
f3945f8
Update unit tests
lealobanov Oct 7, 2024
da08018
Lint
lealobanov Oct 8, 2024
e9217c7
Merge remote-tracking branch 'origin/main' into get-node-version-info…
lealobanov Oct 8, 2024
f3ee89b
Setup integration tests and Kotlin example
lealobanov Oct 8, 2024
f8afbfb
Setup Java example
lealobanov Oct 8, 2024
d7f3fa1
Update FlowCollectionGuarantee
lealobanov Oct 9, 2024
11f2ad5
Update tests
lealobanov Oct 9, 2024
fbd0e87
Lint
lealobanov Oct 9, 2024
f9bb646
Working on models
lealobanov Oct 10, 2024
31666fb
WIP: Update models for block
lealobanov Oct 15, 2024
46be427
WIP: Update models for block
lealobanov Oct 15, 2024
585c458
WIP: Update models for block
lealobanov Oct 15, 2024
2c8caef
Update unit tests, add builder methods
lealobanov Oct 15, 2024
d7b5012
Setup files for missing tests
lealobanov Oct 15, 2024
d311cff
Setup tests for FlowQuorumCertificateTest
lealobanov Oct 15, 2024
0df71b0
Setup tests for FlowTimeoutCertificateTest
lealobanov Oct 15, 2024
008da9f
Setup tests for FlowChunkTest
lealobanov Oct 15, 2024
bfcd2cd
Setup tests for FlowExecutionReceiptMetaTest, FlowExecutionResultTest
lealobanov Oct 15, 2024
5988a58
Lint
lealobanov Oct 15, 2024
b2e9ff0
Lint
lealobanov Oct 15, 2024
4636c3d
Lint
lealobanov Oct 15, 2024
9680355
Merge pull request #120 from onflow/update-block-protobuf
lealobanov Oct 16, 2024
3217387
Merge pull request #118 from onflow/update-collection-guarantee-protobuf
lealobanov Oct 16, 2024
b6cc5ed
Pull from main
lealobanov Oct 16, 2024
332ed19
Code rabbit comments
lealobanov Oct 16, 2024
fc88f83
Code rabbit comments
lealobanov Oct 16, 2024
7bd3078
Update git ignore
lealobanov Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
sdk/gradle.properties
flowdb
.DS_Store
.kotlin/errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.onflow.examples.java.getNodeVersionInfo;

import org.onflow.flow.sdk.FlowAccessApi;
import org.onflow.flow.sdk.FlowNodeVersionInfo;

public class GetNodeVersionInfoAccessAPIConnector {
private final FlowAccessApi accessAPI;

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

public FlowNodeVersionInfo getNodeVersionInfo() {
FlowAccessApi.AccessApiCallResponse<FlowNodeVersionInfo> response = accessAPI.getNodeVersionInfo();
if (response instanceof FlowAccessApi.AccessApiCallResponse.Success) {
return ((FlowAccessApi.AccessApiCallResponse.Success<FlowNodeVersionInfo>) 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,31 @@
package org.onflow.examples.java.getNodeVersionInfo;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onflow.flow.common.test.FlowEmulatorProjectTest;
import org.onflow.flow.common.test.FlowTestClient;
import org.onflow.flow.sdk.FlowAccessApi;
import org.onflow.flow.sdk.FlowNodeVersionInfo;

import static org.junit.jupiter.api.Assertions.*;

@FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json")
public class GetNodeVersionInfoAccessAPIConnectorTest {
@FlowTestClient
private FlowAccessApi accessAPI;
private GetNodeVersionInfoAccessAPIConnector nodeVersionInfoConnector;
@BeforeEach
public void setup() {
nodeVersionInfoConnector = new GetNodeVersionInfoAccessAPIConnector(accessAPI);
}

@Test
public void canFetchNodeVersionInfo() {
FlowNodeVersionInfo nodeVersionInfo = nodeVersionInfoConnector.getNodeVersionInfo();
assertNotNull(nodeVersionInfo, "Node version info should not be null");
assertEquals(nodeVersionInfo.getProtocolVersion(), 0);
assertEquals(nodeVersionInfo.getSporkRootBlockHeight(), 0);
assertEquals(nodeVersionInfo.getNodeRootBlockHeight(), 0);
assertNull(nodeVersionInfo.getCompatibleRange());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.onflow.examples.kotlin.getNodeVersionInfo

import org.onflow.flow.sdk.FlowAccessApi
import org.onflow.flow.sdk.FlowNodeVersionInfo

internal class GetNodeVersionInfoAccessAPIConnector(
private val accessAPI: FlowAccessApi
) {
fun getNodeVersionInfo(): FlowNodeVersionInfo =
when (val response = accessAPI.getNodeVersionInfo()) {
is FlowAccessApi.AccessApiCallResponse.Success -> response.data
is FlowAccessApi.AccessApiCallResponse.Error -> throw Exception(response.message, response.throwable)
}
lealobanov marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.onflow.examples.kotlin.getNodeVersionInfo

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.onflow.flow.common.test.FlowEmulatorProjectTest
import org.onflow.flow.common.test.FlowTestClient
import org.onflow.flow.sdk.FlowAccessApi
import org.onflow.flow.sdk.FlowNodeVersionInfo

@FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json")
internal class GetNodeVersionInfoAccessAPIConnectorTest {
@FlowTestClient
lateinit var accessAPI: FlowAccessApi

private lateinit var nodeVersionInfoConnector: GetNodeVersionInfoAccessAPIConnector

@BeforeEach
fun setup() {
nodeVersionInfoConnector = GetNodeVersionInfoAccessAPIConnector(accessAPI)
}

@Test
fun `Can fetch node version info`() {
val nodeVersionInfo: FlowNodeVersionInfo = nodeVersionInfoConnector.getNodeVersionInfo()
assertNotNull(nodeVersionInfo, "Node version info should not be null")
assertEquals(nodeVersionInfo.protocolVersion, 0)
assertEquals(nodeVersionInfo.sporkRootBlockHeight, 0)
assertEquals(nodeVersionInfo.nodeRootBlockHeight, 0)
assertEquals(nodeVersionInfo.compatibleRange, null)
}
}
2 changes: 1 addition & 1 deletion sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sourceSets {

dependencies {
api("org.jetbrains.kotlin:kotlin-reflect:2.0.21")
api("org.onflow:flow:1.0.0")
api("org.onflow:flow:1.1.0")
lealobanov marked this conversation as resolved.
Show resolved Hide resolved
api("com.github.TrustedDataFramework:java-rlp:1.1.20")
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
api("org.bouncycastle:bcpkix-jdk18on:1.78.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ class TransactionIntegrationTest {
assertThat(networkParams).isEqualTo(FlowChainId.EMULATOR)
}

@Test
fun `Can get node version info`() {
val nodeVersionInfo = try {
handleResult(
accessAPI.getNodeVersionInfo(),
"Failed to get network parameters"
)
} catch (e: Exception) {
fail("Failed to retrieve network parameters: ${e.message}")
}

assertThat(nodeVersionInfo).isNotNull()
assertThat(nodeVersionInfo.protocolVersion).isEqualTo(0)
assertThat(nodeVersionInfo.sporkRootBlockHeight).isEqualTo(0)
assertThat(nodeVersionInfo.nodeRootBlockHeight).isEqualTo(0)
assertThat(nodeVersionInfo.compatibleRange).isEqualTo(null)
}

@Test
fun `Can parse events`() {
val txResult = createAndSubmitAccountCreationTransaction(
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/kotlin/org/onflow/flow/sdk/AsyncFlowAccessApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ interface AsyncFlowAccessApi {

fun getLatestProtocolStateSnapshot(): CompletableFuture<FlowAccessApi.AccessApiCallResponse<FlowSnapshot>>

fun getNodeVersionInfo(): CompletableFuture<FlowAccessApi.AccessApiCallResponse<FlowNodeVersionInfo>>

fun getTransactionsByBlockId(id: FlowId): CompletableFuture<FlowAccessApi.AccessApiCallResponse<List<FlowTransaction>>>

fun getTransactionResultsByBlockId(id: FlowId): CompletableFuture<FlowAccessApi.AccessApiCallResponse<List<FlowTransactionResult>>>
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ interface FlowAccessApi {

fun getLatestProtocolStateSnapshot(): AccessApiCallResponse<FlowSnapshot>

fun getNodeVersionInfo(): AccessApiCallResponse<FlowNodeVersionInfo>

fun getTransactionsByBlockId(id: FlowId): AccessApiCallResponse<List<FlowTransaction>>

fun getTransactionResultsByBlockId(id: FlowId): AccessApiCallResponse<List<FlowTransactionResult>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,32 @@ class AsyncFlowAccessApiImpl(
}
}

override fun getNodeVersionInfo(): CompletableFuture<FlowAccessApi.AccessApiCallResponse<FlowNodeVersionInfo>> {
return try {
completableFuture(
try {
api.getNodeVersionInfo(Access.GetNodeVersionInfoRequest.newBuilder().build())
} catch (e: Exception) {
return CompletableFuture.completedFuture(FlowAccessApi.AccessApiCallResponse.Error("Failed to get node version info", e))
}
lealobanov marked this conversation as resolved.
Show resolved Hide resolved
).handle { response, ex ->
if (ex != null) {
FlowAccessApi.AccessApiCallResponse.Error("Failed to get node version info", ex)
} else {
val compatibleRange = if (response.info.hasCompatibleRange()) {
FlowCompatibleRange(response.info.compatibleRange.startHeight, response.info.compatibleRange.endHeight)
} else {
null
}

FlowAccessApi.AccessApiCallResponse.Success(FlowNodeVersionInfo(response.info.semver, response.info.commit, response.info.sporkId.toByteArray(), response.info.protocolVersion, response.info.sporkRootBlockHeight, response.info.nodeRootBlockHeight, compatibleRange))
lealobanov marked this conversation as resolved.
Show resolved Hide resolved
}
}
} catch (e: Exception) {
CompletableFuture.completedFuture(FlowAccessApi.AccessApiCallResponse.Error("Failed to get node version info", e))
}
}

override fun getTransactionsByBlockId(id: FlowId): CompletableFuture<FlowAccessApi.AccessApiCallResponse<List<FlowTransaction>>> {
return try {
completableFuture(
Expand Down
19 changes: 19 additions & 0 deletions sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,25 @@ class FlowAccessApiImpl(
FlowAccessApi.AccessApiCallResponse.Error("Failed to get latest protocol state snapshot", e)
}

override fun getNodeVersionInfo(): FlowAccessApi.AccessApiCallResponse<FlowNodeVersionInfo> =
try {
val ret = api.getNodeVersionInfo(
Access.GetNodeVersionInfoRequest
.newBuilder()
.build()
)

val compatibleRange = if (ret.info.hasCompatibleRange()) {
FlowCompatibleRange(ret.info.compatibleRange.startHeight, ret.info.compatibleRange.endHeight)
} else {
null
}

FlowAccessApi.AccessApiCallResponse.Success(FlowNodeVersionInfo(ret.info.semver, ret.info.commit, ret.info.sporkId.toByteArray(), ret.info.protocolVersion, ret.info.sporkRootBlockHeight, ret.info.nodeRootBlockHeight, compatibleRange))
} catch (e: Exception) {
FlowAccessApi.AccessApiCallResponse.Error("Failed to get node version info", e)
}

override fun getTransactionsByBlockId(id: FlowId): FlowAccessApi.AccessApiCallResponse<List<FlowTransaction>> =
try {
val ret = api.getTransactionsByBlockID(
Expand Down
Loading
Loading