diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8ff03d2..29174597 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,7 +74,7 @@ jobs: - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.4 - run: rustup update stable && rustup default stable - - run: make build-ios-bindings + - run: make build-xcframework - name: Select Xcode 15.4 run: sudo xcode-select -s /Applications/Xcode_15.4.app - name: Build ${{ matrix.config }} diff --git a/.github/workflows/release-swift.yml b/.github/workflows/release-swift.yml index fa3e242a..86e1f7b2 100644 --- a/.github/workflows/release-swift.yml +++ b/.github/workflows/release-swift.yml @@ -53,12 +53,10 @@ jobs: run: | sudo xcode-select -s /Applications/Xcode_15.4.app - # 6. Build and Package Rust XCFramework - - name: Build and Package Rust XCFramework + # 6. Build and Package XCFramework + - name: Build and Package XCFramework run: | - make build-ios-bindings-release - make zip-rust-xcframework - make compute-rust-checksum + make build-xcframework make generate-package-swift # 7. Update Podspec with Version and Download URL @@ -68,10 +66,10 @@ jobs: sed -i '' "s/^ s\.version *= *.*/ s.version = '${VERSION}'/g" YttriumWrapper.podspec # Construct the download URL - DOWNLOAD_URL="https://github.com/reown-com/yttrium/releases/download/${VERSION}/RustXcframework.xcframework.zip" + DOWNLOAD_URL="https://github.com/reown-com/yttrium/releases/download/${VERSION}/libuniffi_yttrium.xcframework.zip" # Replace the download URL in prepare_command - sed -i '' "s|curl -L -o RustXcframework.xcframework.zip '.*'|curl -L -o RustXcframework.xcframework.zip '${DOWNLOAD_URL}'|g" YttriumWrapper.podspec + sed -i '' "s|curl -L -o libuniffi_yttrium.xcframework.zip '.*'|curl -L -o libuniffi_yttrium.xcframework.zip '${DOWNLOAD_URL}'|g" YttriumWrapper.podspec # 8. Commit and Push Package.swift and Podspec - name: Commit and Push Package.swift and Podspec @@ -80,7 +78,7 @@ jobs: run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - git add Package.swift crates/ffi/YttriumCore/Sources/YttriumCore/* YttriumWrapper.podspec + git add Package.swift platforms/swift/Sources/Yttrium/* YttriumWrapper.podspec if git diff --cached --quiet; then echo "No changes to commit." else @@ -119,15 +117,15 @@ jobs: draft: false prerelease: true - # 11. Upload Rust XCFramework to the Release - - name: Upload Rust XCFramework to Release + # 11. Upload XCFramework to the Release + - name: Upload XCFramework to Release uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./Output/RustXcframework.xcframework.zip - asset_name: RustXcframework.xcframework.zip + asset_path: ./Output/libuniffi_yttrium.xcframework.zip + asset_name: libuniffi_yttrium.xcframework.zip asset_content_type: application/zip # 12. Publish to CocoaPods Trunk @@ -135,4 +133,4 @@ jobs: env: COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} run: | - pod trunk push YttriumWrapper.podspec --allow-warnings \ No newline at end of file + pod trunk push YttriumWrapper.podspec --allow-warnings diff --git a/Cargo.toml b/Cargo.toml index 369c73b8..30774c3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,9 +31,13 @@ alloy = "0.6.1" alloy-provider = "0.6.1" erc6492 = { git = "https://github.com/reown-com/erc6492.git", branch = "main" } +# The values have been configured this way to prevent crashes in Swift debug builds with the default settings. [profile.release] -opt-level = 'z' +debug = true lto = true +opt-level = 0 + + codegen-units = 1 # panic = "abort" # strip = true - it removes kotlin-bindings diff --git a/Makefile b/Makefile index 92edbb2a..449e1578 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,12 @@ build-ios-bindings: build-ios-bindings-release: sh crates/ffi/build-rust-ios-release.sh +build-xcframework: + sh scripts/build-xcframework.sh + +set-up-local-swift-package: + sh scripts/set-up-local-package.sh + test: cargo test --workspace @@ -62,12 +68,6 @@ local-infra-forked: local-infra-7702: cd test/scripts/7702 && sh local-infra.sh -.PHONY: zip-rust-xcframework -zip-rust-xcframework: - mkdir -p Output - cd crates/ffi/YttriumCore/ && \ - zip -r ../../../Output/RustXcframework.xcframework.zip \ - RustXcframework.xcframework \ .PHONY: compute-rust-checksum compute-rust-checksum: @@ -76,8 +76,8 @@ compute-rust-checksum: .PHONY: generate-package-swift generate-package-swift: - chmod +x scripts/generate_package_swift.sh - ./scripts/generate_package_swift.sh + chmod +x scripts/generate-package-swift.sh + ./scripts/generate-package-swift.sh .PHONY: build setup build-ios-bindings build-swift-apple-platforms test-swift-apple-platforms fetch-thirdparty setup-thirdparty test format clean local-infra local-infra-forked local-infra-7702 diff --git a/Package.swift b/Package.swift index 638ce1b1..938821d1 100644 --- a/Package.swift +++ b/Package.swift @@ -2,26 +2,10 @@ import PackageDescription import Foundation -let useLocalRustXcframework = ProcessInfo.processInfo.environment["USE_LOCAL_RUST_XCFRAMEWORK"] == "1" - -let rustXcframeworkTarget: Target = useLocalRustXcframework ? - .binaryTarget( - name: "RustXcframework", - path: "crates/ffi/YttriumCore/RustXcframework.xcframework" - ) : - .binaryTarget( - name: "RustXcframework", - url: "https://github.com/reown-com/yttrium/releases/download/0.2.13/RustXcframework.xcframework.zip", - checksum: "5abd6f384957e2016493d929cdef9b2a1e9aab6d2a9201e74e5477847b804313" - ) - let package = Package( - name: "yttrium", + name: "Yttrium", platforms: [ - .macOS(.v14), - .iOS(.v13), - .watchOS(.v10), - .tvOS(.v17) + .iOS(.v13), .macOS(.v12) ], products: [ .library( @@ -29,34 +13,21 @@ let package = Package( targets: ["Yttrium"] ), ], - dependencies: [ - .package(url: "https://github.com/thebarndog/swift-dotenv.git", from: "2.0.0") - ], targets: [ - rustXcframeworkTarget, - .target( - name: "YttriumCore", - dependencies: [ - "RustXcframework", - .product(name: "SwiftDotenv", package: "swift-dotenv") - ], - path: "crates/ffi/YttriumCore/Sources/YttriumCore" - ), .target( name: "Yttrium", - dependencies: [ - "YttriumCore", - .product(name: "SwiftDotenv", package: "swift-dotenv") - ], - path: "platforms/swift/Sources/Yttrium" - ), - .testTarget( - name: "YttriumTests", - dependencies: [ - "Yttrium", - .product(name: "SwiftDotenv", package: "swift-dotenv") - ], - path: "platforms/swift/Tests/YttriumTests" + dependencies: ["YttriumXCFramework"], + path: "platforms/swift/Sources/Yttrium", + publicHeadersPath: ".", + cSettings: [ + .headerSearchPath(".") + ] ), + .binaryTarget( + name: "YttriumXCFramework", + url: "https://github.com/reown-com/yttrium/releases/download/0.2.22/libuniffi_yttrium.xcframework.zip", + checksum: "582c820d78325294160af8a359b106ef998a19c50ca400ae7ee181b28bede5bb" + ) ] ) + diff --git a/YttriumWrapper.podspec b/YttriumWrapper.podspec index 0a9be6f5..f0819dd0 100644 --- a/YttriumWrapper.podspec +++ b/YttriumWrapper.podspec @@ -1,8 +1,8 @@ Pod::Spec.new do |s| s.name = 'YttriumWrapper' - s.version = '0.2.13' + s.version = '0.2.22' s.summary = '4337 implementation' - s.description = '4337 implementation ' + s.description = '4337 implementation and Chain Abstraction' s.homepage = 'https://reown.com' s.license = { :type => 'MIT', :file => 'LICENSE' } s.authors = 'reown inc.' @@ -14,14 +14,14 @@ Pod::Spec.new do |s| s.swift_version = '5.9' # Include the Swift source files - s.source_files = 'crates/ffi/YttriumCore/Sources/YttriumCore/**/*.{swift,h}' + s.source_files = 'platforms/swift/Sources/Yttrium/**/*.{swift,h}' # Include the vendored framework s.prepare_command = <<-SCRIPT - curl -L -o RustXcframework.xcframework.zip 'https://github.com/reown-com/yttrium/releases/download/0.2.13/RustXcframework.xcframework.zip' - unzip -o RustXcframework.xcframework.zip -d crates/ffi/YttriumCore/ - rm RustXcframework.xcframework.zip + curl -L -o libuniffi_yttrium.xcframework.zip 'https://github.com/reown-com/yttrium/releases/download/0.2.22/libuniffi_yttrium.xcframework.zip' + unzip -o libuniffi_yttrium.xcframework.zip -d platforms/swift/ + rm libuniffi_yttrium.xcframework.zip SCRIPT - s.vendored_frameworks = 'crates/ffi/YttriumCore/RustXcframework.xcframework' + s.vendored_frameworks = 'platforms/swift/target/ios/libuniffi_yttrium.xcframework' end diff --git a/crates/ffi/Cargo.toml b/crates/ffi/Cargo.toml index d9b73763..58da0e57 100644 --- a/crates/ffi/Cargo.toml +++ b/crates/ffi/Cargo.toml @@ -8,9 +8,6 @@ license.workspace = true [lib] crate-type = ["staticlib"] -[build-dependencies] -swift-bridge-build = { git = "https://github.com/wooden-worm/swift-bridge.git", branch = "derive_debug_serde" } - [dependencies] # See: https://github.com/kornelski/rust-security-framework/pull/204 # security-framework = "2.10.0" diff --git a/crates/ffi/build.rs b/crates/ffi/build.rs index ad88e7d3..b4eed53a 100644 --- a/crates/ffi/build.rs +++ b/crates/ffi/build.rs @@ -1,14 +1,14 @@ -use std::path::PathBuf; +//use std::path::PathBuf; fn main() { - let out_dir = PathBuf::from("./generated"); - println!("cargo:rerun-if-changed={}", out_dir.display()); - - let bridges = vec!["src/lib.rs"]; - for path in &bridges { - println!("cargo:rerun-if-changed={}", path); - } - - swift_bridge_build::parse_bridges(bridges) - .write_all_concatenated(out_dir, env!("CARGO_PKG_NAME")); + // let out_dir = PathBuf::from("./generated"); + // println!("cargo:rerun-if-changed={}", out_dir.display()); + // + // let bridges = vec!["src/lib.rs"]; + // for path in &bridges { + // println!("cargo:rerun-if-changed={}", path); + // } + // + // swift_bridge_build::parse_bridges(bridges) + // .write_all_concatenated(out_dir, env!("CARGO_PKG_NAME")); } diff --git a/crates/kotlin-ffi/Cargo.toml b/crates/kotlin-ffi/Cargo.toml index 3002477e..3e26c75a 100644 --- a/crates/kotlin-ffi/Cargo.toml +++ b/crates/kotlin-ffi/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [lib] name = "uniffi_yttrium" -crate-type = ["cdylib"] +crate-type = ["staticlib", "cdylib"] [build-dependencies] uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "e796e00ad150f8b14b61a859a2e8c6497b35074e" } diff --git a/crates/kotlin-ffi/src/lib.rs b/crates/kotlin-ffi/src/lib.rs index a6092af3..17afedfd 100644 --- a/crates/kotlin-ffi/src/lib.rs +++ b/crates/kotlin-ffi/src/lib.rs @@ -1,6 +1,6 @@ uniffi::setup_scaffolding!(); -use alloy::primitives::{Bytes, U256, U64}; +use alloy::primitives::{Bytes as FFIBytes, U256 as FFIU256, U64 as FFIU64}; use alloy::providers::Provider; use yttrium::chain_abstraction::api::route::RouteResponse; use yttrium::chain_abstraction::api::status::{ @@ -14,7 +14,8 @@ use std::time::Duration; use yttrium::chain_abstraction::client::Client; use yttrium::config::Config; use yttrium::transaction::send::safe_test::{ - Address, OwnerSignature as YOwnerSignature, PrimitiveSignature, + Address as FFIAddress, OwnerSignature as YOwnerSignature, + PrimitiveSignature, }; use yttrium::{ account_client::{AccountClient as YAccountClient, SignerType}, @@ -24,7 +25,7 @@ use yttrium::{ }; #[derive(uniffi::Record)] -pub struct AccountClientConfig { +pub struct FFIAccountClientConfig { pub owner_address: String, pub chain_id: u64, pub config: Config, @@ -34,43 +35,43 @@ pub struct AccountClientConfig { } #[derive(uniffi::Record)] -pub struct Transaction { +pub struct FFITransaction { pub to: String, pub value: String, pub data: String, } -uniffi::custom_type!(Address, String, { +uniffi::custom_type!(FFIAddress, String, { try_lift: |val| Ok(val.parse()?), lower: |obj| obj.to_string(), }); -uniffi::custom_type!(U256, String, { +uniffi::custom_type!(FFIU256, String, { try_lift: |val| Ok(val.parse()?), lower: |obj| obj.to_string(), }); -uniffi::custom_type!(U64, String, { +uniffi::custom_type!(FFIU64, String, { try_lift: |val| Ok(val.parse()?), lower: |obj| obj.to_string(), }); -uniffi::custom_type!(Bytes, String, { +uniffi::custom_type!(FFIBytes, String, { try_lift: |val| Ok(val.parse()?), lower: |obj| obj.to_string(), }); #[derive(uniffi::Record)] pub struct InitTransaction { - pub from: Address, - pub to: Address, - pub value: U256, - pub gas: U64, - pub gas_price: U256, - pub data: Bytes, - pub nonce: U64, - pub max_fee_per_gas: U256, - pub max_priority_fee_per_gas: U256, + pub from: FFIAddress, + pub to: FFIAddress, + pub value: FFIU256, + pub gas: FFIU64, + pub gas_price: FFIU256, + pub data: FFIBytes, + pub nonce: FFIU64, + pub max_fee_per_gas: FFIU256, + pub max_priority_fee_per_gas: FFIU256, pub chain_id: String, } @@ -87,13 +88,13 @@ pub struct OwnerSignature { } #[derive(Debug, thiserror::Error, uniffi::Error)] -pub enum Error { +pub enum FFIError { #[error("General {0}")] General(String), } #[derive(uniffi::Object)] -pub struct AccountClient { +pub struct FFIAccountClient { pub owner_address: String, pub chain_id: u64, account_client: YAccountClient, @@ -122,22 +123,22 @@ impl ChainAbstractionClient { pub async fn route( &self, transaction: InitTransaction, - ) -> Result { + ) -> Result { let ca_transaction = CATransaction::from(transaction); self.client .route(ca_transaction) .await - .map_err(|e| Error::General(e.to_string())) + .map_err(|e| FFIError::General(e.to_string())) } pub async fn status( &self, orchestration_id: String, - ) -> Result { + ) -> Result { self.client .status(orchestration_id) .await - .map_err(|e| Error::General(e.to_string())) + .map_err(|e| FFIError::General(e.to_string())) } pub async fn wait_for_success_with_timeout( @@ -145,7 +146,7 @@ impl ChainAbstractionClient { orchestration_id: String, check_in: u64, timeout: u64, - ) -> Result { + ) -> Result { self.client .wait_for_success_with_timeout( orchestration_id, @@ -153,13 +154,13 @@ impl ChainAbstractionClient { Duration::from_secs(timeout), ) .await - .map_err(|e| Error::General(e.to_string())) + .map_err(|e| FFIError::General(e.to_string())) } pub async fn estimate_fees( &self, chain_id: String, - ) -> Result { + ) -> Result { let url = format!( "https://rpc.walletconnect.com/v1?chainId={chain_id}&projectId={}", self.project_id @@ -170,7 +171,7 @@ impl ChainAbstractionClient { provider .estimate_eip1559_fees(None) .await - .map_err(|e| Error::General(e.to_string())) + .map_err(|e| FFIError::General(e.to_string())) .map(|fees| Eip1559Estimation { max_fee_per_gas: fees.max_fee_per_gas.to_string(), max_priority_fee_per_gas: fees @@ -181,9 +182,9 @@ impl ChainAbstractionClient { } #[uniffi::export(async_runtime = "tokio")] -impl AccountClient { +impl FFIAccountClient { #[uniffi::constructor] - pub fn new(config: AccountClientConfig) -> Self { + pub fn new(config: FFIAccountClientConfig) -> Self { let owner_address = config.owner_address.clone(); let signer_type = config.signer_type.clone(); let signer = SignerType::from(signer_type).unwrap(); @@ -215,17 +216,17 @@ impl AccountClient { self.chain_id } - pub async fn get_address(&self) -> Result { + pub async fn get_address(&self) -> Result { self.account_client .get_address() .await - .map_err(|e| Error::General(e.to_string())) + .map_err(|e| FFIError::General(e.to_string())) } pub async fn send_transactions( &self, - transactions: Vec, - ) -> Result { + transactions: Vec, + ) -> Result { let ytransactions: Vec = transactions.into_iter().map(YTransaction::from).collect(); @@ -233,14 +234,14 @@ impl AccountClient { .account_client .send_transactions(ytransactions) .await - .map_err(|e| Error::General(e.to_string()))? + .map_err(|e| FFIError::General(e.to_string()))? .to_string()) } pub async fn prepare_send_transactions( &self, - transactions: Vec, - ) -> Result { + transactions: Vec, + ) -> Result { let ytransactions: Vec = transactions.into_iter().map(YTransaction::from).collect(); @@ -248,14 +249,14 @@ impl AccountClient { .account_client .prepare_send_transactions(ytransactions) .await - .map_err(|e| Error::General(e.to_string()))?; + .map_err(|e| FFIError::General(e.to_string()))?; Ok(PreparedSendTransaction { hash: prepared_send_transaction.hash.to_string(), do_send_transaction_params: serde_json::to_string( &prepared_send_transaction.do_send_transaction_params, ) - .map_err(|e| Error::General(e.to_string()))?, + .map_err(|e| FFIError::General(e.to_string()))?, }) } @@ -263,7 +264,7 @@ impl AccountClient { &self, signatures: Vec, do_send_transaction_params: String, - ) -> Result { + ) -> Result { let mut signatures2: Vec = Vec::with_capacity(signatures.len()); @@ -271,12 +272,12 @@ impl AccountClient { signatures2.push(YOwnerSignature { owner: signature .owner - .parse::
() - .map_err(|e| Error::General(e.to_string()))?, + .parse::() + .map_err(|e| FFIError::General(e.to_string()))?, signature: signature .signature .parse::() - .map_err(|e| Error::General(e.to_string()))?, + .map_err(|e| FFIError::General(e.to_string()))?, }); } @@ -285,10 +286,10 @@ impl AccountClient { .do_send_transactions( signatures2, serde_json::from_str(&do_send_transaction_params) - .map_err(|e| Error::General(e.to_string()))?, + .map_err(|e| FFIError::General(e.to_string()))?, ) .await - .map_err(|e| Error::General(e.to_string()))? + .map_err(|e| FFIError::General(e.to_string()))? .to_string()) } @@ -296,32 +297,34 @@ impl AccountClient { &self, message: String, mnemonic: String, - ) -> Result { + ) -> Result { self.account_client .sign_message_with_mnemonic(message, mnemonic) - .map_err(|e| Error::General(e.to_string())) + .map_err(|e| FFIError::General(e.to_string())) } pub async fn wait_for_user_operation_receipt( &self, user_operation_hash: String, - ) -> Result { + ) -> Result { self.account_client .wait_for_user_operation_receipt( user_operation_hash.parse().map_err(|e| { - Error::General(format!("Parsing user_operation_hash: {e}")) + FFIError::General(format!( + "Parsing user_operation_hash: {e}" + )) })?, ) .await .iter() .map(serde_json::to_string) .collect::>() - .map_err(|e| Error::General(e.to_string())) + .map_err(|e| FFIError::General(e.to_string())) } } -impl From for YTransaction { - fn from(transaction: Transaction) -> Self { +impl From for YTransaction { + fn from(transaction: FFITransaction) -> Self { YTransaction::new_from_strings( transaction.to, transaction.value, diff --git a/platforms/swift/.gitignore b/platforms/swift/.gitignore deleted file mode 100644 index 0023a534..00000000 --- a/platforms/swift/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/platforms/swift/Sources/Yttrium/Yttrium.swift b/platforms/swift/Sources/Yttrium/Yttrium.swift deleted file mode 100644 index 6784c418..00000000 --- a/platforms/swift/Sources/Yttrium/Yttrium.swift +++ /dev/null @@ -1,3 +0,0 @@ - -import Foundation -@_exported import YttriumCore \ No newline at end of file diff --git a/platforms/swift/Sources/Yttrium/uniffi_yttrium.swift b/platforms/swift/Sources/Yttrium/uniffi_yttrium.swift new file mode 100644 index 00000000..8626bdf5 --- /dev/null +++ b/platforms/swift/Sources/Yttrium/uniffi_yttrium.swift @@ -0,0 +1,1722 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +// swiftlint:disable all +import Foundation + +// Depending on the consumer's build setup, the low-level FFI code +// might be in a separate module, or it might be compiled inline into +// this module. This is a bit of light hackery to work with both. +#if canImport(uniffi_yttriumFFI) + import uniffi_yttriumFFI +#endif + +private extension RustBuffer { + // Allocate a new buffer, copying the contents of a `UInt8` array. + init(bytes: [UInt8]) { + let rbuf = bytes.withUnsafeBufferPointer { ptr in + RustBuffer.from(ptr) + } + self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) + } + + static func empty() -> RustBuffer { + RustBuffer(capacity: 0, len: 0, data: nil) + } + + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { + try! rustCall { ffi_uniffi_yttrium_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + } + + // Frees the buffer in place. + // The buffer must not be used after this is called. + func deallocate() { + try! rustCall { ffi_uniffi_yttrium_rustbuffer_free(self, $0) } + } +} + +private extension ForeignBytes { + init(bufferPointer: UnsafeBufferPointer) { + self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) + } +} + +// For every type used in the interface, we provide helper methods for conveniently +// lifting and lowering that type from C-compatible data, and for reading and writing +// values of that type in a buffer. + +// Helper classes/extensions that don't change. +// Someday, this will be in a library of its own. + +private extension Data { + init(rustBuffer: RustBuffer) { + self.init( + bytesNoCopy: rustBuffer.data!, + count: Int(rustBuffer.len), + deallocator: .none + ) + } +} + +// Define reader functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. +// +// With external types, one swift source file needs to be able to call the read +// method on another source file's FfiConverter, but then what visibility +// should Reader have? +// - If Reader is fileprivate, then this means the read() must also +// be fileprivate, which doesn't work with external types. +// - If Reader is internal/public, we'll get compile errors since both source +// files will try define the same type. +// +// Instead, the read() method and these helper functions input a tuple of data + +private func createReader(data: Data) -> (data: Data, offset: Data.Index) { + (data: data, offset: 0) +} + +// Reads an integer at the current offset, in big-endian order, and advances +// the offset on success. Throws if reading the integer would move the +// offset past the end of the buffer. +private func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { + let range = reader.offset ..< reader.offset + MemoryLayout.size + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + if T.self == UInt8.self { + let value = reader.data[reader.offset] + reader.offset += 1 + return value as! T + } + var value: T = 0 + let _ = withUnsafeMutableBytes(of: &value) { reader.data.copyBytes(to: $0, from: range) } + reader.offset = range.upperBound + return value.bigEndian +} + +// Reads an arbitrary number of bytes, to be used to read +// raw bytes, this is useful when lifting strings +private func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> [UInt8] { + let range = reader.offset ..< (reader.offset + count) + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + var value = [UInt8](repeating: 0, count: count) + value.withUnsafeMutableBufferPointer { buffer in + reader.data.copyBytes(to: buffer, from: range) + } + reader.offset = range.upperBound + return value +} + +// Reads a float at the current offset. +private func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { + return try Float(bitPattern: readInt(&reader)) +} + +// Reads a float at the current offset. +private func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { + return try Double(bitPattern: readInt(&reader)) +} + +// Indicates if the offset has reached the end of the buffer. +private func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { + return reader.offset < reader.data.count +} + +// Define writer functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. See the above discussion on Readers for details. + +private func createWriter() -> [UInt8] { + return [] +} + +private func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { + writer.append(contentsOf: byteArr) +} + +// Writes an integer in big-endian order. +// +// Warning: make sure what you are trying to write +// is in the correct type! +private func writeInt(_ writer: inout [UInt8], _ value: T) { + var value = value.bigEndian + withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } +} + +private func writeFloat(_ writer: inout [UInt8], _ value: Float) { + writeInt(&writer, value.bitPattern) +} + +private func writeDouble(_ writer: inout [UInt8], _ value: Double) { + writeInt(&writer, value.bitPattern) +} + +// Protocol for types that transfer other types across the FFI. This is +// analogous to the Rust trait of the same name. +private protocol FfiConverter { + associatedtype FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType + static func write(_ value: SwiftType, into buf: inout [UInt8]) +} + +// Types conforming to `Primitive` pass themselves directly over the FFI. +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} + +extension FfiConverterPrimitive { + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lift(_ value: FfiType) throws -> SwiftType { + return value + } + + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lower(_ value: SwiftType) -> FfiType { + return value + } +} + +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} + +extension FfiConverterRustBuffer { + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lift(_ buf: RustBuffer) throws -> SwiftType { + var reader = createReader(data: Data(rustBuffer: buf)) + let value = try read(from: &reader) + if hasRemaining(reader) { + throw UniffiInternalError.incompleteData + } + buf.deallocate() + return value + } + + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lower(_ value: SwiftType) -> RustBuffer { + var writer = createWriter() + write(value, into: &writer) + return RustBuffer(bytes: writer) + } +} + +// An error type for FFI errors. These errors occur at the UniFFI level, not +// the library level. +private enum UniffiInternalError: LocalizedError { + case bufferOverflow + case incompleteData + case unexpectedOptionalTag + case unexpectedEnumCase + case unexpectedNullPointer + case unexpectedRustCallStatusCode + case unexpectedRustCallError + case unexpectedStaleHandle + case rustPanic(_ message: String) + + public var errorDescription: String? { + switch self { + case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" + case .incompleteData: return "The buffer still has data after lifting its containing value" + case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" + case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" + case .unexpectedNullPointer: return "Raw pointer value was null" + case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" + case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" + case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" + case let .rustPanic(message): return message + } + } +} + +private extension NSLock { + func withLock(f: () throws -> T) rethrows -> T { + lock() + defer { self.unlock() } + return try f() + } +} + +private let CALL_SUCCESS: Int8 = 0 +private let CALL_ERROR: Int8 = 1 +private let CALL_UNEXPECTED_ERROR: Int8 = 2 +private let CALL_CANCELLED: Int8 = 3 + +private extension RustCallStatus { + init() { + self.init( + code: CALL_SUCCESS, + errorBuf: RustBuffer( + capacity: 0, + len: 0, + data: nil + ) + ) + } +} + +private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { + let neverThrow: ((RustBuffer) throws -> Never)? = nil + return try makeRustCall(callback, errorHandler: neverThrow) +} + +private func rustCallWithError( + _ errorHandler: @escaping (RustBuffer) throws -> E, + _ callback: (UnsafeMutablePointer) -> T +) throws -> T { + try makeRustCall(callback, errorHandler: errorHandler) +} + +private func makeRustCall( + _ callback: (UnsafeMutablePointer) -> T, + errorHandler: ((RustBuffer) throws -> E)? +) throws -> T { + uniffiEnsureInitialized() + var callStatus = RustCallStatus() + let returnedVal = callback(&callStatus) + try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) + return returnedVal +} + +private func uniffiCheckCallStatus( + callStatus: RustCallStatus, + errorHandler: ((RustBuffer) throws -> E)? +) throws { + switch callStatus.code { + case CALL_SUCCESS: + return + + case CALL_ERROR: + if let errorHandler = errorHandler { + throw try errorHandler(callStatus.errorBuf) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.unexpectedRustCallError + } + + case CALL_UNEXPECTED_ERROR: + // When the rust code sees a panic, it tries to construct a RustBuffer + // with the message. But if that code panics, then it just sends back + // an empty buffer. + if callStatus.errorBuf.len > 0 { + throw try UniffiInternalError.rustPanic(FfiConverterString.lift(callStatus.errorBuf)) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.rustPanic("Rust panic") + } + + case CALL_CANCELLED: + fatalError("Cancellation not supported yet") + + default: + throw UniffiInternalError.unexpectedRustCallStatusCode + } +} + +private func uniffiTraitInterfaceCall( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> Void +) { + do { + try writeReturn(makeCall()) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private func uniffiTraitInterfaceCallWithError( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> Void, + lowerError: (E) -> RustBuffer +) { + do { + try writeReturn(makeCall()) + } catch let error as E { + callStatus.pointee.code = CALL_ERROR + callStatus.pointee.errorBuf = lowerError(error) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private final class UniffiHandleMap: @unchecked Sendable { + // All mutation happens with this lock held, which is why we implement @unchecked Sendable. + private let lock = NSLock() + private var map: [UInt64: T] = [:] + private var currentHandle: UInt64 = 1 + + func insert(obj: T) -> UInt64 { + lock.withLock { + let handle = currentHandle + currentHandle += 1 + map[handle] = obj + return handle + } + } + + func get(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + @discardableResult + func remove(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map.removeValue(forKey: handle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + var count: Int { + map.count + } +} + +// Public interface members begin here. + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterUInt64: FfiConverterPrimitive { + typealias FfiType = UInt64 + typealias SwiftType = UInt64 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterBool: FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool + + public static func lift(_ value: Int8) throws -> Bool { + return value != 0 + } + + public static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { + return try lift(readInt(&buf)) + } + + public static func write(_ value: Bool, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer + + public static func lift(_ value: RustBuffer) throws -> String { + defer { + value.deallocate() + } + if value.data == nil { + return String() + } + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) + return String(bytes: bytes, encoding: String.Encoding.utf8)! + } + + public static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in + // The swift string gives us int8_t, we want uint8_t. + ptr.withMemoryRebound(to: UInt8.self) { ptr in + // The swift string gives us a trailing null byte, we don't want it. + let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) + return RustBuffer.from(buf) + } + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { + let len: Int32 = try readInt(&buf) + return try String(bytes: readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! + } + + public static func write(_ value: String, into buf: inout [UInt8]) { + let len = Int32(value.utf8.count) + writeInt(&buf, len) + writeBytes(&buf, value.utf8) + } +} + +public protocol ChainAbstractionClientProtocol: AnyObject { + func estimateFees(chainId: String) async throws -> Eip1559Estimation + + func route(transaction: InitTransaction) async throws -> RouteResponse + + func status(orchestrationId: String) async throws -> StatusResponse + + func waitForSuccessWithTimeout(orchestrationId: String, checkIn: UInt64, timeout: UInt64) async throws -> StatusResponseCompleted +} + +open class ChainAbstractionClient: + ChainAbstractionClientProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public init(noPointer _: NoPointer) { + pointer = nil + } + + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_uniffi_yttrium_fn_clone_chainabstractionclient(self.pointer, $0) } + } + + public convenience init(projectId: String) { + let pointer = + try! rustCall { + uniffi_uniffi_yttrium_fn_constructor_chainabstractionclient_new( + FfiConverterString.lower(projectId), $0 + ) + } + self.init(unsafeFromRawPointer: pointer) + } + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_uniffi_yttrium_fn_free_chainabstractionclient(pointer, $0) } + } + + open func estimateFees(chainId: String) async throws -> Eip1559Estimation { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_chainabstractionclient_estimate_fees( + self.uniffiClonePointer(), + FfiConverterString.lower(chainId) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeEip1559Estimation.lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } + + open func route(transaction: InitTransaction) async throws -> RouteResponse { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_chainabstractionclient_route( + self.uniffiClonePointer(), + FfiConverterTypeInitTransaction.lower(transaction) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeRouteResponse_lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } + + open func status(orchestrationId: String) async throws -> StatusResponse { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_chainabstractionclient_status( + self.uniffiClonePointer(), + FfiConverterString.lower(orchestrationId) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeStatusResponse_lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } + + open func waitForSuccessWithTimeout(orchestrationId: String, checkIn: UInt64, timeout: UInt64) async throws -> StatusResponseCompleted { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_chainabstractionclient_wait_for_success_with_timeout( + self.uniffiClonePointer(), + FfiConverterString.lower(orchestrationId), FfiConverterUInt64.lower(checkIn), FfiConverterUInt64.lower(timeout) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeStatusResponseCompleted_lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeChainAbstractionClient: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = ChainAbstractionClient + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> ChainAbstractionClient { + return ChainAbstractionClient(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: ChainAbstractionClient) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChainAbstractionClient { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if ptr == nil { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: ChainAbstractionClient, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeChainAbstractionClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> ChainAbstractionClient { + return try FfiConverterTypeChainAbstractionClient.lift(pointer) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeChainAbstractionClient_lower(_ value: ChainAbstractionClient) -> UnsafeMutableRawPointer { + return FfiConverterTypeChainAbstractionClient.lower(value) +} + +public protocol FfiAccountClientProtocol: AnyObject { + func chainId() -> UInt64 + + func doSendTransactions(signatures: [OwnerSignature], doSendTransactionParams: String) async throws -> String + + func getAddress() async throws -> String + + func prepareSendTransactions(transactions: [FfiTransaction]) async throws -> PreparedSendTransaction + + func sendTransactions(transactions: [FfiTransaction]) async throws -> String + + func signMessageWithMnemonic(message: String, mnemonic: String) throws -> String + + func waitForUserOperationReceipt(userOperationHash: String) async throws -> String +} + +open class FfiAccountClient: + FfiAccountClientProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public init(noPointer _: NoPointer) { + pointer = nil + } + + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_uniffi_yttrium_fn_clone_ffiaccountclient(self.pointer, $0) } + } + + public convenience init(config: FfiAccountClientConfig) { + let pointer = + try! rustCall { + uniffi_uniffi_yttrium_fn_constructor_ffiaccountclient_new( + FfiConverterTypeFFIAccountClientConfig.lower(config), $0 + ) + } + self.init(unsafeFromRawPointer: pointer) + } + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_uniffi_yttrium_fn_free_ffiaccountclient(pointer, $0) } + } + + open func chainId() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall { + uniffi_uniffi_yttrium_fn_method_ffiaccountclient_chain_id(self.uniffiClonePointer(), $0) + }) + } + + open func doSendTransactions(signatures: [OwnerSignature], doSendTransactionParams: String) async throws -> String { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_ffiaccountclient_do_send_transactions( + self.uniffiClonePointer(), + FfiConverterSequenceTypeOwnerSignature.lower(signatures), FfiConverterString.lower(doSendTransactionParams) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterString.lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } + + open func getAddress() async throws -> String { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_ffiaccountclient_get_address( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterString.lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } + + open func prepareSendTransactions(transactions: [FfiTransaction]) async throws -> PreparedSendTransaction { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_ffiaccountclient_prepare_send_transactions( + self.uniffiClonePointer(), + FfiConverterSequenceTypeFFITransaction.lower(transactions) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypePreparedSendTransaction.lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } + + open func sendTransactions(transactions: [FfiTransaction]) async throws -> String { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_ffiaccountclient_send_transactions( + self.uniffiClonePointer(), + FfiConverterSequenceTypeFFITransaction.lower(transactions) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterString.lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } + + open func signMessageWithMnemonic(message: String, mnemonic: String) throws -> String { + return try FfiConverterString.lift(rustCallWithError(FfiConverterTypeFFIError.lift) { + uniffi_uniffi_yttrium_fn_method_ffiaccountclient_sign_message_with_mnemonic(self.uniffiClonePointer(), + FfiConverterString.lower(message), + FfiConverterString.lower(mnemonic), $0) + }) + } + + open func waitForUserOperationReceipt(userOperationHash: String) async throws -> String { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_uniffi_yttrium_fn_method_ffiaccountclient_wait_for_user_operation_receipt( + self.uniffiClonePointer(), + FfiConverterString.lower(userOperationHash) + ) + }, + pollFunc: ffi_uniffi_yttrium_rust_future_poll_rust_buffer, + completeFunc: ffi_uniffi_yttrium_rust_future_complete_rust_buffer, + freeFunc: ffi_uniffi_yttrium_rust_future_free_rust_buffer, + liftFunc: FfiConverterString.lift, + errorHandler: FfiConverterTypeFFIError.lift + ) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFIAccountClient: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = FfiAccountClient + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiAccountClient { + return FfiAccountClient(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiAccountClient) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiAccountClient { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if ptr == nil { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: FfiAccountClient, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIAccountClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiAccountClient { + return try FfiConverterTypeFFIAccountClient.lift(pointer) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIAccountClient_lower(_ value: FfiAccountClient) -> UnsafeMutableRawPointer { + return FfiConverterTypeFFIAccountClient.lower(value) +} + +public struct Eip1559Estimation { + public var maxFeePerGas: String + public var maxPriorityFeePerGas: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(maxFeePerGas: String, maxPriorityFeePerGas: String) { + self.maxFeePerGas = maxFeePerGas + self.maxPriorityFeePerGas = maxPriorityFeePerGas + } +} + +extension Eip1559Estimation: Equatable, Hashable { + public static func == (lhs: Eip1559Estimation, rhs: Eip1559Estimation) -> Bool { + if lhs.maxFeePerGas != rhs.maxFeePerGas { + return false + } + if lhs.maxPriorityFeePerGas != rhs.maxPriorityFeePerGas { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(maxFeePerGas) + hasher.combine(maxPriorityFeePerGas) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeEip1559Estimation: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Eip1559Estimation { + return + try Eip1559Estimation( + maxFeePerGas: FfiConverterString.read(from: &buf), + maxPriorityFeePerGas: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: Eip1559Estimation, into buf: inout [UInt8]) { + FfiConverterString.write(value.maxFeePerGas, into: &buf) + FfiConverterString.write(value.maxPriorityFeePerGas, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeEip1559Estimation_lift(_ buf: RustBuffer) throws -> Eip1559Estimation { + return try FfiConverterTypeEip1559Estimation.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeEip1559Estimation_lower(_ value: Eip1559Estimation) -> RustBuffer { + return FfiConverterTypeEip1559Estimation.lower(value) +} + +public struct FfiAccountClientConfig { + public var ownerAddress: String + public var chainId: UInt64 + public var config: Config + public var signerType: String + public var safe: Bool + public var privateKey: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(ownerAddress: String, chainId: UInt64, config: Config, signerType: String, safe: Bool, privateKey: String) { + self.ownerAddress = ownerAddress + self.chainId = chainId + self.config = config + self.signerType = signerType + self.safe = safe + self.privateKey = privateKey + } +} + +extension FfiAccountClientConfig: Equatable, Hashable { + public static func == (lhs: FfiAccountClientConfig, rhs: FfiAccountClientConfig) -> Bool { + if lhs.ownerAddress != rhs.ownerAddress { + return false + } + if lhs.chainId != rhs.chainId { + return false + } + if lhs.config != rhs.config { + return false + } + if lhs.signerType != rhs.signerType { + return false + } + if lhs.safe != rhs.safe { + return false + } + if lhs.privateKey != rhs.privateKey { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(ownerAddress) + hasher.combine(chainId) + hasher.combine(config) + hasher.combine(signerType) + hasher.combine(safe) + hasher.combine(privateKey) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFIAccountClientConfig: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiAccountClientConfig { + return + try FfiAccountClientConfig( + ownerAddress: FfiConverterString.read(from: &buf), + chainId: FfiConverterUInt64.read(from: &buf), + config: FfiConverterTypeConfig.read(from: &buf), + signerType: FfiConverterString.read(from: &buf), + safe: FfiConverterBool.read(from: &buf), + privateKey: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: FfiAccountClientConfig, into buf: inout [UInt8]) { + FfiConverterString.write(value.ownerAddress, into: &buf) + FfiConverterUInt64.write(value.chainId, into: &buf) + FfiConverterTypeConfig.write(value.config, into: &buf) + FfiConverterString.write(value.signerType, into: &buf) + FfiConverterBool.write(value.safe, into: &buf) + FfiConverterString.write(value.privateKey, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIAccountClientConfig_lift(_ buf: RustBuffer) throws -> FfiAccountClientConfig { + return try FfiConverterTypeFFIAccountClientConfig.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIAccountClientConfig_lower(_ value: FfiAccountClientConfig) -> RustBuffer { + return FfiConverterTypeFFIAccountClientConfig.lower(value) +} + +public struct FfiTransaction { + public var to: String + public var value: String + public var data: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(to: String, value: String, data: String) { + self.to = to + self.value = value + self.data = data + } +} + +extension FfiTransaction: Equatable, Hashable { + public static func == (lhs: FfiTransaction, rhs: FfiTransaction) -> Bool { + if lhs.to != rhs.to { + return false + } + if lhs.value != rhs.value { + return false + } + if lhs.data != rhs.data { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(to) + hasher.combine(value) + hasher.combine(data) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFITransaction: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiTransaction { + return + try FfiTransaction( + to: FfiConverterString.read(from: &buf), + value: FfiConverterString.read(from: &buf), + data: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: FfiTransaction, into buf: inout [UInt8]) { + FfiConverterString.write(value.to, into: &buf) + FfiConverterString.write(value.value, into: &buf) + FfiConverterString.write(value.data, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFITransaction_lift(_ buf: RustBuffer) throws -> FfiTransaction { + return try FfiConverterTypeFFITransaction.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFITransaction_lower(_ value: FfiTransaction) -> RustBuffer { + return FfiConverterTypeFFITransaction.lower(value) +} + +public struct InitTransaction { + public var from: FfiAddress + public var to: FfiAddress + public var value: Ffiu256 + public var gas: Ffiu64 + public var gasPrice: Ffiu256 + public var data: FfiBytes + public var nonce: Ffiu64 + public var maxFeePerGas: Ffiu256 + public var maxPriorityFeePerGas: Ffiu256 + public var chainId: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(from: FfiAddress, to: FfiAddress, value: Ffiu256, gas: Ffiu64, gasPrice: Ffiu256, data: FfiBytes, nonce: Ffiu64, maxFeePerGas: Ffiu256, maxPriorityFeePerGas: Ffiu256, chainId: String) { + self.from = from + self.to = to + self.value = value + self.gas = gas + self.gasPrice = gasPrice + self.data = data + self.nonce = nonce + self.maxFeePerGas = maxFeePerGas + self.maxPriorityFeePerGas = maxPriorityFeePerGas + self.chainId = chainId + } +} + +extension InitTransaction: Equatable, Hashable { + public static func == (lhs: InitTransaction, rhs: InitTransaction) -> Bool { + if lhs.from != rhs.from { + return false + } + if lhs.to != rhs.to { + return false + } + if lhs.value != rhs.value { + return false + } + if lhs.gas != rhs.gas { + return false + } + if lhs.gasPrice != rhs.gasPrice { + return false + } + if lhs.data != rhs.data { + return false + } + if lhs.nonce != rhs.nonce { + return false + } + if lhs.maxFeePerGas != rhs.maxFeePerGas { + return false + } + if lhs.maxPriorityFeePerGas != rhs.maxPriorityFeePerGas { + return false + } + if lhs.chainId != rhs.chainId { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(from) + hasher.combine(to) + hasher.combine(value) + hasher.combine(gas) + hasher.combine(gasPrice) + hasher.combine(data) + hasher.combine(nonce) + hasher.combine(maxFeePerGas) + hasher.combine(maxPriorityFeePerGas) + hasher.combine(chainId) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeInitTransaction: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> InitTransaction { + return + try InitTransaction( + from: FfiConverterTypeFFIAddress.read(from: &buf), + to: FfiConverterTypeFFIAddress.read(from: &buf), + value: FfiConverterTypeFFIU256.read(from: &buf), + gas: FfiConverterTypeFFIU64.read(from: &buf), + gasPrice: FfiConverterTypeFFIU256.read(from: &buf), + data: FfiConverterTypeFFIBytes.read(from: &buf), + nonce: FfiConverterTypeFFIU64.read(from: &buf), + maxFeePerGas: FfiConverterTypeFFIU256.read(from: &buf), + maxPriorityFeePerGas: FfiConverterTypeFFIU256.read(from: &buf), + chainId: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: InitTransaction, into buf: inout [UInt8]) { + FfiConverterTypeFFIAddress.write(value.from, into: &buf) + FfiConverterTypeFFIAddress.write(value.to, into: &buf) + FfiConverterTypeFFIU256.write(value.value, into: &buf) + FfiConverterTypeFFIU64.write(value.gas, into: &buf) + FfiConverterTypeFFIU256.write(value.gasPrice, into: &buf) + FfiConverterTypeFFIBytes.write(value.data, into: &buf) + FfiConverterTypeFFIU64.write(value.nonce, into: &buf) + FfiConverterTypeFFIU256.write(value.maxFeePerGas, into: &buf) + FfiConverterTypeFFIU256.write(value.maxPriorityFeePerGas, into: &buf) + FfiConverterString.write(value.chainId, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeInitTransaction_lift(_ buf: RustBuffer) throws -> InitTransaction { + return try FfiConverterTypeInitTransaction.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeInitTransaction_lower(_ value: InitTransaction) -> RustBuffer { + return FfiConverterTypeInitTransaction.lower(value) +} + +public struct OwnerSignature { + public var owner: String + public var signature: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(owner: String, signature: String) { + self.owner = owner + self.signature = signature + } +} + +extension OwnerSignature: Equatable, Hashable { + public static func == (lhs: OwnerSignature, rhs: OwnerSignature) -> Bool { + if lhs.owner != rhs.owner { + return false + } + if lhs.signature != rhs.signature { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(owner) + hasher.combine(signature) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeOwnerSignature: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> OwnerSignature { + return + try OwnerSignature( + owner: FfiConverterString.read(from: &buf), + signature: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: OwnerSignature, into buf: inout [UInt8]) { + FfiConverterString.write(value.owner, into: &buf) + FfiConverterString.write(value.signature, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeOwnerSignature_lift(_ buf: RustBuffer) throws -> OwnerSignature { + return try FfiConverterTypeOwnerSignature.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeOwnerSignature_lower(_ value: OwnerSignature) -> RustBuffer { + return FfiConverterTypeOwnerSignature.lower(value) +} + +public struct PreparedSendTransaction { + public var hash: String + public var doSendTransactionParams: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(hash: String, doSendTransactionParams: String) { + self.hash = hash + self.doSendTransactionParams = doSendTransactionParams + } +} + +extension PreparedSendTransaction: Equatable, Hashable { + public static func == (lhs: PreparedSendTransaction, rhs: PreparedSendTransaction) -> Bool { + if lhs.hash != rhs.hash { + return false + } + if lhs.doSendTransactionParams != rhs.doSendTransactionParams { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(hash) + hasher.combine(doSendTransactionParams) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypePreparedSendTransaction: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PreparedSendTransaction { + return + try PreparedSendTransaction( + hash: FfiConverterString.read(from: &buf), + doSendTransactionParams: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: PreparedSendTransaction, into buf: inout [UInt8]) { + FfiConverterString.write(value.hash, into: &buf) + FfiConverterString.write(value.doSendTransactionParams, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypePreparedSendTransaction_lift(_ buf: RustBuffer) throws -> PreparedSendTransaction { + return try FfiConverterTypePreparedSendTransaction.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypePreparedSendTransaction_lower(_ value: PreparedSendTransaction) -> RustBuffer { + return FfiConverterTypePreparedSendTransaction.lower(value) +} + +public enum FfiError { + case General(String + ) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFIError: FfiConverterRustBuffer { + typealias SwiftType = FfiError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiError { + let variant: Int32 = try readInt(&buf) + switch variant { + case 1: return try .General( + FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: FfiError, into buf: inout [UInt8]) { + switch value { + case let .General(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + } + } +} + +extension FfiError: Equatable, Hashable {} + +extension FfiError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterSequenceTypeFFITransaction: FfiConverterRustBuffer { + typealias SwiftType = [FfiTransaction] + + public static func write(_ value: [FfiTransaction], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeFFITransaction.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [FfiTransaction] { + let len: Int32 = try readInt(&buf) + var seq = [FfiTransaction]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + try seq.append(FfiConverterTypeFFITransaction.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterSequenceTypeOwnerSignature: FfiConverterRustBuffer { + typealias SwiftType = [OwnerSignature] + + public static func write(_ value: [OwnerSignature], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeOwnerSignature.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [OwnerSignature] { + let len: Int32 = try readInt(&buf) + var seq = [OwnerSignature]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + try seq.append(FfiConverterTypeOwnerSignature.read(from: &buf)) + } + return seq + } +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias FfiAddress = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFIAddress: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiAddress { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: FfiAddress, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> FfiAddress { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: FfiAddress) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIAddress_lift(_ value: RustBuffer) throws -> FfiAddress { + return try FfiConverterTypeFFIAddress.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIAddress_lower(_ value: FfiAddress) -> RustBuffer { + return FfiConverterTypeFFIAddress.lower(value) +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias FfiBytes = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFIBytes: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiBytes { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: FfiBytes, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> FfiBytes { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: FfiBytes) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIBytes_lift(_ value: RustBuffer) throws -> FfiBytes { + return try FfiConverterTypeFFIBytes.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIBytes_lower(_ value: FfiBytes) -> RustBuffer { + return FfiConverterTypeFFIBytes.lower(value) +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias Ffiu256 = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFIU256: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Ffiu256 { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: Ffiu256, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> Ffiu256 { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: Ffiu256) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIU256_lift(_ value: RustBuffer) throws -> Ffiu256 { + return try FfiConverterTypeFFIU256.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIU256_lower(_ value: Ffiu256) -> RustBuffer { + return FfiConverterTypeFFIU256.lower(value) +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias Ffiu64 = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFFIU64: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Ffiu64 { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: Ffiu64, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> Ffiu64 { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: Ffiu64) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIU64_lift(_ value: RustBuffer) throws -> Ffiu64 { + return try FfiConverterTypeFFIU64.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFFIU64_lower(_ value: Ffiu64) -> RustBuffer { + return FfiConverterTypeFFIU64.lower(value) +} + +private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0 +private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1 + +private let uniffiContinuationHandleMap = UniffiHandleMap>() + +private func uniffiRustCallAsync( + rustFutureFunc: () -> UInt64, + pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> Void, + completeFunc: (UInt64, UnsafeMutablePointer) -> F, + freeFunc: (UInt64) -> Void, + liftFunc: (F) throws -> T, + errorHandler: ((RustBuffer) throws -> Swift.Error)? +) async throws -> T { + // Make sure to call uniffiEnsureInitialized() since future creation doesn't have a + // RustCallStatus param, so doesn't use makeRustCall() + uniffiEnsureInitialized() + let rustFuture = rustFutureFunc() + defer { + freeFunc(rustFuture) + } + var pollResult: Int8 + repeat { + pollResult = await withUnsafeContinuation { + pollFunc( + rustFuture, + uniffiFutureContinuationCallback, + uniffiContinuationHandleMap.insert(obj: $0) + ) + } + } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY + + return try liftFunc(makeRustCall( + { completeFunc(rustFuture, $0) }, + errorHandler: errorHandler + )) +} + +// Callback handlers for an async calls. These are invoked by Rust when the future is ready. They +// lift the return value or error and resume the suspended function. +private func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) { + if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) { + continuation.resume(returning: pollResult) + } else { + print("uniffiFutureContinuationCallback invalid handle") + } +} + +private enum InitializationResult { + case ok + case contractVersionMismatch + case apiChecksumMismatch +} + +// Use a global variable to perform the versioning checks. Swift ensures that +// the code inside is only computed once. +private let initializationResult: InitializationResult = { + // Get the bindings contract version from our ComponentInterface + let bindings_contract_version = 29 + // Get the scaffolding contract version by calling the into the dylib + let scaffolding_contract_version = ffi_uniffi_yttrium_uniffi_contract_version() + if bindings_contract_version != scaffolding_contract_version { + return InitializationResult.contractVersionMismatch + } + if uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_estimate_fees() != 51281 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_route() != 214 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_status() != 15758 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_wait_for_success_with_timeout() != 16595 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_chain_id() != 40865 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_do_send_transactions() != 33638 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_get_address() != 38899 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_prepare_send_transactions() != 33465 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_send_transactions() != 46699 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_sign_message_with_mnemonic() != 60647 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_wait_for_user_operation_receipt() != 13654 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_constructor_chainabstractionclient_new() != 39164 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_uniffi_yttrium_checksum_constructor_ffiaccountclient_new() != 64773 { + return InitializationResult.apiChecksumMismatch + } + + return InitializationResult.ok +}() + +private func uniffiEnsureInitialized() { + switch initializationResult { + case .ok: + break + case .contractVersionMismatch: + fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") + case .apiChecksumMismatch: + fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } +} + +// swiftlint:enable all diff --git a/platforms/swift/Sources/Yttrium/uniffi_yttriumFFI.h b/platforms/swift/Sources/Yttrium/uniffi_yttriumFFI.h new file mode 100644 index 00000000..c38eed34 --- /dev/null +++ b/platforms/swift/Sources/Yttrium/uniffi_yttriumFFI.h @@ -0,0 +1,703 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +#pragma once + +#include +#include +#include + +// The following structs are used to implement the lowest level +// of the FFI, and thus useful to multiple uniffied crates. +// We ensure they are declared exactly once, with a header guard, UNIFFI_SHARED_H. +#ifdef UNIFFI_SHARED_H + // We also try to prevent mixing versions of shared uniffi header structs. + // If you add anything to the #else block, you must increment the version suffix in UNIFFI_SHARED_HEADER_V4 + #ifndef UNIFFI_SHARED_HEADER_V4 + #error Combining helper code from multiple versions of uniffi is not supported + #endif // ndef UNIFFI_SHARED_HEADER_V4 +#else +#define UNIFFI_SHARED_H +#define UNIFFI_SHARED_HEADER_V4 +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ + +typedef struct RustBuffer +{ + uint64_t capacity; + uint64_t len; + uint8_t *_Nullable data; +} RustBuffer; + +typedef struct ForeignBytes +{ + int32_t len; + const uint8_t *_Nullable data; +} ForeignBytes; + +// Error definitions +typedef struct RustCallStatus { + int8_t code; + RustBuffer errorBuf; +} RustCallStatus; + +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ +#endif // def UNIFFI_SHARED_H +#ifndef UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK +#define UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK +typedef void (*UniffiRustFutureContinuationCallback)(uint64_t, int8_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE +typedef void (*UniffiForeignFutureFree)(uint64_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE +#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE +typedef void (*UniffiCallbackInterfaceFree)(uint64_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE +#define UNIFFI_FFIDEF_FOREIGN_FUTURE +typedef struct UniffiForeignFuture { + uint64_t handle; + UniffiForeignFutureFree _Nonnull free; +} UniffiForeignFuture; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 +typedef struct UniffiForeignFutureStructU8 { + uint8_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU8; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 +typedef void (*UniffiForeignFutureCompleteU8)(uint64_t, UniffiForeignFutureStructU8 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 +typedef struct UniffiForeignFutureStructI8 { + int8_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI8; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 +typedef void (*UniffiForeignFutureCompleteI8)(uint64_t, UniffiForeignFutureStructI8 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 +typedef struct UniffiForeignFutureStructU16 { + uint16_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU16; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 +typedef void (*UniffiForeignFutureCompleteU16)(uint64_t, UniffiForeignFutureStructU16 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 +typedef struct UniffiForeignFutureStructI16 { + int16_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI16; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 +typedef void (*UniffiForeignFutureCompleteI16)(uint64_t, UniffiForeignFutureStructI16 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 +typedef struct UniffiForeignFutureStructU32 { + uint32_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 +typedef void (*UniffiForeignFutureCompleteU32)(uint64_t, UniffiForeignFutureStructU32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 +typedef struct UniffiForeignFutureStructI32 { + int32_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 +typedef void (*UniffiForeignFutureCompleteI32)(uint64_t, UniffiForeignFutureStructI32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 +typedef struct UniffiForeignFutureStructU64 { + uint64_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 +typedef void (*UniffiForeignFutureCompleteU64)(uint64_t, UniffiForeignFutureStructU64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 +typedef struct UniffiForeignFutureStructI64 { + int64_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 +typedef void (*UniffiForeignFutureCompleteI64)(uint64_t, UniffiForeignFutureStructI64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 +typedef struct UniffiForeignFutureStructF32 { + float returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructF32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 +typedef void (*UniffiForeignFutureCompleteF32)(uint64_t, UniffiForeignFutureStructF32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 +typedef struct UniffiForeignFutureStructF64 { + double returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructF64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 +typedef void (*UniffiForeignFutureCompleteF64)(uint64_t, UniffiForeignFutureStructF64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER +typedef struct UniffiForeignFutureStructPointer { + void*_Nonnull returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructPointer; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER +typedef void (*UniffiForeignFutureCompletePointer)(uint64_t, UniffiForeignFutureStructPointer + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER +typedef struct UniffiForeignFutureStructRustBuffer { + RustBuffer returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructRustBuffer; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER +typedef void (*UniffiForeignFutureCompleteRustBuffer)(uint64_t, UniffiForeignFutureStructRustBuffer + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID +typedef struct UniffiForeignFutureStructVoid { + RustCallStatus callStatus; +} UniffiForeignFutureStructVoid; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID +typedef void (*UniffiForeignFutureCompleteVoid)(uint64_t, UniffiForeignFutureStructVoid + ); + +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CLONE_CHAINABSTRACTIONCLIENT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CLONE_CHAINABSTRACTIONCLIENT +void*_Nonnull uniffi_uniffi_yttrium_fn_clone_chainabstractionclient(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_FREE_CHAINABSTRACTIONCLIENT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_FREE_CHAINABSTRACTIONCLIENT +void uniffi_uniffi_yttrium_fn_free_chainabstractionclient(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CONSTRUCTOR_CHAINABSTRACTIONCLIENT_NEW +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CONSTRUCTOR_CHAINABSTRACTIONCLIENT_NEW +void*_Nonnull uniffi_uniffi_yttrium_fn_constructor_chainabstractionclient_new(RustBuffer project_id, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_ESTIMATE_FEES +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_ESTIMATE_FEES +uint64_t uniffi_uniffi_yttrium_fn_method_chainabstractionclient_estimate_fees(void*_Nonnull ptr, RustBuffer chain_id +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_ROUTE +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_ROUTE +uint64_t uniffi_uniffi_yttrium_fn_method_chainabstractionclient_route(void*_Nonnull ptr, RustBuffer transaction +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_STATUS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_STATUS +uint64_t uniffi_uniffi_yttrium_fn_method_chainabstractionclient_status(void*_Nonnull ptr, RustBuffer orchestration_id +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_WAIT_FOR_SUCCESS_WITH_TIMEOUT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_CHAINABSTRACTIONCLIENT_WAIT_FOR_SUCCESS_WITH_TIMEOUT +uint64_t uniffi_uniffi_yttrium_fn_method_chainabstractionclient_wait_for_success_with_timeout(void*_Nonnull ptr, RustBuffer orchestration_id, uint64_t check_in, uint64_t timeout +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CLONE_FFIACCOUNTCLIENT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CLONE_FFIACCOUNTCLIENT +void*_Nonnull uniffi_uniffi_yttrium_fn_clone_ffiaccountclient(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_FREE_FFIACCOUNTCLIENT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_FREE_FFIACCOUNTCLIENT +void uniffi_uniffi_yttrium_fn_free_ffiaccountclient(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CONSTRUCTOR_FFIACCOUNTCLIENT_NEW +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_CONSTRUCTOR_FFIACCOUNTCLIENT_NEW +void*_Nonnull uniffi_uniffi_yttrium_fn_constructor_ffiaccountclient_new(RustBuffer config, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_CHAIN_ID +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_CHAIN_ID +uint64_t uniffi_uniffi_yttrium_fn_method_ffiaccountclient_chain_id(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_DO_SEND_TRANSACTIONS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_DO_SEND_TRANSACTIONS +uint64_t uniffi_uniffi_yttrium_fn_method_ffiaccountclient_do_send_transactions(void*_Nonnull ptr, RustBuffer signatures, RustBuffer do_send_transaction_params +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_GET_ADDRESS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_GET_ADDRESS +uint64_t uniffi_uniffi_yttrium_fn_method_ffiaccountclient_get_address(void*_Nonnull ptr +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_PREPARE_SEND_TRANSACTIONS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_PREPARE_SEND_TRANSACTIONS +uint64_t uniffi_uniffi_yttrium_fn_method_ffiaccountclient_prepare_send_transactions(void*_Nonnull ptr, RustBuffer transactions +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_SEND_TRANSACTIONS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_SEND_TRANSACTIONS +uint64_t uniffi_uniffi_yttrium_fn_method_ffiaccountclient_send_transactions(void*_Nonnull ptr, RustBuffer transactions +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_SIGN_MESSAGE_WITH_MNEMONIC +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_SIGN_MESSAGE_WITH_MNEMONIC +RustBuffer uniffi_uniffi_yttrium_fn_method_ffiaccountclient_sign_message_with_mnemonic(void*_Nonnull ptr, RustBuffer message, RustBuffer mnemonic, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_WAIT_FOR_USER_OPERATION_RECEIPT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_FN_METHOD_FFIACCOUNTCLIENT_WAIT_FOR_USER_OPERATION_RECEIPT +uint64_t uniffi_uniffi_yttrium_fn_method_ffiaccountclient_wait_for_user_operation_receipt(void*_Nonnull ptr, RustBuffer user_operation_hash +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_ALLOC +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_ALLOC +RustBuffer ffi_uniffi_yttrium_rustbuffer_alloc(uint64_t size, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_FROM_BYTES +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_FROM_BYTES +RustBuffer ffi_uniffi_yttrium_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_FREE +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_FREE +void ffi_uniffi_yttrium_rustbuffer_free(RustBuffer buf, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_RESERVE +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUSTBUFFER_RESERVE +RustBuffer ffi_uniffi_yttrium_rustbuffer_reserve(RustBuffer buf, uint64_t additional, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U8 +void ffi_uniffi_yttrium_rust_future_poll_u8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U8 +void ffi_uniffi_yttrium_rust_future_cancel_u8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U8 +void ffi_uniffi_yttrium_rust_future_free_u8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U8 +uint8_t ffi_uniffi_yttrium_rust_future_complete_u8(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I8 +void ffi_uniffi_yttrium_rust_future_poll_i8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I8 +void ffi_uniffi_yttrium_rust_future_cancel_i8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I8 +void ffi_uniffi_yttrium_rust_future_free_i8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I8 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I8 +int8_t ffi_uniffi_yttrium_rust_future_complete_i8(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U16 +void ffi_uniffi_yttrium_rust_future_poll_u16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U16 +void ffi_uniffi_yttrium_rust_future_cancel_u16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U16 +void ffi_uniffi_yttrium_rust_future_free_u16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U16 +uint16_t ffi_uniffi_yttrium_rust_future_complete_u16(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I16 +void ffi_uniffi_yttrium_rust_future_poll_i16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I16 +void ffi_uniffi_yttrium_rust_future_cancel_i16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I16 +void ffi_uniffi_yttrium_rust_future_free_i16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I16 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I16 +int16_t ffi_uniffi_yttrium_rust_future_complete_i16(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U32 +void ffi_uniffi_yttrium_rust_future_poll_u32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U32 +void ffi_uniffi_yttrium_rust_future_cancel_u32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U32 +void ffi_uniffi_yttrium_rust_future_free_u32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U32 +uint32_t ffi_uniffi_yttrium_rust_future_complete_u32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I32 +void ffi_uniffi_yttrium_rust_future_poll_i32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I32 +void ffi_uniffi_yttrium_rust_future_cancel_i32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I32 +void ffi_uniffi_yttrium_rust_future_free_i32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I32 +int32_t ffi_uniffi_yttrium_rust_future_complete_i32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_U64 +void ffi_uniffi_yttrium_rust_future_poll_u64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_U64 +void ffi_uniffi_yttrium_rust_future_cancel_u64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_U64 +void ffi_uniffi_yttrium_rust_future_free_u64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_U64 +uint64_t ffi_uniffi_yttrium_rust_future_complete_u64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_I64 +void ffi_uniffi_yttrium_rust_future_poll_i64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_I64 +void ffi_uniffi_yttrium_rust_future_cancel_i64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_I64 +void ffi_uniffi_yttrium_rust_future_free_i64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_I64 +int64_t ffi_uniffi_yttrium_rust_future_complete_i64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_F32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_F32 +void ffi_uniffi_yttrium_rust_future_poll_f32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_F32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_F32 +void ffi_uniffi_yttrium_rust_future_cancel_f32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_F32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_F32 +void ffi_uniffi_yttrium_rust_future_free_f32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_F32 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_F32 +float ffi_uniffi_yttrium_rust_future_complete_f32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_F64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_F64 +void ffi_uniffi_yttrium_rust_future_poll_f64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_F64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_F64 +void ffi_uniffi_yttrium_rust_future_cancel_f64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_F64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_F64 +void ffi_uniffi_yttrium_rust_future_free_f64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_F64 +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_F64 +double ffi_uniffi_yttrium_rust_future_complete_f64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_POINTER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_POINTER +void ffi_uniffi_yttrium_rust_future_poll_pointer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_POINTER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_POINTER +void ffi_uniffi_yttrium_rust_future_cancel_pointer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_POINTER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_POINTER +void ffi_uniffi_yttrium_rust_future_free_pointer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_POINTER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_POINTER +void*_Nonnull ffi_uniffi_yttrium_rust_future_complete_pointer(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_RUST_BUFFER +void ffi_uniffi_yttrium_rust_future_poll_rust_buffer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_RUST_BUFFER +void ffi_uniffi_yttrium_rust_future_cancel_rust_buffer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_RUST_BUFFER +void ffi_uniffi_yttrium_rust_future_free_rust_buffer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_RUST_BUFFER +RustBuffer ffi_uniffi_yttrium_rust_future_complete_rust_buffer(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_VOID +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_POLL_VOID +void ffi_uniffi_yttrium_rust_future_poll_void(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_VOID +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_CANCEL_VOID +void ffi_uniffi_yttrium_rust_future_cancel_void(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_VOID +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_FREE_VOID +void ffi_uniffi_yttrium_rust_future_free_void(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_VOID +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_RUST_FUTURE_COMPLETE_VOID +void ffi_uniffi_yttrium_rust_future_complete_void(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_ESTIMATE_FEES +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_ESTIMATE_FEES +uint16_t uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_estimate_fees(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_ROUTE +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_ROUTE +uint16_t uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_route(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_STATUS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_STATUS +uint16_t uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_status(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_WAIT_FOR_SUCCESS_WITH_TIMEOUT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_CHAINABSTRACTIONCLIENT_WAIT_FOR_SUCCESS_WITH_TIMEOUT +uint16_t uniffi_uniffi_yttrium_checksum_method_chainabstractionclient_wait_for_success_with_timeout(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_CHAIN_ID +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_CHAIN_ID +uint16_t uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_chain_id(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_DO_SEND_TRANSACTIONS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_DO_SEND_TRANSACTIONS +uint16_t uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_do_send_transactions(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_GET_ADDRESS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_GET_ADDRESS +uint16_t uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_get_address(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_PREPARE_SEND_TRANSACTIONS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_PREPARE_SEND_TRANSACTIONS +uint16_t uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_prepare_send_transactions(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_SEND_TRANSACTIONS +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_SEND_TRANSACTIONS +uint16_t uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_send_transactions(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_SIGN_MESSAGE_WITH_MNEMONIC +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_SIGN_MESSAGE_WITH_MNEMONIC +uint16_t uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_sign_message_with_mnemonic(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_WAIT_FOR_USER_OPERATION_RECEIPT +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_METHOD_FFIACCOUNTCLIENT_WAIT_FOR_USER_OPERATION_RECEIPT +uint16_t uniffi_uniffi_yttrium_checksum_method_ffiaccountclient_wait_for_user_operation_receipt(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_CONSTRUCTOR_CHAINABSTRACTIONCLIENT_NEW +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_CONSTRUCTOR_CHAINABSTRACTIONCLIENT_NEW +uint16_t uniffi_uniffi_yttrium_checksum_constructor_chainabstractionclient_new(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_CONSTRUCTOR_FFIACCOUNTCLIENT_NEW +#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_YTTRIUM_CHECKSUM_CONSTRUCTOR_FFIACCOUNTCLIENT_NEW +uint16_t uniffi_uniffi_yttrium_checksum_constructor_ffiaccountclient_new(void + +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_UNIFFI_CONTRACT_VERSION +#define UNIFFI_FFIDEF_FFI_UNIFFI_YTTRIUM_UNIFFI_CONTRACT_VERSION +uint32_t ffi_uniffi_yttrium_uniffi_contract_version(void + +); +#endif + diff --git a/platforms/swift/Sources/Yttrium/yttrium.swift b/platforms/swift/Sources/Yttrium/yttrium.swift new file mode 100644 index 00000000..a69de09e --- /dev/null +++ b/platforms/swift/Sources/Yttrium/yttrium.swift @@ -0,0 +1,1873 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +// swiftlint:disable all +import Foundation + +// Depending on the consumer's build setup, the low-level FFI code +// might be in a separate module, or it might be compiled inline into +// this module. This is a bit of light hackery to work with both. +#if canImport(yttriumFFI) + import yttriumFFI +#endif + +private extension RustBuffer { + // Allocate a new buffer, copying the contents of a `UInt8` array. + init(bytes: [UInt8]) { + let rbuf = bytes.withUnsafeBufferPointer { ptr in + RustBuffer.from(ptr) + } + self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) + } + + static func empty() -> RustBuffer { + RustBuffer(capacity: 0, len: 0, data: nil) + } + + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { + try! rustCall { ffi_yttrium_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + } + + // Frees the buffer in place. + // The buffer must not be used after this is called. + func deallocate() { + try! rustCall { ffi_yttrium_rustbuffer_free(self, $0) } + } +} + +private extension ForeignBytes { + init(bufferPointer: UnsafeBufferPointer) { + self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) + } +} + +// For every type used in the interface, we provide helper methods for conveniently +// lifting and lowering that type from C-compatible data, and for reading and writing +// values of that type in a buffer. + +// Helper classes/extensions that don't change. +// Someday, this will be in a library of its own. + +private extension Data { + init(rustBuffer: RustBuffer) { + self.init( + bytesNoCopy: rustBuffer.data!, + count: Int(rustBuffer.len), + deallocator: .none + ) + } +} + +// Define reader functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. +// +// With external types, one swift source file needs to be able to call the read +// method on another source file's FfiConverter, but then what visibility +// should Reader have? +// - If Reader is fileprivate, then this means the read() must also +// be fileprivate, which doesn't work with external types. +// - If Reader is internal/public, we'll get compile errors since both source +// files will try define the same type. +// +// Instead, the read() method and these helper functions input a tuple of data + +private func createReader(data: Data) -> (data: Data, offset: Data.Index) { + (data: data, offset: 0) +} + +// Reads an integer at the current offset, in big-endian order, and advances +// the offset on success. Throws if reading the integer would move the +// offset past the end of the buffer. +private func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { + let range = reader.offset ..< reader.offset + MemoryLayout.size + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + if T.self == UInt8.self { + let value = reader.data[reader.offset] + reader.offset += 1 + return value as! T + } + var value: T = 0 + let _ = withUnsafeMutableBytes(of: &value) { reader.data.copyBytes(to: $0, from: range) } + reader.offset = range.upperBound + return value.bigEndian +} + +// Reads an arbitrary number of bytes, to be used to read +// raw bytes, this is useful when lifting strings +private func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> [UInt8] { + let range = reader.offset ..< (reader.offset + count) + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + var value = [UInt8](repeating: 0, count: count) + value.withUnsafeMutableBufferPointer { buffer in + reader.data.copyBytes(to: buffer, from: range) + } + reader.offset = range.upperBound + return value +} + +// Reads a float at the current offset. +private func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { + return try Float(bitPattern: readInt(&reader)) +} + +// Reads a float at the current offset. +private func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { + return try Double(bitPattern: readInt(&reader)) +} + +// Indicates if the offset has reached the end of the buffer. +private func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { + return reader.offset < reader.data.count +} + +// Define writer functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. See the above discussion on Readers for details. + +private func createWriter() -> [UInt8] { + return [] +} + +private func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { + writer.append(contentsOf: byteArr) +} + +// Writes an integer in big-endian order. +// +// Warning: make sure what you are trying to write +// is in the correct type! +private func writeInt(_ writer: inout [UInt8], _ value: T) { + var value = value.bigEndian + withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } +} + +private func writeFloat(_ writer: inout [UInt8], _ value: Float) { + writeInt(&writer, value.bitPattern) +} + +private func writeDouble(_ writer: inout [UInt8], _ value: Double) { + writeInt(&writer, value.bitPattern) +} + +// Protocol for types that transfer other types across the FFI. This is +// analogous to the Rust trait of the same name. +private protocol FfiConverter { + associatedtype FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType + static func write(_ value: SwiftType, into buf: inout [UInt8]) +} + +// Types conforming to `Primitive` pass themselves directly over the FFI. +private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} + +extension FfiConverterPrimitive { + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lift(_ value: FfiType) throws -> SwiftType { + return value + } + + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lower(_ value: SwiftType) -> FfiType { + return value + } +} + +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} + +extension FfiConverterRustBuffer { + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lift(_ buf: RustBuffer) throws -> SwiftType { + var reader = createReader(data: Data(rustBuffer: buf)) + let value = try read(from: &reader) + if hasRemaining(reader) { + throw UniffiInternalError.incompleteData + } + buf.deallocate() + return value + } + + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public static func lower(_ value: SwiftType) -> RustBuffer { + var writer = createWriter() + write(value, into: &writer) + return RustBuffer(bytes: writer) + } +} + +// An error type for FFI errors. These errors occur at the UniFFI level, not +// the library level. +private enum UniffiInternalError: LocalizedError { + case bufferOverflow + case incompleteData + case unexpectedOptionalTag + case unexpectedEnumCase + case unexpectedNullPointer + case unexpectedRustCallStatusCode + case unexpectedRustCallError + case unexpectedStaleHandle + case rustPanic(_ message: String) + + public var errorDescription: String? { + switch self { + case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" + case .incompleteData: return "The buffer still has data after lifting its containing value" + case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" + case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" + case .unexpectedNullPointer: return "Raw pointer value was null" + case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" + case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" + case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" + case let .rustPanic(message): return message + } + } +} + +private extension NSLock { + func withLock(f: () throws -> T) rethrows -> T { + lock() + defer { self.unlock() } + return try f() + } +} + +private let CALL_SUCCESS: Int8 = 0 +private let CALL_ERROR: Int8 = 1 +private let CALL_UNEXPECTED_ERROR: Int8 = 2 +private let CALL_CANCELLED: Int8 = 3 + +private extension RustCallStatus { + init() { + self.init( + code: CALL_SUCCESS, + errorBuf: RustBuffer( + capacity: 0, + len: 0, + data: nil + ) + ) + } +} + +private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { + let neverThrow: ((RustBuffer) throws -> Never)? = nil + return try makeRustCall(callback, errorHandler: neverThrow) +} + +private func rustCallWithError( + _ errorHandler: @escaping (RustBuffer) throws -> E, + _ callback: (UnsafeMutablePointer) -> T +) throws -> T { + try makeRustCall(callback, errorHandler: errorHandler) +} + +private func makeRustCall( + _ callback: (UnsafeMutablePointer) -> T, + errorHandler: ((RustBuffer) throws -> E)? +) throws -> T { + uniffiEnsureInitialized() + var callStatus = RustCallStatus() + let returnedVal = callback(&callStatus) + try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) + return returnedVal +} + +private func uniffiCheckCallStatus( + callStatus: RustCallStatus, + errorHandler: ((RustBuffer) throws -> E)? +) throws { + switch callStatus.code { + case CALL_SUCCESS: + return + + case CALL_ERROR: + if let errorHandler = errorHandler { + throw try errorHandler(callStatus.errorBuf) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.unexpectedRustCallError + } + + case CALL_UNEXPECTED_ERROR: + // When the rust code sees a panic, it tries to construct a RustBuffer + // with the message. But if that code panics, then it just sends back + // an empty buffer. + if callStatus.errorBuf.len > 0 { + throw try UniffiInternalError.rustPanic(FfiConverterString.lift(callStatus.errorBuf)) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.rustPanic("Rust panic") + } + + case CALL_CANCELLED: + fatalError("Cancellation not supported yet") + + default: + throw UniffiInternalError.unexpectedRustCallStatusCode + } +} + +private func uniffiTraitInterfaceCall( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> Void +) { + do { + try writeReturn(makeCall()) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private func uniffiTraitInterfaceCallWithError( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> Void, + lowerError: (E) -> RustBuffer +) { + do { + try writeReturn(makeCall()) + } catch let error as E { + callStatus.pointee.code = CALL_ERROR + callStatus.pointee.errorBuf = lowerError(error) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private final class UniffiHandleMap: @unchecked Sendable { + // All mutation happens with this lock held, which is why we implement @unchecked Sendable. + private let lock = NSLock() + private var map: [UInt64: T] = [:] + private var currentHandle: UInt64 = 1 + + func insert(obj: T) -> UInt64 { + lock.withLock { + let handle = currentHandle + currentHandle += 1 + map[handle] = obj + return handle + } + } + + func get(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + @discardableResult + func remove(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map.removeValue(forKey: handle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + var count: Int { + map.count + } +} + +// Public interface members begin here. + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterUInt64: FfiConverterPrimitive { + typealias FfiType = UInt64 + typealias SwiftType = UInt64 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer + + public static func lift(_ value: RustBuffer) throws -> String { + defer { + value.deallocate() + } + if value.data == nil { + return String() + } + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) + return String(bytes: bytes, encoding: String.Encoding.utf8)! + } + + public static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in + // The swift string gives us int8_t, we want uint8_t. + ptr.withMemoryRebound(to: UInt8.self) { ptr in + // The swift string gives us a trailing null byte, we don't want it. + let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) + return RustBuffer.from(buf) + } + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { + let len: Int32 = try readInt(&buf) + return try String(bytes: readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! + } + + public static func write(_ value: String, into buf: inout [UInt8]) { + let len = Int32(value.utf8.count) + writeInt(&buf, len) + writeBytes(&buf, value.utf8) + } +} + +public protocol AccountClientProtocol: AnyObject {} + +open class AccountClient: + AccountClientProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public init(noPointer _: NoPointer) { + pointer = nil + } + + #if swift(>=5.8) + @_documentation(visibility: private) + #endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_yttrium_fn_clone_accountclient(self.pointer, $0) } + } + + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_yttrium_fn_free_accountclient(pointer, $0) } + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeAccountClient: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = AccountClient + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> AccountClient { + return AccountClient(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: AccountClient) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AccountClient { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if ptr == nil { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: AccountClient, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeAccountClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> AccountClient { + return try FfiConverterTypeAccountClient.lift(pointer) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeAccountClient_lower(_ value: AccountClient) -> UnsafeMutableRawPointer { + return FfiConverterTypeAccountClient.lower(value) +} + +public struct Config { + public var endpoints: Endpoints + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(endpoints: Endpoints) { + self.endpoints = endpoints + } +} + +extension Config: Equatable, Hashable { + public static func == (lhs: Config, rhs: Config) -> Bool { + if lhs.endpoints != rhs.endpoints { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(endpoints) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeConfig: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Config { + return + try Config( + endpoints: FfiConverterTypeEndpoints.read(from: &buf) + ) + } + + public static func write(_ value: Config, into buf: inout [UInt8]) { + FfiConverterTypeEndpoints.write(value.endpoints, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeConfig_lift(_ buf: RustBuffer) throws -> Config { + return try FfiConverterTypeConfig.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeConfig_lower(_ value: Config) -> RustBuffer { + return FfiConverterTypeConfig.lower(value) +} + +public struct Endpoint { + public var baseUrl: String + public var apiKey: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(baseUrl: String, apiKey: String) { + self.baseUrl = baseUrl + self.apiKey = apiKey + } +} + +extension Endpoint: Equatable, Hashable { + public static func == (lhs: Endpoint, rhs: Endpoint) -> Bool { + if lhs.baseUrl != rhs.baseUrl { + return false + } + if lhs.apiKey != rhs.apiKey { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(baseUrl) + hasher.combine(apiKey) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeEndpoint: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Endpoint { + return + try Endpoint( + baseUrl: FfiConverterString.read(from: &buf), + apiKey: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: Endpoint, into buf: inout [UInt8]) { + FfiConverterString.write(value.baseUrl, into: &buf) + FfiConverterString.write(value.apiKey, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeEndpoint_lift(_ buf: RustBuffer) throws -> Endpoint { + return try FfiConverterTypeEndpoint.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeEndpoint_lower(_ value: Endpoint) -> RustBuffer { + return FfiConverterTypeEndpoint.lower(value) +} + +public struct Endpoints { + public var rpc: Endpoint + public var bundler: Endpoint + public var paymaster: Endpoint + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(rpc: Endpoint, bundler: Endpoint, paymaster: Endpoint) { + self.rpc = rpc + self.bundler = bundler + self.paymaster = paymaster + } +} + +extension Endpoints: Equatable, Hashable { + public static func == (lhs: Endpoints, rhs: Endpoints) -> Bool { + if lhs.rpc != rhs.rpc { + return false + } + if lhs.bundler != rhs.bundler { + return false + } + if lhs.paymaster != rhs.paymaster { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(rpc) + hasher.combine(bundler) + hasher.combine(paymaster) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeEndpoints: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Endpoints { + return + try Endpoints( + rpc: FfiConverterTypeEndpoint.read(from: &buf), + bundler: FfiConverterTypeEndpoint.read(from: &buf), + paymaster: FfiConverterTypeEndpoint.read(from: &buf) + ) + } + + public static func write(_ value: Endpoints, into buf: inout [UInt8]) { + FfiConverterTypeEndpoint.write(value.rpc, into: &buf) + FfiConverterTypeEndpoint.write(value.bundler, into: &buf) + FfiConverterTypeEndpoint.write(value.paymaster, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeEndpoints_lift(_ buf: RustBuffer) throws -> Endpoints { + return try FfiConverterTypeEndpoints.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeEndpoints_lower(_ value: Endpoints) -> RustBuffer { + return FfiConverterTypeEndpoints.lower(value) +} + +public struct FundingMetadata { + public var chainId: String + public var tokenContract: Address + public var symbol: String + public var amount: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(chainId: String, tokenContract: Address, symbol: String, amount: String) { + self.chainId = chainId + self.tokenContract = tokenContract + self.symbol = symbol + self.amount = amount + } +} + +extension FundingMetadata: Equatable, Hashable { + public static func == (lhs: FundingMetadata, rhs: FundingMetadata) -> Bool { + if lhs.chainId != rhs.chainId { + return false + } + if lhs.tokenContract != rhs.tokenContract { + return false + } + if lhs.symbol != rhs.symbol { + return false + } + if lhs.amount != rhs.amount { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(chainId) + hasher.combine(tokenContract) + hasher.combine(symbol) + hasher.combine(amount) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeFundingMetadata: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FundingMetadata { + return + try FundingMetadata( + chainId: FfiConverterString.read(from: &buf), + tokenContract: FfiConverterTypeAddress.read(from: &buf), + symbol: FfiConverterString.read(from: &buf), + amount: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: FundingMetadata, into buf: inout [UInt8]) { + FfiConverterString.write(value.chainId, into: &buf) + FfiConverterTypeAddress.write(value.tokenContract, into: &buf) + FfiConverterString.write(value.symbol, into: &buf) + FfiConverterString.write(value.amount, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFundingMetadata_lift(_ buf: RustBuffer) throws -> FundingMetadata { + return try FfiConverterTypeFundingMetadata.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeFundingMetadata_lower(_ value: FundingMetadata) -> RustBuffer { + return FfiConverterTypeFundingMetadata.lower(value) +} + +public struct Metadata { + public var fundingFrom: [FundingMetadata] + public var checkIn: UInt64 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(fundingFrom: [FundingMetadata], checkIn: UInt64) { + self.fundingFrom = fundingFrom + self.checkIn = checkIn + } +} + +extension Metadata: Equatable, Hashable { + public static func == (lhs: Metadata, rhs: Metadata) -> Bool { + if lhs.fundingFrom != rhs.fundingFrom { + return false + } + if lhs.checkIn != rhs.checkIn { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(fundingFrom) + hasher.combine(checkIn) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeMetadata: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Metadata { + return + try Metadata( + fundingFrom: FfiConverterSequenceTypeFundingMetadata.read(from: &buf), + checkIn: FfiConverterUInt64.read(from: &buf) + ) + } + + public static func write(_ value: Metadata, into buf: inout [UInt8]) { + FfiConverterSequenceTypeFundingMetadata.write(value.fundingFrom, into: &buf) + FfiConverterUInt64.write(value.checkIn, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeMetadata_lift(_ buf: RustBuffer) throws -> Metadata { + return try FfiConverterTypeMetadata.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeMetadata_lower(_ value: Metadata) -> RustBuffer { + return FfiConverterTypeMetadata.lower(value) +} + +public struct RouteResponseAvailable { + public var orchestrationId: String + public var transactions: [Transaction] + public var metadata: Metadata + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(orchestrationId: String, transactions: [Transaction], metadata: Metadata) { + self.orchestrationId = orchestrationId + self.transactions = transactions + self.metadata = metadata + } +} + +extension RouteResponseAvailable: Equatable, Hashable { + public static func == (lhs: RouteResponseAvailable, rhs: RouteResponseAvailable) -> Bool { + if lhs.orchestrationId != rhs.orchestrationId { + return false + } + if lhs.transactions != rhs.transactions { + return false + } + if lhs.metadata != rhs.metadata { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(orchestrationId) + hasher.combine(transactions) + hasher.combine(metadata) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeRouteResponseAvailable: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RouteResponseAvailable { + return + try RouteResponseAvailable( + orchestrationId: FfiConverterString.read(from: &buf), + transactions: FfiConverterSequenceTypeTransaction.read(from: &buf), + metadata: FfiConverterTypeMetadata.read(from: &buf) + ) + } + + public static func write(_ value: RouteResponseAvailable, into buf: inout [UInt8]) { + FfiConverterString.write(value.orchestrationId, into: &buf) + FfiConverterSequenceTypeTransaction.write(value.transactions, into: &buf) + FfiConverterTypeMetadata.write(value.metadata, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseAvailable_lift(_ buf: RustBuffer) throws -> RouteResponseAvailable { + return try FfiConverterTypeRouteResponseAvailable.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseAvailable_lower(_ value: RouteResponseAvailable) -> RustBuffer { + return FfiConverterTypeRouteResponseAvailable.lower(value) +} + +/** + * Bridging check error response that should be returned as a normal HTTP 200 + * response + */ +public struct RouteResponseError { + public var error: BridgingError + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(error: BridgingError) { + self.error = error + } +} + +extension RouteResponseError: Equatable, Hashable { + public static func == (lhs: RouteResponseError, rhs: RouteResponseError) -> Bool { + if lhs.error != rhs.error { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(error) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeRouteResponseError: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RouteResponseError { + return + try RouteResponseError( + error: FfiConverterTypeBridgingError.read(from: &buf) + ) + } + + public static func write(_ value: RouteResponseError, into buf: inout [UInt8]) { + FfiConverterTypeBridgingError.write(value.error, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseError_lift(_ buf: RustBuffer) throws -> RouteResponseError { + return try FfiConverterTypeRouteResponseError.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseError_lower(_ value: RouteResponseError) -> RustBuffer { + return FfiConverterTypeRouteResponseError.lower(value) +} + +public struct RouteResponseNotRequired { + public var flag: [String] + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(flag: [String]) { + self.flag = flag + } +} + +extension RouteResponseNotRequired: Equatable, Hashable { + public static func == (lhs: RouteResponseNotRequired, rhs: RouteResponseNotRequired) -> Bool { + if lhs.flag != rhs.flag { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(flag) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeRouteResponseNotRequired: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RouteResponseNotRequired { + return + try RouteResponseNotRequired( + flag: FfiConverterSequenceString.read(from: &buf) + ) + } + + public static func write(_ value: RouteResponseNotRequired, into buf: inout [UInt8]) { + FfiConverterSequenceString.write(value.flag, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseNotRequired_lift(_ buf: RustBuffer) throws -> RouteResponseNotRequired { + return try FfiConverterTypeRouteResponseNotRequired.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseNotRequired_lower(_ value: RouteResponseNotRequired) -> RustBuffer { + return FfiConverterTypeRouteResponseNotRequired.lower(value) +} + +public struct StatusResponseCompleted { + public var createdAt: UInt64 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(createdAt: UInt64) { + self.createdAt = createdAt + } +} + +extension StatusResponseCompleted: Equatable, Hashable { + public static func == (lhs: StatusResponseCompleted, rhs: StatusResponseCompleted) -> Bool { + if lhs.createdAt != rhs.createdAt { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(createdAt) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeStatusResponseCompleted: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> StatusResponseCompleted { + return + try StatusResponseCompleted( + createdAt: FfiConverterUInt64.read(from: &buf) + ) + } + + public static func write(_ value: StatusResponseCompleted, into buf: inout [UInt8]) { + FfiConverterUInt64.write(value.createdAt, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponseCompleted_lift(_ buf: RustBuffer) throws -> StatusResponseCompleted { + return try FfiConverterTypeStatusResponseCompleted.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponseCompleted_lower(_ value: StatusResponseCompleted) -> RustBuffer { + return FfiConverterTypeStatusResponseCompleted.lower(value) +} + +public struct StatusResponseError { + public var createdAt: UInt64 + public var error: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(createdAt: UInt64, error: String) { + self.createdAt = createdAt + self.error = error + } +} + +extension StatusResponseError: Equatable, Hashable { + public static func == (lhs: StatusResponseError, rhs: StatusResponseError) -> Bool { + if lhs.createdAt != rhs.createdAt { + return false + } + if lhs.error != rhs.error { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(createdAt) + hasher.combine(error) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeStatusResponseError: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> StatusResponseError { + return + try StatusResponseError( + createdAt: FfiConverterUInt64.read(from: &buf), + error: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: StatusResponseError, into buf: inout [UInt8]) { + FfiConverterUInt64.write(value.createdAt, into: &buf) + FfiConverterString.write(value.error, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponseError_lift(_ buf: RustBuffer) throws -> StatusResponseError { + return try FfiConverterTypeStatusResponseError.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponseError_lower(_ value: StatusResponseError) -> RustBuffer { + return FfiConverterTypeStatusResponseError.lower(value) +} + +public struct StatusResponsePending { + public var createdAt: UInt64 + /** + * Polling interval in ms for the client + */ + public var checkIn: UInt64 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(createdAt: UInt64, + /** + * Polling interval in ms for the client + */ checkIn: UInt64) + { + self.createdAt = createdAt + self.checkIn = checkIn + } +} + +extension StatusResponsePending: Equatable, Hashable { + public static func == (lhs: StatusResponsePending, rhs: StatusResponsePending) -> Bool { + if lhs.createdAt != rhs.createdAt { + return false + } + if lhs.checkIn != rhs.checkIn { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(createdAt) + hasher.combine(checkIn) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeStatusResponsePending: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> StatusResponsePending { + return + try StatusResponsePending( + createdAt: FfiConverterUInt64.read(from: &buf), + checkIn: FfiConverterUInt64.read(from: &buf) + ) + } + + public static func write(_ value: StatusResponsePending, into buf: inout [UInt8]) { + FfiConverterUInt64.write(value.createdAt, into: &buf) + FfiConverterUInt64.write(value.checkIn, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponsePending_lift(_ buf: RustBuffer) throws -> StatusResponsePending { + return try FfiConverterTypeStatusResponsePending.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponsePending_lower(_ value: StatusResponsePending) -> RustBuffer { + return FfiConverterTypeStatusResponsePending.lower(value) +} + +public struct Transaction { + public var from: Address + public var to: Address + public var value: U256 + public var gas: U64 + public var data: Bytes + public var nonce: U64 + public var chainId: String + public var gasPrice: U256 + public var maxFeePerGas: U256 + public var maxPriorityFeePerGas: U256 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(from: Address, to: Address, value: U256, gas: U64, data: Bytes, nonce: U64, chainId: String, gasPrice: U256, maxFeePerGas: U256, maxPriorityFeePerGas: U256) { + self.from = from + self.to = to + self.value = value + self.gas = gas + self.data = data + self.nonce = nonce + self.chainId = chainId + self.gasPrice = gasPrice + self.maxFeePerGas = maxFeePerGas + self.maxPriorityFeePerGas = maxPriorityFeePerGas + } +} + +extension Transaction: Equatable, Hashable { + public static func == (lhs: Transaction, rhs: Transaction) -> Bool { + if lhs.from != rhs.from { + return false + } + if lhs.to != rhs.to { + return false + } + if lhs.value != rhs.value { + return false + } + if lhs.gas != rhs.gas { + return false + } + if lhs.data != rhs.data { + return false + } + if lhs.nonce != rhs.nonce { + return false + } + if lhs.chainId != rhs.chainId { + return false + } + if lhs.gasPrice != rhs.gasPrice { + return false + } + if lhs.maxFeePerGas != rhs.maxFeePerGas { + return false + } + if lhs.maxPriorityFeePerGas != rhs.maxPriorityFeePerGas { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(from) + hasher.combine(to) + hasher.combine(value) + hasher.combine(gas) + hasher.combine(data) + hasher.combine(nonce) + hasher.combine(chainId) + hasher.combine(gasPrice) + hasher.combine(maxFeePerGas) + hasher.combine(maxPriorityFeePerGas) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeTransaction: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Transaction { + return + try Transaction( + from: FfiConverterTypeAddress.read(from: &buf), + to: FfiConverterTypeAddress.read(from: &buf), + value: FfiConverterTypeU256.read(from: &buf), + gas: FfiConverterTypeU64.read(from: &buf), + data: FfiConverterTypeBytes.read(from: &buf), + nonce: FfiConverterTypeU64.read(from: &buf), + chainId: FfiConverterString.read(from: &buf), + gasPrice: FfiConverterTypeU256.read(from: &buf), + maxFeePerGas: FfiConverterTypeU256.read(from: &buf), + maxPriorityFeePerGas: FfiConverterTypeU256.read(from: &buf) + ) + } + + public static func write(_ value: Transaction, into buf: inout [UInt8]) { + FfiConverterTypeAddress.write(value.from, into: &buf) + FfiConverterTypeAddress.write(value.to, into: &buf) + FfiConverterTypeU256.write(value.value, into: &buf) + FfiConverterTypeU64.write(value.gas, into: &buf) + FfiConverterTypeBytes.write(value.data, into: &buf) + FfiConverterTypeU64.write(value.nonce, into: &buf) + FfiConverterString.write(value.chainId, into: &buf) + FfiConverterTypeU256.write(value.gasPrice, into: &buf) + FfiConverterTypeU256.write(value.maxFeePerGas, into: &buf) + FfiConverterTypeU256.write(value.maxPriorityFeePerGas, into: &buf) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeTransaction_lift(_ buf: RustBuffer) throws -> Transaction { + return try FfiConverterTypeTransaction.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeTransaction_lower(_ value: Transaction) -> RustBuffer { + return FfiConverterTypeTransaction.lower(value) +} + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum BridgingError { + case noRoutesAvailable + case insufficientFunds + case insufficientGasFunds +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeBridgingError: FfiConverterRustBuffer { + typealias SwiftType = BridgingError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BridgingError { + let variant: Int32 = try readInt(&buf) + switch variant { + case 1: return .noRoutesAvailable + + case 2: return .insufficientFunds + + case 3: return .insufficientGasFunds + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: BridgingError, into buf: inout [UInt8]) { + switch value { + case .noRoutesAvailable: + writeInt(&buf, Int32(1)) + + case .insufficientFunds: + writeInt(&buf, Int32(2)) + + case .insufficientGasFunds: + writeInt(&buf, Int32(3)) + } + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeBridgingError_lift(_ buf: RustBuffer) throws -> BridgingError { + return try FfiConverterTypeBridgingError.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeBridgingError_lower(_ value: BridgingError) -> RustBuffer { + return FfiConverterTypeBridgingError.lower(value) +} + +extension BridgingError: Equatable, Hashable {} + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum RouteResponse { + case success(RouteResponseSuccess + ) + case error(RouteResponseError + ) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeRouteResponse: FfiConverterRustBuffer { + typealias SwiftType = RouteResponse + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RouteResponse { + let variant: Int32 = try readInt(&buf) + switch variant { + case 1: return try .success(FfiConverterTypeRouteResponseSuccess.read(from: &buf) + ) + + case 2: return try .error(FfiConverterTypeRouteResponseError.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: RouteResponse, into buf: inout [UInt8]) { + switch value { + case let .success(v1): + writeInt(&buf, Int32(1)) + FfiConverterTypeRouteResponseSuccess.write(v1, into: &buf) + + case let .error(v1): + writeInt(&buf, Int32(2)) + FfiConverterTypeRouteResponseError.write(v1, into: &buf) + } + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponse_lift(_ buf: RustBuffer) throws -> RouteResponse { + return try FfiConverterTypeRouteResponse.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponse_lower(_ value: RouteResponse) -> RustBuffer { + return FfiConverterTypeRouteResponse.lower(value) +} + +extension RouteResponse: Equatable, Hashable {} + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum RouteResponseSuccess { + case available(RouteResponseAvailable + ) + case notRequired(RouteResponseNotRequired + ) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeRouteResponseSuccess: FfiConverterRustBuffer { + typealias SwiftType = RouteResponseSuccess + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RouteResponseSuccess { + let variant: Int32 = try readInt(&buf) + switch variant { + case 1: return try .available(FfiConverterTypeRouteResponseAvailable.read(from: &buf) + ) + + case 2: return try .notRequired(FfiConverterTypeRouteResponseNotRequired.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: RouteResponseSuccess, into buf: inout [UInt8]) { + switch value { + case let .available(v1): + writeInt(&buf, Int32(1)) + FfiConverterTypeRouteResponseAvailable.write(v1, into: &buf) + + case let .notRequired(v1): + writeInt(&buf, Int32(2)) + FfiConverterTypeRouteResponseNotRequired.write(v1, into: &buf) + } + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseSuccess_lift(_ buf: RustBuffer) throws -> RouteResponseSuccess { + return try FfiConverterTypeRouteResponseSuccess.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteResponseSuccess_lower(_ value: RouteResponseSuccess) -> RustBuffer { + return FfiConverterTypeRouteResponseSuccess.lower(value) +} + +extension RouteResponseSuccess: Equatable, Hashable {} + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum StatusResponse { + case pending(StatusResponsePending + ) + case completed(StatusResponseCompleted + ) + case error(StatusResponseError + ) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeStatusResponse: FfiConverterRustBuffer { + typealias SwiftType = StatusResponse + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> StatusResponse { + let variant: Int32 = try readInt(&buf) + switch variant { + case 1: return try .pending(FfiConverterTypeStatusResponsePending.read(from: &buf) + ) + + case 2: return try .completed(FfiConverterTypeStatusResponseCompleted.read(from: &buf) + ) + + case 3: return try .error(FfiConverterTypeStatusResponseError.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: StatusResponse, into buf: inout [UInt8]) { + switch value { + case let .pending(v1): + writeInt(&buf, Int32(1)) + FfiConverterTypeStatusResponsePending.write(v1, into: &buf) + + case let .completed(v1): + writeInt(&buf, Int32(2)) + FfiConverterTypeStatusResponseCompleted.write(v1, into: &buf) + + case let .error(v1): + writeInt(&buf, Int32(3)) + FfiConverterTypeStatusResponseError.write(v1, into: &buf) + } + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponse_lift(_ buf: RustBuffer) throws -> StatusResponse { + return try FfiConverterTypeStatusResponse.lift(buf) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeStatusResponse_lower(_ value: StatusResponse) -> RustBuffer { + return FfiConverterTypeStatusResponse.lower(value) +} + +extension StatusResponse: Equatable, Hashable {} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterSequenceString: FfiConverterRustBuffer { + typealias SwiftType = [String] + + public static func write(_ value: [String], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterString.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] { + let len: Int32 = try readInt(&buf) + var seq = [String]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + try seq.append(FfiConverterString.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterSequenceTypeFundingMetadata: FfiConverterRustBuffer { + typealias SwiftType = [FundingMetadata] + + public static func write(_ value: [FundingMetadata], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeFundingMetadata.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [FundingMetadata] { + let len: Int32 = try readInt(&buf) + var seq = [FundingMetadata]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + try seq.append(FfiConverterTypeFundingMetadata.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +private struct FfiConverterSequenceTypeTransaction: FfiConverterRustBuffer { + typealias SwiftType = [Transaction] + + public static func write(_ value: [Transaction], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeTransaction.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Transaction] { + let len: Int32 = try readInt(&buf) + var seq = [Transaction]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + try seq.append(FfiConverterTypeTransaction.read(from: &buf)) + } + return seq + } +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias Address = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeAddress: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Address { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: Address, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> Address { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: Address) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeAddress_lift(_ value: RustBuffer) throws -> Address { + return try FfiConverterTypeAddress.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeAddress_lower(_ value: Address) -> RustBuffer { + return FfiConverterTypeAddress.lower(value) +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias Bytes = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeBytes: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bytes { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: Bytes, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> Bytes { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: Bytes) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeBytes_lift(_ value: RustBuffer) throws -> Bytes { + return try FfiConverterTypeBytes.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeBytes_lower(_ value: Bytes) -> RustBuffer { + return FfiConverterTypeBytes.lower(value) +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias U256 = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeU256: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> U256 { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: U256, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> U256 { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: U256) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeU256_lift(_ value: RustBuffer) throws -> U256 { + return try FfiConverterTypeU256.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeU256_lower(_ value: U256) -> RustBuffer { + return FfiConverterTypeU256.lower(value) +} + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias U64 = String + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public struct FfiConverterTypeU64: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> U64 { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: U64, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> U64 { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: U64) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeU64_lift(_ value: RustBuffer) throws -> U64 { + return try FfiConverterTypeU64.lift(value) +} + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif +public func FfiConverterTypeU64_lower(_ value: U64) -> RustBuffer { + return FfiConverterTypeU64.lower(value) +} + +private enum InitializationResult { + case ok + case contractVersionMismatch + case apiChecksumMismatch +} + +// Use a global variable to perform the versioning checks. Swift ensures that +// the code inside is only computed once. +private let initializationResult: InitializationResult = { + // Get the bindings contract version from our ComponentInterface + let bindings_contract_version = 29 + // Get the scaffolding contract version by calling the into the dylib + let scaffolding_contract_version = ffi_yttrium_uniffi_contract_version() + if bindings_contract_version != scaffolding_contract_version { + return InitializationResult.contractVersionMismatch + } + + return InitializationResult.ok +}() + +private func uniffiEnsureInitialized() { + switch initializationResult { + case .ok: + break + case .contractVersionMismatch: + fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") + case .apiChecksumMismatch: + fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } +} + +// swiftlint:enable all diff --git a/platforms/swift/Sources/Yttrium/yttriumFFI.h b/platforms/swift/Sources/Yttrium/yttriumFFI.h new file mode 100644 index 00000000..5411e496 --- /dev/null +++ b/platforms/swift/Sources/Yttrium/yttriumFFI.h @@ -0,0 +1,550 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +#pragma once + +#include +#include +#include + +// The following structs are used to implement the lowest level +// of the FFI, and thus useful to multiple uniffied crates. +// We ensure they are declared exactly once, with a header guard, UNIFFI_SHARED_H. +#ifdef UNIFFI_SHARED_H + // We also try to prevent mixing versions of shared uniffi header structs. + // If you add anything to the #else block, you must increment the version suffix in UNIFFI_SHARED_HEADER_V4 + #ifndef UNIFFI_SHARED_HEADER_V4 + #error Combining helper code from multiple versions of uniffi is not supported + #endif // ndef UNIFFI_SHARED_HEADER_V4 +#else +#define UNIFFI_SHARED_H +#define UNIFFI_SHARED_HEADER_V4 +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ + +typedef struct RustBuffer +{ + uint64_t capacity; + uint64_t len; + uint8_t *_Nullable data; +} RustBuffer; + +typedef struct ForeignBytes +{ + int32_t len; + const uint8_t *_Nullable data; +} ForeignBytes; + +// Error definitions +typedef struct RustCallStatus { + int8_t code; + RustBuffer errorBuf; +} RustCallStatus; + +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ +#endif // def UNIFFI_SHARED_H +#ifndef UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK +#define UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK +typedef void (*UniffiRustFutureContinuationCallback)(uint64_t, int8_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE +typedef void (*UniffiForeignFutureFree)(uint64_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE +#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE +typedef void (*UniffiCallbackInterfaceFree)(uint64_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE +#define UNIFFI_FFIDEF_FOREIGN_FUTURE +typedef struct UniffiForeignFuture { + uint64_t handle; + UniffiForeignFutureFree _Nonnull free; +} UniffiForeignFuture; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 +typedef struct UniffiForeignFutureStructU8 { + uint8_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU8; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 +typedef void (*UniffiForeignFutureCompleteU8)(uint64_t, UniffiForeignFutureStructU8 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 +typedef struct UniffiForeignFutureStructI8 { + int8_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI8; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 +typedef void (*UniffiForeignFutureCompleteI8)(uint64_t, UniffiForeignFutureStructI8 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 +typedef struct UniffiForeignFutureStructU16 { + uint16_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU16; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 +typedef void (*UniffiForeignFutureCompleteU16)(uint64_t, UniffiForeignFutureStructU16 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 +typedef struct UniffiForeignFutureStructI16 { + int16_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI16; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 +typedef void (*UniffiForeignFutureCompleteI16)(uint64_t, UniffiForeignFutureStructI16 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 +typedef struct UniffiForeignFutureStructU32 { + uint32_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 +typedef void (*UniffiForeignFutureCompleteU32)(uint64_t, UniffiForeignFutureStructU32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 +typedef struct UniffiForeignFutureStructI32 { + int32_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 +typedef void (*UniffiForeignFutureCompleteI32)(uint64_t, UniffiForeignFutureStructI32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 +typedef struct UniffiForeignFutureStructU64 { + uint64_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 +typedef void (*UniffiForeignFutureCompleteU64)(uint64_t, UniffiForeignFutureStructU64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 +typedef struct UniffiForeignFutureStructI64 { + int64_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 +typedef void (*UniffiForeignFutureCompleteI64)(uint64_t, UniffiForeignFutureStructI64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 +typedef struct UniffiForeignFutureStructF32 { + float returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructF32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 +typedef void (*UniffiForeignFutureCompleteF32)(uint64_t, UniffiForeignFutureStructF32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 +typedef struct UniffiForeignFutureStructF64 { + double returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructF64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 +typedef void (*UniffiForeignFutureCompleteF64)(uint64_t, UniffiForeignFutureStructF64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER +typedef struct UniffiForeignFutureStructPointer { + void*_Nonnull returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructPointer; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER +typedef void (*UniffiForeignFutureCompletePointer)(uint64_t, UniffiForeignFutureStructPointer + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER +typedef struct UniffiForeignFutureStructRustBuffer { + RustBuffer returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructRustBuffer; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER +typedef void (*UniffiForeignFutureCompleteRustBuffer)(uint64_t, UniffiForeignFutureStructRustBuffer + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID +typedef struct UniffiForeignFutureStructVoid { + RustCallStatus callStatus; +} UniffiForeignFutureStructVoid; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID +typedef void (*UniffiForeignFutureCompleteVoid)(uint64_t, UniffiForeignFutureStructVoid + ); + +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_YTTRIUM_FN_CLONE_ACCOUNTCLIENT +#define UNIFFI_FFIDEF_UNIFFI_YTTRIUM_FN_CLONE_ACCOUNTCLIENT +void*_Nonnull uniffi_yttrium_fn_clone_accountclient(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_YTTRIUM_FN_FREE_ACCOUNTCLIENT +#define UNIFFI_FFIDEF_UNIFFI_YTTRIUM_FN_FREE_ACCOUNTCLIENT +void uniffi_yttrium_fn_free_accountclient(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_ALLOC +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_ALLOC +RustBuffer ffi_yttrium_rustbuffer_alloc(uint64_t size, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_FROM_BYTES +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_FROM_BYTES +RustBuffer ffi_yttrium_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_FREE +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_FREE +void ffi_yttrium_rustbuffer_free(RustBuffer buf, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_RESERVE +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUSTBUFFER_RESERVE +RustBuffer ffi_yttrium_rustbuffer_reserve(RustBuffer buf, uint64_t additional, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U8 +void ffi_yttrium_rust_future_poll_u8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U8 +void ffi_yttrium_rust_future_cancel_u8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U8 +void ffi_yttrium_rust_future_free_u8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U8 +uint8_t ffi_yttrium_rust_future_complete_u8(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I8 +void ffi_yttrium_rust_future_poll_i8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I8 +void ffi_yttrium_rust_future_cancel_i8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I8 +void ffi_yttrium_rust_future_free_i8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I8 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I8 +int8_t ffi_yttrium_rust_future_complete_i8(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U16 +void ffi_yttrium_rust_future_poll_u16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U16 +void ffi_yttrium_rust_future_cancel_u16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U16 +void ffi_yttrium_rust_future_free_u16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U16 +uint16_t ffi_yttrium_rust_future_complete_u16(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I16 +void ffi_yttrium_rust_future_poll_i16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I16 +void ffi_yttrium_rust_future_cancel_i16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I16 +void ffi_yttrium_rust_future_free_i16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I16 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I16 +int16_t ffi_yttrium_rust_future_complete_i16(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U32 +void ffi_yttrium_rust_future_poll_u32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U32 +void ffi_yttrium_rust_future_cancel_u32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U32 +void ffi_yttrium_rust_future_free_u32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U32 +uint32_t ffi_yttrium_rust_future_complete_u32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I32 +void ffi_yttrium_rust_future_poll_i32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I32 +void ffi_yttrium_rust_future_cancel_i32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I32 +void ffi_yttrium_rust_future_free_i32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I32 +int32_t ffi_yttrium_rust_future_complete_i32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_U64 +void ffi_yttrium_rust_future_poll_u64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_U64 +void ffi_yttrium_rust_future_cancel_u64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_U64 +void ffi_yttrium_rust_future_free_u64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_U64 +uint64_t ffi_yttrium_rust_future_complete_u64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_I64 +void ffi_yttrium_rust_future_poll_i64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_I64 +void ffi_yttrium_rust_future_cancel_i64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_I64 +void ffi_yttrium_rust_future_free_i64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_I64 +int64_t ffi_yttrium_rust_future_complete_i64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_F32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_F32 +void ffi_yttrium_rust_future_poll_f32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_F32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_F32 +void ffi_yttrium_rust_future_cancel_f32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_F32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_F32 +void ffi_yttrium_rust_future_free_f32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_F32 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_F32 +float ffi_yttrium_rust_future_complete_f32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_F64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_F64 +void ffi_yttrium_rust_future_poll_f64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_F64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_F64 +void ffi_yttrium_rust_future_cancel_f64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_F64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_F64 +void ffi_yttrium_rust_future_free_f64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_F64 +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_F64 +double ffi_yttrium_rust_future_complete_f64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_POINTER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_POINTER +void ffi_yttrium_rust_future_poll_pointer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_POINTER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_POINTER +void ffi_yttrium_rust_future_cancel_pointer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_POINTER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_POINTER +void ffi_yttrium_rust_future_free_pointer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_POINTER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_POINTER +void*_Nonnull ffi_yttrium_rust_future_complete_pointer(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_RUST_BUFFER +void ffi_yttrium_rust_future_poll_rust_buffer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_RUST_BUFFER +void ffi_yttrium_rust_future_cancel_rust_buffer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_RUST_BUFFER +void ffi_yttrium_rust_future_free_rust_buffer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_RUST_BUFFER +RustBuffer ffi_yttrium_rust_future_complete_rust_buffer(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_VOID +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_POLL_VOID +void ffi_yttrium_rust_future_poll_void(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_VOID +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_CANCEL_VOID +void ffi_yttrium_rust_future_cancel_void(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_VOID +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_FREE_VOID +void ffi_yttrium_rust_future_free_void(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_VOID +#define UNIFFI_FFIDEF_FFI_YTTRIUM_RUST_FUTURE_COMPLETE_VOID +void ffi_yttrium_rust_future_complete_void(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_YTTRIUM_UNIFFI_CONTRACT_VERSION +#define UNIFFI_FFIDEF_FFI_YTTRIUM_UNIFFI_CONTRACT_VERSION +uint32_t ffi_yttrium_uniffi_contract_version(void + +); +#endif + diff --git a/platforms/swift/Tests/YttriumTests/YttriumTests.swift b/platforms/swift/Tests/YttriumTests/YttriumTests.swift deleted file mode 100644 index e5ffc6e5..00000000 --- a/platforms/swift/Tests/YttriumTests/YttriumTests.swift +++ /dev/null @@ -1,9 +0,0 @@ -import XCTest -@testable import Yttrium - -final class YttriumTests: XCTestCase { - - func testYttrium() { - - } -} \ No newline at end of file diff --git a/scripts/build-xcframework.sh b/scripts/build-xcframework.sh new file mode 100755 index 00000000..64c965ad --- /dev/null +++ b/scripts/build-xcframework.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env zsh + +set -e +set -u + +PACKAGE_NAME="uniffi_yttrium" +fat_simulator_lib_dir="target/ios-simulator-fat/release" +swift_package_dir="platforms/swift/Sources/Yttrium" + +build_rust_libraries() { + #### Building for aarch64-apple-ios (Physical Devices) #### + echo "Building for aarch64-apple-ios..." + + # Set environment variables + export CC_aarch64_apple_ios="$(xcrun --sdk iphoneos --find clang)" + export AR_aarch64_apple_ios="$(xcrun --sdk iphoneos --find ar)" + export CARGO_TARGET_AARCH64_APPLE_IOS_LINKER="$CC_aarch64_apple_ios" + export RUSTFLAGS="-C linker=$CC_aarch64_apple_ios -C link-arg=-miphoneos-version-min=13.0" + + # Build + cargo build --lib --release --target aarch64-apple-ios + + # Unset environment variables + unset CC_aarch64_apple_ios + unset AR_aarch64_apple_ios + unset CARGO_TARGET_AARCH64_APPLE_IOS_LINKER + unset RUSTFLAGS + + #### Building for x86_64-apple-ios (Simulator on Intel Macs) #### + echo "Building for x86_64-apple-ios..." + + # Set environment variables + export CC_x86_64_apple_ios="$(xcrun --sdk iphonesimulator --find clang)" + export AR_x86_64_apple_ios="$(xcrun --sdk iphonesimulator --find ar)" + export CARGO_TARGET_X86_64_APPLE_IOS_LINKER="$CC_x86_64_apple_ios" + export RUSTFLAGS="-C linker=$CC_x86_64_apple_ios -C link-arg=-mios-simulator-version-min=13.0" + + # Build + cargo build --lib --release --target x86_64-apple-ios + + # Unset environment variables + unset CC_x86_64_apple_ios + unset AR_x86_64_apple_ios + unset CARGO_TARGET_X86_64_APPLE_IOS_LINKER + unset RUSTFLAGS + + #### Building for aarch64-apple-ios-sim (Simulator on ARM Macs) #### + echo "Building for aarch64-apple-ios-sim..." + + # Set environment variables + export CC_aarch64_apple_ios_sim="$(xcrun --sdk iphonesimulator --find clang)" + export AR_aarch64_apple_ios_sim="$(xcrun --sdk iphonesimulator --find ar)" + export CARGO_TARGET_AARCH64_APPLE_IOS_SIM_LINKER="$CC_aarch64_apple_ios_sim" + export RUSTFLAGS="-C linker=$CC_aarch64_apple_ios_sim -C link-arg=-mios-simulator-version-min=13.0" + + # Build + cargo build --lib --release --target aarch64-apple-ios-sim + + # Unset environment variables + unset CC_aarch64_apple_ios_sim + unset AR_aarch64_apple_ios_sim + unset CARGO_TARGET_AARCH64_APPLE_IOS_SIM_LINKER + unset RUSTFLAGS +} + +generate_ffi() { + echo "Generating framework module mapping and FFI bindings..." + cargo run --features uniffi/cli --bin uniffi-bindgen generate \ + --library target/aarch64-apple-ios/release/lib$1.dylib \ + --language swift \ + --out-dir target/uniffi-xcframework-staging + + echo "Creating module.modulemap" + cat target/uniffi-xcframework-staging/yttriumFFI.modulemap \ + target/uniffi-xcframework-staging/uniffi_yttriumFFI.modulemap \ + > target/uniffi-xcframework-staging/module.modulemap + + echo "Copying bindings to Swift package directory..." + mkdir -p "$swift_package_dir" + cp target/uniffi-xcframework-staging/*.swift "$swift_package_dir/" + cp target/uniffi-xcframework-staging/*.h "$swift_package_dir/" +} + +create_fat_simulator_lib() { + echo "Creating a fat library for x86_64 and aarch64 simulators..." + mkdir -p "$fat_simulator_lib_dir" + lipo -create \ + target/x86_64-apple-ios/release/lib$1.a \ + target/aarch64-apple-ios-sim/release/lib$1.a \ + -output "$fat_simulator_lib_dir/lib$1.a" +} + +build_xcframework() { + echo "Generating XCFramework..." + rm -rf target/ios + mkdir -p target/ios + xcodebuild -create-xcframework \ + -library target/aarch64-apple-ios/release/lib$1.a -headers target/uniffi-xcframework-staging \ + -library "$fat_simulator_lib_dir/lib$1.a" -headers target/uniffi-xcframework-staging \ + -output target/ios/lib$1.xcframework +} + +# Add the necessary Rust targets +rustup target add aarch64-apple-ios +rustup target add x86_64-apple-ios +rustup target add aarch64-apple-ios-sim + +# Execute the build steps +build_rust_libraries +generate_ffi $PACKAGE_NAME +create_fat_simulator_lib $PACKAGE_NAME +build_xcframework $PACKAGE_NAME diff --git a/scripts/generate-package-swift.sh b/scripts/generate-package-swift.sh new file mode 100644 index 00000000..c555f5ec --- /dev/null +++ b/scripts/generate-package-swift.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +set -e + +# Variables +: "${VERSION:?Error: VERSION environment variable is not set.}" +PACKAGE_VERSION="$VERSION" +RUST_XCFRAMEWORK_DIR="target/ios/libuniffi_yttrium.xcframework" +RUST_XCFRAMEWORK_ZIP="libuniffi_yttrium.xcframework.zip" +REPO_URL="https://github.com/reown-com/yttrium" + +# 1. Zip the XCFramework +echo "Zipping Rust XCFramework..." +mkdir -p Output +zip -r Output/$RUST_XCFRAMEWORK_ZIP $RUST_XCFRAMEWORK_DIR + +# 2. Compute the checksum +echo "Computing checksum for Rust XCFramework..." +RUST_CHECKSUM=$(swift package compute-checksum Output/$RUST_XCFRAMEWORK_ZIP) +echo "Rust XCFramework checksum: $RUST_CHECKSUM" + +# 3. Generate Package.swift +echo "Generating Package.swift..." +cat > Package.swift < Package.swift <