Skip to content

Commit

Permalink
Merge branch '2.0' into python/single-account
Browse files Browse the repository at this point in the history
  • Loading branch information
Brord van Wierst authored Dec 13, 2023
2 parents 2f2b0fa + 1259a9b commit 92be08f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
59 changes: 28 additions & 31 deletions bindings/python/iota_sdk/types/block/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

@json
@dataclass
class Block:
"""A block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`.
Shared data is stored alongside such a block in the header fields.
class BlockHeader:
"""The block header which holds data that is shared between different block body types.
Attributes:
protocol_version: Protocol version of the network to which this block belongs.
Expand All @@ -26,8 +25,6 @@ class Block:
slot_commitment_id: The identifier of the slot to which this block commits.
latest_finalized_slot: The slot index of the latest finalized slot.
issuer_id: The identifier of the account that issued this block.
body: Holds either a `BasicBlockBody` or a `ValidationBlockBody`.
signature: The Block signature.
"""
protocol_version: int
network_id: int = field(metadata=config(
Expand All @@ -39,41 +36,41 @@ class Block:
slot_commitment_id: HexStr
latest_finalized_slot: SlotIndex
issuer_id: HexStr
body: BlockBody
signature: Signature

def id(self, params: ProtocolParameters) -> HexStr:
"""Returns the block ID as a hexadecimal string.
"""
return Utils.block_id(self, params)


@json
@dataclass
class UnsignedBlock:
"""An unsigned block type that can hold either a `BasicBlock` or a `ValidationBlock`.
Shared data is stored alongside such a block in the header fields.
"""An unsigned block type that can hold either a `BasicBlockBody` or a `ValidationBlockBody`.
Data that is shared between different block body types is stored in the block header.
Attributes:
protocol_version: Protocol version of the network to which this block belongs.
network_id: The identifier of the network to which this block belongs.
issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds.
slot_commitment_id: The identifier of the slot to which this block commits.
latest_finalized_slot: The slot index of the latest finalized slot.
issuer_id: The identifier of the account that issued this block.
block: Holds either a `BasicBlock` or a `ValidationBlock`.
header: The block header.
body: Holds either a `BasicBlockBody` or a `ValidationBlockBody`.
"""
protocol_version: int
network_id: int = field(metadata=config(
encoder=str
))
issuing_time: int = field(metadata=config(
encoder=str
))
slot_commitment_id: HexStr
latest_finalized_slot: SlotIndex
issuer_id: HexStr
header: BlockHeader
body: BlockBody


@json
@dataclass
class Block:
"""A signed block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`.
Data that is shared between different block body types is stored in the block header.
Attributes:
header: The block header.
body: Holds either a `BasicBlockBody` or a `ValidationBlockBody`.
signature: The Block signature.
"""
header: BlockHeader
body: BlockBody
signature: Signature

def id(self, params: ProtocolParameters) -> HexStr:
"""Returns the block ID as a hexadecimal string.
"""
return Utils.block_id(self, params)


BlockBody: TypeAlias = Union[BasicBlockBody, ValidationBlockBody]
2 changes: 1 addition & 1 deletion sdk/src/client/secret/ledger_nano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl SecretManagerConfig for LedgerSecretManager {
/// This method finds out if we have to switch to blind signing mode.
pub fn needs_blind_signing(prepared_transaction: &PreparedTransactionData, buffer_size: usize) -> bool {
if !prepared_transaction.transaction.outputs().iter().all(
|output| matches!(output, Output::Basic(o) if o.simple_deposit_address().is_some()&& o.address().is_ed25519()),
|output| matches!(output, Output::Basic(o) if o.simple_deposit_address().is_some() && o.address().is_ed25519()),
) {
return true;
}
Expand Down
19 changes: 19 additions & 0 deletions sdk/src/types/block/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ impl Address {

crate::def_is_as_opt!(Address: Ed25519, Account, Nft, Anchor, ImplicitAccountCreation, Multi, Restricted);

/// Checks whether the address is backed by an [`Ed25519Address`].
pub fn is_ed25519_backed(&self) -> bool {
match self {
Self::Ed25519(_) | Self::ImplicitAccountCreation(_) => true,
Self::Restricted(restricted) => restricted.address().is_ed25519(),
_ => false,
}
}

/// Returns the backing [`Ed25519Address`], if any.
pub fn backing_ed25519(&self) -> Option<&Ed25519Address> {
match self {
Self::Ed25519(ed25519) => Some(ed25519),
Self::ImplicitAccountCreation(implicit) => Some(implicit.ed25519_address()),
Self::Restricted(restricted) => restricted.address().as_ed25519_opt(),
_ => None,
}
}

/// Tries to create an [`Address`] from a bech32 encoded string.
pub fn try_from_bech32(address: impl AsRef<str>) -> Result<Self, Error> {
Bech32Address::try_from_str(address).map(|res| res.inner)
Expand Down

0 comments on commit 92be08f

Please sign in to comment.