Skip to content

Commit

Permalink
Merge branch '2.0' of https://github.com/iotaledger/iota-sdk into 500…
Browse files Browse the repository at this point in the history
…-error-patch
  • Loading branch information
marc2332 committed Feb 21, 2024
2 parents cdf2aac + 9dc5cba commit fea61fb
Show file tree
Hide file tree
Showing 79 changed files with 1,009 additions and 638 deletions.
33 changes: 15 additions & 18 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{method::WalletMethod, response::Response};
/// Call a wallet method.
pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletMethod) -> crate::Result<Response> {
let response = match method {
WalletMethod::Accounts => Response::OutputsData(wallet.data().await.accounts().cloned().collect()),
WalletMethod::Accounts => Response::OutputsData(wallet.ledger().await.accounts().cloned().collect()),
#[cfg(feature = "stronghold")]
WalletMethod::Backup { destination, password } => {
wallet.backup(destination, password).await?;
Expand Down Expand Up @@ -144,25 +144,22 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
// wallet.deregister_participation_event(&event_id).await?;
// Response::Ok
// }
WalletMethod::GetAddress => {
let address = wallet.address().await;
Response::Address(address)
}
WalletMethod::GetAddress => Response::Address(wallet.address().await),
WalletMethod::GetBalance => Response::Balance(wallet.balance().await?),
WalletMethod::GetFoundryOutput { token_id } => {
let output = wallet.get_foundry_output(token_id).await?;
Response::Output(output)
}
WalletMethod::GetIncomingTransaction { transaction_id } => wallet
.data()
.ledger()
.await
.get_incoming_transaction(&transaction_id)
.map_or_else(
|| Response::Transaction(None),
|transaction| Response::Transaction(Some(Box::new(TransactionWithMetadataDto::from(transaction)))),
),
WalletMethod::GetOutput { output_id } => {
Response::OutputData(wallet.data().await.get_output(&output_id).cloned().map(Box::new))
Response::OutputData(wallet.ledger().await.get_output(&output_id).cloned().map(Box::new))
}
// #[cfg(feature = "participation")]
// WalletMethod::GetParticipationEvent { event_id } => {
Expand Down Expand Up @@ -191,7 +188,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
// }
WalletMethod::GetTransaction { transaction_id } => Response::Transaction(
wallet
.data()
.ledger()
.await
.get_transaction(&transaction_id)
.map(TransactionWithMetadataDto::from)
Expand Down Expand Up @@ -227,28 +224,28 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
Response::PreparedTransaction(data)
}
WalletMethod::ImplicitAccounts => {
Response::OutputsData(wallet.data().await.implicit_accounts().cloned().collect())
Response::OutputsData(wallet.ledger().await.implicit_accounts().cloned().collect())
}
WalletMethod::IncomingTransactions => Response::Transactions(
wallet
.data()
.ledger()
.await
.incoming_transactions()
.values()
.map(TransactionWithMetadataDto::from)
.collect(),
),
WalletMethod::Outputs { filter_options } => {
let wallet_data = wallet.data().await;
let wallet_ledger = wallet.ledger().await;
Response::OutputsData(if let Some(filter) = filter_options {
wallet_data.filtered_outputs(filter).cloned().collect()
wallet_ledger.filtered_outputs(filter).cloned().collect()
} else {
wallet_data.outputs().values().cloned().collect()
wallet_ledger.outputs().values().cloned().collect()
})
}
WalletMethod::PendingTransactions => Response::Transactions(
wallet
.data()
.ledger()
.await
.pending_transactions()
.map(TransactionWithMetadataDto::from)
Expand Down Expand Up @@ -444,19 +441,19 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
WalletMethod::Sync { options } => Response::Balance(wallet.sync(options).await?),
WalletMethod::Transactions => Response::Transactions(
wallet
.data()
.ledger()
.await
.transactions()
.values()
.map(TransactionWithMetadataDto::from)
.collect(),
),
WalletMethod::UnspentOutputs { filter_options } => {
let wallet_data = wallet.data().await;
let wallet_ledger = wallet.ledger().await;
Response::OutputsData(if let Some(filter) = filter_options {
wallet_data.filtered_unspent_outputs(filter).cloned().collect()
wallet_ledger.filtered_unspent_outputs(filter).cloned().collect()
} else {
wallet_data.unspent_outputs().values().cloned().collect()
wallet_ledger.unspent_outputs().values().cloned().collect()
})
}
};
Expand Down
4 changes: 3 additions & 1 deletion bindings/nodejs/examples/client/11-build-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ async function run() {
const basicOutputWithMetadata = await client.buildBasicOutput({
amount: BigInt(1000000),
unlockConditions: [addressUnlockCondition],
features: [new MetadataFeature(utf8ToHex('Hello World!'))],
features: [
new MetadataFeature({ data: utf8ToHex('Hello World!') }),
],
});

console.log(JSON.stringify(basicOutputWithMetadata, null, 2));
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/13-build-account-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ async function run() {
],
features: [
new SenderFeature(new Ed25519Address(hexAddress)),
new MetadataFeature(utf8ToHex('hello')),
new MetadataFeature({ data: utf8ToHex('hello') }),
],
immutableFeatures: [
new IssuerFeature(new Ed25519Address(hexAddress)),
new MetadataFeature(utf8ToHex('hello')),
new MetadataFeature({ data: utf8ToHex('hello') }),
],
});

Expand Down
4 changes: 3 additions & 1 deletion bindings/nodejs/examples/client/15-build-nft-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ async function run() {
],
features: [
new SenderFeature(new Ed25519Address(hexAddress)),
new MetadataFeature(utf8ToHex('mutable metadata')),
new MetadataFeature({
data: utf8ToHex('mutable metadata'),
}),
new TagFeature(utf8ToHex('my tag')),
],
});
Expand Down
6 changes: 4 additions & 2 deletions bindings/nodejs/examples/how_tos/outputs/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ async function run() {
const nftOutputWithMetadata = await client.buildNftOutput({
nftId: '0x0000000000000000000000000000000000000000000000000000000000000000',
unlockConditions: [addressUnlockCondition],
features: [new MetadataFeature(utf8ToHex('Hello, World!'))],
features: [
new MetadataFeature({ data: utf8ToHex('Hello, World!') }),
],
});

// Output with immutable metadata feature
const nftOutputWithImmutableMetadata = await client.buildNftOutput({
nftId: '0x0000000000000000000000000000000000000000000000000000000000000000',
unlockConditions: [addressUnlockCondition],
immutableFeatures: [
new MetadataFeature(utf8ToHex('Hello, World!')),
new MetadataFeature({ data: utf8ToHex('Hello, World!') }),
],
});

Expand Down
31 changes: 27 additions & 4 deletions bindings/nodejs/lib/types/block/output/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { EpochIndex } from '../../block/slot';
import { NativeToken } from '../../models/native-token';
import { HexEncodedString } from '../../utils/hex-encoding';

/**
* Printable ASCII characters.
*/
export declare type PrintableASCII = string;

/**
* All of the feature block types.
*/
Expand Down Expand Up @@ -88,14 +93,30 @@ class IssuerFeature extends Feature {
*/
class MetadataFeature extends Feature {
/** Defines metadata (arbitrary binary data) that will be stored in the output. */
readonly data: string;
readonly entries: { [key: PrintableASCII]: HexEncodedString };

/**
* @param data The metadata stored with the feature.
* @param entries The metadata stored with the feature.
*/
constructor(data: string) {
constructor(entries: { [key: PrintableASCII]: HexEncodedString }) {
super(FeatureType.Metadata);
this.data = data;
this.entries = entries;
}
}

/**
* A Metadata Feature that can only be changed by the State Controller.
*/
class StateMetadataFeature extends Feature {
/** Defines metadata (arbitrary binary data) that will be stored in the output. */
readonly entries: { [key: PrintableASCII]: HexEncodedString };

/**
* @param entries The metadata stored with the feature.
*/
constructor(entries: { [key: PrintableASCII]: HexEncodedString }) {
super(FeatureType.StateMetadata);
this.entries = entries;
}
}

Expand Down Expand Up @@ -213,6 +234,7 @@ const FeatureDiscriminator = {
{ value: SenderFeature, name: FeatureType.Sender as any },
{ value: IssuerFeature, name: FeatureType.Issuer as any },
{ value: MetadataFeature, name: FeatureType.Metadata as any },
{ value: StateMetadataFeature, name: FeatureType.StateMetadata as any },
{ value: TagFeature, name: FeatureType.Tag as any },
{ value: NativeTokenFeature, name: FeatureType.NativeToken as any },
{ value: BlockIssuerFeature, name: FeatureType.BlockIssuer as any },
Expand All @@ -227,6 +249,7 @@ export {
SenderFeature,
IssuerFeature,
MetadataFeature,
StateMetadataFeature,
TagFeature,
NativeTokenFeature,
BlockIssuerFeature,
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/block/output/irc-27.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Irc27Metadata {
}

asFeature(): MetadataFeature {
return new MetadataFeature(this.asHex());
return new MetadataFeature({ 'irc-27': this.asHex() });
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/block/output/irc-30.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Irc30Metadata {
}

asFeature(): MetadataFeature {
return new MetadataFeature(this.asHex());
return new MetadataFeature({ 'irc-30': this.asHex() });
}
}

Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/wallet/transaction-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import {
AccountAddress,
AccountId,
Address,
Bech32Address,
ContextInput,
OutputId,
} from '../block';
import { TaggedDataPayload } from '../block/payload/tagged';
import { Burn } from '../client';
import { u256, HexEncodedString, NumericString, u64 } from '../utils';
import { Bip44Address } from './address';

/** Options for creating a transaction. */
export interface TransactionOptions {
Expand Down Expand Up @@ -56,7 +56,7 @@ export type ReuseAddress = {
export type CustomAddress = {
/** The name of the strategy. */
strategy: 'CustomAddress';
value: Bip44Address;
value: Address;
};

/** Options for creating Native Tokens. */
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/examples/client/build_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
]
features = [
SenderFeature(Ed25519Address(hexAddress)),
MetadataFeature(utf8_to_hex('Hello, World!'))
MetadataFeature({'data': utf8_to_hex('Hello, World!')})
]
immutable_features = [
IssuerFeature(Ed25519Address(hexAddress)),
MetadataFeature(utf8_to_hex('Hello, World!'))
MetadataFeature({'data': utf8_to_hex('Hello, World!')})
]

# Build account output
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/client/build_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
address_unlock_condition,
],
features=[
MetadataFeature(utf8_to_hex('Hello, World!'))
MetadataFeature({'data': utf8_to_hex('Hello, World!')})
],
amount=1000000,
)
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/examples/how_tos/outputs/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
address_unlock_condition,
],
features=[
MetadataFeature(utf8_to_hex('Hello, World!'))
MetadataFeature({'data': utf8_to_hex('Hello, World!')})
],
)
outputs.append(nft_output)
Expand All @@ -69,7 +69,7 @@
address_unlock_condition,
],
immutable_features=[
MetadataFeature(utf8_to_hex('Hello, World!'))
MetadataFeature({'data': utf8_to_hex('Hello, World!')})
],
)
outputs.append(nft_output)
Expand Down
13 changes: 9 additions & 4 deletions bindings/python/iota_sdk/types/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ class BaseCoinBalance:
Attributes:
total: The total balance.
available: The available amount of the total balance.
voting_power: The voting power of the wallet.
# voting_power: The voting power of the wallet.
"""
total: int = field(metadata=config(
encoder=str
))
available: int = field(metadata=config(
encoder=str
))
voting_power: int = field(metadata=config(
encoder=str
))
# TODO https://github.com/iotaledger/iota-sdk/issues/1822
# voting_power: int = field(metadata=config(
# encoder=str
# ))


@json
Expand All @@ -39,9 +40,13 @@ class ManaBalance:
Attributes:
total: The total balance.
available: The available amount of the total balance.
rewards: Mana rewards of account and delegation outputs.
"""
total: DecayedMana
available: DecayedMana
rewards: int = field(metadata=config(
encoder=str
))


