Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
23 changes: 1 addition & 22 deletions bindings/go/examples/stake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,9 @@ func main() {
}
log.Printf("Staking to validator %v", validatorName)

coinObjId, _ := sdk.ObjectIdFromHex("0xd04077fe3b6fad13b3d4ed0d535b7ca92afcac8f0f2a0e0925fb9f4f0b30c699")

iotaSystemAddress := sdk.AddressSystem()

iotaSystemId := sdk.ObjectIdSystem()

iotaSystemModule, _ := sdk.NewIdentifier("iota_system")

requestAddStakeFn, _ := sdk.NewIdentifier("request_add_stake")

builder := sdk.TransactionBuilderInit(myAddress, client)

builder.MoveCall(
iotaSystemAddress,
iotaSystemModule,
requestAddStakeFn,
[]*sdk.PtbArgument{
sdk.PtbArgumentSharedMut(iotaSystemId),
sdk.PtbArgumentObjectId(coinObjId),
sdk.PtbArgumentAddress(validator.Address),
},
nil,
nil,
)
builder.Stake(sdk.PtbArgumentU64(1000000000), validator.Address)

res, err := builder.DryRun(false)
if err.(*sdk.SdkFfiError) != nil {
Expand Down
19 changes: 2 additions & 17 deletions bindings/go/examples/unstake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func main() {
client := sdk.GraphQlClientNewDevnet()

stakedIotaType := "0x3::staking_pool::StakedIota"
stakedIotaType := sdk.StructTagStakedIota().String()
stakedIotas, err := client.Objects(&sdk.ObjectFilter{TypeTag: &stakedIotaType}, nil)
if err.(*sdk.SdkFfiError) != nil {
log.Fatalf("Failed to get staked iota: %v", err)
Expand All @@ -22,23 +22,8 @@ func main() {
}
stakedIota := stakedIotas.Data[0]

iotaSystemAddress := sdk.AddressSystem()

iotaSystemId := sdk.ObjectIdSystem()

iotaSystemModule, _ := sdk.NewIdentifier("iota_system")

requestAddStakeFn, _ := sdk.NewIdentifier("request_withdraw_stake")

builder := sdk.TransactionBuilderInit(stakedIota.Owner().AsAddress(), client)
builder.MoveCall(
iotaSystemAddress,
iotaSystemModule,
requestAddStakeFn,
[]*sdk.PtbArgument{sdk.PtbArgumentSharedMut(iotaSystemId), sdk.PtbArgumentObjectId(stakedIota.ObjectId())},
nil,
nil,
)
builder.Unstake(sdk.PtbArgumentObjectId(stakedIota.ObjectId()))

res, err := builder.DryRun(false)
if err.(*sdk.SdkFfiError) != nil {
Expand Down
48 changes: 48 additions & 0 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5813,6 +5813,15 @@ func uniffiCheckChecksums() {
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_stake()
})
if checksum != 41361 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_stake: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_transfer_objects()
})
Expand All @@ -5822,6 +5831,15 @@ func uniffiCheckChecksums() {
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_unstake()
})
if checksum != 30530 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_unstake: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_upgrade()
})
Expand Down Expand Up @@ -24248,9 +24266,16 @@ type TransactionBuilderInterface interface {
SplitCoins(coin *PtbArgument, amounts []*PtbArgument, names []string) *TransactionBuilder
// Set the sponsor of the transaction.
Sponsor(sponsor *Address) *TransactionBuilder
// Add stake to a validator's staking pool.
//
// This is a high-level function which will split the provided stake amount
// from the gas coin and then stake using the resulting coin.
Stake(stake *PtbArgument, validatorAddress *Address) *TransactionBuilder
// Transfer a list of objects to the given address, without producing any
// result.
TransferObjects(recipient *Address, objects []*PtbArgument) *TransactionBuilder
// Withdraw stake from a validator's staking pool.
Unstake(stakedIota *PtbArgument) *TransactionBuilder
// Upgrade a Move package.
//
// - `modules`: is the modules' bytecode for the modules to be published
Expand Down Expand Up @@ -24589,6 +24614,19 @@ func (_self *TransactionBuilder) Sponsor(sponsor *Address) *TransactionBuilder {
}))
}

// Add stake to a validator's staking pool.
//
// This is a high-level function which will split the provided stake amount
// from the gas coin and then stake using the resulting coin.
func (_self *TransactionBuilder) Stake(stake *PtbArgument, validatorAddress *Address) *TransactionBuilder {
_pointer := _self.ffiObject.incrementPointer("*TransactionBuilder")
defer _self.ffiObject.decrementPointer()
return FfiConverterTransactionBuilderINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
return C.uniffi_iota_sdk_ffi_fn_method_transactionbuilder_stake(
_pointer,FfiConverterPtbArgumentINSTANCE.Lower(stake), FfiConverterAddressINSTANCE.Lower(validatorAddress),_uniffiStatus)
}))
}

