Skip to content

Commit

Permalink
Bump libxmtp (#247)
Browse files Browse the repository at this point in the history
* dump the latest libxmtp

* move to the latest libxmtp

* set version

* comment out the policy stuff

* Update Group.kt
  • Loading branch information
nplasterer authored May 24, 2024
1 parent 9e06a7c commit f779708
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class GroupTest {
assertEquals(alixGroup.memberAddresses().size, 3)
assertEquals(boGroup.memberAddresses().size, 3)

assertEquals(boGroup.permissionLevel(), GroupPermissions.EVERYONE_IS_ADMIN)
assertEquals(alixGroup.permissionLevel(), GroupPermissions.EVERYONE_IS_ADMIN)
// assertEquals(boGroup.permissionLevel(), GroupPermissions.EVERYONE_IS_ADMIN)
// assertEquals(alixGroup.permissionLevel(), GroupPermissions.EVERYONE_IS_ADMIN)
assertEquals(boGroup.adminAddress().lowercase(), boClient.address.lowercase())
assertEquals(alixGroup.adminAddress().lowercase(), boClient.address.lowercase())
assert(boGroup.isAdmin())
Expand Down Expand Up @@ -143,8 +143,8 @@ class GroupTest {
assertEquals(alixGroup.memberAddresses().size, 2)
assertEquals(boGroup.memberAddresses().size, 2)

assertEquals(boGroup.permissionLevel(), GroupPermissions.GROUP_CREATOR_IS_ADMIN)
assertEquals(alixGroup.permissionLevel(), GroupPermissions.GROUP_CREATOR_IS_ADMIN)
// assertEquals(boGroup.permissionLevel(), GroupPermissions.GROUP_CREATOR_IS_ADMIN)
// assertEquals(alixGroup.permissionLevel(), GroupPermissions.GROUP_CREATOR_IS_ADMIN)
assertEquals(boGroup.adminAddress().lowercase(), boClient.address.lowercase())
assertEquals(alixGroup.adminAddress().lowercase(), boClient.address.lowercase())
assert(boGroup.isAdmin())
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: c974c9b
Version: 5b7cb6b
Branch: main
Date: 2024-05-03 16:18:08 +0000
Date: 2024-05-23 17:10:07 +0000
7 changes: 3 additions & 4 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import uniffi.xmtpv3.FfiGroupMetadata
import uniffi.xmtpv3.FfiListMessagesOptions
import uniffi.xmtpv3.FfiMessage
import uniffi.xmtpv3.FfiMessageCallback
import uniffi.xmtpv3.GroupPermissions
import java.util.Date
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.DurationUnit
Expand Down Expand Up @@ -157,9 +156,9 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
return libXMTPGroup.addedByAddress()
}

fun permissionLevel(): GroupPermissions {
return metadata.policyType()
}
// fun permissionLevel(): GroupPermissions {
// return metadata.policyType()
// }

fun isAdmin(): Boolean {
return metadata.creatorAccountAddress().lowercase() == client.address.lowercase()
Expand Down
164 changes: 148 additions & 16 deletions library/src/main/java/xmtpv3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,11 @@ internal interface _UniFFILib : Library {
`ptr`: Pointer, _uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue

fun uniffi_xmtpv3_fn_method_ffigroupmetadata_policy_type(
fun uniffi_xmtpv3_fn_free_ffigrouppermissions(
`ptr`: Pointer, _uniffi_out_err: RustCallStatus,
): Unit

fun uniffi_xmtpv3_fn_method_ffigrouppermissions_policy_type(
`ptr`: Pointer, _uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue

Expand Down Expand Up @@ -586,6 +590,10 @@ internal interface _UniFFILib : Library {
`ptr`: Pointer, _uniffi_out_err: RustCallStatus,
): Pointer

fun uniffi_xmtpv3_fn_method_ffixmtpclient_db_reconnect(
`ptr`: Pointer,
): Pointer

fun uniffi_xmtpv3_fn_method_ffixmtpclient_installation_id(
`ptr`: Pointer, _uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
Expand All @@ -594,6 +602,10 @@ internal interface _UniFFILib : Library {
`ptr`: Pointer, `recoverableWalletSignature`: RustBuffer.ByValue,
): Pointer

fun uniffi_xmtpv3_fn_method_ffixmtpclient_release_db_connection(
`ptr`: Pointer, _uniffi_out_err: RustCallStatus,
): Unit

fun uniffi_xmtpv3_fn_method_ffixmtpclient_text_to_sign(
`ptr`: Pointer, _uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
Expand Down Expand Up @@ -1034,7 +1046,7 @@ internal interface _UniFFILib : Library {
fun uniffi_xmtpv3_checksum_method_ffigroupmetadata_creator_account_address(
): Short

fun uniffi_xmtpv3_checksum_method_ffigroupmetadata_policy_type(
fun uniffi_xmtpv3_checksum_method_ffigrouppermissions_policy_type(
): Short

fun uniffi_xmtpv3_checksum_method_ffistreamcloser_end(
Expand Down Expand Up @@ -1076,12 +1088,18 @@ internal interface _UniFFILib : Library {
fun uniffi_xmtpv3_checksum_method_ffixmtpclient_conversations(
): Short

fun uniffi_xmtpv3_checksum_method_ffixmtpclient_db_reconnect(
): Short

fun uniffi_xmtpv3_checksum_method_ffixmtpclient_installation_id(
): Short

fun uniffi_xmtpv3_checksum_method_ffixmtpclient_register_identity(
): Short

fun uniffi_xmtpv3_checksum_method_ffixmtpclient_release_db_connection(
): Short

fun uniffi_xmtpv3_checksum_method_ffixmtpclient_text_to_sign(
): Short

Expand Down Expand Up @@ -1228,7 +1246,7 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_xmtpv3_checksum_method_ffigroupmetadata_creator_account_address() != 1906.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroupmetadata_policy_type() != 22845.toShort()) {
if (lib.uniffi_xmtpv3_checksum_method_ffigrouppermissions_policy_type() != 43161.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffistreamcloser_end() != 47211.toShort()) {
Expand Down Expand Up @@ -1270,12 +1288,18 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_conversations() != 31628.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_db_reconnect() != 33037.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_installation_id() != 62523.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_register_identity() != 64634.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_release_db_connection() != 12677.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_text_to_sign() != 25727.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -2350,9 +2374,6 @@ public interface FfiGroupMetadataInterface {
fun `conversationType`(): String
fun `creatorAccountAddress`(): String

@Throws(GenericException::class)
fun `policyType`(): GroupPermissions

companion object
}

Expand Down Expand Up @@ -2401,11 +2422,64 @@ class FfiGroupMetadata(
}


companion object

}

public object FfiConverterTypeFfiGroupMetadata : FfiConverter<FfiGroupMetadata, Pointer> {
override fun lower(value: FfiGroupMetadata): Pointer = value.callWithPointer { it }

override fun lift(value: Pointer): FfiGroupMetadata {
return FfiGroupMetadata(value)
}

override fun read(buf: ByteBuffer): FfiGroupMetadata {
// The Rust code always writes pointers as 8 bytes, and will
// fail to compile if they don't fit.
return lift(Pointer(buf.getLong()))
}

override fun allocationSize(value: FfiGroupMetadata) = 8

override fun write(value: FfiGroupMetadata, buf: ByteBuffer) {
// The Rust code always expects pointers written as 8 bytes,
// and will fail to compile if they don't fit.
buf.putLong(Pointer.nativeValue(lower(value)))
}
}


public interface FfiGroupPermissionsInterface {
@Throws(GenericException::class)
fun `policyType`(): GroupPermissions

companion object
}

class FfiGroupPermissions(
pointer: Pointer,
) : FFIObject(pointer), FfiGroupPermissionsInterface {

/**
* Disconnect the object from the underlying Rust object.
*
* It can be called more than once, but once called, interacting with the object
* causes an `IllegalStateException`.
*
* Clients **must** call this method once done with the object, or cause a memory leak.
*/
override protected fun freeRustArcPtr() {
rustCall() { status ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_free_ffigrouppermissions(this.pointer, status)
}
}


@Throws(GenericException::class)
override fun `policyType`(): GroupPermissions =
callWithPointer {
rustCallWithError(GenericException) { _status ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroupmetadata_policy_type(
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffigrouppermissions_policy_type(
it,

_status
Expand All @@ -2420,22 +2494,22 @@ class FfiGroupMetadata(

}

public object FfiConverterTypeFfiGroupMetadata : FfiConverter<FfiGroupMetadata, Pointer> {
override fun lower(value: FfiGroupMetadata): Pointer = value.callWithPointer { it }
public object FfiConverterTypeFfiGroupPermissions : FfiConverter<FfiGroupPermissions, Pointer> {
override fun lower(value: FfiGroupPermissions): Pointer = value.callWithPointer { it }

override fun lift(value: Pointer): FfiGroupMetadata {
return FfiGroupMetadata(value)
override fun lift(value: Pointer): FfiGroupPermissions {
return FfiGroupPermissions(value)
}

override fun read(buf: ByteBuffer): FfiGroupMetadata {
override fun read(buf: ByteBuffer): FfiGroupPermissions {
// The Rust code always writes pointers as 8 bytes, and will
// fail to compile if they don't fit.
return lift(Pointer(buf.getLong()))
}

override fun allocationSize(value: FfiGroupMetadata) = 8
override fun allocationSize(value: FfiGroupPermissions) = 8

override fun write(value: FfiGroupMetadata, buf: ByteBuffer) {
override fun write(value: FfiGroupPermissions, buf: ByteBuffer) {
// The Rust code always expects pointers written as 8 bytes,
// and will fail to compile if they don't fit.
buf.putLong(Pointer.nativeValue(lower(value)))
Expand Down Expand Up @@ -2878,10 +2952,16 @@ public interface FfiXmtpClientInterface {
@Throws(GenericException::class)
suspend fun `canMessage`(`accountAddresses`: List<String>): Map<String, Boolean>
fun `conversations`(): FfiConversations

@Throws(GenericException::class)
suspend fun `dbReconnect`()
fun `installationId`(): ByteArray

@Throws(GenericException::class)
suspend fun `registerIdentity`(`recoverableWalletSignature`: ByteArray?)

@Throws(GenericException::class)
fun `releaseDbConnection`()
fun `textToSign`(): String?

companion object
Expand Down Expand Up @@ -2962,6 +3042,38 @@ class FfiXmtpClient(
FfiConverterTypeFfiConversations.lift(it)
}


@Throws(GenericException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `dbReconnect`() {
return uniffiRustCallAsync(
callWithPointer { thisPtr ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffixmtpclient_db_reconnect(
thisPtr,

)
},
{ future, continuation ->
_UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_poll_void(
future,
continuation
)
},
{ future, continuation ->
_UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_complete_void(
future,
continuation
)
},
{ future -> _UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_free_void(future) },
// lift function
{ Unit },

// Error FFI converter
GenericException.ErrorHandler,
)
}

override fun `installationId`(): ByteArray =
callWithPointer {
rustCall() { _status ->
Expand Down Expand Up @@ -3007,6 +3119,19 @@ class FfiXmtpClient(
)
}

@Throws(GenericException::class)
override fun `releaseDbConnection`() =
callWithPointer {
rustCallWithError(GenericException) { _status ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffixmtpclient_release_db_connection(
it,

_status
)
}
}


override fun `textToSign`(): String? =
callWithPointer {
rustCall() { _status ->
Expand Down Expand Up @@ -3522,6 +3647,7 @@ sealed class GenericException(message: String) : Exception(message) {
class GroupException(message: String) : GenericException(message)
class Signature(message: String) : GenericException(message)
class GroupMetadata(message: String) : GenericException(message)
class GroupMutablePermissions(message: String) : GenericException(message)
class Generic(message: String) : GenericException(message)


Expand All @@ -3542,7 +3668,8 @@ public object FfiConverterTypeGenericError : FfiConverterRustBuffer<GenericExcep
5 -> GenericException.GroupException(FfiConverterString.read(buf))
6 -> GenericException.Signature(FfiConverterString.read(buf))
7 -> GenericException.GroupMetadata(FfiConverterString.read(buf))
8 -> GenericException.Generic(FfiConverterString.read(buf))
8 -> GenericException.GroupMutablePermissions(FfiConverterString.read(buf))
9 -> GenericException.Generic(FfiConverterString.read(buf))
else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
}

Expand Down Expand Up @@ -3589,10 +3716,15 @@ public object FfiConverterTypeGenericError : FfiConverterRustBuffer<GenericExcep
Unit
}

is GenericException.Generic -> {
is GenericException.GroupMutablePermissions -> {
buf.putInt(8)
Unit
}

is GenericException.Generic -> {
buf.putInt(9)
Unit
}
}.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
}

Expand Down
Binary file modified library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so
Binary file not shown.

0 comments on commit f779708

Please sign in to comment.