Struct dcl_crypto::account::Address

source ·
pub struct Address(/* private fields */);

Implementations§

source§

impl Address

source

pub fn zero() -> Self

Creates an instance of the zero address

  use dcl_crypto::account::Address;
  assert_eq!(Address::zero().to_string(), "0x0000000000000000000000000000000000000000")
source

pub fn checksum(&self) -> String

Calculate ERC-55 version of the address

    use dcl_crypto::account::Address;
    assert_eq!(Address::try_from("0x0f5d2fb29fb7d3cfee444a200298f468908cc942").unwrap().checksum(), "0x0F5D2fB29fb7d3CFeE444a200298f468908cC942");
    assert_eq!(Address::try_from("0x554bb6488ba955377359bed16b84ed0822679cdc").unwrap().checksum(), "0x554BB6488bA955377359bED16b84Ed0822679CDC");
    assert_eq!(Address::try_from("0x1784ef41af86e97f8d28afe95b573a24aeda966e").unwrap().checksum(), "0x1784Ef41af86e97f8D28aFe95b573a24aEDa966e");
    assert_eq!(Address::from([255; 20]).checksum(), "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF");
    assert_eq!(Address::from([0; 20]).checksum(), "0x0000000000000000000000000000000000000000");

Methods from Deref<Target = H160>§

pub fn as_bytes(&self) -> &[u8]

Extracts a byte slice containing the entire fixed hash.

pub fn as_fixed_bytes(&self) -> &[u8; 20]

Extracts a reference to the byte array containing the entire fixed hash.

pub fn as_ptr(&self) -> *const u8

Returns a constant raw pointer to the value.

pub fn covers(&self, b: &H160) -> bool

Returns true if all bits set in b are also set in self.

pub fn is_zero(&self) -> bool

Returns true if no bits are set.

pub fn to_low_u64_be(&self) -> u64

Returns the lowest 8 bytes interpreted as big-endian.

Note

For hash type with less than 8 bytes the missing bytes are interpreted as being zero.

pub fn to_low_u64_le(&self) -> u64

Returns the lowest 8 bytes interpreted as little-endian.

Note

For hash type with less than 8 bytes the missing bytes are interpreted as being zero.

pub fn to_low_u64_ne(&self) -> u64

Returns the lowest 8 bytes interpreted as native-endian.

Note

For hash type with less than 8 bytes the missing bytes are interpreted as being zero.

Trait Implementations§

source§

impl Clone for Address

source§

fn clone(&self) -> Address

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Address

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Address

source§

fn default() -> Address

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Address

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Address

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format an Address into it string representation

  use dcl_crypto::account::Address;
  assert_eq!(Address::from([0; 20]).to_string(), "0x0000000000000000000000000000000000000000");
  assert_eq!(Address::from([255; 20]).to_string(), "0xffffffffffffffffffffffffffffffffffffffff");
source§

impl From<[u8; 20]> for Address

source§

fn from(value: [u8; 20]) -> Self

Converts [u8; 20] into an Address

  use dcl_crypto::account::Address;

  let address = Address::from([0; 20]);
  assert_eq!(address.to_string(), "0x0000000000000000000000000000000000000000")
source§

impl From<Address> for String

source§

fn from(value: Address) -> Self

Formats an Address into its String representation

source§

impl From<H160> for Address

source§

fn from(value: H160) -> Self

Converts an H160 into an Address

  use web3::types::H160;
  use dcl_crypto::account::Address;

  let address = Address::from(H160([0; 20]));
  assert_eq!(address.to_string(), "0x0000000000000000000000000000000000000000")
source§

impl LowerHex for Address

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the Address into its hexadecimal lowercase representation

    use dcl_crypto::account::Address;
    let address = Address::from([255; 20]);
    let zero = Address::from([0; 20]);

    assert_eq!(format!("{zero:x}"), "0000000000000000000000000000000000000000");
    assert_eq!(format!("{address:x}"), "ffffffffffffffffffffffffffffffffffffffff");

    assert_eq!(format!("{zero:#x}"), "0x0000000000000000000000000000000000000000");
    assert_eq!(format!("{address:#x}"), "0xffffffffffffffffffffffffffffffffffffffff");
source§

impl PartialEq<H160> for &Address

source§

fn eq(&self, other: &H160) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<H160> for Address

source§

fn eq(&self, other: &H160) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Address

source§

fn eq(&self, other: &Address) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Address

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&str> for Address

source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Converts an hexadecimal representation into an Address

  use dcl_crypto::account::Address;

  let lower_address = Address::try_from("0xf15fd08462c3248b2bfe9c39b48af7801fc303db");
  let upper_address = Address::try_from("0xF15FD08462C3248B2BFE9C39B48AF7801FC303DB");
  let address_expected: [u8; 20] = [ 241, 95, 208, 132, 98, 195, 36, 139, 43, 254, 156, 57, 180, 138, 247, 128, 31, 195, 3, 219];
  assert_eq!(lower_address.unwrap(), Address::from(address_expected));
  assert_eq!(upper_address.unwrap(), Address::from(address_expected));

It requires the address string to be prefixed with 0x

  use dcl_crypto::account::{Address, DecodeHexError};

  let not_prefixed_address = Address::try_from("f15fd08462c3248b2bfe9c39b48af7801fc303db");
  assert_eq!(not_prefixed_address.is_err(), true);
  assert_eq!(not_prefixed_address, Err(DecodeHexError::MissingPrefix));

It requires the address to be 42 characters long

  use dcl_crypto::account::{Address, DecodeHexError};

  let len_41_address = Address::try_from("0xf15fd08462c3248b2bfe9c39b48af7801fc303d");
  assert_eq!(len_41_address.is_err(), true);
  assert_eq!(len_41_address, Err(DecodeHexError::InvalidLength));

  let len_43_address = Address::try_from("0xf15fd08462c3248b2bfe9c39b48af7801fc303dbb");
  assert_eq!(len_43_address.is_err(), true);
  assert_eq!(len_43_address, Err(DecodeHexError::InvalidLength));

It requires all characters to be hexadecimals

  use dcl_crypto::account::{Address, DecodeHexError};

  let not_hex_address = Address::try_from("0xf15fd08462c3248b2bfe9c39b48af7801fc303dx");
  assert_eq!(not_hex_address.is_err(), true);
  assert_eq!(not_hex_address, Err(DecodeHexError::InvalidHexCharacter{ c: 'x', index: 41}));
§

type Error = DecodeHexError

The type returned in the event of a conversion error.
source§

impl TryFrom<String> for Address

§

type Error = DecodeHexError

The type returned in the event of a conversion error.
source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl UpperHex for Address

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the Address into its hexadecimal uppercase representation

    use dcl_crypto::account::Address;
    let address = Address::from([255; 20]);
    let zero = Address::from([0; 20]);

    assert_eq!(format!("{zero:X}"), "0000000000000000000000000000000000000000");
    assert_eq!(format!("{address:X}"), "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");

    assert_eq!(format!("{zero:#X}"), "0X0000000000000000000000000000000000000000");
    assert_eq!(format!("{address:#X}"), "0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
source§

impl Deref for Address

§

type Target = H160

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Copy for Address

source§

impl StructuralPartialEq for Address

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,