Skip to content

Commit

Permalink
Merge branch '2.0' into api-tips-example-test
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Nov 27, 2023
2 parents 044a997 + 0a0413a commit 4e0001a
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 100 deletions.
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/block/core/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export class BasicBlock extends Block {
/**
* Blocks that are weakly directly approved.
*/
readonly weakParents!: WeakParents;
readonly weakParents?: WeakParents;
/**
* Blocks that are directly referenced to adjust opinion.
*/
readonly shallowLikeParents!: ShallowLikeParents;
readonly shallowLikeParents?: ShallowLikeParents;
/**
* The payload contents.
*/
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/block/core/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export class ValidationBlock extends Block {
/**
* Blocks that are weakly directly approved.
*/
readonly weakParents!: WeakParents;
readonly weakParents?: WeakParents;
/**
* Blocks that are directly referenced to adjust opinion.
*/
readonly shallowLikeParents!: ShallowLikeParents;
readonly shallowLikeParents?: ShallowLikeParents;

/**
* The highest supported protocol version the issuer of this block supports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class Transaction {
@Type(() => Input, {
discriminator: ContextInputDiscriminator,
})
readonly contextInputs: ContextInput[];
readonly contextInputs?: ContextInput[];

@Type(() => Input, {
discriminator: InputDiscriminator,
})
readonly inputs: Input[];

readonly allotments: ManaAllotment[];
readonly allotments?: ManaAllotment[];

private capabilities?: HexEncodedString;

Expand Down
12 changes: 8 additions & 4 deletions bindings/nodejs/lib/types/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ export interface Balance {
requiredStorageDeposit: RequiredStorageDeposit;
/** The balance of the native tokens */
nativeTokens: NativeTokenBalance[];
/** Nft outputs */
nfts: string[];
/** Account outputs */
accounts: string[];
/** Foundry outputs */
foundries: string[];
/** Nft outputs */
nfts: string[];
/** Delegation outputs */
delegations: string[];
/**
* Outputs with multiple unlock conditions and if they can currently be spent or not. If there is a
* TimelockUnlockCondition or ExpirationUnlockCondition this can change at any time
Expand All @@ -56,14 +58,16 @@ export interface BaseCoinBalance {

/** The required storage deposit per output type */
export interface RequiredStorageDeposit {
/** The required amount for Alias outputs. */
account: u64;
/** The required amount for Basic outputs. */
basic: u64;
/** The required amount for Account outputs. */
account: u64;
/** The required amount for Foundry outputs. */
foundry: u64;
/** The required amount for NFT outputs. */
nft: u64;
/** The required amount for Delegation outputs. */
delegation: u64;
}

/** The balance of a native token */
Expand Down
16 changes: 11 additions & 5 deletions bindings/python/iota_sdk/types/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ class RequiredStorageDeposit:
"""Required storage deposit for the outputs in the account.
Attributes:
account: The required amount for account outputs.
basic: The required amount for basic outputs.
account: The required amount for account outputs.
foundry: The required amount for foundry outputs.
nft: The required amount for nft outputs.
delegation: The required amount for delegation outputs.
"""
account: int = field(metadata=config(
basic: int = field(metadata=config(
encoder=str
))
basic: int = field(metadata=config(
account: int = field(metadata=config(
encoder=str
))
foundry: int = field(metadata=config(
Expand All @@ -48,6 +49,9 @@ class RequiredStorageDeposit:
nft: int = field(metadata=config(
encoder=str
))
delegation: int = field(metadata=config(
encoder=str
))


@json
Expand Down Expand Up @@ -82,15 +86,17 @@ class Balance:
base_coin: The base coin balance.
required_storage_deposit: The required storage deposit.
native_tokens: The balances of all native tokens.
nfts: All owned NFTs.
accounts: All owned accounts.
foundries: All owned foundries.
nfts: All owned NFTs.
delegations: All owned delegation outputs.
potentially_locked_outputs: A list of potentially locked outputs.
"""
base_coin: BaseCoinBalance
required_storage_deposit: RequiredStorageDeposit
native_tokens: List[NativeTokensBalance]
nfts: List[HexStr]
accounts: List[HexStr]
foundries: List[HexStr]
nfts: List[HexStr]
delegations: List[HexStr]
potentially_locked_outputs: dict[HexStr, bool]
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/types/block/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class BasicBlock:
payload: The optional payload of this block.
"""
strong_parents: List[HexStr]
weak_parents: List[HexStr]
shallow_like_parents: List[HexStr]
max_burned_mana: int = field(metadata=config(
encoder=str
))
weak_parents: Optional[List[HexStr]] = None
shallow_like_parents: Optional[List[HexStr]] = None
payload: Optional[Payload] = None
type: int = field(
default_factory=lambda: int(BlockType.Basic),
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/iota_sdk/types/block/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import annotations
from dataclasses import dataclass, field
from typing import List
from typing import List, Optional
from iota_sdk.types.block.block import BlockType
from iota_sdk.types.common import HexStr, json

Expand All @@ -23,10 +23,10 @@ class ValidationBlock:
protocol_parameters_hash: The hash of the protocol parameters for the Highest Supported Version.
"""
strong_parents: List[HexStr]
weak_parents: List[HexStr]
shallow_like_parents: List[HexStr]
highest_supported_version: int
protocol_parameters_hash: HexStr
weak_parents: Optional[List[HexStr]] = None
shallow_like_parents: Optional[List[HexStr]] = None
type: int = field(
default_factory=lambda: int(BlockType.Validation),
init=False)
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/types/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class Transaction:
"""
network_id: str
creation_slot: SlotIndex
context_inputs: List[ContextInput]
inputs: List[UtxoInput]
allotments: List[ManaAllotment]
capabilities: Optional[HexStr] = field(default=None, init=False)
outputs: List[Output]
context_inputs: Optional[List[ContextInput]] = None
allotments: Optional[List[ManaAllotment]] = None
payload: Optional[Payload] = None

def with_capabilities(self, capabilities: bytes):
Expand Down
23 changes: 13 additions & 10 deletions sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use serde::{Deserialize, Serialize};

use crate::{
types::block::{
address::Bech32Address,
core::Parents,
output::{dto::OutputDto, AccountId, OutputId, OutputMetadata, OutputWithMetadata},
protocol::ProtocolParameters,
protocol::{ProtocolParameters, ProtocolParametersHash},
semantic::TransactionFailureReason,
slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex},
BlockId,
Expand Down Expand Up @@ -208,24 +209,24 @@ pub struct ManaRewardsResponse {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CommitteeResponse {
/// The epoch index of the committee.
pub epoch_index: EpochIndex,
/// The validators of the committee.
pub committee: Box<[CommitteeMember]>,
/// The total amount of delegated and staked IOTA coins in the selected committee.
#[serde(with = "string")]
pub total_stake: u64,
/// The total amount of staked IOTA coins in the selected committee.
#[serde(with = "string")]
pub total_validator_stake: u64,
/// The validators of the committee.
pub committee: Box<[CommitteeMember]>,
/// The epoch index of the committee.
pub epoch: EpochIndex,
}

/// Returns information of a committee member.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CommitteeMember {
/// The account identifier of the validator
pub account_id: AccountId,
/// Account address of the validator.
pub address: Bech32Address,
/// The total stake of the pool, including delegators.
#[serde(with = "string")]
pub pool_stake: u64,
Expand All @@ -241,10 +242,10 @@ pub struct CommitteeMember {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ValidatorResponse {
/// The account identifier of the validator
account_id: AccountId,
/// Account address of the validator.
address: Bech32Address,
/// The epoch index until which the validator registered to stake.
staking_end_epoch: EpochIndex,
staking_epoch_end: EpochIndex,
/// The total stake of the pool, including delegators.
#[serde(with = "string")]
pool_stake: u64,
Expand All @@ -258,6 +259,8 @@ pub struct ValidatorResponse {
active: bool,
/// The latest protocol version the validator supported.
latest_supported_protocol_version: u8,
// The protocol hash of the latest supported protocol of the validator.
latest_supported_protocol_hash: ProtocolParametersHash,
}

/// Response of GET /api/core/v3/blocks/issuance
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/types/block/core/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ pub(crate) mod dto {
#[serde(rename = "type")]
pub kind: u8,
pub strong_parents: BTreeSet<BlockId>,
#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
pub weak_parents: BTreeSet<BlockId>,
#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
pub shallow_like_parents: BTreeSet<BlockId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub payload: Option<PayloadDto>,
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/types/block/core/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ pub(crate) mod dto {
#[serde(rename = "type")]
pub kind: u8,
pub strong_parents: BTreeSet<BlockId>,
#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
pub weak_parents: BTreeSet<BlockId>,
#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
pub shallow_like_parents: BTreeSet<BlockId>,
pub highest_supported_version: u8,
pub protocol_parameters_hash: ProtocolParametersHash,
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/types/block/payload/signed_transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,10 @@ pub(crate) mod dto {
pub struct TransactionDto {
pub network_id: String,
pub creation_slot: SlotIndex,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub context_inputs: Vec<ContextInput>,
pub inputs: Vec<Input>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub allotments: Vec<ManaAllotmentDto>,
#[serde(default, skip_serializing_if = "TransactionCapabilities::is_none")]
pub capabilities: TransactionCapabilities,
Expand Down
32 changes: 21 additions & 11 deletions sdk/src/wallet/operations/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@ where
let output = &output_data.output;
let storage_cost = output.minimum_amount(storage_score_params);

// Add account and foundry outputs here because they can't have a
// Add account, foundry, and delegation outputs here because they can't have a
// [`StorageDepositReturnUnlockCondition`] or time related unlock conditions
match output {
Output::Account(output) => {
Output::Account(account) => {
// Add amount
balance.base_coin.total += output.amount();
balance.base_coin.total += account.amount();
// Add storage deposit
balance.required_storage_deposit.account += storage_cost;
if !wallet_data.locked_outputs.contains(output_id) {
total_storage_cost += storage_cost;
}

let account_id = output.account_id_non_null(output_id);
let account_id = account.account_id_non_null(output_id);
balance.accounts.push(account_id);
}
Output::Foundry(output) => {
Output::Foundry(foundry) => {
// Add amount
balance.base_coin.total += output.amount();
balance.base_coin.total += foundry.amount();
// Add storage deposit
balance.required_storage_deposit.foundry += storage_cost;
if !wallet_data.locked_outputs.contains(output_id) {
Expand All @@ -91,7 +91,19 @@ where
total_native_tokens.add_native_token(*native_token)?;
}

balance.foundries.push(output.id());
balance.foundries.push(foundry.id());
}
Output::Delegation(delegation) => {
// Add amount
balance.base_coin.total += delegation.amount();
// Add storage deposit
balance.required_storage_deposit.delegation += storage_cost;
if !wallet_data.locked_outputs.contains(output_id) {
total_storage_cost += storage_cost;
}

let delegation_id = delegation.delegation_id_non_null(output_id);
balance.delegations.push(delegation_id);
}
_ => {
// If there is only an [AddressUnlockCondition], then we can spend the output at any time
Expand All @@ -102,8 +114,8 @@ where
.as_ref()
{
// add nft_id for nft outputs
if let Output::Nft(output) = &output {
let nft_id = output.nft_id_non_null(output_id);
if let Output::Nft(nft) = &output {
let nft_id = nft.nft_id_non_null(output_id);
balance.nfts.push(nft_id);
}

Expand Down Expand Up @@ -223,9 +235,7 @@ where
}
}
}
// }
}
// }

self.finish(
balance,
Expand Down
Loading

0 comments on commit 4e0001a

Please sign in to comment.