// Transfer a list of objects to the given address, without producing any
// result.
func (_self *TransactionBuilder) TransferObjects(recipient *Address, objects []*PtbArgument) *TransactionBuilder {
Expand All @@ -24600,6 +24638,16 @@ func (_self *TransactionBuilder) TransferObjects(recipient *Address, objects []*
}))
}

// Withdraw stake from a validator's staking pool.
func (_self *TransactionBuilder) Unstake(stakedIota *PtbArgument) *TransactionBuilder {
_pointer := _self.ffiObject.incrementPointer("*TransactionBuilder")
defer _self.ffiObject.decrementPointer()
return FfiConverterTransactionBuilderINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
return C.uniffi_iota_sdk_ffi_fn_method_transactionbuilder_unstake(
_pointer,FfiConverterPtbArgumentINSTANCE.Lower(stakedIota),_uniffiStatus)
}))
}

// Upgrade a Move package.
//
// - `modules`: is the modules' bytecode for the modules to be published
Expand Down
22 changes: 22 additions & 0 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4374,11 +4374,21 @@ void* uniffi_iota_sdk_ffi_fn_method_transactionbuilder_split_coins(void* ptr, vo
void* uniffi_iota_sdk_ffi_fn_method_transactionbuilder_sponsor(void* ptr, void* sponsor, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_STAKE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_STAKE
void* uniffi_iota_sdk_ffi_fn_method_transactionbuilder_stake(void* ptr, void* stake, void* validator_address, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_TRANSFER_OBJECTS
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_TRANSFER_OBJECTS
void* uniffi_iota_sdk_ffi_fn_method_transactionbuilder_transfer_objects(void* ptr, void* recipient, RustBuffer objects, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_UNSTAKE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_UNSTAKE
void* uniffi_iota_sdk_ffi_fn_method_transactionbuilder_unstake(void* ptr, void* staked_iota, RustCallStatus *out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_UPGRADE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_TRANSACTIONBUILDER_UPGRADE
void* uniffi_iota_sdk_ffi_fn_method_transactionbuilder_upgrade(void* ptr, void* package_data, void* package, void* ticket, RustBuffer name, RustCallStatus *out_status
Expand Down Expand Up @@ -10318,12 +10328,24 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_split_coins(void
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_SPONSOR
uint16_t uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_sponsor(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_STAKE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_STAKE
uint16_t uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_stake(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_TRANSFER_OBJECTS
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_TRANSFER_OBJECTS
uint16_t uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_transfer_objects(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_UNSTAKE
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_UNSTAKE
uint16_t uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_unstake(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_TRANSACTIONBUILDER_UPGRADE
Expand Down
18 changes: 1 addition & 17 deletions bindings/kotlin/examples/Stake.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import iota_sdk.Address
import iota_sdk.GraphQlClient
import iota_sdk.Identifier
import iota_sdk.ObjectId
import iota_sdk.PtbArgument
import iota_sdk.TransactionBuilder
import kotlinx.coroutines.runBlocking
Expand All @@ -26,23 +24,9 @@ fun main() = runBlocking {

println("Staking to validator ${validator.name ?: "with no name"}")

val coinId =
ObjectId.fromHex(
"0xd04077fe3b6fad13b3d4ed0d535b7ca92afcac8f0f2a0e0925fb9f4f0b30c699"
)

val builder = TransactionBuilder.init(myAddress, client)

builder.moveCall(
Address.system(),
Identifier("iota_system"),
Identifier("request_add_stake"),
listOf(
PtbArgument.sharedMut(ObjectId.system()),
PtbArgument.objectId(coinId),
PtbArgument.address(validator.address)
),
)
builder.stake(PtbArgument.u64(1000000000uL), validator.address)

val res = builder.dryRun()

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

import iota_sdk.Address
import iota_sdk.GraphQlClient
import iota_sdk.Identifier
import iota_sdk.ObjectFilter
import iota_sdk.ObjectId
import iota_sdk.PtbArgument
import iota_sdk.StructTag
import iota_sdk.TransactionBuilder
import kotlinx.coroutines.runBlocking

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

val stakedIotas = client.objects(ObjectFilter(typeTag = "0x3::staking_pool::StakedIota"))
val stakedIotas = client.objects(ObjectFilter(typeTag = StructTag.stakedIota().toString()))
if (stakedIotas.data.isEmpty()) {
throw Exception("no validators found")
}
val stakedIota = stakedIotas.data[0]

val builder = TransactionBuilder.init(stakedIota.owner().asAddress(), client)

builder.moveCall(
Address.system(),
Identifier("iota_system"),
Identifier("request_withdraw_stake"),
listOf(
PtbArgument.sharedMut(ObjectId.system()),
PtbArgument.objectId(stakedIota.objectId())
),
)
builder.unstake(PtbArgument.objectId(stakedIota.objectId()))

val res = builder.dryRun()

Expand Down
64 changes: 64 additions & 0 deletions bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2885,6 +2885,10 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {










Expand Down Expand Up @@ -4117,8 +4121,12 @@ fun uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_split_coins(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_sponsor(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_stake(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_transfer_objects(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_unstake(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_upgrade(
): Short
fun uniffi_iota_sdk_ffi_checksum_method_transactioneffects_as_v1(
Expand Down Expand Up @@ -6490,8 +6498,12 @@ fun uniffi_iota_sdk_ffi_fn_method_transactionbuilder_split_coins(`ptr`: Pointer,
): Pointer
fun uniffi_iota_sdk_ffi_fn_method_transactionbuilder_sponsor(`ptr`: Pointer,`sponsor`: Pointer,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_iota_sdk_ffi_fn_method_transactionbuilder_stake(`ptr`: Pointer,`stake`: Pointer,`validatorAddress`: Pointer,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_iota_sdk_ffi_fn_method_transactionbuilder_transfer_objects(`ptr`: Pointer,`recipient`: Pointer,`objects`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_iota_sdk_ffi_fn_method_transactionbuilder_unstake(`ptr`: Pointer,`stakedIota`: Pointer,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_iota_sdk_ffi_fn_method_transactionbuilder_upgrade(`ptr`: Pointer,`packageData`: Pointer,`package`: Pointer,`ticket`: Pointer,`name`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_iota_sdk_ffi_fn_clone_transactioneffects(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
Expand Down Expand Up @@ -9240,9 +9252,15 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
if (lib.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_sponsor() != 25655.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_stake() != 41361.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_transfer_objects() != 16313.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_unstake() != 30530.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_iota_sdk_ffi_checksum_method_transactionbuilder_upgrade() != 3616.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -40794,12 +40812,25 @@ public interface TransactionBuilderInterface {
*/
fun `sponsor`(`sponsor`: Address): TransactionBuilder

/**
* Add stake to a validator's staking pool.
*
* This is a high-level function which will split the provided stake amount
* from the gas coin and then stake using the resulting coin.
*/
fun `stake`(`stake`: PtbArgument, `validatorAddress`: Address): TransactionBuilder

/**
* Transfer a list of objects to the given address, without producing any
* result.
*/
fun `transferObjects`(`recipient`: Address, `objects`: List<PtbArgument>): TransactionBuilder

/**
* Withdraw stake from a validator's staking pool.
*/
fun `unstake`(`stakedIota`: PtbArgument): TransactionBuilder

/**
* Upgrade a Move package.
*
Expand Down Expand Up @@ -41234,6 +41265,24 @@ open class TransactionBuilder: Disposable, AutoCloseable, TransactionBuilderInte



/**
* Add stake to a validator's staking pool.
*
* This is a high-level function which will split the provided stake amount
* from the gas coin and then stake using the resulting coin.
*/override fun `stake`(`stake`: PtbArgument, `validatorAddress`: Address): TransactionBuilder {
return FfiConverterTypeTransactionBuilder.lift(
callWithPointer {
uniffiRustCall() { _status ->
UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_transactionbuilder_stake(
it, FfiConverterTypePTBArgument.lower(`stake`),FfiConverterTypeAddress.lower(`validatorAddress`),_status)
}
}
)
}



/**
* Transfer a list of objects to the given address, without producing any
* result.
Expand All @@ -41250,6 +41299,21 @@ open class TransactionBuilder: Disposable, AutoCloseable, TransactionBuilderInte



/**
* Withdraw stake from a validator's staking pool.
*/override fun `unstake`(`stakedIota`: PtbArgument): TransactionBuilder {
return FfiConverterTypeTransactionBuilder.lift(
callWithPointer {
uniffiRustCall() { _status ->
UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_transactionbuilder_unstake(
it, FfiConverterTypePTBArgument.lower(`stakedIota`),_status)
}
}
)
}



/**
* Upgrade a Move package.
*
Expand Down
Loading
Loading