pub trait SeedInput {
    // Provided method
    fn to_ethaddr_seed(&self) -> [u8; 42] { ... }
}
Expand description

Available types of input seed

Currently supports:

Provided Methods§

source

fn to_ethaddr_seed(&self) -> [u8; 42]

Convert given Ethereum address string or raw bytes data to the following well-formed Ethereum address seed: 0x(hex_letters_lowercase)

Apply this function on seeds to generate standard Ethereum blockies
(commonly seen as icons of wallet addresses, on many other Ethereum platforms).

Valid input seed

Calling this function on invalid input seeds (other than above) is not an error, but return value should be considered as an undefined, garbage value.
Therefore, be sure to VALIDATE YOURSELF whether input seeds are valid before using!

Example
  • General usage
use eth_blockies::SeedInput;

// "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC" (str slice)
// -> b"0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc" (byte str - 42B)
let addr1 = "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC"
    .to_ethaddr_seed();
assert_eq!(addr1, *b"0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc");

// "e686c14ff9c11038f2b1c9ad617f2346cfb817dc" (String)
// -> b"0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc" (byte str - 42B)
let addr2 = String::from("e686c14ff9c11038f2b1c9ad617f2346cfb817dc")
    .to_ethaddr_seed();
assert_eq!(addr1, addr2);

// 0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc (byte array - 20B)
// -> b"0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc" (byte str - 42B)
let addr3 = [
        0xe6, 0x86, 0xc1, 0x4f, 0xf9, 0xc1, 0x10, 0x38, 0xf2, 0xb1,
        0xc9, 0xad, 0x61, 0x7f, 0x23, 0x46, 0xcf, 0xb8, 0x17, 0xdc,
    ].to_ethaddr_seed();
assert_eq!(addr2, addr3);
  • Calling without use eth_blockies::SeedInput; statement
// "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC"
// -> "0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc"
let addr = <dyn eth_blockies::SeedInput>::
    to_ethaddr_seed(&"0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC");
assert_eq!(addr, *b"0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc");

Implementations on Foreign Types§

source§

impl<const N: usize> SeedInput for [u8; N]

source§

impl<const N: usize> SeedInput for &[u8; N]

source§

impl SeedInput for &String

source§

impl SeedInput for &Vec<u8>

source§

impl SeedInput for &[u8]

source§

fn to_ethaddr_seed(&self) -> [u8; 42]

source§

impl SeedInput for &str

source§

impl SeedInput for String

source§

impl SeedInput for Vec<u8>

Implementors§