Struct catenis_api_client::async_impl::CatenisClient
source · pub struct CatenisClient { /* private fields */ }
Expand description
Represents an asynchronous Catenis API client.
Implementations
sourceimpl CatenisClient
impl CatenisClient
sourcepub fn new(device_credentials: Option<DeviceCredentials>) -> Result<Self>
pub fn new(device_credentials: Option<DeviceCredentials>) -> Result<Self>
Instantiate a new asynchronous Catenis API client object with default option settings.
Note: if no virtual device credentials are passed, the resulting client object should only be used to call public API methods.
sourcepub fn new_with_options<'a, I>(
device_credentials: Option<DeviceCredentials>,
opts: I
) -> Result<Self>where
I: IntoIterator,
<I as IntoIterator>::Item: Borrow<ClientOptions<'a>>,
pub fn new_with_options<'a, I>(
device_credentials: Option<DeviceCredentials>,
opts: I
) -> Result<Self>where
I: IntoIterator,
<I as IntoIterator>::Item: Borrow<ClientOptions<'a>>,
Instantiate a new asynchronous Catenis API client object with alternative option settings.
Note: if no virtual device credentials are passed, the resulting client object should only be used to call public API methods.
sourcepub fn new_ws_notify_channel(
&self,
notify_event: NotificationEvent
) -> WsNotifyChannel
pub fn new_ws_notify_channel(
&self,
notify_event: NotificationEvent
) -> WsNotifyChannel
Instantiate a new asynchronous WebSocket notification channel object for a given Catenis notification event.
Example
use catenis_api_client::{
async_impl,
ClientOptions, Environment, Result,
api::NotificationEvent,
};
let ctn_client = async_impl::CatenisClient::new_with_options(
Some((
"drc3XdxNtzoucpw9xiRp",
concat!(
"4c1749c8e86f65e0a73e5fb19f2aa9e74a716bc22d7956bf3072b4bc3fbfe2a0",
"d138ad0d4bcfee251e4e5f54d6e92b8fd4eb36958a7aeaeeb51e8d2fcc4552c3"
),
).into()),
&[
ClientOptions::Environment(Environment::Sandbox),
],
)?;
// Instantiate asynchronous WebSocket notification channel object for New Message Received
// notification event
let notify_channel = ctn_client.new_ws_notify_channel(NotificationEvent::NewMsgReceived);
sourcepub async fn log_message(
&mut self,
message: Message,
options: Option<LogMessageOptions>
) -> Result<LogMessageResult>
pub async fn log_message(
&mut self,
message: Message,
options: Option<LogMessageOptions>
) -> Result<LogMessageResult>
Call Log Message API method.
Examples
Log a message in a single call:
use catenis_api_client::{
api::*,
};
let result = ctn_client.log_message(
Message::Whole(String::from("My message")),
Some(LogMessageOptions {
encoding: Some(Encoding::UTF8),
encrypt: Some(true),
off_chain: Some(true),
storage: Some(Storage::Auto),
async_: None,
}),
).await?;
println!("ID of logged message: {}", result.message_id.unwrap());
Log a message in chunks:
use catenis_api_client::{
api::*,
};
let message = [
"First part of message",
"Second part of message",
"Third and last part of message"
];
for idx in 0..message.len() {
let mut continuation_token = None;
let result = ctn_client.log_message(
Message::Chunk(ChunkedMessage {
data: Some(String::from(message[idx])),
is_final: Some(idx < message.len() - 1),
continuation_token: if let Some(token) = &continuation_token {
Some(String::from(token))
} else {
None
},
}),
Some(LogMessageOptions {
encoding: Some(Encoding::UTF8),
encrypt: Some(true),
off_chain: Some(true),
storage: Some(Storage::Auto),
async_: None,
}),
).await?;
if let Some(token) = result.continuation_token {
continuation_token = Some(token);
} else {
println!("ID of logged message: {}", result.message_id.unwrap());
}
}
sourcepub async fn send_message(
&mut self,
message: Message,
target_device: DeviceId,
options: Option<SendMessageOptions>
) -> Result<SendMessageResult>
pub async fn send_message(
&mut self,
message: Message,
target_device: DeviceId,
options: Option<SendMessageOptions>
) -> Result<SendMessageResult>
Call Send Message API method.
Examples
Send a message in a single call:
use catenis_api_client::{
api::*,
};
let result = ctn_client.send_message(
Message::Whole(String::from("My message")),
DeviceId {
id: String::from("d8YpQ7jgPBJEkBrnvp58"),
is_prod_unique_id: None,
},
Some(SendMessageOptions {
encoding: Some(Encoding::UTF8),
encrypt: Some(true),
off_chain: Some(true),
storage: Some(Storage::Auto),
read_confirmation: Some(true),
async_: None,
}),
).await?;
println!("ID of sent message: {}", result.message_id.unwrap());
Send a message in chunks:
use catenis_api_client::{
api::*,
};
let message = [
"First part of message",
"Second part of message",
"Third and last part of message"
];
for idx in 0..message.len() {
let mut continuation_token = None;
let result = ctn_client.send_message(
Message::Chunk(ChunkedMessage {
data: Some(String::from(message[idx])),
is_final: Some(idx < message.len() - 1),
continuation_token: if let Some(token) = &continuation_token {
Some(String::from(token))
} else {
None
},
}),
DeviceId {
id: String::from("d8YpQ7jgPBJEkBrnvp58"),
is_prod_unique_id: None,
},
Some(SendMessageOptions {
encoding: Some(Encoding::UTF8),
encrypt: Some(true),
off_chain: Some(true),
storage: Some(Storage::Auto),
read_confirmation: Some(true),
async_: None,
}),
).await?;
if let Some(token) = result.continuation_token {
continuation_token = Some(token);
} else {
println!("ID of sent message: {}", result.message_id.unwrap());
}
}
sourcepub async fn read_message(
&mut self,
message_id: &str,
options: Option<ReadMessageOptions>
) -> Result<ReadMessageResult>
pub async fn read_message(
&mut self,
message_id: &str,
options: Option<ReadMessageOptions>
) -> Result<ReadMessageResult>
Call Read Message API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.read_message(
"o3muoTnnD6cXYyarYY38",
Some(ReadMessageOptions {
encoding: Some(Encoding::UTF8),
continuation_token: None,
data_chunk_size: None,
async_: None,
}),
).await?;
println!("Read message: {}", result.msg_data.unwrap());
sourcepub async fn retrieve_message_container(
&mut self,
message_id: &str
) -> Result<RetrieveMessageContainerResult>
pub async fn retrieve_message_container(
&mut self,
message_id: &str
) -> Result<RetrieveMessageContainerResult>
Call Retrieve Message Container API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_message_container(
"o3muoTnnD6cXYyarYY38",
).await?;
if let Some(off_chain) = result.off_chain {
println!("IPFS CID of Catenis off-chain message envelope: {}", off_chain.cid);
}
if let Some(blockchain) = result.blockchain {
println!("ID of blockchain transaction containing the message: {}", blockchain.txid);
}
if let Some(external_storage) = result.external_storage {
println!("IPFS reference to message: {}", external_storage.ipfs);
}
sourcepub async fn retrieve_message_origin(
&self,
message_id: &str,
msg_to_sign: Option<&str>
) -> Result<RetrieveMessageOriginResult>
pub async fn retrieve_message_origin(
&self,
message_id: &str,
msg_to_sign: Option<&str>
) -> Result<RetrieveMessageOriginResult>
Call Retrieve Message Origin API method.
Note: this is a public API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_message_origin(
"o3muoTnnD6cXYyarYY38",
Some("Any text to be signed"),
).await?;
if let Some(tx) = result.tx {
println!("Catenis message transaction info: {:?}", tx);
}
if let Some(off_chain_msg_env) = result.off_chain_msg_envelope {
println!("Off-chain message envelope info: {:?}", off_chain_msg_env);
}
if let Some(proof) = result.proof {
println!("Origin proof info: {:?}", proof);
}
sourcepub async fn retrieve_message_progress(
&mut self,
message_id: &str
) -> Result<RetrieveMessageProgressResult>
pub async fn retrieve_message_progress(
&mut self,
message_id: &str
) -> Result<RetrieveMessageProgressResult>
Call Retrieve Message Progress API method.
Note: this method should be passed an ephemeral message ID: either a provisional message ID or a cached message ID.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_message_progress(
"pTZCgjKYEyHfu4rNPWct",
).await?;
println!("Number of bytes processed so far: {}", result.progress.bytes_processed);
if result.progress.done {
if let Some(true) = result.progress.success {
// Get result
println!("Asynchronous processing result: {:?}", result.result.unwrap());
} else {
// Process error
let error = result.progress.error.unwrap();
println!("Asynchronous processing error: [{}] - {}", error.code, error.message);
}
} else {
// Asynchronous processing not done yet. Continue pooling
}
sourcepub async fn list_messages(
&mut self,
options: Option<ListMessagesOptions>
) -> Result<ListMessagesResult>
pub async fn list_messages(
&mut self,
options: Option<ListMessagesOptions>
) -> Result<ListMessagesResult>
Call List Messages API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_messages(
Some(ListMessagesOptions {
action: Some(MessageActionOption::Send),
direction: Some(MessageDirectionOption::Inbound),
from_devices: None,
to_devices: None,
read_state: Some(MessageReadStateOption::Unread),
start_date: Some("2020-12-22T00:00:00Z".into()),
end_date: None,
limit: None,
skip: None,
}),
).await?;
if result.msg_count > 0 {
println!("Returned messages: {:?}", result.messages);
if result.has_more {
println!("Not all messages have been returned");
}
}
sourcepub async fn issue_asset(
&mut self,
asset_info: NewAssetInfo,
amount: f64,
holding_device: Option<DeviceId>
) -> Result<IssueAssetResult>
pub async fn issue_asset(
&mut self,
asset_info: NewAssetInfo,
amount: f64,
holding_device: Option<DeviceId>
) -> Result<IssueAssetResult>
Call Issue Asset API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.issue_asset(
NewAssetInfo {
name: String::from("XYZ001"),
description: Some(String::from("My first test asset")),
can_reissue: true,
decimal_places: 2,
},
1_500.0,
None,
).await?;
println!("ID of newly issued asset: {}", result.asset_id);
sourcepub async fn reissue_asset(
&mut self,
asset_id: &str,
amount: f64,
holding_device: Option<DeviceId>
) -> Result<ReissueAssetResult>
pub async fn reissue_asset(
&mut self,
asset_id: &str,
amount: f64,
holding_device: Option<DeviceId>
) -> Result<ReissueAssetResult>
Call Reissue Asset API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.reissue_asset(
"aBy2ovnucyWaSB6Tro9x",
650.25,
Some(DeviceId {
id: String::from("d8YpQ7jgPBJEkBrnvp58"),
is_prod_unique_id: None,
}),
).await?;
println!("Total existent asset balance (after issuance): {}", result.total_existent_balance);
sourcepub async fn transfer_asset(
&mut self,
asset_id: &str,
amount: f64,
receiving_device: DeviceId
) -> Result<TransferAssetResult>
pub async fn transfer_asset(
&mut self,
asset_id: &str,
amount: f64,
receiving_device: DeviceId
) -> Result<TransferAssetResult>
Call Transfer Asset API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.transfer_asset(
"aBy2ovnucyWaSB6Tro9x",
50.75,
DeviceId {
id: String::from("d8YpQ7jgPBJEkBrnvp58"),
is_prod_unique_id: None,
},
).await?;
println!("Remaining asset balance: {}", result.remaining_balance);
sourcepub async fn retrieve_asset_info(
&mut self,
asset_id: &str
) -> Result<RetrieveAssetInfoResult>
pub async fn retrieve_asset_info(
&mut self,
asset_id: &str
) -> Result<RetrieveAssetInfoResult>
Call Retrieve Asset Info API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_asset_info(
"aBy2ovnucyWaSB6Tro9x",
).await?;
println!("Asset info: {:?}", result);
sourcepub async fn get_asset_balance(
&mut self,
asset_id: &str
) -> Result<GetAssetBalanceResult>
pub async fn get_asset_balance(
&mut self,
asset_id: &str
) -> Result<GetAssetBalanceResult>
Call Get Asset Balance API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.get_asset_balance(
"aBy2ovnucyWaSB6Tro9x",
).await?;
println!("Current asset balance: {}", result.total);
println!("Amount not yet confirmed: {}", result.unconfirmed);
sourcepub async fn list_owned_assets(
&mut self,
limit: Option<u16>,
skip: Option<usize>
) -> Result<ListOwnedAssetsResult>
pub async fn list_owned_assets(
&mut self,
limit: Option<u16>,
skip: Option<usize>
) -> Result<ListOwnedAssetsResult>
Call List Owned Assets API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_owned_assets(
Some(200),
Some(0),
).await?;
for owned_asset in result.owned_assets {
println!("Asset ID: {}", owned_asset.asset_id);
println!(" - current asset balance: {}", owned_asset.balance.total);
println!(" - amount not yet confirmed: {}\n", owned_asset.balance.unconfirmed);
}
if result.has_more {
println!("Not all owned assets have been returned");
}
sourcepub async fn list_issued_assets(
&mut self,
limit: Option<u16>,
skip: Option<usize>
) -> Result<ListIssuedAssetsResult>
pub async fn list_issued_assets(
&mut self,
limit: Option<u16>,
skip: Option<usize>
) -> Result<ListIssuedAssetsResult>
Call List Issued Assets API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_issued_assets(
Some(200),
Some(0),
).await?;
for issued_asset in result.issued_assets {
println!("Asset ID: {}", issued_asset.asset_id);
println!(" - total existent balance: {}\n", issued_asset.total_existent_balance);
}
if result.has_more {
println!("Not all issued assets have been returned");
}
sourcepub async fn retrieve_asset_issuance_history(
&mut self,
asset_id: &str,
start_date: Option<UtcDateTime>,
end_date: Option<UtcDateTime>,
limit: Option<u16>,
skip: Option<usize>
) -> Result<RetrieveAssetIssuanceHistoryResult>
pub async fn retrieve_asset_issuance_history(
&mut self,
asset_id: &str,
start_date: Option<UtcDateTime>,
end_date: Option<UtcDateTime>,
limit: Option<u16>,
skip: Option<usize>
) -> Result<RetrieveAssetIssuanceHistoryResult>
Call Retrieve Asset Issuance History API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_asset_issuance_history(
"aBy2ovnucyWaSB6Tro9x",
Some("2020-12-01T00:00:00Z".into()),
None,
Some(200),
Some(0),
).await?;
for issuance_event in result.issuance_events {
match issuance_event {
AssetIssuanceEventEntry::Regular(regular_asset_event) => {
println!("Issuance date: {}", regular_asset_event.date);
println!(" - issued amount: {}", regular_asset_event.amount);
println!(
" - device to which issued amount had been assigned: {:?}\n",
regular_asset_event.holding_device
);
}
AssetIssuanceEventEntry::NonFungible(non_fungible_asset_event) => {
println!("Issuance date: {}", non_fungible_asset_event.date);
println!(" - IDs of issued non-fungible tokens: {:?}", non_fungible_asset_event.nf_token_ids);
println!(
" - devices to which issued non-fungible tokens have been assigned: {:?}\n",
non_fungible_asset_event.holding_devices
);
}
}
}
if result.has_more {
println!("Not all asset issuance events have been returned");
}
sourcepub async fn list_asset_holders(
&mut self,
asset_id: &str,
limit: Option<u16>,
skip: Option<usize>
) -> Result<ListAssetHoldersResult>
pub async fn list_asset_holders(
&mut self,
asset_id: &str,
limit: Option<u16>,
skip: Option<usize>
) -> Result<ListAssetHoldersResult>
Call List Asset Holders API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_asset_holders(
"aBy2ovnucyWaSB6Tro9x",
Some(200),
Some(0),
).await?;
for asset_holder in result.asset_holders {
if let Some(holder) = asset_holder.holder {
println!("Asset holder ID: {}", holder.device_id);
println!(" - detailed holder info: {:?}", holder);
println!(
" - amount of asset currently held by device: {}",
asset_holder.balance.total
);
println!(" - amount not yet confirmed: {}\n", asset_holder.balance.unconfirmed);
} else {
println!("Migrated asset:");
println!(" - total migrated amount: {}", asset_holder.balance.total);
println!(" - amount not yet confirmed: {}", asset_holder.balance.unconfirmed);
}
}
if result.has_more {
println!("Not all asset holders have been returned");
}
sourcepub async fn export_asset(
&mut self,
asset_id: &str,
foreign_blockchain: ForeignBlockchain,
token: NewForeignTokenInfo,
options: Option<ExportAssetOptions>
) -> Result<ExportAssetResult>
pub async fn export_asset(
&mut self,
asset_id: &str,
foreign_blockchain: ForeignBlockchain,
token: NewForeignTokenInfo,
options: Option<ExportAssetOptions>
) -> Result<ExportAssetResult>
Call Export Asset API method.
Examples
Estimate export cost (in foregin blockchain’s native coin):
use catenis_api_client::{
api::*,
};
let result = ctn_client.export_asset(
"aH2AkrrL55GcThhPNa3J",
ForeignBlockchain::Ethereum,
NewForeignTokenInfo {
name: String::from("Catenis test token #10"),
symbol: String::from("CTK10"),
},
Some(ExportAssetOptions {
consumption_profile: None,
estimate_only: Some(true),
}),
).await?;
println!(
"Estimated foreign blockchain transaction execution price: {}",
result.estimated_price.unwrap()
);
Export asset:
use catenis_api_client::{
api::*,
};
let result = ctn_client.export_asset(
"aH2AkrrL55GcThhPNa3J",
ForeignBlockchain::Ethereum,
NewForeignTokenInfo {
name: String::from("Catenis test token #10"),
symbol: String::from("CTK10"),
},
None,
).await?;
println!("Pending asset export: {:?}", result);
// Start polling for asset export outcome
sourcepub async fn migrate_asset(
&mut self,
asset_id: &str,
foreign_blockchain: ForeignBlockchain,
migration: AssetMigration,
options: Option<MigrateAssetOptions>
) -> Result<MigrateAssetResult>
pub async fn migrate_asset(
&mut self,
asset_id: &str,
foreign_blockchain: ForeignBlockchain,
migration: AssetMigration,
options: Option<MigrateAssetOptions>
) -> Result<MigrateAssetResult>
Call Migrate Asset API method.
Examples
Estimate migration cost (in foreign blockchain’s native coin):
use catenis_api_client::{
api::*,
};
let result = ctn_client.migrate_asset(
"aH2AkrrL55GcThhPNa3J",
ForeignBlockchain::Ethereum,
AssetMigration::Info(AssetMigrationInfo {
direction: AssetMigrationDirection::Outward,
amount: 50.0,
dest_address: Some(String::from("0xe247c9BfDb17e7D8Ae60a744843ffAd19C784943")),
}),
Some(MigrateAssetOptions {
consumption_profile: None,
estimate_only: Some(true),
}),
).await?;
println!(
"Estimated foreign blockchain transaction execution price: {}",
result.estimated_price.unwrap()
);
Migrate asset:
use catenis_api_client::{
api::*,
};
let result = ctn_client.migrate_asset(
"aH2AkrrL55GcThhPNa3J",
ForeignBlockchain::Ethereum,
AssetMigration::Info(AssetMigrationInfo {
direction: AssetMigrationDirection::Outward,
amount: 50.0,
dest_address: Some(String::from("0xe247c9BfDb17e7D8Ae60a744843ffAd19C784943")),
}),
None,
).await?;
println!("Pending asset migration: {:?}", result);
// Start polling for asset migration outcome
Reprocess a (failed) migration:
use catenis_api_client::{
api::*,
};
let result = ctn_client.migrate_asset(
"aH2AkrrL55GcThhPNa3J",
ForeignBlockchain::Ethereum,
AssetMigration::ID(String::from("gq8x3efLpEXTkGQchHTb")),
None,
).await?;
println!("Pending asset migration: {:?}", result);
// Start polling for asset migration outcome
sourcepub async fn asset_export_outcome(
&mut self,
asset_id: &str,
foreign_blockchain: ForeignBlockchain
) -> Result<AssetExportOutcomeResult>
pub async fn asset_export_outcome(
&mut self,
asset_id: &str,
foreign_blockchain: ForeignBlockchain
) -> Result<AssetExportOutcomeResult>
Call Asset Export Outcome API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.asset_export_outcome(
"aH2AkrrL55GcThhPNa3J",
ForeignBlockchain::Ethereum,
).await?;
match result.status {
AssetExportStatus::Success => {
// Asset successfully exported
println!("Foreign token ID (address): {}", result.token.id.unwrap());
},
AssetExportStatus::Pending => {
// Final asset export state not yet reached
},
AssetExportStatus::Error => {
// Asset export has failed. Process error
println!(
"Error executing foreign blockchain transaction: {}",
result.foreign_transaction.error.unwrap()
);
},
}
sourcepub async fn asset_migration_outcome(
&mut self,
migration_id: &str
) -> Result<AssetMigrationOutcomeResult>
pub async fn asset_migration_outcome(
&mut self,
migration_id: &str
) -> Result<AssetMigrationOutcomeResult>
Call Asset Migration Outcome API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.asset_migration_outcome(
"gq8x3efLpEXTkGQchHTb",
).await?;
match result.status {
AssetMigrationStatus::Success => {
// Asset amount successfully migrated
println!("Asset amount successfully migrated");
},
AssetMigrationStatus::Pending => {
// Final asset migration state not yet reached
},
_ => {
// Asset migration has failed. Process error
if let Some(error) = result.catenis_service.error {
println!("Error executing Catenis service: {}", error);
}
if let Some(error) = result.foreign_transaction.error {
println!("Error executing foreign blockchain transaction: {}", error);
}
},
}
sourcepub async fn list_exported_assets(
&mut self,
options: Option<ListExportedAssetsOptions>
) -> Result<ListExportedAssetsResult>
pub async fn list_exported_assets(
&mut self,
options: Option<ListExportedAssetsOptions>
) -> Result<ListExportedAssetsResult>
Call List Exported Assets API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_exported_assets(
Some(ListExportedAssetsOptions {
asset_id: None,
foreign_blockchain: Some(ForeignBlockchain::Ethereum),
token_symbol: None,
status: Some(vec![AssetExportStatus::Success]),
negate_status: None,
start_date: Some("2021-08-01T00:00:00Z".into()),
end_date: None,
limit: None,
skip: None,
}),
).await?;
if result.exported_assets.len() > 0 {
println!("Returned asset exports: {:?}", result.exported_assets);
if result.has_more {
println!("Not all asset exports have been returned");
}
}
sourcepub async fn list_asset_migrations(
&mut self,
options: Option<ListAssetMigrationsOptions>
) -> Result<ListAssetMigrationsResult>
pub async fn list_asset_migrations(
&mut self,
options: Option<ListAssetMigrationsOptions>
) -> Result<ListAssetMigrationsResult>
Call List Asset Migrations API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_asset_migrations(
Some(ListAssetMigrationsOptions {
asset_id: None,
foreign_blockchain: Some(ForeignBlockchain::Ethereum),
direction: Some(AssetMigrationDirection::Outward),
status: Some(vec![
AssetMigrationStatus::Interrupted,
AssetMigrationStatus::Error,
]),
negate_status: None,
start_date: Some("2021-08-01T00:00:00Z".into()),
end_date: None,
limit: None,
skip: None,
}),
).await?;
if result.asset_migrations.len() > 0 {
println!("Returned asset migrations: {:?}", result.asset_migrations);
if result.has_more {
println!("Not all asset migrations have been returned");
}
}
sourcepub async fn list_permission_events(
&mut self
) -> Result<ListPermissionEventsResult>
pub async fn list_permission_events(
&mut self
) -> Result<ListPermissionEventsResult>
Call List Permission Events API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_permission_events().await?;
for (event, description) in result {
println!("Permission event: {} - {}", event.to_string(), description);
}
sourcepub async fn retrieve_permission_rights(
&mut self,
event: PermissionEvent
) -> Result<RetrievePermissionRightsResult>
pub async fn retrieve_permission_rights(
&mut self,
event: PermissionEvent
) -> Result<RetrievePermissionRightsResult>
Call Retrieve Permission Rights API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_permission_rights(
PermissionEvent::ReceiveMsg,
).await?;
println!("Default (system) permission right: {:?}", result.system);
if let Some(rights_setting) = result.catenis_node {
if let Some(catenis_node_idxs) = rights_setting.allow {
println!(
"Index of Catenis nodes to which permission is granted: {:?}",
catenis_node_idxs
);
}
if let Some(catenis_node_idxs) = rights_setting.deny {
println!(
"Index of Catenis nodes to which permission is not granted: {:?}",
catenis_node_idxs
);
}
}
if let Some(rights_setting) = result.client {
if let Some(client_ids) = rights_setting.allow {
println!("ID of clients to which permission is granted: {:?}", client_ids);
}
if let Some(client_ids) = rights_setting.deny {
println!("ID of clients to which permission is not granted: {:?}", client_ids);
}
}
if let Some(rights_setting) = result.device {
if let Some(devices) = rights_setting.allow {
println!("Devices to which permission is granted: {:?}", devices);
}
if let Some(devices) = rights_setting.deny {
println!("Devices to which permission is not granted: {:?}", devices);
}
}
sourcepub async fn set_permission_rights(
&mut self,
event: PermissionEvent,
rights: AllPermissionRightsUpdate
) -> Result<SetPermissionRightsResult>
pub async fn set_permission_rights(
&mut self,
event: PermissionEvent,
rights: AllPermissionRightsUpdate
) -> Result<SetPermissionRightsResult>
Call Set Permission Rights API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.set_permission_rights(
PermissionEvent::ReceiveMsg,
AllPermissionRightsUpdate {
system: Some(PermissionRight::Deny),
catenis_node: Some(PermissionRightsUpdate {
allow: Some(vec![
String::from("self"),
]),
deny: None,
none: None,
}),
client: Some(PermissionRightsUpdate {
allow: Some(vec![
String::from("self"),
String::from("c3gBoX45xk3yAmenyDRD"),
]),
deny: None,
none: None,
}),
device: Some(DevicePermissionRightsUpdate {
allow: None,
deny: Some(vec![
DeviceId {
id: String::from("self"),
is_prod_unique_id: None,
},
DeviceId {
id: String::from("ABCD001"),
is_prod_unique_id: Some(true),
},
]),
none: None,
}),
},
).await?;
println!("Permission rights successfully set");
sourcepub async fn check_effective_permission_right(
&mut self,
event: PermissionEvent,
device: DeviceId
) -> Result<CheckEffectivePermissionRightResult>
pub async fn check_effective_permission_right(
&mut self,
event: PermissionEvent,
device: DeviceId
) -> Result<CheckEffectivePermissionRightResult>
Call Check Effective Permission Right API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.check_effective_permission_right(
PermissionEvent::ReceiveMsg,
DeviceId {
id: String::from("d8YpQ7jgPBJEkBrnvp58"),
is_prod_unique_id: None,
},
).await?;
let (device_id, right) = result.iter().next().unwrap();
println!("Effective right for device {}: {:?}", device_id, right);
sourcepub async fn retrieve_device_identification_info(
&mut self,
device: DeviceId
) -> Result<RetrieveDeviceIdentificationInfoResult>
pub async fn retrieve_device_identification_info(
&mut self,
device: DeviceId
) -> Result<RetrieveDeviceIdentificationInfoResult>
Call Retrieve Device Identification Info API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_device_identification_info(
DeviceId {
id: String::from("self"),
is_prod_unique_id: None,
},
).await?;
println!("Device's Catenis node ID info: {:?}", result.catenis_node);
println!("Device's client ID info: {:?}", result.client);
println!("Device's own ID info: {:?}", result.device);
sourcepub async fn list_notification_events(
&mut self
) -> Result<ListNotificationEventsResult>
pub async fn list_notification_events(
&mut self
) -> Result<ListNotificationEventsResult>
Call List Notification Events API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.list_notification_events().await?;
for (event, description) in result {
println!("Notification event: {} - {}", event.to_string(), description);
}
sourcepub async fn issue_non_fungible_asset(
&mut self,
issuance_info_or_cont_token: NFAssetIssuanceInfoOrContToken,
non_fungible_tokens: Option<Vec<Option<NewNonFungibleTokenInfo>>>,
is_final: Option<bool>
) -> Result<IssueNonFungibleAssetResult>
pub async fn issue_non_fungible_asset(
&mut self,
issuance_info_or_cont_token: NFAssetIssuanceInfoOrContToken,
non_fungible_tokens: Option<Vec<Option<NewNonFungibleTokenInfo>>>,
is_final: Option<bool>
) -> Result<IssueNonFungibleAssetResult>
Call Issue Non-Fungible Asset API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.issue_non_fungible_asset(
NFAssetIssuanceInfoOrContToken::IssuanceInfo(NonFungibleAssetIssuanceInfo {
asset_info: Some(NewNonFungibleAssetInfo {
name: String::from("Catenis NFA 1"),
description: Some(String::from("Non-fungible asset #1 for testing")),
can_reissue: true
}),
encrypt_nft_contents: None,
holding_devices: None,
async_: None,
}),
Some(vec![
Some(NewNonFungibleTokenInfo {
metadata: Some(NewNonFungibleTokenMetadata {
name: String::from("NFA1 NFT 1"),
description: Some(String::from("First token of non-fungible asset #1")),
custom: None,
}),
contents: Some(NewNonFungibleTokenContents {
data: String::from("Contents of first token of Catenis non-fungible asset #1"),
encoding: Encoding::UTF8
}),
}),
Some(NewNonFungibleTokenInfo {
metadata: Some(NewNonFungibleTokenMetadata {
name: String::from("NFA1 NFT 2"),
description: Some(String::from("Second token of non-fungible asset #1")),
custom: None,
}),
contents: Some(NewNonFungibleTokenContents {
data: String::from("Contents of second token of Catenis non-fungible asset #1"),
encoding: Encoding::UTF8
}),
}),
]),
Some(true)
).await?;
println!("ID of newly created non-fungible asset: {}", result.asset_id.unwrap());
println!("IDs of newly issued non-fungible tokens: {:?}", result.nf_token_ids.unwrap());
sourcepub async fn reissue_non_fungible_asset(
&mut self,
asset_id: &str,
reissuance_info_or_cont_token: NFAssetReissuanceInfoOrContToken,
non_fungible_tokens: Option<Vec<Option<NewNonFungibleTokenInfo>>>,
is_final: Option<bool>
) -> Result<ReissueNonFungibleAssetResult>
pub async fn reissue_non_fungible_asset(
&mut self,
asset_id: &str,
reissuance_info_or_cont_token: NFAssetReissuanceInfoOrContToken,
non_fungible_tokens: Option<Vec<Option<NewNonFungibleTokenInfo>>>,
is_final: Option<bool>
) -> Result<ReissueNonFungibleAssetResult>
Call Reissue Non-Fungible Asset API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.reissue_non_fungible_asset(
"ahfTzqgWAXnMR6Z57mcp",
NFAssetReissuanceInfoOrContToken::ReissuanceInfo(NonFungibleAssetReissuanceInfo {
encrypt_nft_contents: None,
holding_devices: None,
async_: None,
}),
Some(vec![
Some(NewNonFungibleTokenInfo {
metadata: Some(NewNonFungibleTokenMetadata {
name: String::from("NFA1 NFT 3"),
description: Some(String::from("Third token of non-fungible asset #1")),
custom: None,
}),
contents: Some(NewNonFungibleTokenContents {
data: String::from("Contents of third token of non-fungible asset #1"),
encoding: Encoding::UTF8
}),
}),
Some(NewNonFungibleTokenInfo {
metadata: Some(NewNonFungibleTokenMetadata {
name: String::from("NFA1 NFT 4"),
description: Some(String::from("Forth token of non-fungible asset #1")),
custom: None,
}),
contents: Some(NewNonFungibleTokenContents {
data: String::from("Contents of forth token of non-fungible asset #1"),
encoding: Encoding::UTF8
}),
}),
]),
Some(true)
).await?;
println!("IDs of newly issued non-fungible tokens: {:?}", result.nf_token_ids.unwrap());
sourcepub async fn retrieve_non_fungible_asset_issuance_progress(
&mut self,
issuance_id: &str
) -> Result<RetrieveNFAssetIssuanceProgressResult>
pub async fn retrieve_non_fungible_asset_issuance_progress(
&mut self,
issuance_id: &str
) -> Result<RetrieveNFAssetIssuanceProgressResult>
Call Retrieve Non-Fungible Asset Issuance Progress API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_non_fungible_asset_issuance_progress(
"iWWKqTx6svmErabyCZKM",
).await?;
if let Some(asset_id) = result.asset_id {
println!("Reissuance for non-fungible asset: {}", asset_id);
}
println!("Percent processed: {}", result.progress.percent_processed.to_string());
if result.progress.done {
if let Some(true) = result.progress.success {
// Get result
let issuance_result = result.result.unwrap();
if let Some(asset_id) = issuance_result.asset_id {
println!("ID of newly created non-fungible asset: {}", asset_id);
}
println!("IDs of newly issued non-fungible tokens:: {:?}", issuance_result.nf_token_ids);
} else {
// Process error
let error = result.progress.error.unwrap();
println!("Asynchronous processing error: [{}] - {}", error.code, error.message);
}
} else {
// Asynchronous processing not done yet. Continue pooling
}
sourcepub async fn retrieve_non_fungible_token(
&mut self,
token_id: &str,
options: Option<RetrieveNonFungibleTokenOptions>
) -> Result<RetrieveNonFungibleTokenResult>
pub async fn retrieve_non_fungible_token(
&mut self,
token_id: &str,
options: Option<RetrieveNonFungibleTokenOptions>
) -> Result<RetrieveNonFungibleTokenResult>
Call Retrieve Non-Fungible Token API method.
Example
use catenis_api_client::{
api::*,
};
#[derive(Debug, Clone, Eq, PartialEq)]
struct NFTokenData {
pub asset_id: Option<String>,
pub metadata: Option<NonFungibleTokenMetadata>,
pub contents: Option<Vec<String>>,
}
let mut retrieve_options = RetrieveNonFungibleTokenOptions {
retrieve_contents: None,
contents_only: None,
contents_encoding: None,
data_chunk_size: Some(1024),
async_: None,
continuation_token: None,
};
let mut nf_token_data = NFTokenData {
asset_id: None,
metadata: None,
contents: None,
};
let mut nf_token_contents = vec![];
loop {
let is_init_call = retrieve_options.continuation_token.is_none();
let result = ctn_client.retrieve_non_fungible_token("tDGQpGy627J6uAw4grYq", retrieve_options.into()).await?;
if let Some(nf_token) = result.non_fungible_token {
if is_init_call {
// Initial call. Get the token data
nf_token_data.asset_id = nf_token.asset_id;
nf_token_data.metadata = nf_token.metadata;
if let Some(nft_contents) = nf_token.contents {
nf_token_contents.push(nft_contents.data);
}
} else if let Some(nft_contents) = nf_token.contents {
// Add next contents part to token data
nf_token_contents.push(nft_contents.data);
}
}
if result.continuation_token.is_some() {
// Whole contents data not yet retrieved. Prepare to get next part
retrieve_options = RetrieveNonFungibleTokenOptions {
retrieve_contents: None,
contents_only: None,
contents_encoding: None,
data_chunk_size: None,
async_: None,
continuation_token: result.continuation_token,
};
} else {
break;
}
}
if nf_token_contents.len() > 0 {
nf_token_data.contents = Some(nf_token_contents);
}
println!("Non-fungible token data: {:?}", nf_token_data);
sourcepub async fn retrieve_non_fungible_token_retrieval_progress(
&mut self,
token_id: &str,
retrieval_id: &str
) -> Result<RetrieveNFTokenRetrievalProgressResult>
pub async fn retrieve_non_fungible_token_retrieval_progress(
&mut self,
token_id: &str,
retrieval_id: &str
) -> Result<RetrieveNFTokenRetrievalProgressResult>
Call Retrieve Non-Fungible Token Retrieval Progress API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_non_fungible_token_retrieval_progress(
"tDGQpGy627J6uAw4grYq",
"rGEcL2HhoarCupvbkrv9",
).await?;
println!("Bytes already retrieved: {}", result.progress.bytes_retrieved.to_string());
if result.progress.done {
if let Some(true) = result.progress.success {
// Finish retrieving the non-fungible token data
let result2 = ctn_client.retrieve_non_fungible_token(
"tDGQpGy627J6uAw4grYq",
Some(RetrieveNonFungibleTokenOptions {
retrieve_contents: None,
contents_only: None,
contents_encoding: None,
data_chunk_size: None,
async_: None,
continuation_token: result.continuation_token,
}),
).await?;
// Display result
println!("Non-fungible token data: {:?}", result2);
} else {
// Process error
let error = result.progress.error.unwrap();
println!("Asynchronous processing error: [{}] - {}", error.code, error.message);
}
} else {
// Asynchronous processing not done yet. Continue pooling
}
sourcepub async fn transfer_non_fungible_token(
&mut self,
token_id: &str,
receiving_device: DeviceId,
async_: Option<bool>
) -> Result<TransferNonFungibleTokenResult>
pub async fn transfer_non_fungible_token(
&mut self,
token_id: &str,
receiving_device: DeviceId,
async_: Option<bool>
) -> Result<TransferNonFungibleTokenResult>
Call Transfer Non-Fungible Token API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.transfer_non_fungible_token(
"tDGQpGy627J6uAw4grYq",
DeviceId {
id: String::from("d8YpQ7jgPBJEkBrnvp58"),
is_prod_unique_id: None,
},
None,
).await?;
println!("Non-fungible token successfully transferred");
sourcepub async fn retrieve_non_fungible_token_transfer_progress(
&mut self,
token_id: &str,
transfer_id: &str
) -> Result<RetrieveNFTokenTransferProgressResult>
pub async fn retrieve_non_fungible_token_transfer_progress(
&mut self,
token_id: &str,
transfer_id: &str
) -> Result<RetrieveNFTokenTransferProgressResult>
Call Retrieve Non-Fungible Token Transfer Progress API method.
Example
use catenis_api_client::{
api::*,
};
let result = ctn_client.retrieve_non_fungible_token_transfer_progress(
"tDGQpGy627J6uAw4grYq",
"xuYnPMKQSBXi28wRaZpN",
).await?;
println!("Current data manipulation: {:?}", result.progress.data_manipulation);
if result.progress.done {
if let Some(true) = result.progress.success {
// Display result
println!("Non-fungible token successfully transferred");
} else {
// Process error
let error = result.progress.error.unwrap();
println!("Asynchronous processing error: [{}] - {}", error.code, error.message);
}
} else {
// Asynchronous processing not done yet. Continue pooling
}
Trait Implementations
sourceimpl Clone for CatenisClient
impl Clone for CatenisClient
sourcefn clone(&self) -> CatenisClient
fn clone(&self) -> CatenisClient
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more