use std::path::Path; use jsonrpsee::async_client::ClientBuilder; use jsonrpsee::core::client::SubscriptionClientT; use jsonrpsee::core::Error; use jsonrpsee::http_client::HttpClientBuilder; use jsonrpsee::proc_macros::rpc; use serde::Deserialize; use serde_json::Value; use tokio::net::ToSocketAddrs; #[rpc(client)] pub trait Rpc { #[method(name = "addDevice", param_kind = map)] async fn add_device( &self, account: Option, uri: String, ) -> Result; #[method(name = "block", param_kind = map)] fn block( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, ) -> Result; #[method(name = "deleteLocalAccountData", param_kind = map)] fn delete_local_account_data( &self, account: Option, #[allow(non_snake_case)] ignoreRegistered: Option, ) -> Result; #[method(name = "getUserStatus", param_kind = map)] fn get_user_status( &self, account: Option, recipients: Vec, ) -> Result; #[method(name = "joinGroup", param_kind = map)] fn join_group(&self, account: Option, uri: String) -> Result; #[method(name = "finishLink", param_kind = map)] fn finish_link( &self, #[allow(non_snake_case)] deviceLinkUri: String, #[allow(non_snake_case)] deviceName: String, ) -> Result; #[method(name = "listAccounts", param_kind = map)] fn list_accounts(&self) -> Result; #[method(name = "listContacts", param_kind = map)] fn list_contacts( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] allRecipients: bool, blocked: Option, name: Option, ) -> Result; #[method(name = "listDevices", param_kind = map)] fn list_devices(&self, account: Option) -> Result; #[method(name = "listGroups", param_kind = map)] fn list_groups( &self, account: Option, #[allow(non_snake_case)] groupIds: Vec, ) -> Result; #[method(name = "listIdentities", param_kind = map)] fn list_identities( &self, account: Option, number: Option, ) -> Result; #[method(name = "listStickerPacks", param_kind = map)] fn list_sticker_packs(&self, account: Option) -> Result; #[method(name = "quitGroup", param_kind = map)] fn quit_group( &self, account: Option, #[allow(non_snake_case)] groupId: String, delete: bool, admins: Vec, ) -> Result; #[method(name = "register", param_kind = map)] fn register( &self, account: Option, voice: bool, captcha: Option, ) -> Result; #[method(name = "removeContact", param_kind = map)] fn remove_contact( &self, account: Option, recipient: String, forget: bool, ) -> Result; #[method(name = "removeDevice", param_kind = map)] fn remove_device( &self, account: Option, #[allow(non_snake_case)] deviceId: u32, ) -> Result; #[method(name = "removePin", param_kind = map)] fn remove_pin(&self, account: Option) -> Result; #[method(name = "remoteDelete", param_kind = map)] fn remote_delete( &self, account: Option, #[allow(non_snake_case)] targetTimestamp: u64, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, #[allow(non_snake_case)] noteToSelf: bool, ) -> Result; #[method(name = "send", param_kind = map)] fn send( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, #[allow(non_snake_case)] noteToSelf: bool, #[allow(non_snake_case)] endSession: bool, message: String, attachments: Vec, mentions: Vec, #[allow(non_snake_case)] quoteTimestamp: Option, #[allow(non_snake_case)] quoteAuthor: Option, #[allow(non_snake_case)] quoteMessage: Option, #[allow(non_snake_case)] quoteMention: Vec, #[allow(non_snake_case)] quoteAttachment: Vec, sticker: Option, #[allow(non_snake_case)] storyTimestamp: Option, #[allow(non_snake_case)] storyAuthor: Option, ) -> Result; #[method(name = "sendContacts", param_kind = map)] fn send_contacts(&self, account: Option) -> Result; #[method(name = "sendPaymentNotification", param_kind = map)] fn send_payment_notification( &self, account: Option, recipient: String, receipt: String, note: String, ) -> Result; #[method(name = "sendReaction", param_kind = map)] fn send_reaction( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, #[allow(non_snake_case)] noteToSelf: bool, emoji: String, #[allow(non_snake_case)] targetAuthor: String, #[allow(non_snake_case)] targetTimestamp: u64, remove: bool, story: bool, ) -> Result; #[method(name = "sendReceipt", param_kind = map)] fn send_receipt( &self, account: Option, recipient: String, #[allow(non_snake_case)] targetTimestamps: Vec, r#type: String, ) -> Result; #[method(name = "sendSyncRequest", param_kind = map)] fn send_sync_request(&self, account: Option) -> Result; #[method(name = "sendTyping", param_kind = map)] fn send_typing( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, stop: bool, ) -> Result; #[method(name = "setPin", param_kind = map)] fn set_pin(&self, account: Option, pin: String) -> Result; #[method(name = "submitRateLimitChallenge", param_kind = map)] fn submit_rate_limit_challenge( &self, account: Option, challenge: String, captcha: String, ) -> Result; #[method(name = "startLink", param_kind = map)] fn start_link(&self, account: Option) -> Result; #[method(name = "trust", param_kind = map)] fn trust( &self, account: Option, recipient: String, #[allow(non_snake_case)] trustAllKnownKeys: bool, #[allow(non_snake_case)] verifiedSafetyNumber: Option, ) -> Result; #[method(name = "unblock", param_kind = map)] fn unblock( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, ) -> Result; #[method(name = "unregister", param_kind = map)] fn unregister( &self, account: Option, #[allow(non_snake_case)] deleteAccount: bool, ) -> Result; #[method(name = "updateAccount", param_kind = map)] fn update_account( &self, account: Option, #[allow(non_snake_case)] deviceName: Option, ) -> Result; #[method(name = "updateConfiguration", param_kind = map)] fn update_configuration( &self, account: Option, #[allow(non_snake_case)] readReceiptes: Option, #[allow(non_snake_case)] unidentifiedDeliveryIndicators: Option, #[allow(non_snake_case)] typingIndicators: Option, #[allow(non_snake_case)] linkPreviews: Option, ) -> Result; #[method(name = "updateContact", param_kind = map)] fn update_contact( &self, account: Option, recipient: String, name: Option, expiration: Option, ) -> Result; #[method(name = "updateGroup", param_kind = map)] fn update_group( &self, account: Option, #[allow(non_snake_case)] groupId: Option, name: Option, description: Option, avatar: Option, member: Vec, #[allow(non_snake_case)] removeMember: Vec, admin: Vec, #[allow(non_snake_case)] removeAdmin: Vec, ban: Vec, unban: Vec, #[allow(non_snake_case)] resetLink: bool, #[allow(non_snake_case)] link: Option, #[allow(non_snake_case)] setPermissionAddMember: Option, #[allow(non_snake_case)] setPermissionEditDetails: Option, #[allow(non_snake_case)] setPermissionSendMessages: Option, expiration: Option, ) -> Result; #[method(name = "updateProfile", param_kind = map)] fn update_profile( &self, account: Option, #[allow(non_snake_case)] givenName: Option, #[allow(non_snake_case)] familyName: Option, about: Option, #[allow(non_snake_case)] aboutEmoji: Option, #[allow(non_snake_case)] mobileCoinAddress: Option, avatar: Option, #[allow(non_snake_case)] removeAvatar: bool, ) -> Result; #[method(name = "uploadStickerPack", param_kind = map)] fn upload_sticker_pack( &self, account: Option, path: String, ) -> Result; #[method(name = "verify", param_kind = map)] fn verify( &self, account: Option, #[allow(non_snake_case)] verificationCode: String, pin: Option, ) -> Result; #[subscription( name = "subscribeReceive" => "receive", unsubscribe = "unsubscribeReceive", item = Value, param_kind = map )] async fn subscribe_receive(&self, account: Option) -> SubscriptionResult; #[method(name = "version")] fn version(&self) -> Result; } #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct JsonLink { pub device_link_uri: String, } pub async fn connect_tcp(tcp: impl ToSocketAddrs) -> Result { let (sender, receiver) = super::transports::tcp::connect(tcp).await?; Ok(ClientBuilder::default().build_with_tokio(sender, receiver)) } pub async fn connect_unix( socket_path: impl AsRef, ) -> Result { let (sender, receiver) = super::transports::ipc::connect(socket_path).await?; Ok(ClientBuilder::default().build_with_tokio(sender, receiver)) } pub async fn connect_http(uri: &str) -> Result { HttpClientBuilder::default().build(uri) }