Skip to content

Commit

Permalink
Update iota.rs rev and participation error handling (#1813)
Browse files Browse the repository at this point in the history
* Update iota.rs rev and participation error handling

* Bump client rev

* Address review comments

* More changelog
  • Loading branch information
Thoralf-M authored Feb 7, 2023
1 parent a83f64d commit a90f869
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 59 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Memory` and `Wasm` storage adapters;
- `ParticipationEventWithNodes`;
- Support for target `wasm32-unknown-unknown`;
- `Error::Participation`;

### Changed

Expand All @@ -59,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Message::{GetAccount, VerifyMnemonic, SetClientOptions, SetStrongholdPassword, SetStrongholdPasswordClearInterval, StoreMnemonic, EmitTestEvent, Bech32ToHex, ClearListeners}` to named fields for better error messages;
- Made `AccountManager::stop_background_syncing()` async to await until syncing actually stopped;
- `OutputData::input_signing_data` returns `Result<Option<InputSigningData>>` instead of `Result<InputSigningData>>`;
- `OutputData::input_signing_data` accepts `Option<AliasTransition>` instead of `bool`;

### Removed

Expand All @@ -72,6 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Stop endlessly requesting inaccessible incoming transactions;
- Update addresses when a client config with a different HRP is passed;
- Return client errors from `Account::get_participation_overview()`;

## 1.0.0-rc.4 - 2022-12-23

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fern-logger = { version = "0.5.0", default-features = false }
futures = { version = "0.3.25", default-features = false }
getset = { version = "0.1.2", default-features = false }
# iota-client = { version = "2.0.1-rc.5", default-features = false, features = [ "message_interface", "tls" ] }
iota-client = { git = "https://github.com/iotaledger/iota.rs", rev = "767eb0e3d2e3ac7a4653a736b5ca20f8ff0b3dd1", default-features = false, features = [ "message_interface", "tls" ] }
iota-client = { git = "https://github.com/iotaledger/iota.rs", rev = "59cf0dd10ced608aab55913bbc261c3765e618f2", default-features = false, features = [ "message_interface", "tls" ] }
iota-crypto = { version = "0.15.3", default-features = false, features = [ "std", "chacha", "blake2b", "ed25519", "random", "slip10", "bip39", "bip39-en" ] }
log = { version = "0.4.17", default-features = false }
packable = { version = "0.7.0", default-features = false, features = [ "serde", "primitive-types" ] }
Expand Down
10 changes: 5 additions & 5 deletions bindings/nodejs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 45 additions & 3 deletions bindings/python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/participation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::{env, str::FromStr};

use dotenv::dotenv;
use iota_client::{
node_api::participation::types::ParticipationEventId, node_manager::node::Node, request_funds_from_faucet, Url,
api_types::plugins::participation::types::ParticipationEventId, node_manager::node::Node,
request_funds_from_faucet, Url,
};
use iota_wallet::{
account_manager::AccountManager,
Expand Down
2 changes: 1 addition & 1 deletion src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{

use getset::{Getters, Setters};
use iota_client::{
api_types::response::OutputWithMetadataResponse,
api_types::core::response::OutputWithMetadataResponse,
block::{
output::{FoundryId, FoundryOutput, OutputId},
payload::{
Expand Down
13 changes: 6 additions & 7 deletions src/account/operations/helpers/time.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota_client::block::address::Address;
use iota_client::block::{address::Address, output::AliasTransition};

use crate::account::types::{AddressWithUnspentOutputs, OutputData};

Expand All @@ -13,19 +13,18 @@ pub(crate) fn can_output_be_unlocked_now(
alias_and_nft_addresses: &[Address],
output_data: &OutputData,
current_time: u32,
alias_state_transition: bool,
alias_transition: Option<AliasTransition>,
) -> crate::Result<bool> {
if let Some(unlock_conditions) = output_data.output.unlock_conditions() {
if unlock_conditions.is_time_locked(current_time) {
return Ok(false);
}
}

let (required_unlock_address, _unlocked_alias_or_nft_address) = output_data.output.required_and_unlocked_address(
current_time,
&output_data.output_id,
alias_state_transition,
)?;
let (required_unlock_address, _unlocked_alias_or_nft_address) =
output_data
.output
.required_and_unlocked_address(current_time, &output_data.output_id, alias_transition)?;

Ok(account_addresses
.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/account/operations/output_claiming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl AccountHandle {
output,
local_time,
// Not relevant without alias addresses
true,
None,
)?
{
match outputs_to_claim {
Expand Down Expand Up @@ -105,7 +105,7 @@ impl AccountHandle {
output,
local_time,
// Not relevant without alias addresses
true,
None,
)?
{
match outputs_to_claim {
Expand Down
2 changes: 1 addition & 1 deletion src/account/operations/output_consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl AccountHandle {
return Ok(false);
}

can_output_be_unlocked_now(account_addresses, &[], output_data, current_time, true)?
can_output_be_unlocked_now(account_addresses, &[], output_data, current_time, None)?
} else {
false
})
Expand Down
4 changes: 3 additions & 1 deletion src/account/operations/participation/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use std::collections::HashMap;

use iota_client::{
node_api::participation::types::{ParticipationEventId, ParticipationEventStatus, ParticipationEventType},
api_types::plugins::participation::types::{
ParticipationEventId, ParticipationEventStatus, ParticipationEventType,
},
node_manager::node::Node,
Client,
};
Expand Down
26 changes: 15 additions & 11 deletions src/account/operations/participation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ pub mod voting_power;
use std::collections::{hash_map::Entry, HashMap};

use iota_client::{
block::output::{unlock_condition::UnlockCondition, Output, OutputId},
node_api::participation::{
api_types::plugins::participation::{
responses::TrackedParticipation,
types::{participation::Participations, ParticipationEventData, ParticipationEventId, PARTICIPATION_TAG},
types::{ParticipationEventData, ParticipationEventId, Participations, PARTICIPATION_TAG},
},
block::output::{unlock_condition::UnlockCondition, Output, OutputId},
node_manager::node::Node,
Client,
};
Expand Down Expand Up @@ -97,17 +97,21 @@ impl AccountHandle {

let results = futures::future::try_join_all(tasks).await?;
for (result, output_data) in results {
if let Ok(status) = result {
for (event_id, participation) in status.participations {
match participations.entry(event_id) {
Entry::Vacant(entry) => {
entry.insert(HashMap::from([(output_data.output_id, participation)]));
}
Entry::Occupied(mut entry) => {
entry.get_mut().insert(output_data.output_id, participation);
match result {
Ok(status) => {
for (event_id, participation) in status.participations {
match participations.entry(event_id) {
Entry::Vacant(entry) => {
entry.insert(HashMap::from([(output_data.output_id, participation)]));
}
Entry::Occupied(mut entry) => {
entry.get_mut().insert(output_data.output_id, participation);
}
}
}
}
Err(iota_client::Error::NotFound(_)) => {}
Err(e) => return Err(crate::Error::Client(e.into())),
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/account/operations/participation/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

use iota_client::{
api_types::plugins::participation::types::{
Participation, ParticipationEventId, Participations, PARTICIPATION_TAG,
},
block::{
output::{
feature::{MetadataFeature, TagFeature},
BasicOutputBuilder, Feature,
},
payload::TaggedDataPayload,
},
node_api::participation::types::{
participation::{Participation, Participations},
ParticipationEventId, PARTICIPATION_TAG,
},
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion src/account/operations/participation/voting_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use iota_client::{
api_types::plugins::participation::types::{Participations, PARTICIPATION_TAG},
block::{
output::{
feature::{MetadataFeature, TagFeature},
Expand All @@ -10,7 +11,6 @@ use iota_client::{
},
payload::TaggedDataPayload,
},
node_api::participation::types::{participation::Participations, PARTICIPATION_TAG},
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion src/account/operations/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use iota_client::{
api_types::dto::LedgerInclusionStateDto,
api_types::core::dto::LedgerInclusionStateDto,
block::{
payload::{transaction::TransactionId, Payload},
Block, BlockId,
Expand Down
2 changes: 1 addition & 1 deletion src/account/operations/syncing/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{str::FromStr, time::Instant};

use crypto::keys::slip10::Chain;
use iota_client::{
api_types::response::OutputWithMetadataResponse,
api_types::core::response::OutputWithMetadataResponse,
block::{
input::Input,
output::{dto::OutputDto, Output, OutputId},
Expand Down
2 changes: 1 addition & 1 deletion src/account/operations/syncing/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use iota_client::{
api_types::dto::LedgerInclusionStateDto,
api_types::core::dto::LedgerInclusionStateDto,
block::{input::Input, output::OutputId, payload::transaction::TransactionEssence, BlockId},
Error as ClientError,
};
Expand Down
Loading

0 comments on commit a90f869

Please sign in to comment.