-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable lazy tangle updates in the
Account
(#377)
* Implement pushing unpublished commits to tangle * Improve methods added to the storage interface * Bail early if no commits to publish * Implement new storage methods for `Stronghold` * Implement clippy suggestions * Add lazy publish example * Add lazy publish test * Apply format * Replace `unwrap` with `?` * Implement a "network-resilient" test runner * Make identity updates thread-safe * Expand docs, fix nitpicks * Add lock to `publish_changes` * Return locks lazily in `get_lock` * Remove lock when deleting from index * Clone locks when cloning the index * Rename document to did in all examples * Fix spelling, docs, naming * Improve docs, simplify code * Add `IdentityLock` type * Rename `publish_changes` -> `publish_updates`
- Loading branch information
1 parent
d5d46dc
commit 60f70c9
Showing
15 changed files
with
454 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020-2021 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! cargo run --example account_lazy | ||
use identity::account::Account; | ||
use identity::account::Command; | ||
use identity::account::IdentityCreate; | ||
use identity::account::IdentitySnapshot; | ||
use identity::account::Result; | ||
use identity::core::Url; | ||
use identity::iota::IotaDID; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
pretty_env_logger::init(); | ||
|
||
// Create a new Account with auto publishing set to false. | ||
// This means updates are not pushed to the tangle automatically. | ||
// Rather, when we publish, multiple updates are batched together. | ||
let account: Account = Account::builder().autopublish(false).build().await?; | ||
|
||
// Create a new Identity with default settings. | ||
// The identity will only be written to the local storage - not published to the tangle. | ||
let snapshot: IdentitySnapshot = account.create_identity(IdentityCreate::default()).await?; | ||
|
||
// Retrieve the DID from the newly created Identity state. | ||
let did: &IotaDID = snapshot.identity().try_did()?; | ||
|
||
let command: Command = Command::create_service() | ||
.fragment("example-service") | ||
.type_("LinkedDomains") | ||
.endpoint(Url::parse("https://example.org")?) | ||
.finish()?; | ||
account.update_identity(did, command).await?; | ||
|
||
// Publish the newly created DID document, | ||
// including the new service, to the tangle. | ||
account.publish_updates(did).await?; | ||
|
||
// Add another service. | ||
let command: Command = Command::create_service() | ||
.fragment("another-service") | ||
.type_("LinkedDomains") | ||
.endpoint(Url::parse("https://example.org")?) | ||
.finish()?; | ||
account.update_identity(did, command).await?; | ||
|
||
// Delete the previously added service. | ||
let command: Command = Command::delete_service().fragment("example-service").finish()?; | ||
account.update_identity(did, command).await?; | ||
|
||
// Publish the updates as one message to the tangle. | ||
account.publish_updates(did).await?; | ||
|
||
// Resolve the document to confirm its consistency. | ||
let doc = account.resolve_identity(did).await?; | ||
|
||
println!("[Example] Document: {:#?}", doc); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.