Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 62 additions & 0 deletions bindings/go/examples/custom_query/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

package main

import (
"fmt"
"log"

sdk "bindings/iota_sdk_ffi"
)

func main() {
client := sdk.GraphQlClientNewDevnet()

queryEpochDataStr := `
query MyQuery($id: UInt53) {
epoch(id: $id) {
epochId
referenceGasPrice
totalGasFees
totalCheckpoints
totalTransactions
}
}`

queryEpochData := sdk.Query{
Query: queryEpochDataStr,
}
res1, err := client.RunQuery(queryEpochData)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to run a query: %v", err)
}
fmt.Println(res1)

variablesJson := `{"id": 1}`
variables := string(variablesJson)

queryEpochDataWithVariables := sdk.Query{
Query: queryEpochDataStr,
Variables: &variables,
}
res2, err := client.RunQuery(queryEpochDataWithVariables)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to run a query with variables: %v", err)
}
fmt.Println(res2)

queryChainIdStr := `
query MyQuery {
chainIdentifier
}`
queryChainId := sdk.Query{
Query: queryChainIdStr,
}
res3, err := client.RunQuery(queryChainId)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to run a query: %v", err)
}
fmt.Println(res3)

}
82 changes: 82 additions & 0 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,15 @@ func uniffiCheckChecksums() {
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_graphqlclient_run_query()
})
if checksum != 54586 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_graphqlclient_run_query: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_graphqlclient_service_config()
})
Expand Down Expand Up @@ -11367,6 +11376,8 @@ type GraphQlClientInterface interface {
// This will return `Ok(None)` if the epoch requested is not available in
// the GraphQL service (e.g., due to pruning).
ReferenceGasPrice(epoch *uint64) (*uint64, error)
// Run a query.
RunQuery(query Query) (Value, error)
// Get the GraphQL service configuration, including complexity limits, read
// and mutation limits, supported versions, and others.
ServiceConfig() (ServiceConfig, error)
Expand Down Expand Up @@ -12585,6 +12596,38 @@ func (_self *GraphQlClient) ReferenceGasPrice(epoch *uint64) (*uint64, error) {
return res, err
}

// Run a query.
func (_self *GraphQlClient) RunQuery(query Query) (Value, error) {
_pointer := _self.ffiObject.incrementPointer("*GraphQlClient")
defer _self.ffiObject.decrementPointer()
res, err :=uniffiRustCallAsync[SdkFfiError](
FfiConverterSdkFfiErrorINSTANCE,
// completeFn
func(handle C.uint64_t, status *C.RustCallStatus) RustBufferI {
res := C.ffi_iota_sdk_ffi_rust_future_complete_rust_buffer(handle, status)
return GoRustBuffer {
inner: res,
}
},
// liftFn
func(ffi RustBufferI) Value {
return FfiConverterTypeValueINSTANCE.Lift(ffi)
},
C.uniffi_iota_sdk_ffi_fn_method_graphqlclient_run_query(
_pointer,FfiConverterQueryINSTANCE.Lower(query)),
// pollFn
func (handle C.uint64_t, continuation C.UniffiRustFutureContinuationCallback, data C.uint64_t) {
C.ffi_iota_sdk_ffi_rust_future_poll_rust_buffer(handle, continuation, data)
},
// freeFn
func (handle C.uint64_t) {
C.ffi_iota_sdk_ffi_rust_future_free_rust_buffer(handle)
},
)

return res, err
}

// Get the GraphQL service configuration, including complexity limits, read
// and mutation limits, supported versions, and others.
func (_self *GraphQlClient) ServiceConfig() (ServiceConfig, error) {
Expand Down Expand Up @@ -25914,6 +25957,45 @@ type FfiDestroyerProtocolConfigs struct {}
func (_ FfiDestroyerProtocolConfigs) Destroy(value ProtocolConfigs) {
value.Destroy()
}
type Query struct {
Query string
Variables *Value
}

func (r *Query) Destroy() {
FfiDestroyerString{}.Destroy(r.Query);
FfiDestroyerOptionalTypeValue{}.Destroy(r.Variables);
}

type FfiConverterQuery struct {}

var FfiConverterQueryINSTANCE = FfiConverterQuery{}

func (c FfiConverterQuery) Lift(rb RustBufferI) Query {
return LiftFromRustBuffer[Query](c, rb)
}

func (c FfiConverterQuery) Read(reader io.Reader) Query {
return Query {
FfiConverterStringINSTANCE.Read(reader),
FfiConverterOptionalTypeValueINSTANCE.Read(reader),
}
}

func (c FfiConverterQuery) Lower(value Query) C.RustBuffer {
return LowerIntoRustBuffer[Query](c, value)
}

func (c FfiConverterQuery) Write(writer io.Writer, value Query) {
FfiConverterStringINSTANCE.Write(writer, value.Query);
FfiConverterOptionalTypeValueINSTANCE.Write(writer, value.Variables);
}

type FfiDestroyerQuery struct {}

func (_ FfiDestroyerQuery) Destroy(value Query) {
value.Destroy()
}
// Randomness update
//
// # BCS
Expand Down
11 changes: 11 additions & 0 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,11 @@ uint64_t uniffi_iota_sdk_ffi_fn_method_graphqlclient_protocol_config(void* ptr,
uint64_t uniffi_iota_sdk_ffi_fn_method_graphqlclient_reference_gas_price(void* ptr, RustBuffer epoch
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_GRAPHQLCLIENT_RUN_QUERY
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_GRAPHQLCLIENT_RUN_QUERY
uint64_t uniffi_iota_sdk_ffi_fn_method_graphqlclient_run_query(void* ptr, RustBuffer query
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_GRAPHQLCLIENT_SERVICE_CONFIG
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_GRAPHQLCLIENT_SERVICE_CONFIG
uint64_t uniffi_iota_sdk_ffi_fn_method_graphqlclient_service_config(void* ptr
Expand Down Expand Up @@ -5738,6 +5743,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_graphqlclient_protocol_config(void
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_GRAPHQLCLIENT_REFERENCE_GAS_PRICE
uint16_t uniffi_iota_sdk_ffi_checksum_method_graphqlclient_reference_gas_price(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_GRAPHQLCLIENT_RUN_QUERY
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_GRAPHQLCLIENT_RUN_QUERY
uint16_t uniffi_iota_sdk_ffi_checksum_method_graphqlclient_run_query(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_GRAPHQLCLIENT_SERVICE_CONFIG
Expand Down
2 changes: 2 additions & 0 deletions bindings/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
kotlin("jvm") version "1.9.24"
kotlin("plugin.serialization") version "1.9.24"
application
}

Expand All @@ -11,6 +12,7 @@ repositories { mavenCentral() }

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
implementation("net.java.dev.jna:jna:5.13.0")
}

Expand Down
45 changes: 45 additions & 0 deletions bindings/kotlin/examples/CustomQuery.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import iota_sdk.GraphQlClient
import iota_sdk.Query
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

fun main() = runBlocking {
val client = GraphQlClient.newDevnet()

val queryEpochDataStr =
"""
query MyQuery(${'$'}id: UInt53) {
epoch(id: ${'$'}id) {
epochId
referenceGasPrice
totalGasFees
totalCheckpoints
totalTransactions
}
}
""".trimIndent()

val queryEpochData = Query(queryEpochDataStr)
val res1 = client.runQuery(queryEpochData)
println(res1)

val variables = mapOf("id" to 1)
val queryEpochDataWithVariables = Query(queryEpochDataStr, Json.encodeToString(variables))

val res2 = client.runQuery(queryEpochDataWithVariables)
println(res2)

val queryChainIdStr =
"""
query MyQuery {
chainIdentifier
}
""".trimIndent()
val queryChainId = Query(queryChainIdStr)
val res3 = client.runQuery(queryChainId)
println(res3)
}
70 changes: 70 additions & 0 deletions bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,8 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {








Expand Down Expand Up @@ -2491,6 +2493,8 @@ fun uniffi_iota_sdk_ffi_checksum_method_graphqlclient_protocol_config(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_graphqlclient_reference_gas_price(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_graphqlclient_run_query(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_graphqlclient_service_config(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_graphqlclient_set_rpc_server(
Expand Down Expand Up @@ -4114,6 +4118,8 @@ fun uniffi_iota_sdk_ffi_fn_method_graphqlclient_protocol_config(`ptr`: Pointer,`
): Long
fun uniffi_iota_sdk_ffi_fn_method_graphqlclient_reference_gas_price(`ptr`: Pointer,`epoch`: RustBuffer.ByValue,
): Long
fun uniffi_iota_sdk_ffi_fn_method_graphqlclient_run_query(`ptr`: Pointer,`query`: RustBuffer.ByValue,
): Long
fun uniffi_iota_sdk_ffi_fn_method_graphqlclient_service_config(`ptr`: Pointer,
): Long
fun uniffi_iota_sdk_ffi_fn_method_graphqlclient_set_rpc_server(`ptr`: Pointer,`server`: RustBuffer.ByValue,
Expand Down Expand Up @@ -5787,6 +5793,9 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
if (lib.uniffi_iota_sdk_ffi_checksum_method_graphqlclient_reference_gas_price() != 39065.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_iota_sdk_ffi_checksum_method_graphqlclient_run_query() != 54586.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_iota_sdk_ffi_checksum_method_graphqlclient_service_config() != 11931.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -18837,6 +18846,11 @@ public interface GraphQlClientInterface {
*/
suspend fun `referenceGasPrice`(`epoch`: kotlin.ULong? = null): kotlin.ULong?

/**
* Run a query.
*/
suspend fun `runQuery`(`query`: Query): Value

/**
* Get the GraphQL service configuration, including complexity limits, read
* and mutation limits, supported versions, and others.
Expand Down Expand Up @@ -19883,6 +19897,30 @@ open class GraphQlClient: Disposable, AutoCloseable, GraphQlClientInterface
}


/**
* Run a query.
*/
@Throws(SdkFfiException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `runQuery`(`query`: Query) : Value {
return uniffiRustCallAsync(
callWithPointer { thisPtr ->
UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_graphqlclient_run_query(
thisPtr,
FfiConverterTypeQuery.lower(`query`),
)
},
{ future, callback, continuation -> UniffiLib.INSTANCE.ffi_iota_sdk_ffi_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.INSTANCE.ffi_iota_sdk_ffi_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.INSTANCE.ffi_iota_sdk_ffi_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterTypeValue.lift(it) },
// Error FFI converter
SdkFfiException.ErrorHandler,
)
}


/**
* Get the GraphQL service configuration, including complexity limits, read
* and mutation limits, supported versions, and others.
Expand Down Expand Up @@ -45475,6 +45513,38 @@ public object FfiConverterTypeProtocolConfigs: FfiConverterRustBuffer<ProtocolCo



data class Query (
var `query`: kotlin.String,
var `variables`: Value? = null
) {

companion object
}

/**
* @suppress
*/
public object FfiConverterTypeQuery: FfiConverterRustBuffer<Query> {
override fun read(buf: ByteBuffer): Query {
return Query(
FfiConverterString.read(buf),
FfiConverterOptionalTypeValue.read(buf),
)
}

override fun allocationSize(value: Query) = (
FfiConverterString.allocationSize(value.`query`) +
FfiConverterOptionalTypeValue.allocationSize(value.`variables`)
)

override fun write(value: Query, buf: ByteBuffer) {
FfiConverterString.write(value.`query`, buf)
FfiConverterOptionalTypeValue.write(value.`variables`, buf)
}
}



/**
* Randomness update
*
Expand Down
Loading