use std::fs::read;
use async_std::stream::StreamExt;
#[allow(unused_imports)]
use nextgraph::local_broker::{
app_request, app_request_stream, doc_fetch_repo_subscribe, doc_sparql_update,
init_local_broker, session_start, session_stop, user_connect, user_disconnect, wallet_close,
wallet_create_v0, wallet_get, wallet_get_file, wallet_import, wallet_open_with_mnemonic_words,
wallet_read_file, wallet_was_opened, LocalBrokerConfig, SessionConfig,
};
use nextgraph::net::types::BootstrapContentV0;
use nextgraph::repo::errors::NgError;
use nextgraph::repo::log::*;
use nextgraph::repo::types::PubKey;
use nextgraph::wallet::types::CreateWalletV0;
use nextgraph::wallet::{display_mnemonic, emojis::display_pazzle};
#[async_std::main]
async fn main() -> std::io::Result<()> {
init_local_broker(Box::new(|| LocalBrokerConfig::InMemory)).await;
let wallet_file =
read("/Users/nl/Downloads/wallet-Hr-UITwGtjE1k6lXBoVGzD4FQMiDkM3T6bSeAi9PXt4A.ngw")
.expect("read wallet file");
let wallet = wallet_read_file(wallet_file).await?;
let mnemonic_words = vec![
"jealous".to_string(),
"during".to_string(),
"elevator".to_string(),
"swallow".to_string(),
"pen".to_string(),
"phone".to_string(),
"like".to_string(),
"employ".to_string(),
"myth".to_string(),
"remember".to_string(),
"question".to_string(),
"lemon".to_string(),
];
let opened_wallet = wallet_open_with_mnemonic_words(&wallet, &mnemonic_words, [2, 3, 2, 3])?;
let user_id = opened_wallet.personal_identity();
let wallet_name = opened_wallet.name();
let client = wallet_import(wallet.clone(), opened_wallet, true).await?;
let session = session_start(SessionConfig::new_in_memory(&user_id, &wallet_name)).await?;
let status = user_connect(&user_id).await?;
let result = doc_sparql_update(
session.session_id,
"INSERT DATA { <did:ng:_> <example:predicate> \"An example value10\". }".to_string(),
Some("did:ng:o:Dn0QpE9_4jhta1mUWRl_LZh1SbXUkXfOB5eu38PNIk4A:v:Z4ihjV3KMVIqBxzjP6hogVLyjkZunLsb7MMsCR0kizQA".to_string()),
)
.await;
log_debug!("{:?}", result);
user_disconnect(&user_id).await?;
session_stop(&user_id).await?;
wallet_close(&wallet_name).await?;
Ok(())
}