Skip to content

Commit

Permalink
Merge branch '2.0' into feat/output-storage-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 authored Jan 16, 2024
2 parents 2e26ed1 + f80ba17 commit 15f0358
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions bindings/nodejs/lib/types/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export interface SyncOptions {
syncOnlyMostBasicOutputs?: boolean;
/** Sync native token foundries, so their metadata can be returned in the balance. Default: false. */
syncNativeTokenFoundries?: boolean;
/// Sync implicit accounts.
syncImplicitAccounts?: boolean;
}

/** Specifies what outputs should be synced for the ed25519 address from the wallet. */
Expand Down
1 change: 1 addition & 0 deletions bindings/nodejs/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export * from './units-helper';
export * from './utf8';
export * from './utils';
export * from '../types/utils';
Expand Down
20 changes: 12 additions & 8 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,23 @@ impl FromStr for OutputSelector {
pub async fn accounts_command(wallet: &Wallet) -> Result<(), Error> {
let wallet_data = wallet.data().await;
let accounts = wallet_data.accounts();
let hrp = wallet.client().get_bech32_hrp().await?;

println_log_info!("Accounts:\n");

for account in accounts {
let output_id = account.output_id;
let account_id = account.output.as_account().account_id_non_null(&output_id);
let account_address = account_id.to_bech32(wallet.client().get_bech32_hrp().await?);
let account_address = account_id.to_bech32(hrp);
let bic = wallet
.client()
.get_account_congestion(&account_id)
.await?
.block_issuance_credits;
.await
.map(|r| r.block_issuance_credits)
.ok();

println_log_info!(
"{:<16} {output_id}\n{:<16} {account_id}\n{:<16} {account_address}\n{:<16} {bic}\n",
"{:<16} {output_id}\n{:<16} {account_id}\n{:<16} {account_address}\n{:<16} {bic:?}\n",
"Output ID:",
"Account ID:",
"Account Address:",
Expand Down Expand Up @@ -698,21 +700,23 @@ pub async fn implicit_account_transition_command(
pub async fn implicit_accounts_command(wallet: &Wallet) -> Result<(), Error> {
let wallet_data = wallet.data().await;
let implicit_accounts = wallet_data.implicit_accounts();
let hrp = wallet.client().get_bech32_hrp().await?;

println_log_info!("Implicit accounts:\n");

for implicit_account in implicit_accounts {
let output_id = implicit_account.output_id;
let account_id = AccountId::from(&output_id);
let account_address = account_id.to_bech32(wallet.client().get_bech32_hrp().await?);
let account_address = account_id.to_bech32(hrp);
let bic = wallet
.client()
.get_account_congestion(&account_id)
.await?
.block_issuance_credits;
.await
.map(|r| r.block_issuance_credits)
.ok();

println_log_info!(
"{:<16} {output_id}\n{:<16} {account_id}\n{:<16} {account_address}\n{:<16} {bic}\n",
"{:<16} {output_id}\n{:<16} {account_id}\n{:<16} {account_address}\n{:<16} {bic:?}\n",
"Output ID:",
"Account ID:",
"Account Address:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
use derive_more::From;

use crate::types::block::{
address::AccountAddress,
address::{AccountAddress, Address},
error::Error,
output::{StorageScore, StorageScoreParameters},
};

/// Defines the permanent [`AccountAddress`] that owns this output.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, From, packable::Packable)]
pub struct ImmutableAccountAddressUnlockCondition(AccountAddress);
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, From, packable::Packable)]
pub struct ImmutableAccountAddressUnlockCondition(#[packable(verify_with = verify_address)] Address);

impl ImmutableAccountAddressUnlockCondition {
/// The [`UnlockCondition`](crate::types::block::output::UnlockCondition) kind of an
Expand All @@ -20,12 +21,12 @@ impl ImmutableAccountAddressUnlockCondition {
/// Creates a new [`ImmutableAccountAddressUnlockCondition`].
#[inline(always)]
pub fn new(address: impl Into<AccountAddress>) -> Self {
Self(address.into())
Self(Address::from(address.into()))
}

/// Returns the account address of an [`ImmutableAccountAddressUnlockCondition`].
pub fn address(&self) -> &AccountAddress {
&self.0
self.0.as_account()
}
}

Expand All @@ -35,6 +36,15 @@ impl StorageScore for ImmutableAccountAddressUnlockCondition {
}
}

#[inline]
fn verify_address<const VERIFY: bool>(address: &Address) -> Result<(), Error> {
if VERIFY && !address.is_account() {
Err(Error::InvalidAddressKind(address.kind()))
} else {
Ok(())
}
}

#[cfg(feature = "serde")]
mod dto {
use serde::{Deserialize, Serialize};
Expand All @@ -45,14 +55,14 @@ mod dto {
struct ImmutableAccountAddressUnlockConditionDto {
#[serde(rename = "type")]
kind: u8,
address: AccountAddress,
address: Address,
}

impl From<&ImmutableAccountAddressUnlockCondition> for ImmutableAccountAddressUnlockConditionDto {
fn from(value: &ImmutableAccountAddressUnlockCondition) -> Self {
Self {
kind: ImmutableAccountAddressUnlockCondition::KIND,
address: value.0,
address: value.0.clone(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/tests/types/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn builder() {
let mut builder = FoundryOutput::build_with_amount(amount, 234, rand_token_scheme())
.with_serial_number(85)
.with_native_token(NativeToken::new(TokenId::from(foundry_id), 1000).unwrap())
.with_unlock_conditions([account_1])
.with_unlock_conditions([account_1.clone()])
.add_feature(metadata_1.clone())
.replace_feature(metadata_2.clone())
.with_immutable_features([metadata_2.clone()])
Expand All @@ -45,7 +45,7 @@ fn builder() {
.clear_unlock_conditions()
.clear_features()
.clear_immutable_features()
.replace_unlock_condition(account_2);
.replace_unlock_condition(account_2.clone());
let output = builder.clone().finish().unwrap();
assert_eq!(output.unlock_conditions().immutable_account_address(), Some(&account_2));
assert!(output.features().is_empty());
Expand Down

0 comments on commit 15f0358

Please sign in to comment.