Skip to content

Commit

Permalink
Use IdentityBuilder in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Oct 21, 2021
1 parent 08ada09 commit 3d1b716
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
5 changes: 1 addition & 4 deletions examples/account/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use identity::account::Account;
use identity::account::AccountBuilder;
use identity::account::AccountStorage;
use identity::account::AutoSave;
use identity::account::IdentityCreate;
use identity::account::Result;
use identity::iota::IotaDID;
use identity::iota::Network;
Expand Down Expand Up @@ -55,10 +54,8 @@ async fn main() -> Result<()> {

// Create an identity specifically on the devnet by passing `network_name`
// The same applies if we wanted to create an identity on a private tangle
let id_create = IdentityCreate::new().network(network_name)?;

// Create a new Identity with the network name set.
let identity: Account = match builder.create_identity(id_create).await {
let identity: Account = match builder.create_identity().network(network_name)?.build().await {
Ok(identity) => identity,
Err(err) => {
eprintln!("[Example] Error: {:?} {}", err, err.to_string());
Expand Down
4 changes: 2 additions & 2 deletions examples/account/create_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::path::PathBuf;

use identity::account::Account;
use identity::account::AccountStorage;
use identity::account::IdentityCreate;
use identity::account::Result;
use identity::iota::IotaDID;

Expand All @@ -28,7 +27,8 @@ async fn main() -> Result<()> {
// and publishes it to the IOTA mainnet.
let account: Account = Account::builder()
.storage(AccountStorage::Stronghold(stronghold_path, Some(password)))
.create_identity(IdentityCreate::default())
.create_identity()
.build()
.await?;

// Retrieve the did of the newly created identity.
Expand Down
5 changes: 2 additions & 3 deletions examples/account/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::path::PathBuf;

use identity::account::Account;
use identity::account::AccountStorage;
use identity::account::IdentityCreate;
use identity::account::Result;
use identity::core::Url;
use identity::iota::IotaDID;
Expand All @@ -24,8 +23,8 @@ async fn main() -> Result<()> {
// Rather, when we publish, multiple updates are batched together.
let mut account: Account = Account::builder()
.storage(AccountStorage::Stronghold(stronghold_path, Some(password)))
.autopublish(false)
.create_identity(IdentityCreate::default())
.create_identity()
.build()
.await?;

// Add a new service to the local DID document.
Expand Down
4 changes: 2 additions & 2 deletions examples/account/manipulate_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::path::PathBuf;

use identity::account::Account;
use identity::account::AccountStorage;
use identity::account::IdentityCreate;
use identity::account::Result;
use identity::core::Url;
use identity::did::MethodScope;
Expand All @@ -28,7 +27,8 @@ async fn main() -> Result<()> {
// Create a new Account with the default configuration
let mut account: Account = Account::builder()
.storage(AccountStorage::Stronghold(stronghold_path, Some(password)))
.create_identity(IdentityCreate::default())
.create_identity()
.build()
.await?;

// ===========================================================================
Expand Down
4 changes: 2 additions & 2 deletions examples/account/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::path::PathBuf;

use identity::account::Account;
use identity::account::AccountStorage;
use identity::account::IdentityCreate;
use identity::account::Result;
use identity::core::json;
use identity::core::FromJson;
Expand All @@ -33,7 +32,8 @@ async fn main() -> Result<()> {
// Create a new Account with stronghold storage.
let mut account: Account = Account::builder()
.storage(AccountStorage::Stronghold(stronghold_path, Some(password)))
.create_identity(IdentityCreate::default())
.create_identity()
.build()
.await?;

// ===========================================================================
Expand Down
7 changes: 3 additions & 4 deletions identity-account/src/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use identity_iota::did::IotaDID;
use crate::account::Account;
use crate::account::AccountBuilder;
use crate::error::Result;
use crate::identity::IdentityCreate;

#[tokio::test]
async fn test_account_high_level() -> Result<()> {
let mut builder: AccountBuilder = AccountBuilder::default().testmode(true);

let account1: Account = builder.create_identity(IdentityCreate::default()).await?;
let account1: Account = builder.create_identity().build().await?;

builder = builder.autopublish(false);

let account2: Account = builder.create_identity(IdentityCreate::default()).await?;
let account2: Account = builder.create_identity().build().await?;

assert!(account1.autopublish());
assert!(!account2.autopublish());
Expand All @@ -40,7 +39,7 @@ async fn test_account_did_lease() -> Result<()> {
let mut builder: AccountBuilder = AccountBuilder::default().testmode(true);

let did: IotaDID = {
let account: Account = builder.create_identity(IdentityCreate::default()).await?;
let account: Account = builder.create_identity().build().await?;
account.did().to_owned()
}; // <-- Lease released here.

Expand Down

0 comments on commit 3d1b716

Please sign in to comment.