@json
Expand Down
18 changes: 17 additions & 1 deletion bindings/python/iota_sdk/types/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ class MetadataFeature:
entries: Dict[str, HexStr]


@json
@dataclass
class StateMetadataFeature:
"""A Metadata Feature that can only be changed by the State Controller.
Attributes:
entries: A key-value map where the keys are graphic ASCII strings and the values hex-encoded binary data.
"""
type: int = field(
default_factory=lambda: int(
FeatureType.StateMetadata),
init=False)
entries: Dict[str, HexStr]


@json
@dataclass
class TagFeature:
Expand Down Expand Up @@ -149,7 +163,7 @@ class StakingFeature:


Feature: TypeAlias = Union[SenderFeature, IssuerFeature,
MetadataFeature, TagFeature, NativeTokenFeature, BlockIssuerFeature, StakingFeature]
MetadataFeature, StateMetadataFeature, TagFeature, NativeTokenFeature, BlockIssuerFeature, StakingFeature]


# pylint: disable=too-many-return-statements
Expand All @@ -167,6 +181,8 @@ def deserialize_feature(d: Dict[str, Any]) -> Feature:
return IssuerFeature.from_dict(d)
if feature_type == FeatureType.Metadata:
return MetadataFeature.from_dict(d)
if feature_type == FeatureType.StateMetadata:
return StateMetadataFeature.from_dict(d)
if feature_type == FeatureType.Tag:
return TagFeature.from_dict(d)
if feature_type == FeatureType.NativeToken:
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/irc_27.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def as_hex(self):
def as_feature(self):
"""Turns this schema into a MetadataFeature type
"""
MetadataFeature(self.as_hex())
MetadataFeature({'irc-27': self.as_hex()})
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/irc_30.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def as_hex(self):
def as_feature(self):
"""Turns this schema into a MetadataFeature type
"""
MetadataFeature(self.as_hex())
MetadataFeature({'irc-30': self.as_hex()})
Loading

0 comments on commit fea61fb

Please sign in to comment.