mod.rs

Overview

This file defines and implements the AccountAddress struct, a wrapper around a 256-bit unsigned integer (UInt256), representing an account address within the system. It provides essential conversions, formatting, serialization, and bitwise operations for the address type. The file also exposes a submodule direct_bit_access_operations for related low-level bit manipulation functionality.

AccountAddress Struct

Description

AccountAddress encapsulates a UInt256 value, representing a 256-bit account address. This abstraction allows for convenient handling, display, and interoperability with other types such as tvm_types::AccountId.

Derivations

These traits enable copying, comparison, hashing, and ordering of AccountAddress instances.

Fields

Methods

to_hex_string(&self) -> String

Returns a hexadecimal string representation of the account address.

Example:

let addr = AccountAddress(UInt256::default());
println!("{}", addr.to_hex_string());

This method calls to_hex_string on the inner UInt256.

Trait Implementations

Display

Formats the AccountAddress as a hexadecimal string for user-facing output.

Debug

Provides debug formatting by outputting the hex string representation of the address.

FromStr

Enables parsing an AccountAddress from a string.

Default

Creates a default AccountAddress initialized with a zeroed UInt256.

Serialize and Deserialize

Supports serialization and deserialization via serde:

This allows integration with external formats such as JSON or binary.

From Conversions

Conversions between AccountAddress and tvm_types::AccountId:

These conversions facilitate interoperability with other system components that use AccountId types.

BitAnd Operator Overload for References

Implements the bitwise AND operator (&) for references to AccountAddress.

Note: The implementation could be optimized for performance.

Example:

let a: AccountAddress = ...;
let b: AccountAddress = ...;
let result = &a & &b;

Submodule: direct_bit_access_operations

This submodule is publicly exposed but its contents are not detailed here. It likely contains additional bit manipulation utilities for AccountAddress or related types.

Implementation Details and Algorithms

Interaction with Other System Components


Diagram: AccountAddress Structure and Key Traits

classDiagram
class AccountAddress {
+UInt256 0
+to_hex_string()
+bitand()
}
AccountAddress ..> UInt256 : encapsulates
AccountAddress ..> tvm_types::AccountId : converts to/from
AccountAddress ..|> std::fmt::Display
AccountAddress ..|> std::fmt::Debug
AccountAddress ..|> std::str::FromStr
AccountAddress ..|> serde::Serialize
AccountAddress ..|> serde::Deserialize
AccountAddress ..|> std::default::Default
AccountAddress ..|> std::ops::BitAnd

This diagram illustrates relationships of AccountAddress with underlying data and implemented traits.